diff --git a/aegisub/src/command/command.cpp b/aegisub/src/command/command.cpp index 17853fbec..2d6dcf80e 100644 --- a/aegisub/src/command/command.cpp +++ b/aegisub/src/command/command.cpp @@ -51,7 +51,9 @@ namespace cmd { } void call(std::string const& name, agi::Context*c) { - (*find_command(name)->second)(c); + Command &cmd = *find_command(name)->second; + if (cmd.Validate(c)) + cmd(c); } wxBitmap const& Command::Icon(int size) { diff --git a/aegisub/src/dialog_search_replace.cpp b/aegisub/src/dialog_search_replace.cpp index 707d82e56..b8cea979a 100644 --- a/aegisub/src/dialog_search_replace.cpp +++ b/aegisub/src/dialog_search_replace.cpp @@ -336,7 +336,7 @@ void SearchReplaceEngine::ReplaceNext(bool DoReplace) { // Update video if (updateVideo) { - (*cmd::get("video/jump/start"))(context); + cmd::call("video/jump/start", context); } else if (DoReplace) Modified = true; diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index e42f7e81d..9eea6e2d0 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -347,7 +347,7 @@ int FrameMain::TryToCloseSubs(bool enableCancel) { if (enableCancel) flags |= wxCANCEL; int result = wxMessageBox(wxString::Format(_("Do you want to save changes to %s?"), GetScriptFileName()), _("Unsaved changes"), flags, this); if (result == wxYES) { - (*cmd::get("subtitle/save"))(context.get()); + cmd::call("subtitle/save", context.get()); // If it fails saving, return cancel anyway return context->ass->IsModified() ? wxCANCEL : wxYES; } diff --git a/aegisub/src/hotkey.cpp b/aegisub/src/hotkey.cpp index 6f712693a..f9856ead9 100644 --- a/aegisub/src/hotkey.cpp +++ b/aegisub/src/hotkey.cpp @@ -126,7 +126,7 @@ bool check(std::string const& context, agi::Context *c, int key_code, wchar_t ke /// The bottom line should be removed after all the hotkey commands are fixed. /// This is to avoid pointless exceptions. if (command.find("/") != std::string::npos) { - (*cmd::get(command))(c); + cmd::call(command, c); return true; } } diff --git a/aegisub/src/toggle_bitmap.cpp b/aegisub/src/toggle_bitmap.cpp index ac8acf1dc..4b4072be2 100644 --- a/aegisub/src/toggle_bitmap.cpp +++ b/aegisub/src/toggle_bitmap.cpp @@ -51,8 +51,8 @@ ToggleBitmap::ToggleBitmap(wxWindow *parent, agi::Context *context, const char *cmd_name, int icon_size, const char *ht_ctx, wxSize const& size) : wxControl(parent, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER) , context(context) -, command(cmd::get(cmd_name)) -, img(command->Icon(icon_size)) +, command(*cmd::get(cmd_name)) +, img(command.Icon(icon_size)) { int w = size.GetWidth() != -1 ? size.GetWidth() : img.GetWidth(); int h = size.GetHeight() != -1 ? size.GetHeight() : img.GetHeight(); @@ -62,13 +62,14 @@ ToggleBitmap::ToggleBitmap(wxWindow *parent, agi::Context *context, const char * SetBackgroundStyle(wxBG_STYLE_PAINT); - ToolTipManager::Bind(this, command->StrHelp(), ht_ctx, cmd_name); + ToolTipManager::Bind(this, command.StrHelp(), ht_ctx, cmd_name); Bind(wxEVT_PAINT, &ToggleBitmap::OnPaint, this); Bind(wxEVT_LEFT_DOWN, &ToggleBitmap::OnMouseEvent, this); } void ToggleBitmap::OnMouseEvent(wxMouseEvent &) { - (*command)(context); + if (command.Validate(context)) + command(context); Refresh(false); } @@ -76,7 +77,7 @@ void ToggleBitmap::OnPaint(wxPaintEvent &) { wxAutoBufferedPaintDC dc(this); // Get background color - wxColour bgColor = command->IsActive(context) ? wxColour(0,255,0) : wxColour(255,0,0); + wxColour bgColor = command.IsActive(context) ? wxColour(0,255,0) : wxColour(255,0,0); wxColor sysCol = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT); bgColor.Set( (sysCol.Red() + bgColor.Red()) / 2, diff --git a/aegisub/src/toggle_bitmap.h b/aegisub/src/toggle_bitmap.h index 4d0c63660..df74f1fed 100644 --- a/aegisub/src/toggle_bitmap.h +++ b/aegisub/src/toggle_bitmap.h @@ -49,7 +49,7 @@ namespace cmd { class Command; } /// DOCME class ToggleBitmap : public wxControl { agi::Context *context; - cmd::Command *command; + cmd::Command &command; wxBitmap img; void OnMouseEvent(wxMouseEvent &evt);