From: Abdelrazak Younes Date: Tue, 23 Jun 2009 08:54:21 +0000 (+0000) Subject: Paragraph::collectWords() and MenuDefinition::expandSpellingSuggestions(): reuse... X-Git-Tag: 2.0.0~6219 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=5d40a42f6017db96fd1250da475c08301f92b3c8;p=features.git Paragraph::collectWords() and MenuDefinition::expandSpellingSuggestions(): reuse Paragraph::spellCheck(). 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 --- diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 3965a61d3c..19997fa51b 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -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; } diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 7024bab362..1d46602815 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -46,10 +46,10 @@ #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);