]> git.lyx.org Git - lyx.git/blobdiff - src/AppleSpellChecker.cpp
Fix bug #7212: Paragraph::forToc has to include the labelString.
[lyx.git] / src / AppleSpellChecker.cpp
index 71f7e1e25be3334d7c04322d6b849668d36bdb9c..702f49baccce52f62236c4f2b7d510543ebad643 100644 (file)
@@ -34,6 +34,10 @@ struct AppleSpellChecker::Private
 
        /// the speller
        AppleSpeller speller;
+       
+       /// language map
+       map<string, string> languageMap;
+       
 };
 
 
@@ -77,23 +81,34 @@ string AppleSpellChecker::Private::toString(SpellCheckResult status)
 
 SpellChecker::Result AppleSpellChecker::check(WordLangTuple const & word)
 {
+       if (!hasDictionary(word.lang()))
+               return WORD_OK;
+
        string const word_str = to_utf8(word.word());
+       string const lang = d->languageMap[word.lang()->code()];
        SpellCheckResult result =
                AppleSpeller_check(d->speller,
-                       word_str.c_str(), word.lang()->code().c_str());
+                       word_str.c_str(), lang.c_str());
        LYXERR(Debug::GUI, "spellCheck: \"" <<
                   word.word() << "\" = " << d->toString(result) <<
-                  ", lang = " << word.lang()->code()) ;
+                  ", lang = " << lang) ;
        return d->toResult(result);
 }
 
 
+void AppleSpellChecker::advanceChangeNumber()
+{
+       nextChangeNumber();
+}
+
+
 // add to personal dictionary
 void AppleSpellChecker::insert(WordLangTuple const & word)
 {
        string const word_str = to_utf8(word.word());
        AppleSpeller_learn(d->speller, word_str.c_str());
        LYXERR(Debug::GUI, "learn word: \"" << word.word() << "\"") ;
+       advanceChangeNumber();
 }
 
 
@@ -103,6 +118,7 @@ void AppleSpellChecker::remove(WordLangTuple const & word)
        string const word_str = to_utf8(word.word());
        AppleSpeller_unlearn(d->speller, word_str.c_str());
        LYXERR(Debug::GUI, "unlearn word: \"" << word.word() << "\"") ;
+       advanceChangeNumber();
 }
 
 
@@ -111,6 +127,8 @@ void AppleSpellChecker::accept(WordLangTuple const & word)
 {
        string const word_str = to_utf8(word.word());
        AppleSpeller_ignore(d->speller, word_str.c_str());
+       LYXERR(Debug::GUI, "ignore word: \"" << word.word() << "\"") ;
+       advanceChangeNumber();
 }
 
 
@@ -130,7 +148,21 @@ void AppleSpellChecker::suggest(WordLangTuple const & wl,
 
 bool AppleSpellChecker::hasDictionary(Language const * lang) const
 {
-       return AppleSpeller_hasLanguage(d->speller,lang->code().c_str());
+       string const langmap = d->languageMap[lang->code()];
+       bool result = !langmap.empty();
+
+       if (result)
+               return result;
+
+       result = AppleSpeller_hasLanguage(d->speller,lang->code().c_str());
+       if (result) {
+               d->languageMap[lang->code()] = lang->code();
+       } else {
+               result = AppleSpeller_hasLanguage(d->speller,lang->lang().c_str());
+               if (result)
+                       d->languageMap[lang->code()] = lang->lang();
+       }
+       return result;
 }