]> git.lyx.org Git - features.git/commitdiff
Remove LYX_LAYOUT_DEFAULT - it is very very old, even klyx doesn't use it.
authorJohn Levon <levon@movementarian.org>
Tue, 6 Aug 2002 22:38:44 +0000 (22:38 +0000)
committerJohn Levon <levon@movementarian.org>
Tue, 6 Aug 2002 22:38:44 +0000 (22:38 +0000)
Commit the multi-language spellcheck patch.

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

28 files changed:
src/BufferView.h
src/BufferView2.C
src/ChangeLog
src/SpellBase.h
src/WordLangTuple.h [new file with mode: 0644]
src/buffer.C
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlSpellchecker.C
src/frontends/controllers/ControlSpellchecker.h
src/insets/ChangeLog
src/insets/inset.C
src/insets/inset.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetert.C
src/insets/insetert.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/ispell.C
src/ispell.h
src/layout.h
src/lyxtext.h
src/pspell.C
src/pspell.h
src/text.C
src/text2.C

index 2603dadf1b1005d35efcc49a1ac9a248baea0efb..fb7b2983419e3521b04476c3d072b49ba8ca5fd4 100644 (file)
@@ -19,6 +19,7 @@
 #include "commandtags.h"
 
 #include "insets/inset.h"
+#include "WordLangTuple.h"
 
 #include <boost/utility.hpp>
 
@@ -124,8 +125,8 @@ public:
        void endOfSpellCheck();
        ///
        void selectLastWord();
-       ///
-       string const nextWord(float & value);
+       /// return the next word
+       WordLangTuple const nextWord(float & value);
        ///
        bool gotoLabel(string const & label);
        ///
index 389201ce5fd88b8755fa3b16fff4e639dbea69a3..f09e7bfeb8910921c66ce88ee98f2c08a81420c1 100644 (file)
@@ -443,11 +443,11 @@ void BufferView::paste()
 
 
 /* these functions are for the spellchecker */
