]> git.lyx.org Git - lyx.git/blobdiff - src/HunspellChecker.cpp
Compile fix.
[lyx.git] / src / HunspellChecker.cpp
index 240d2978ac00fafc8d5d55b8cd430d05181dc073..83bd586dcfc29dd8eb03288a5e44bf584fb532fd 100644 (file)
@@ -46,9 +46,6 @@ typedef vector<WordLangTuple> IgnoreList;
 
 } // anon namespace
 
-#ifndef HUNSPELL_DICT
-# define HUNSPELL_DICT "dict"
-#endif
 
 struct HunspellChecker::Private
 {
@@ -56,6 +53,8 @@ struct HunspellChecker::Private
 
        ~Private();
 
+       const string dictPath(int selector);
+       bool haveLanguageFiles(string const & hpath);
        bool haveDictionary(string const & lang, string & hpath);
        bool haveDictionary(string const & lang);
        Hunspell * addSpeller(string const & lang, string & hpath);
@@ -68,6 +67,11 @@ struct HunspellChecker::Private
        Spellers spellers_;
        ///
        IgnoreList ignored_;
+
+       /// the location below system/user directory
+       /// there the aff+dic files lookup will happen
+       const string dictDirectory(void) const { return "dict"; }
+       int maxLookupSelector(void) const { return 3; }
 };
 
 
@@ -82,8 +86,7 @@ HunspellChecker::Private::~Private()
 }
 
 
-namespace {
-bool haveLanguageFiles(string const & hpath)
+bool HunspellChecker::Private::haveLanguageFiles(string const & hpath)
 {
        FileName const affix(hpath + ".aff");
        FileName const dict(hpath + ".dic");
@@ -91,23 +94,20 @@ bool haveLanguageFiles(string const & hpath)
 }
 
 
-#define MAX_SELECTOR 3
-string dictPath(int selector)
+const string HunspellChecker::Private::dictPath(int selector)
 {
        switch (selector) {
        case 2:
-               return addName(lyx::support::package().system_support().absFileName(),HUNSPELL_DICT);
+               return addName(lyx::support::package().system_support().absFileName(),dictDirectory());
                break;
        case 1:
-               return addName(lyx::support::package().user_support().absFileName(),HUNSPELL_DICT);
+               return addName(lyx::support::package().user_support().absFileName(),dictDirectory());
                break;
        default:
                return lyxrc.hunspelldir_path;
        }
 }
 
-}
-
 
 bool HunspellChecker::Private::haveDictionary(string const & lang, string & hpath)
 {
@@ -135,7 +135,7 @@ bool HunspellChecker::Private::haveDictionary(string const & lang, string & hpat
 bool HunspellChecker::Private::haveDictionary(string const & lang)
 {
        bool result = false;
-       for ( int p = 0; !result && p < MAX_SELECTOR; p++ ) {
+       for ( int p = 0; !result && p < maxLookupSelector(); p++ ) {
                string lpath = dictPath(p);
                result = haveDictionary(lang, lpath);
        }
@@ -172,7 +172,7 @@ Hunspell * HunspellChecker::Private::addSpeller(string const & lang,string & pat
 Hunspell * HunspellChecker::Private::addSpeller(string const & lang)
 {
        Hunspell * h = 0;
-       for ( int p = 0; p < MAX_SELECTOR && 0 == h; p++ ) {
+       for ( int p = 0; p < maxLookupSelector() && 0 == h; p++ ) {
                string lpath = dictPath(p);
                h = addSpeller(lang, lpath);
        }
@@ -207,18 +207,18 @@ HunspellChecker::~HunspellChecker()
 SpellChecker::Result HunspellChecker::check(WordLangTuple const & wl)
 {
        if (d->isIgnored(wl))
-               return OK;
+               return WORD_OK;
 
        Hunspell * h = d->speller(wl.lang()->code());
        if (!h)
-               return OK;
+               return WORD_OK;
        int info;
 
        string const encoding = h->get_dic_encoding();
        string const word_to_check = to_iconv_encoding(wl.word(), encoding);
        
        if (h->spell(word_to_check.c_str(), &info))
-               return OK;
+               return WORD_OK;
 
        if (info & SPELL_COMPOUND) {
                // FIXME: What to do with that?
@@ -233,6 +233,12 @@ SpellChecker::Result HunspellChecker::check(WordLangTuple const & wl)
 }
 
 
+void HunspellChecker::advanceChangeNumber()
+{
+       nextChangeNumber();
+}
+
+
 void HunspellChecker::insert(WordLangTuple const & wl)
 {
        string const word_to_check = to_utf8(wl.word());
@@ -240,12 +246,14 @@ void HunspellChecker::insert(WordLangTuple const & wl)
        if (!h)
                return;
        h->add(word_to_check.c_str());
+       advanceChangeNumber();
 }
 
 
 void HunspellChecker::accept(WordLangTuple const & wl)
 {
        d->ignored_.push_back(wl);
+       advanceChangeNumber();
 }