X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FHunspellChecker.cpp;h=6dc6647b5cf4829687bc1418ef89dd9b707a09c4;hb=2e253eab0fe4cd318d153ace513829be93a97800;hp=67c7e27cc422fc93fde4e1b8aaf639f8590333d4;hpb=2992bb04da2b9f72e595df21ba9e8206af7c1816;p=lyx.git diff --git a/src/HunspellChecker.cpp b/src/HunspellChecker.cpp index 67c7e27cc4..6dc6647b5c 100644 --- a/src/HunspellChecker.cpp +++ b/src/HunspellChecker.cpp @@ -47,7 +47,7 @@ typedef map LangPersonalWordList; typedef vector IgnoreList; -} // anon namespace +} // namespace struct HunspellChecker::Private @@ -65,6 +65,7 @@ struct HunspellChecker::Private Hunspell * addSpeller(Language const * lang, string & hpath); Hunspell * addSpeller(Language const * lang); Hunspell * speller(Language const * lang); + Hunspell * lookup(Language const * lang); /// ignored words bool isIgnored(WordLangTuple const & wl) const; /// personal word list interface @@ -85,7 +86,7 @@ struct HunspellChecker::Private const string dictDirectory(void) const { return "dicts"; } int maxLookupSelector(void) const { return 5; } const string HunspellDictionaryName(Language const * lang) { - return lang->variety().empty() + return lang->variety().empty() ? lang->code() : lang->code() + "-" + lang->variety(); } @@ -154,9 +155,9 @@ const string HunspellChecker::Private::dictPath(int selector) { switch (selector) { case 4: - return addName(hunspellPackageDictDirectory(),dictDirectory()); + return hunspellPackageDictDirectory(); case 3: - return addName(myspellPackageDictDirectory(),dictDirectory()); + return myspellPackageDictDirectory(); case 2: return addName(package().system_support().absFileName(),dictDirectory()); case 1: @@ -169,13 +170,17 @@ const string HunspellChecker::Private::dictPath(int selector) bool HunspellChecker::Private::haveDictionary(Language const * lang, string & hpath) { - if (hpath.empty()) + if (hpath.empty() || !lang) return false; + if (lookup(lang)) return true; + + string d_name = HunspellDictionaryName(lang); + LYXERR(Debug::FILES, "check hunspell path: " << hpath - << " for language " << (lang ? lang->lang() : "NULL" )); + << " for language " << lang->lang() << " with name " << d_name); - string h_path = addName(hpath, HunspellDictionaryName(lang)); + string h_path = addName(hpath, d_name); // first we try lang code+variety if (haveLanguageFiles(h_path)) { LYXERR(Debug::FILES, " found " << h_path); @@ -201,24 +206,27 @@ bool HunspellChecker::Private::haveDictionary(Language const * lang) string lpath = dictPath(p); result = haveDictionary(lang, lpath); } - // FIXME: if result is false... - // we should indicate somehow that this language is not - // supported, probably by popping a warning. But we'll need to - // remember which warnings we've issued. return result; } Hunspell * HunspellChecker::Private::speller(Language const * lang) { + Hunspell * h = lookup(lang); + if (h) return h; + setUserPath(lyxrc.hunspelldir_path); - Spellers::iterator it = spellers_.find(lang->lang()); - if (it != spellers_.end()) - return it->second; return addSpeller(lang); } +Hunspell * HunspellChecker::Private::lookup(Language const * lang) +{ + Spellers::iterator it = spellers_.find(lang->lang()); + return it != spellers_.end() ? it->second : 0; +} + + Hunspell * HunspellChecker::Private::addSpeller(Language const * lang,string & path) { if (!haveDictionary(lang, path)) { @@ -229,7 +237,7 @@ Hunspell * HunspellChecker::Private::addSpeller(Language const * lang,string & p FileName const affix(path + ".aff"); FileName const dict(path + ".dic"); Hunspell * h = new Hunspell(affix.absFileName().c_str(), dict.absFileName().c_str()); - LYXERR(Debug::FILES, "Hunspell speller for langage " << lang << " at " << dict << " found"); + LYXERR(Debug::FILES, "Hunspell speller for langage " << lang << " at " << dict << " added."); spellers_[lang->lang()] = h; return h; }