-string const BufferView::nextWord(float & value)
+WordLangTuple const BufferView::nextWord(float & value)
 {
        if (!available()) {
                value = 1;
-               return string();
+               return WordLangTuple();
        }
 
        return text->selectNextWordToSpellcheck(this, value);
index a91b09a96689f8b259a74a6a7f3082ca7f0fb6f6..49c48513693c757d173661a19a1ffea940a45a19 100644 (file)
@@ -1,3 +1,21 @@
+2002-08-06  John Levon  <levon@movementarian.org>
+
+       * WordLangTuple.h: new file for word + language code tuple
+       * SpellBase.h:
+       * pspell.h:
+       * pspell.C:
+       * ispell.h:
+       * ispell.C:
+       * lyxtext.h: 
+       * text.C:
+       * text2.C:
+       * BufferView.h:
+       * BufferView2.C: use WordLangTuple
+       * layout.h:
+       * buffer.C: remove very dead LYX_LAYOUT_DEFAULT
 2002-08-06  John Levon  <levon@movementarian.org>
 
        * lyx_main.C: fix cmdline batch handling
index 0120a0bb075ff9fb129b8f7093f832a521099403..1348c1e24c0eaee599cf2c482d328bc4beb3ee1e 100644 (file)
@@ -12,6 +12,8 @@
 
 #include "LString.h" // can't forward declare...
 
+#include "WordLangTuple.h"
 class BufferParams;
 
 /**
@@ -38,17 +40,17 @@ public:
        /// clean up on messy exit
        virtual void cleanUp() = 0;
 
-       /// check the given word and return the result
-       virtual enum Result check(string const &) = 0;
+       /// check the given word of the given lang code and return the result
+       virtual enum Result check(WordLangTuple const &) = 0;
 
        /// finish this spellchecker instance
        virtual void close() = 0;
 
        /// insert the given word into the personal dictionary
-       virtual void insert(string const &) = 0;
+       virtual void insert(WordLangTuple const &) = 0;
 
        /// accept the given word temporarily
-       virtual void accept(string const &) = 0;
+       virtual void accept(WordLangTuple const &) = 0;
 
        /// return the next near miss after a MISSED result
        virtual string const nextMiss() = 0;
diff --git a/src/WordLangTuple.h b/src/WordLangTuple.h
new file mode 100644 (file)
index 0000000..d58ca4a
--- /dev/null
@@ -0,0 +1,43 @@
+/**
+ * \file WordLangTuple.h
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author John Levon <levon@movementarian.org>
+ */
+
+#ifndef WORD_LANG_TUPLE_H
+#define WORD_LANG_TUPLE_H
+#include <config.h>
+#include "LString.h" 
+/**
+ * A word and its given language code ("en_US").
+ * This is used for spellchecking.
+ */
+class WordLangTuple {
+public:
+       WordLangTuple() {};
+       WordLangTuple(string const & w, string const & c)
+               : word_(w), code_(c) {}
+       /// return the word
+       string const word() const {
+               return word_;
+       }
+
+       /// return its language code
+       string const lang_code() const {
+               return code_;
+       }
+
+private:
+       /// the word
+       string word_;
+       /// language code of word
+       string code_;
+};
+#endif // WORD_LANG_TUPLE_H
index 2b3371ab52898f0120f45379970f669f54844eb1..c5d5110e8e4dcecb33b9967d0ec2abb5836793f1 100644 (file)
@@ -948,9 +948,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                int tmpret = lex.findToken(string_paragraph_separation);
                if (tmpret == -1)
                        ++tmpret;
-               if (tmpret != LYX_LAYOUT_DEFAULT)
-                       params.paragraph_separation =
-                               static_cast<BufferParams::PARSEP>(tmpret);
+               params.paragraph_separation =
+                       static_cast<BufferParams::PARSEP>(tmpret);
        } else if (token == "\\defskip") {
                lex.nextToken();
                params.defskip = VSpace(lex.getString());
@@ -965,31 +964,29 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                int tmpret = lex.findToken(string_quotes_language);
                if (tmpret == -1)
                        ++tmpret;
-               if (tmpret != LYX_LAYOUT_DEFAULT) {
-                       InsetQuotes::quote_language tmpl =
-                               InsetQuotes::EnglishQ;
-                       switch (tmpret) {
-                       case 0:
-                               tmpl = InsetQuotes::EnglishQ;
-                               break;
-                       case 1:
-                               tmpl = InsetQuotes::SwedishQ;
-                               break;
-                       case 2:
-                               tmpl = InsetQuotes::GermanQ;
-                               break;
-                       case 3:
-                               tmpl = InsetQuotes::PolishQ;
-                               break;
-                       case 4:
-                               tmpl = InsetQuotes::FrenchQ;
-                               break;
-                       case 5:
-                               tmpl = InsetQuotes::DanishQ;
-                               break;
-                       }
-                       params.quotes_language = tmpl;
+               InsetQuotes::quote_language tmpl =
+                       InsetQuotes::EnglishQ;
+               switch (tmpret) {
+               case 0:
+                       tmpl = InsetQuotes::EnglishQ;
+                       break;
+               case 1:
+                       tmpl = InsetQuotes::SwedishQ;
+                       break;
+               case 2:
+                       tmpl = InsetQuotes::GermanQ;
+                       break;
+               case 3:
+                       tmpl = InsetQuotes::PolishQ;
+                       break;
+               case 4:
+                       tmpl = InsetQuotes::FrenchQ;
+                       break;
+               case 5:
+                       tmpl = InsetQuotes::DanishQ;
+                       break;
                }
+               params.quotes_language = tmpl;
        } else if (token == "\\quotes_times") {
                lex.nextToken();
                switch (lex.getInteger()) {
@@ -1029,8 +1026,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                int tmpret = lex.findToken(string_orientation);
                if (tmpret == -1)
                        ++tmpret;
-               if (tmpret != LYX_LAYOUT_DEFAULT)
-                       params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
+               params.orientation =
+                       static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
        } else if (token == "\\paperwidth") {
                lex.next();
                params.paperwidth = lex.getString();
@@ -1173,11 +1170,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
        } else if (token == "\\align") {
                int tmpret = lex.findToken(string_align);
                if (tmpret == -1) ++tmpret;
-               if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
-                       int const tmpret2 = int(pow(2.0, tmpret));
-                       //lyxerr << "Tmpret2 = " << tmpret2 << endl;
-                       par->params().align(LyXAlignment(tmpret2));
-               }
+               int const tmpret2 = int(pow(2.0, tmpret));
+               par->params().align(LyXAlignment(tmpret2));
        } else if (token == "\\added_space_top") {
                lex.nextToken();
                VSpace value = VSpace(lex.getString());
index 0b35cd27ffad1380a595263e5e45a42faa0a5b0f..58bf5ef657ac1ad4cb7cecce8fca1233d02503e4 100644 (file)
@@ -1,3 +1,8 @@
+2002-08-06  John Levon  <levon@movementarian.org>
+
+       * ControlSpellchecker.C:
+       * ControlSpellchecker.h: use WordLangTuple 
 2002-08-06  John Levon  <levon@movementarian.org>
 
        * ControlSpellchecker.C: show an alert with the
index 10420d6c65b5ac3b8b3fed815f3103c9fee2d256..0a341353b3492ae55240f770807fc38b8f914472 100644 (file)
@@ -91,7 +91,7 @@ void ControlSpellchecker::check()
        while ((res == SpellBase::OK || res == SpellBase::IGNORE) && !stop_) {
                word_ = lv_.view()->nextWord(newval_);
 
-               if (word_.empty()) {
+               if (word_.word().empty()) {
                        clearParams();
                        break;
                }
@@ -99,19 +99,23 @@ void ControlSpellchecker::check()
                ++count_;
 
                // Update slider if and only if value has changed
-               newvalue_ = int(100.0*newval_);
+               newvalue_ = int(100.0 * newval_);
                if (newvalue_!= oldval_) {
                        oldval_ = newvalue_;
                        // set progress bar
                        view().partialUpdate(0);
                }
 
-               if (!speller_->alive()) clearParams();
+               if (!speller_->alive()) {
+                       clearParams();
+                       stop();
+                       return;
+               }
 
                res = speller_->check(word_);
        }
 
-       if (!stop_ && !word_.empty())
+       if (!stop_ && !word_.word().empty())
                lv_.view()->selectLastWord();
 
        // set suggestions
@@ -124,6 +128,8 @@ void ControlSpellchecker::check()
 void ControlSpellchecker::replace(string const & replacement)
 {
        lv_.view()->replaceWord(replacement);
+       // fix up the count
+       --count_;
        check();
 }
 
@@ -155,7 +161,7 @@ string ControlSpellchecker::getSuggestion()
 
 string ControlSpellchecker::getWord()
 {
-       string tmp = word_;
+       string tmp = word_.word();
        if (rtl_)
                std::reverse(tmp.begin(), tmp.end());
        return tmp;
@@ -214,7 +220,6 @@ void ControlSpellchecker::clearParams()
 
        // reset values to initial
        rtl_ = false;
-       word_.erase();
        newval_ = 0.0;
        oldval_ = 0;
        newvalue_ = 0;
index 75b58b51ee0108bbc83c729ac98ff2cbe912fbb7..65a515f12afe031a205cdeaec7644f0e9c82587b 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "ControlDialog_impl.h"
 #include "LString.h"
+#include "WordLangTuple.h"
 
 class SpellBase;
  
@@ -78,8 +79,8 @@ private:
        /// right to left
        bool rtl_;
 
-       /// current word being checked
-       string word_;
+       /// current word being checked and lang code
+       WordLangTuple word_;
 
        /// values for progress
        float newval_;
index 016b120f4e1ae3998ee2c955575805ce332e82be..316749adfa97c3e62cfac498c5aa0c5d1575eeff 100644 (file)
@@ -1,3 +1,16 @@
+2002-08-06  John Levon  <levon@movementarian.org>
+
+       * inset.h: 
+       * inset.C: 
+       * insetcollapsable.h: 
+       * insetcollapsable.C: 
+       * insetert.h:
+       * insetert.C:
+       * insettabular.h:
+       * insettabular.C:
+       * insettext.h:
+       * insettext.C: use WordLangTuple for spellcheck
 2002-08-06  Angus Leeming  <leeming@lyx.org>
 
        * insetinclude.C: add a monitor to the previewed image, so that the
index 4fa75c48d91b7f6bf4ca6ca694c441197d77e008..4429c12cb8bc43663c971145b90824f3e79f720e 100644 (file)
@@ -359,13 +359,13 @@ LyXCursor const & Inset::cursor(BufferView * bv) const
 }
 
 
-string const UpdatableInset::selectNextWordToSpellcheck(BufferView *bv,
+WordLangTuple UpdatableInset::selectNextWordToSpellcheck(BufferView *bv,
                                            float & value) const
 {
        // we have to unlock ourself in this function by default!
        bv->unlockInset(const_cast<UpdatableInset *>(this));
        value = 0;
-       return string();
+       return WordLangTuple();
 }
 
 
index fa81f39f000e2e54eeee893951647004357b196a..48ff4741fc0dc80119b00cc40f7b7159d3315e50 100644 (file)
@@ -19,6 +19,7 @@
 #include "LString.h"
 #include "commandtags.h"
 #include "frontends/mouse_state.h"
+#include "WordLangTuple.h"
 #include "LColor.h"
 
 class LyXFont;
@@ -536,7 +537,7 @@ public:
        ///
        virtual bool allowSpellcheck() { return false; }
        ///
-       virtual string const selectNextWordToSpellcheck(BufferView *, float & value) const;
+       virtual WordLangTuple selectNextWordToSpellcheck(BufferView *, float & value) const;
        ///
        virtual void selectSelectedWord(BufferView *) { return; }
        ///
index de8e98f74087331991c7e78b7f43b334c12f08f6..ffba580c7f2500c1007fcf97badea053e49e7cee 100644 (file)
@@ -667,14 +667,14 @@ bool InsetCollapsable::searchBackward(BufferView * bv, string const & str,
 }
 
 
-string const InsetCollapsable::selectNextWordToSpellcheck(BufferView * bv,
+WordLangTuple InsetCollapsable::selectNextWordToSpellcheck(BufferView * bv,
                                              float & value) const
 {
-       string const str = inset.selectNextWordToSpellcheck(bv, value);
-       if (first_after_edit && str.empty())
+       WordLangTuple word = inset.selectNextWordToSpellcheck(bv, value);
+       if (first_after_edit && word.word().empty())
                close(bv);
        first_after_edit = false;
-       return str;
+       return word;
 }
 
 
index b9fca1d3d37f67461976a0a6721290a002f379fa..8ae7d2a593f52c327621516b0530fe389892969c 100644 (file)
@@ -176,7 +176,8 @@ public:
        void close(BufferView *) const;
        ///
        bool allowSpellcheck() { return inset.allowSpellcheck(); }
-       string const selectNextWordToSpellcheck(BufferView *, float &) const;
+
+       WordLangTuple selectNextWordToSpellcheck(BufferView *, float &) const;
 
        void selectSelectedWord(BufferView * bv) {
                inset.selectSelectedWord(bv);
index e7a3a8f980853cf329dbf4a07917da6cbbcdcf43..a05d684befce813b607869621a26c187f41eb72c 100644 (file)
@@ -674,11 +674,11 @@ void InsetERT::close(BufferView * bv) const
 }
 
 
-string const InsetERT::selectNextWordToSpellcheck(BufferView * bv,
+WordLangTuple InsetERT::selectNextWordToSpellcheck(BufferView * bv,
                                                  float &) const
 {
        bv->unlockInset(const_cast<InsetERT *>(this));
-       return string();
+       return WordLangTuple();
 }
 
 
index 4675049f8ec3a513926642c4b1198c326f92d03d..3b580ed938e8f552650f6f0549d482af934a6655 100644 (file)
@@ -114,7 +114,8 @@ public:
        void close(BufferView *) const;
        ///
        bool allowSpellcheck() { return false; }
-       string const selectNextWordToSpellcheck(BufferView *, float &) const;
+
+       WordLangTuple selectNextWordToSpellcheck(BufferView *, float &) const;
        ///
        int ascent(BufferView *, LyXFont const &) const;
        ///
index f88e9dbb83f5e5b944f4f89f8c743fc32d856405..2749679a351f64811b42f3f08a635a2b498c361a 100644 (file)
@@ -2675,20 +2675,20 @@ Inset * InsetTabular::getInsetFromID(int id_arg) const
 }
 
 
-string const
+WordLangTuple
 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
 {
        nodraw(true);
        if (the_locking_inset) {
-               string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
-               if (!str.empty()) {
+               WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
+               if (!word.word().empty()) {
                        nodraw(false);
-                       return str;
+                       return word;
                }
                if (tabular->IsLastCell(actcell)) {
                        bv->unlockInset(const_cast<InsetTabular *>(this));
                        nodraw(false);
-                       return string();
+                       return WordLangTuple();
                }
                ++actcell;
        }
@@ -2696,26 +2696,26 @@ InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
        UpdatableInset * inset =
                static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
        inset->edit(bv, 0,  0, mouse_button::none);
-       string const str(selectNextWordInt(bv, value));
+       WordLangTuple word(selectNextWordInt(bv, value));
        nodraw(false);
-       if (!str.empty())
+       if (!word.word().empty())
                resetPos(bv);
-       return str;
+       return word;
 }
 
 
-string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
+WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
 {
        // when entering this function the inset should be ALWAYS locked!
        lyx::Assert(the_locking_inset);
 
-       string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
-       if (!str.empty())
-               return str;
+       WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
+       if (!word.word().empty())
+               return word;
 
        if (tabular->IsLastCell(actcell)) {
                bv->unlockInset(const_cast<InsetTabular *>(this));
-               return string();
+               return WordLangTuple();
        }
 
        // otherwise we have to lock the next inset and ask for it's selecttion
index 298790526cfdc320df6fd7cfdd4680e02b15a214..329a67df7c65d53b3bbda71e8f044518e36ff054 100644 (file)
@@ -216,7 +216,7 @@ public:
        LyXCursor const & cursor(BufferView *) const;
        ///
        bool allowSpellcheck() { return true; }
-       string const selectNextWordToSpellcheck(BufferView *, float & value) const;
+       WordLangTuple selectNextWordToSpellcheck(BufferView *, float & value) const;
        void selectSelectedWord(BufferView *);
        void toggleSelection(BufferView *, bool kill_selection);
        ///
@@ -316,7 +316,7 @@ private:
        void getSelection(int & scol, int & ecol,
                          int & srow, int & erow) const;
        ///
-       string selectNextWordInt(BufferView *, float & value) const;
+       WordLangTuple selectNextWordInt(BufferView *, float & value) const;
        ///
        bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
 
index c3b93db51082af2eec8a6af922366dd48c99972d..b191f313eadedfba2f6bcbf4d74a39d9493be45e 100644 (file)
@@ -2581,34 +2581,34 @@ Inset * InsetText::getInsetFromID(int id_arg) const
 }
 
 
-string const InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
+WordLangTuple InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
 {
        bool clear = false;
-       string str;
+       WordLangTuple word;
 
        if (!lt) {
                lt = getLyXText(bv);
                clear = true;
        }
        if (the_locking_inset) {
-               str = the_locking_inset->selectNextWordToSpellcheck(bv, value);
-               if (!str.empty()) {
+               word = the_locking_inset->selectNextWordToSpellcheck(bv, value);
+               if (!word.word().empty()) {
                        value += cy(bv);
                        if (clear)
                                lt = 0;
-                       return str;
+                       return word;
                }
-               // we have to go on checking so move cusor to the next char
+               // we have to go on checking so move cursor to the next char
                lt->cursor.pos(lt->cursor.pos() + 1);
        }
-       str = lt->selectNextWordToSpellcheck(bv, value);
-       if (str.empty())
+       word = lt->selectNextWordToSpellcheck(bv, value);
+       if (word.word().empty())
                bv->unlockInset(const_cast<InsetText *>(this));
        else
                value = cy(bv);
        if (clear)
                lt = 0;
-       return str;
+       return word;
 }
 
 
index eaeba72355bd8a62fbcb83a06f77304a15506ee0..7b1723daa40916304e88b0857623639f9388887e 100644 (file)
@@ -230,7 +230,7 @@ public:
        ///
        bool allowSpellcheck() { return true; }
        ///
-       string const selectNextWordToSpellcheck(BufferView *,
+       WordLangTuple selectNextWordToSpellcheck(BufferView *,
                                                float & value) const;
        void selectSelectedWord(BufferView *);
        ///
index 95dfcf2eb37169a092bfa1fc832b5a19247b5f95..c8e8721ee063c1e814f279288932d21c78ba6ddb 100644 (file)
@@ -303,13 +303,13 @@ void ISpell::cleanUp()
 }
 
 
-enum ISpell::Result ISpell::check(string const & word)
+enum ISpell::Result ISpell::check(WordLangTuple const & word)
 {
        // FIXME Please rewrite to use string.
 
        Result res;
  
-       ::fputs(word.c_str(), out);
+       ::fputs(word.word().c_str(), out);
        ::fputc('\n', out);
 
        char buf[1024];
@@ -374,18 +374,18 @@ void ISpell::close()
 }
 
 
-void ISpell::insert(string const & word)
+void ISpell::insert(WordLangTuple const & word)
 {
        ::fputc('*', out); // Insert word in personal dictionary
-       ::fputs(word.c_str(), out);
+       ::fputs(word.word().c_str(), out);
        ::fputc('\n', out);
 }
 
 
-void ISpell::accept(string const & word)
+void ISpell::accept(WordLangTuple const & word)
 {
        ::fputc('@', out); // Accept in this session
-       ::fputs(word.c_str(), out);
+       ::fputs(word.word().c_str(), out);
        ::fputc('\n', out);
 }
 
index 477cef9ae0ce8189b652a3079c5b579c0d834a74..cb1affed2c243e1b2b0e6088924691f4b96eab80 100644 (file)
@@ -30,16 +30,16 @@ public:
        virtual void cleanUp();
 
        /// check the given word and return the result
-       virtual enum Result check(string const & word);
+       virtual enum Result check(WordLangTuple const & word);
 
        /// finish this spellchecker instance
        virtual void close();
 
        /// insert the given word into the personal dictionary
-       virtual void insert(string const & word);
+       virtual void insert(WordLangTuple const & word);
 
        /// accept the given word temporarily
-       virtual void accept(string const & word);
+       virtual void accept(WordLangTuple const & word);
 
        /// return the next near miss after a MISSED result
        virtual string const nextMiss();
index 83a6228936b1df6cb3c3c34b8939b6835a715cdf..fd86e9910f00f880fe6f82b168e909bdd5b35e4f 100644 (file)
 #ifndef LAYOUT_H
 #define LAYOUT_H
 
-enum layout_default {
-       ///
-       LYX_LAYOUT_DEFAULT = 99
-};
-
-
 /// The different output types
 enum OutputType {
        ///
index 949681298d438d1d5ea0ea6f641dec19c55121cc..076562856b2b062e4a91080fa590bec730e57fbc 100644 (file)
@@ -21,6 +21,7 @@
 #include "layout.h"
 #include "LColor.h"
 #include "insets/inset.h"
+#include "WordLangTuple.h"
 
 class Buffer;
 class BufferParams;
@@ -302,7 +303,7 @@ public:
         to the beginning of this word.
         With SelectSelectedWord can this be highlighted really
         */
-       string const selectNextWordToSpellcheck(BufferView *, float & value) const;
+       WordLangTuple selectNextWordToSpellcheck(BufferView *, float & value) const;
        ///
        void selectSelectedWord(BufferView *);
        /// returns true if par was empty and was removed
index cba210de6c04efe1e48a1a699486bc38ba19165f..f31605d02a9d1201fd96be1a5fb982f7306f6c6d 100644 (file)
@@ -28,16 +28,9 @@ extern "C" {
 using std::endl;
 
 PSpell::PSpell(BufferParams const &, string const & lang)
-       : sc(0), els(0), spell_error_object(0), alive_(false)
+       : els(0), spell_error_object(0)
 {
-       PspellConfig * config = new_pspell_config();
-       pspell_config_replace(config, "language-tag", lang.c_str());
-       spell_error_object = new_pspell_manager(config);
-       if (pspell_error_number(spell_error_object) == 0) {
-               sc = to_pspell_manager(spell_error_object);
-               spell_error_object = 0;
-               alive_ = true;
-       }
+       addManager(lang); 
 }
 
 
@@ -47,6 +40,13 @@ PSpell::~PSpell()
        close();
        if (els)
                delete_pspell_string_emulation(els);
+       Managers::iterator it = managers_.begin();
+       Managers::iterator end = managers_.end();
+       for (; it != end; ++it) { 
+               delete_pspell_manager(it->second.manager);
+               delete_pspell_config(it->second.config);
+       }
 }
 
 
@@ -59,21 +59,49 @@ void PSpell::cleanUp()
 }
 
 
-enum PSpell::Result PSpell::check(string const & word)
+void PSpell::addManager(string const & lang)
+{
+       PspellConfig * config = new_pspell_config();
+       pspell_config_replace(config, "language-tag", lang.c_str());
+       PspellCanHaveError * err = new_pspell_manager(config);
+       if (spell_error_object)
+               delete_pspell_can_have_error(spell_error_object);
+       spell_error_object = 0;
+       if (pspell_error_number(err) == 0) {
+               Manager m;
+               m.manager = to_pspell_manager(err);
+               m.config = config;
+               managers_[lang] = m;
+       } else {
+               spell_error_object = err;
+       }
+}
+
+enum PSpell::Result PSpell::check(WordLangTuple const & word)
 {
        Result res = UNKNOWN;
  
-       if (!sc)
-               return res;
+       Managers::iterator it = managers_.find(word.lang_code());
+       if (it == managers_.end()) {
+               addManager(word.lang_code());
+               it = managers_.find(word.lang_code());
+               // FIXME
+               if (it == managers_.end()) 
+                       return res;
+       }
 
-       int word_ok = pspell_manager_check(sc, word.c_str());
+       PspellManager * m = it->second.manager;
+       int word_ok = pspell_manager_check(m, word.word().c_str());
        lyx::Assert(word_ok != -1);
 
        if (word_ok) {
                res = OK;
        } else {
                PspellWordList const * sugs =
-                       pspell_manager_suggest(sc, word.c_str());
+                       pspell_manager_suggest(m, word.word().c_str());
                lyx::Assert(sugs != 0);
                els = pspell_word_list_elements(sugs);
                if (pspell_word_list_empty(sugs))
@@ -87,22 +115,28 @@ enum PSpell::Result PSpell::check(string const & word)
 
 void PSpell::close()
 {
-       if (sc)
-               pspell_manager_save_all_word_lists(sc);
+       Managers::iterator it = managers_.begin();
+       Managers::iterator end = managers_.end();
+       for (; it != end; ++it) { 
+               pspell_manager_save_all_word_lists(it->second.manager);
+       }
 }
 
 
-void PSpell::insert(string const & word)
+void PSpell::insert(WordLangTuple const & word)
 {
-       if (sc)
-               pspell_manager_add_to_personal(sc, word.c_str());
+       Managers::iterator it = managers_.find(word.lang_code());
+       if (it != managers_.end())
+               pspell_manager_add_to_personal(it->second.manager, word.word().c_str());
 }
 
 
-void PSpell::accept(string const & word)
+void PSpell::accept(WordLangTuple const & word)
 {
-       if (sc)
-               pspell_manager_add_to_session(sc, word.c_str());
+       Managers::iterator it = managers_.find(word.lang_code());
+       if (it != managers_.end()) 
+               pspell_manager_add_to_session(it->second.manager, word.word().c_str());
 }
 
 
index dd393ba4ce16f6043fd696a51dee82a1f05c75db..6ab6dabb9cd3828e3f07f7174b7140c7a7ff8812 100644 (file)
 #ifndef LYX_PSPELL_H
 #define LYX_PSPELL_H
 
+#include <map>
 #include "SpellBase.h"
 
 class PspellManager;
 class PspellStringEmulation;
 class PspellCanHaveError;
+class PspellConfig; 
 
 class BufferParams;
 
@@ -28,23 +31,26 @@ public:
 
        virtual ~PSpell();
 
-       /// return true if the spellchecker instance still exists
-       virtual bool alive() { return alive_; }
+       /**
+        * return true if the spellchecker instance still exists
+        * Always true for pspell, since there is no separate process
+        */
+       virtual bool alive() { return true; }
 
        /// clean up on messy exit
        virtual void cleanUp();
 
        /// check the given word and return the result
-       virtual enum Result check(string const & word);
+       virtual enum Result check(WordLangTuple const &);
 
        /// finish this spellchecker instance
        virtual void close();
 
        /// insert the given word into the personal dictionary
-       virtual void insert(string const & word);
+       virtual void insert(WordLangTuple const &);
 
        /// accept the given word temporarily
-       virtual void accept(string const & word);
+       virtual void accept(WordLangTuple const &);
 
        /// return the next near miss after a MISSED result
        virtual string const nextMiss();
@@ -53,14 +59,23 @@ public:
        virtual string const error();
 
 private:
-       /// main manager
-       PspellManager * sc;
+       /// add a manager of the given language
+       void addManager(string const & lang);
+
+       struct Manager {
+               PspellManager * manager;
+               PspellConfig * config;
+       };
+       typedef std::map<string, struct Manager> Managers;
+
+       /// the managers
+       Managers managers_;
        /// FIXME
        PspellStringEmulation * els;
        /// FIXME
        PspellCanHaveError * spell_error_object;
-       /// initialised properly ?
-       bool alive_;
 };
 
 #endif // PSPELL_H
index 7f35a5fadbfc5f5ebc452ab4c9c110a3aea17f46..466185d29e1fe9de80726dbd9f2cc13d9a82ca05 100644 (file)
@@ -2393,19 +2393,19 @@ bool LyXText::selectWordWhenUnderCursor(BufferView * bview,
 
 // This function is only used by the spellchecker for NextWord().
 // It doesn't handle LYX_ACCENTs and probably never will.
-string const LyXText::selectNextWordToSpellcheck(BufferView * bview,
+WordLangTuple LyXText::selectNextWordToSpellcheck(BufferView * bview,
                                                 float & value) const
 {
        if (the_locking_inset) {
-               string str = the_locking_inset->selectNextWordToSpellcheck(bview, value);
-               if (!str.empty()) {
+               WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bview, value);
+               if (!word.word().empty()) {
                        value += float(cursor.y())/float(height);
-                       return str;
+                       return word;
                }
-               // we have to go on checking so move cusor to the next char
+               // we have to go on checking so move cursor to the next char
                if (cursor.pos() == cursor.par()->size()) {
                        if (!cursor.par()->next())
-                               return str;
+                               return word;
                        cursor.par(cursor.par()->next());
                        cursor.pos(0);
                } else
@@ -2457,6 +2457,9 @@ string const LyXText::selectNextWordToSpellcheck(BufferView * bview,
        // Start the selection from here
        selection.cursor = cursor;
 
+       string lang_code(
+               getFont(bview->buffer(), cursor.par(), cursor.pos())
+                       .language()->code());
        // and find the end of the word (insets like optional hyphens
        // and ligature break are part of a word)
        while (cursor.pos() < cursor.par()->size()
@@ -2472,7 +2475,7 @@ string const LyXText::selectNextWordToSpellcheck(BufferView * bview,
                                str += cursor.par()->getChar(i);
                }
        }
-       return str;
+       return WordLangTuple(str, lang_code);
 }
 
 
index c41e4f74fbc27d3f0f7a88f773d5e0bbda669ddf..4d725b75df17369b4fd39f1bff32c908ab931e7d 100644 (file)
@@ -1092,8 +1092,8 @@ string LyXText::getStringToIndex(BufferView * bview)
        // Try implicit word selection
        // If there is a change in the language the implicit word selection
        // is disabled.
-       LyXCursor resetCursor = cursor;
-       bool implicitSelection = selectWordWhenUnderCursor(bview, PREVIOUS_WORD);
+       LyXCursor const reset_cursor = cursor;
+       bool const implicitSelection = selectWordWhenUnderCursor(bview, PREVIOUS_WORD);
 
        if (!selection.set()) {
                bview->owner()->message(_("Nothing to index!"));
@@ -1110,7 +1110,7 @@ string LyXText::getStringToIndex(BufferView * bview)
        //and cursor is set to the original position.
        if (implicitSelection) {
                clearSelection();
-               cursor = resetCursor;
+               cursor = reset_cursor;
                setCursor(bview, cursor.par(), cursor.pos());
                selection.cursor = cursor;
        }