]> git.lyx.org Git - features.git/commitdiff
Paragraph::collectWords() and MenuDefinition::expandSpellingSuggestions(): reuse...
authorAbdelrazak Younes <younes@lyx.org>
Tue, 23 Jun 2009 08:54:21 +0000 (08:54 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 23 Jun 2009 08:54:21 +0000 (08:54 +0000)
Paragraph::collectWords() now also collects spellchecker suggested words for inline word completion.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30240 a592a061-630c-0410-9148-cb99ea01b6c8

src/Paragraph.cpp
src/frontends/qt4/Menus.cpp

index 3965a61d3c96db9b0628dc6fffb6d5c97ae43993..19997fa51b8d81f7814b3b47e23e24269b70731a 100644 (file)
@@ -3027,40 +3027,24 @@ void Paragraph::locateWord(pos_type & from, pos_type & to,
 
 void Paragraph::collectWords()
 {
-       SpellChecker * speller = theSpellChecker();
-
-       //lyxerr << "Words: ";
        pos_type n = size();
+       WordLangTuple wl;
+       docstring_list suggestions;
        for (pos_type pos = 0; pos < n; ++pos) {
                if (isWordSeparator(pos))
                        continue;
                pos_type from = pos;
                locateWord(from, pos, WHOLE_WORD);
-               if (!lyxrc.spellcheck_continuously && pos - from < 6)
-                       continue;
-
-               docstring word = asString(from, pos, false);
-               if (pos - from >= 6)
+               if (pos - from >= 6) {
+                       docstring word = asString(from, pos, AS_STR_NONE);
                        d->words_.insert(word);
-
-               if (!lyxrc.spellcheck_continuously || !speller)
-                       continue;
-               
-               string const lang_code = lyxrc.spellchecker_alt_lang.empty()
-                       ? getFontSettings(d->inset_owner_->buffer().params(), from).language()->code()
-                       : lyxrc.spellchecker_alt_lang;
-               WordLangTuple wl(word, lang_code);
-               SpellChecker::Result res = speller->check(wl);
-               // ... just ignore any error that the spellchecker reports.
-               if (!speller->error().empty())
-                       continue;
-               bool const misspelled = res != SpellChecker::OK
-                       && res != SpellChecker::IGNORED_WORD;
-               d->fontlist_.setMisspelled(from, pos, misspelled);
-
-               //lyxerr << word << " ";
+               }
+               if (lyxrc.spellcheck_continuously
+                   && spellCheck(from, pos, wl, suggestions)) {
+                       for (size_t i = 0; i != suggestions.size(); ++i)
+                               d->words_.insert(suggestions[i]);
+               }
        }
-       //lyxerr << std::endl;
 }
 
 
index 7024bab3624753c9fc71e3a9406b2eb02adf8418..1d4660281588ff38e436e6dba04ca725f2a3f030 100644 (file)
 #include "Paragraph.h"
 #include "ParIterator.h"
 #include "Session.h"
-#include "SpellChecker.h"
 #include "TextClass.h"
 #include "TocBackend.h"
 #include "Toolbars.h"
+#include "WordLangTuple.h"
 
 #include "insets/Inset.h"
 #include "insets/InsetCitation.h"
@@ -718,26 +718,26 @@ void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
 {
        if (!bv)
                return;
+       WordLangTuple wl;
+       docstring_list suggestions;
+       pos_type from = bv->cursor().pos();
+       pos_type to = from;
        Paragraph const & par = bv->cursor().paragraph();
-       if (!par.isMisspelled(bv->cursor().pos()))
+       if (!par.spellCheck(from, to, wl, suggestions))
                return;
-       LYXERR0("Misspelled Word!");
-
-       SpellChecker * speller = theSpellChecker();
-       docstring word;
-       int i = 0;
+       LYXERR(Debug::GUI, "Misspelled Word! Suggested Words = ");
+       size_t i = 0;
        MenuItem item(MenuItem::Submenu, qt_("more spelling suggestions"));
        item.setSubmenu(MenuDefinition(qt_("more spelling suggestions")));
-       while (!(word = speller->nextMiss()).empty()) {
-               LYXERR0("Misspelled Word = " << word);
-               MenuItem w(MenuItem::Command, toqstr(word),
-                       FuncRequest(LFUN_WORD_REPLACE, word));
-               if (i < 10) {
+       for (; i != suggestions.size(); ++i) {
+               docstring const & suggestion = suggestions[i];
+               LYXERR(Debug::GUI, suggestion);
+               MenuItem w(MenuItem::Command, toqstr(suggestion),
+                       FuncRequest(LFUN_WORD_REPLACE, suggestion));
+               if (i < 10)
                        add(w);
-               } else {
+               else
                        item.submenu().add(w);
-               }
-               ++i;
        }
        if (i >= 10)
                add(item);