From 777649a55166eda43e8252d9438d16ba0efc429b Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 5 Feb 2013 08:47:54 -0800 Subject: [PATCH] Update the character count asynchronously --- aegisub/src/subs_edit_box.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/aegisub/src/subs_edit_box.cpp b/aegisub/src/subs_edit_box.cpp index e5e250e3d..c984b8f60 100644 --- a/aegisub/src/subs_edit_box.cpp +++ b/aegisub/src/subs_edit_box.cpp @@ -55,6 +55,7 @@ #include "validators.h" #include "video_context.h" +#include #include #include @@ -575,11 +576,15 @@ void SubsEditBox::CallCommand(const char *cmd_name) { } void SubsEditBox::UpdateCharacterCount(std::string const& text) { - size_t length = MaxLineLength(text); - char_count->SetValue(wxString::Format("%lu", (unsigned long)length)); - size_t limit = (size_t)OPT_GET("Subtitle/Character Limit")->GetInt(); - if (limit && length > limit) - char_count->SetBackgroundColour(to_wx(OPT_GET("Colour/Subtitle/Syntax/Background/Error")->GetColor())); - else - char_count->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + agi::dispatch::Background().Async([=]{ + size_t length = MaxLineLength(text); + agi::dispatch::Main().Async([=]{ + char_count->SetValue(wxString::Format("%lu", (unsigned long)length)); + size_t limit = (size_t)OPT_GET("Subtitle/Character Limit")->GetInt(); + if (limit && length > limit) + char_count->SetBackgroundColour(to_wx(OPT_GET("Colour/Subtitle/Syntax/Background/Error")->GetColor())); + else + char_count->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + }); + }); }