Update the character counter synchronously

It's not longer even vaguely in the realm of slow enough to justify
dumping off on a background thread.
This commit is contained in:
Thomas Goyne 2014-04-18 18:59:45 -07:00
parent 2de95818db
commit 8aea747b88

View file

@ -54,7 +54,6 @@
#include "video_context.h" #include "video_context.h"
#include <libaegisub/character_count.h> #include <libaegisub/character_count.h>
#include <libaegisub/dispatch.h>
#include <libaegisub/util.h> #include <libaegisub/util.h>
#include <functional> #include <functional>
@ -586,15 +585,11 @@ void SubsEditBox::CallCommand(const char *cmd_name) {
void SubsEditBox::UpdateCharacterCount(std::string const& text) { void SubsEditBox::UpdateCharacterCount(std::string const& text) {
auto ignore_whitespace = OPT_GET("Subtitle/Character Counter/Ignore Whitespace")->GetBool(); auto ignore_whitespace = OPT_GET("Subtitle/Character Counter/Ignore Whitespace")->GetBool();
agi::dispatch::Background().Async([=]{ size_t length = agi::MaxLineLength(text, ignore_whitespace);
size_t length = agi::MaxLineLength(text, ignore_whitespace); char_count->SetValue(wxString::Format("%lu", (unsigned long)length));
agi::dispatch::Main().Async([=]{ size_t limit = (size_t)OPT_GET("Subtitle/Character Limit")->GetInt();
char_count->SetValue(wxString::Format("%lu", (unsigned long)length)); if (limit && length > limit)
size_t limit = (size_t)OPT_GET("Subtitle/Character Limit")->GetInt(); char_count->SetBackgroundColour(to_wx(OPT_GET("Colour/Subtitle/Syntax/Background/Error")->GetColor()));
if (limit && length > limit) else
char_count->SetBackgroundColour(to_wx(OPT_GET("Colour/Subtitle/Syntax/Background/Error")->GetColor())); char_count->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
else
char_count->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
});
});
} }