]> git.lyx.org Git - features.git/commitdiff
* ADD LFUN_SPELLING_ADD and LFUN_SPELLING_IGNORE (bug 6102).
authorJürgen Spitzmüller <spitz@lyx.org>
Tue, 19 Jan 2010 08:21:56 +0000 (08:21 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Tue, 19 Jan 2010 08:21:56 +0000 (08:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33089 a592a061-630c-0410-9148-cb99ea01b6c8

src/FuncCode.h
src/LyXAction.cpp
src/Text3.cpp
src/frontends/qt4/Menus.cpp

index 1f468b6c8e1eb4dd759ecd1b5cd3334cb8a1a734..8c96005b8fc537e8884170f674c27476c0e2ad29 100644 (file)
@@ -442,7 +442,9 @@ enum FuncCode
        LFUN_BUFFER_CLOSE_ALL,          // vfr 20090806
        LFUN_GRAPHICS_RELOAD,           // vfr 20090810
        LFUN_SCREEN_SHOW_CURSOR,        // vfr, 20090325
+       LFUN_SPELLING_ADD,              // spitz 20100118
        // 345
+       LFUN_SPELLING_IGNORE,           // spitz 20100118
 
        LFUN_LASTACTION                 // end of the table
 };
index d9a3f50b1c7fe59db6bc672374d10c29ec439b92..d3ad97544e89cec93d2b681866552a28361643ef 100644 (file)
@@ -980,6 +980,28 @@ void LyXAction::init()
  * \endvar
  */
                { LFUN_WORD_LOWCASE, "word-lowcase", Noop, Edit },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_SPELLING_ADD
+ * \li Action: Add the word under the cursor to the respective
+ *             spell checker dictionary.
+ * \li Syntax: spelling-add [<STRING>] [<LANG>]
+ * \li Params: <WORD>: word to add
+               <LANG>: language code (see file languages)
+ * \li Origin: JSpitzm, 18 Jan 2010
+ * \endvar
+ */
+               { LFUN_SPELLING_ADD, "spelling-add", ReadOnly, Edit },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_SPELLING_IGNORE
+ * \li Action: Let the spell checker ignore the word under the cursor
+ *             in the current session for the given language.
+ * \li Syntax: spelling-ignore [<WORD>] [<LANG>]
+ * \li Params: <WORD>: word to ignore
+               <LANG>: language code (see file languages)
+ * \li Origin: JSpitzm, 18 Jan 2010
+ * \endvar
+ */
+               { LFUN_SPELLING_IGNORE, "spelling-ignore", ReadOnly, Edit },
 /*!
  * \var lyx::FuncCode lyx::LFUN_THESAURUS_ENTRY
  * \li Action: Look up thesaurus entries with respect to the word under the cursor.
index 71c1772354644d147eec3d2cb2d3e79f80fb7763..ef69765de726a6afa0169bd2040d779dc0e241f3 100644 (file)
 #include "LyXRC.h"
 #include "Paragraph.h"
 #include "ParagraphParameters.h"
+#include "SpellChecker.h"
 #include "TextClass.h"
 #include "TextMetrics.h"
 #include "VSpace.h"
+#include "WordLangTuple.h"
 
 #include "frontends/Application.h"
 #include "frontends/Clipboard.h"
@@ -1996,6 +1998,48 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
+       case LFUN_SPELLING_ADD: {
+               docstring word = from_utf8(cmd.getArg(0));
+               string code;
+               string variety;
+               if (word.empty()) {
+                       word = cur.selectionAsString(false);
+                       // FIXME
+                       if (word.size() > 100 || word.empty()) {
+                               // Get word or selection
+                               selectWordWhenUnderCursor(cur, WHOLE_WORD);
+                               word = cur.selectionAsString(false);
+                       }
+                       code = cur.getFont().language()->code();
+                       variety = cur.getFont().language()->variety();
+               } else
+                       variety = split(cmd.getArg(1), code, '-');
+               WordLangTuple wl(word, code, variety);
+               theSpellChecker()->insert(wl);
+               break;
+       }
+
+       case LFUN_SPELLING_IGNORE: {
+               docstring word = from_utf8(cmd.getArg(0));
+               string code;
+               string variety;
+               if (word.empty()) {
+                       word = cur.selectionAsString(false);
+                       // FIXME
+                       if (word.size() > 100 || word.empty()) {
+                               // Get word or selection
+                               selectWordWhenUnderCursor(cur, WHOLE_WORD);
+                               word = cur.selectionAsString(false);
+                       }
+                       code = cur.getFont().language()->code();
+                       variety = cur.getFont().language()->variety();
+               } else
+                       variety = split(cmd.getArg(1), code, '-');
+               WordLangTuple wl(word, code, variety);
+               theSpellChecker()->accept(wl);
+               break;
+       }
+
        case LFUN_PARAGRAPH_PARAMS_APPLY: {
                // Given data, an encoding of the ParagraphParameters
                // generated in the Paragraph dialog, this function sets
@@ -2505,6 +2549,11 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_BREAK_PARAGRAPH:
                enable = cur.inset().getLayout().isMultiPar();
                break;
+       
+       case LFUN_SPELLING_ADD:
+       case LFUN_SPELLING_IGNORE:
+               enable = theSpellChecker();
+               break;
 
        case LFUN_WORD_DELETE_FORWARD:
        case LFUN_WORD_DELETE_BACKWARD:
index 80b3fbeb61f16b6137b0923ede42346efbd2de2c..8de4f83257d98e75c7508b816216b44b04262085 100644 (file)
@@ -741,6 +741,16 @@ void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
        }
        if (i >= 10)
                add(item);
+       if (i > 0)
+               add(MenuItem(MenuItem::Separator));
+       docstring arg = wl.word() + " " + from_ascii(wl.lang_code());
+       if (!wl.lang_variety().empty())
+               arg += from_ascii("-") + from_ascii(wl.lang_variety());
+       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)));
+       
 }