From 193074b3847b0364c8270c96614993e4500c938e Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sat, 4 Apr 2009 17:25:14 +0000 Subject: [PATCH] Spellchecker: More simplifications. This change makes it possible (at long last!) to go to the work area, do some edition and then come back to the SpellChecker. We probably need a [Continue] button. * Buffer::nextWord(): go back a bit to return the current word. * SpellChecker and Dialog: get rid of the complicated, useless exitEarly() handling. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29092 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 6 +++- src/frontends/qt4/Dialog.cpp | 2 -- src/frontends/qt4/Dialog.h | 5 ---- src/frontends/qt4/GuiSpellchecker.cpp | 40 ++++----------------------- src/frontends/qt4/GuiSpellchecker.h | 6 +--- 5 files changed, 11 insertions(+), 48 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 04572db74b..90ce575534 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -3091,8 +3091,12 @@ bool Buffer::nextWord(DocIterator & from, DocIterator & to, bool inword = false; bool ignoreword = false; string lang_code; + // Go backward a bit if needed in order to return the word currently + // pointed by 'from'. + while (from && from.pos() && isLetter(from)) + from.backwardPos(); + // OK, we start from here. to = from; - while (to.depth()) { if (isLetter(to)) { if (!inword) { diff --git a/src/frontends/qt4/Dialog.cpp b/src/frontends/qt4/Dialog.cpp index a7e0b51df9..d1ff82fc7f 100644 --- a/src/frontends/qt4/Dialog.cpp +++ b/src/frontends/qt4/Dialog.cpp @@ -158,8 +158,6 @@ void Dialog::showView() // Make sure the dialog controls are correctly enabled/disabled with // readonly status. checkStatus(); - if (exitEarly()) - return; QWidget * w = asQWidget(); w->setWindowTitle(title_); diff --git a/src/frontends/qt4/Dialog.h b/src/frontends/qt4/Dialog.h index 06243457e1..3924222399 100644 --- a/src/frontends/qt4/Dialog.h +++ b/src/frontends/qt4/Dialog.h @@ -195,11 +195,6 @@ public: */ virtual bool disconnectOnApply() const { return false; } - /** \return true if Dialog::View::show() should not display the dialog - * after running update. Currently, only ControlSpellchecker - * makes use of that. - */ - virtual bool exitEarly() const { return false; } //@} /** \c Kernel part: a wrapper making the LyX kernel available to the dialog. diff --git a/src/frontends/qt4/GuiSpellchecker.cpp b/src/frontends/qt4/GuiSpellchecker.cpp index 56969abeec..b5dadeb5f6 100644 --- a/src/frontends/qt4/GuiSpellchecker.cpp +++ b/src/frontends/qt4/GuiSpellchecker.cpp @@ -48,7 +48,7 @@ namespace frontend { GuiSpellchecker::GuiSpellchecker(GuiView & lv) - : GuiDialog(lv, "spellchecker", qt_("Spellchecker")), exitEarly_(false), + : GuiDialog(lv, "spellchecker", qt_("Spellchecker")), progress_(0), count_(0) { setupUi(this); @@ -108,31 +108,8 @@ void GuiSpellchecker::reject() void GuiSpellchecker::updateContents() { - // The clauses below are needed because the spellchecker - // has many flaws (see bugs 1950, 2218). - // Basically, we have to distinguish the case where a - // spellcheck has already been performed for the whole - // document (exitEarly() == true, isVisible() == false) - // from the rest (exitEarly() == false, isVisible() == true). - // FIXME: rewrite the whole beast! - static bool check_after_early_exit; - if (exitEarly()) { - // a spellcheck has already been performed, + if (hasFocus()) check(); - check_after_early_exit = true; - } - else if (isVisible()) { - // the above check triggers a second update, - // and isVisible() is true then. Prevent a - // second check that skips the first word - if (check_after_early_exit) - // don't check, but reset the bool. - // business as usual after this. - check_after_early_exit = false; - else - // perform spellcheck (default case) - check(); - } } @@ -195,21 +172,12 @@ bool GuiSpellchecker::initialiseParams(string const &) } -void GuiSpellchecker::clearParams() -{ - LYXERR(Debug::GUI, "Spellchecker::clearParams"); -} - - void GuiSpellchecker::check() { LYXERR(Debug::GUI, "Check the spelling of a word"); DocIterator from = bufferview()->cursor(); - while (from && from.pos() && isLetter(from)) - from.backwardPos(); DocIterator to; - exitEarly_ = false; WordLangTuple word_lang; docstring_list suggestions; @@ -231,9 +199,11 @@ void GuiSpellchecker::check() // end of document if (from == to) { showSummary(); - exitEarly_ = true; return; } + if (!isVisible()) + show(); + word_ = word_lang; int const progress_bar = total_ diff --git a/src/frontends/qt4/GuiSpellchecker.h b/src/frontends/qt4/GuiSpellchecker.h index 1aebefae3c..d2bccdd932 100644 --- a/src/frontends/qt4/GuiSpellchecker.h +++ b/src/frontends/qt4/GuiSpellchecker.h @@ -56,13 +56,11 @@ private: /// bool initialiseParams(std::string const & data); /// - void clearParams(); + void clearParams() {} /// Not needed here void dispatchParams() {} /// bool isBufferDependent() const { return true; } - /// - bool exitEarly() const { return exitEarly_; } /// replace word with replacement void replace(docstring const &); @@ -77,8 +75,6 @@ private: /// show count of checked words at normal exit void showSummary(); - /// set to true when spellchecking is finished - bool exitEarly_; /// current word being checked and lang code WordLangTuple word_; /// values for progress -- 2.39.2