Load the thesaurus dictionary asynchronously

This commit is contained in:
Thomas Goyne 2013-12-19 19:44:29 -08:00
parent 6957cd76a6
commit dbf5af1d49
3 changed files with 13 additions and 9 deletions

View file

@ -85,6 +85,7 @@ enum {
SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, agi::Context *context)
: ScintillaTextCtrl(parent, -1, "", wxDefaultPosition, wsize, style)
, spellchecker(SpellCheckerFactory::GetSpellChecker())
, thesaurus(agi::util::make_unique<Thesaurus>())
, context(context)
{
// Set properties
@ -387,9 +388,6 @@ void SubsTextEditCtrl::AddSpellCheckerEntries(wxMenu &menu) {
void SubsTextEditCtrl::AddThesaurusEntries(wxMenu &menu) {
if (currentWord.empty()) return;
if (!thesaurus)
thesaurus = agi::util::make_unique<Thesaurus>();
auto results = thesaurus->Lookup(currentWord);
thesSugs.clear();

View file

@ -29,6 +29,7 @@
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/range/algorithm.hpp>
#include <libaegisub/dispatch.h>
#include <libaegisub/fs.h>
#include <libaegisub/log.h>
#include <libaegisub/path.h>
@ -99,7 +100,17 @@ void Thesaurus::OnLanguageChanged() {
LOG_I("thesaurus/file") << "Using thesaurus: " << dat;
impl = agi::util::make_unique<agi::Thesaurus>(dat, idx);
agi::dispatch::Background().Async([=]{
try {
auto thes = agi::util::make_unique<agi::Thesaurus>(dat, idx);
agi::dispatch::Main().Sync([&]{
impl = std::move(thes);
});
}
catch (agi::Exception const& e) {
LOG_E("thesaurus") << e.GetChainedMessage();
}
});
}
void Thesaurus::OnPathChanged() {

View file

@ -14,11 +14,6 @@
//
// Aegisub Project http://www.aegisub.org/
/// @file thesaurus.h
/// @see thesaurus.cpp
/// @ingroup thesaurus
///
#include <memory>
#include <string>
#include <vector>