X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FEnchantChecker.cpp;h=8cc37812b4c7e558c57331bde91b63c98611b11b;hb=13739f37d5208e87e97c44ef2eeba35807ddb9c5;hp=23cbee923e55f48ed7ffd81d7aa019ab8d43ae5a;hpb=7746747506617b952e04e2e805c3688f4fef5256;p=lyx.git diff --git a/src/EnchantChecker.cpp b/src/EnchantChecker.cpp index 23cbee923e..8cc37812b4 100644 --- a/src/EnchantChecker.cpp +++ b/src/EnchantChecker.cpp @@ -34,7 +34,7 @@ struct Speller { enchant::Dict * speller; }; -typedef std::map Spellers; +typedef map Spellers; } // anon namespace @@ -69,6 +69,11 @@ EnchantChecker::Private::~Private() enchant::Dict * EnchantChecker::Private::addSpeller(string const & lang) { enchant::Broker * instance = enchant::Broker::instance(); + + if (!instance->dict_exists(lang)) + // FIXME error handling? + return 0; + enchant::Dict * dict = instance->request_dict(lang); if (dict) { @@ -105,33 +110,43 @@ EnchantChecker::~EnchantChecker() SpellChecker::Result EnchantChecker::check(WordLangTuple const & word) { - enchant::Dict * m = d->speller(word.lang_code()); + enchant::Dict * m = d->speller(word.lang()->code()); - if (!m) - return OK; + if (!m || word.word().empty()) + return WORD_OK; - std::string utf8word(to_utf8(word.word())); + string utf8word = to_utf8(word.word()); if (m->check(utf8word)) - return OK; + return WORD_OK; return UNKNOWN_WORD; } +void EnchantChecker::advanceChangeNumber() +{ + nextChangeNumber(); +} + + void EnchantChecker::insert(WordLangTuple const & word) { - Spellers::iterator it = d->spellers_.find(word.lang_code()); - if (it != d->spellers_.end()) + Spellers::iterator it = d->spellers_.find(word.lang()->code()); + if (it != d->spellers_.end()) { it->second.speller->add(to_utf8(word.word())); + advanceChangeNumber(); + } } void EnchantChecker::accept(WordLangTuple const & word) { - Spellers::iterator it = d->spellers_.find(word.lang_code()); - if (it != d->spellers_.end()) + Spellers::iterator it = d->spellers_.find(word.lang()->code()); + if (it != d->spellers_.end()) { it->second.speller->add_to_session(to_utf8(word.word())); + advanceChangeNumber(); + } } @@ -139,7 +154,7 @@ void EnchantChecker::suggest(WordLangTuple const & wl, docstring_list & suggestions) { suggestions.clear(); - enchant::Dict * m = d->speller(wl.lang_code()); + enchant::Dict * m = d->speller(wl.lang()->code()); if (!m) return; @@ -154,6 +169,15 @@ void EnchantChecker::suggest(WordLangTuple const & wl, } +bool EnchantChecker::hasDictionary(Language const * lang) const +{ + if (!lang) + return false; + enchant::Broker * instance = enchant::Broker::instance(); + return (instance->dict_exists(lang->code())); +} + + docstring const EnchantChecker::error() { return docstring();