]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/Menus.cpp
Implement LFUN_SPELLING_REMOVE (patch from switt)
[lyx.git] / src / frontends / qt4 / Menus.cpp
index 5e4665499e2ce717d76173cbee5b87fb0175d328..2abf282e7ce54afc82e94aa68916aa24e8aa868a 100644 (file)
@@ -46,6 +46,7 @@
 #include "Paragraph.h"
 #include "ParIterator.h"
 #include "Session.h"
+#include "SpellChecker.h"
 #include "TextClass.h"
 #include "TocBackend.h"
 #include "Toolbars.h"
@@ -730,39 +731,55 @@ void MenuDefinition::expandGraphicsGroups(BufferView const * bv)
 
 void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
 {
-       if (!bv || !lyxrc.spellcheck_continuously)
+       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.spellCheck(from, to, wl, suggestions))
-               return;
-       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")));
-       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
-                       item.submenu().add(w);
+       SpellChecker::Result res = par.spellCheck(from, to, wl, suggestions);
+       switch (res) {
+       case SpellChecker::UNKNOWN_WORD:
+               if (lyxrc.spellcheck_continuously) {
+                       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")));
+                       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
+                                       item.submenu().add(w);
+                       }
+                       if (i >= 10)
+                               add(item);
+                       if (i > 0)
+                               add(MenuItem(MenuItem::Separator));
+                       docstring const arg = wl.word() + " " + from_ascii(wl.lang()->lang());
+                       add(MenuItem(MenuItem::Command, qt_("Add to personal dictionary|c"),
+                                       FuncRequest(LFUN_SPELLING_ADD, arg)));
+                       add(MenuItem(MenuItem::Command, qt_("Ignore all|I"),
+                                       FuncRequest(LFUN_SPELLING_IGNORE, arg)));
+               }
+               break;
+       case SpellChecker::LEARNED_WORD: {
+                       LYXERR(Debug::GUI, "Learned Word.");
+                       docstring const arg = wl.word() + " " + from_ascii(wl.lang()->lang());
+                       add(MenuItem(MenuItem::Command, qt_("Remove from personal dictionary|r"),
+                                       FuncRequest(LFUN_SPELLING_REMOVE, arg)));
+               }
+               break;
+       case SpellChecker::WORD_OK:
+       case SpellChecker::COMPOUND_WORD:
+       case SpellChecker::ROOT_FOUND:
+       case SpellChecker::IGNORED_WORD:
+               break;
        }
-       if (i >= 10)
-               add(item);
-       if (i > 0)
-               add(MenuItem(MenuItem::Separator));
-       docstring const arg = wl.word() + " " + from_ascii(wl.lang()->lang());
-       add(MenuItem(MenuItem::Command, qt_("Add to personal dictionary|c"),
-                       FuncRequest(LFUN_SPELLING_ADD, arg)));
-       add(MenuItem(MenuItem::Command, qt_("Ignore all|I"),
-                       FuncRequest(LFUN_SPELLING_IGNORE, arg)));
-       
 }
 
 struct sortLanguageByName {