From 4c4ea92d0f557880685a3debdc22a1733f93736e Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 31 Jan 2012 00:43:59 +0000 Subject: [PATCH] Update all spellcheckers after adding a word Previously adding a word to the dictionary via the spell checker dialog would not update the dictionary used by the subs edit box and vice-versa. Originally committed to SVN as r6396. --- aegisub/src/spellchecker_hunspell.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/aegisub/src/spellchecker_hunspell.cpp b/aegisub/src/spellchecker_hunspell.cpp index 628835e21..d1ed6ed60 100644 --- a/aegisub/src/spellchecker_hunspell.cpp +++ b/aegisub/src/spellchecker_hunspell.cpp @@ -43,7 +43,7 @@ #ifndef AGI_PRE #include #include -#include +#include #include #include @@ -89,7 +89,7 @@ void HunspellSpellChecker::AddWord(wxString word) { // Add it to the in-memory dictionary hunspell->add(conv->Convert(sword).c_str()); - std::list words; + std::set words; // Ensure that the path exists wxFileName fn(userDicPath); @@ -103,7 +103,7 @@ void HunspellSpellChecker::AddWord(wxString word) { remove_copy_if( ++agi::line_iterator(*stream), agi::line_iterator(), - back_inserter(words), + inserter(words, words.end()), mem_fun_ref(&std::string::empty)); } catch (agi::FileNotFoundError&) { @@ -112,13 +112,20 @@ void HunspellSpellChecker::AddWord(wxString word) { } // Add the word - words.push_back(sword); - words.sort(); + words.insert(sword); // Write the new dictionary - agi::io::Save writer(STD_STR(userDicPath)); - writer.Get() << words.size() << "\n"; - copy(words.begin(), words.end(), std::ostream_iterator(writer.Get(), "\n")); + { + agi::io::Save writer(STD_STR(userDicPath)); + writer.Get() << words.size() << "\n"; + copy(words.begin(), words.end(), std::ostream_iterator(writer.Get(), "\n")); + } + + // Announce a language change so that any other spellcheckers pick up the + // new word + lang_listener.Block(); + OPT_SET("Tool/Spell Checker/Language")->SetString(OPT_GET("Tool/Spell Checker/Language")->GetString()); + lang_listener.Unblock(); } bool HunspellSpellChecker::CheckWord(wxString word) {