Call Validate before invoking commands via hotkeys

Originally committed to SVN as r6448.
This commit is contained in:
Thomas Goyne 2012-02-07 01:22:23 +00:00
parent 51cbc353b3
commit 38c905d32a
6 changed files with 13 additions and 10 deletions

View file

@ -51,7 +51,9 @@ namespace cmd {
} }
void call(std::string const& name, agi::Context*c) { 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) { wxBitmap const& Command::Icon(int size) {

View file

@ -336,7 +336,7 @@ void SearchReplaceEngine::ReplaceNext(bool DoReplace) {
// Update video // Update video
if (updateVideo) { if (updateVideo) {
(*cmd::get("video/jump/start"))(context); cmd::call("video/jump/start", context);
} }
else if (DoReplace) Modified = true; else if (DoReplace) Modified = true;

View file

@ -347,7 +347,7 @@ int FrameMain::TryToCloseSubs(bool enableCancel) {
if (enableCancel) flags |= wxCANCEL; if (enableCancel) flags |= wxCANCEL;
int result = wxMessageBox(wxString::Format(_("Do you want to save changes to %s?"), GetScriptFileName()), _("Unsaved changes"), flags, this); int result = wxMessageBox(wxString::Format(_("Do you want to save changes to %s?"), GetScriptFileName()), _("Unsaved changes"), flags, this);
if (result == wxYES) { if (result == wxYES) {
(*cmd::get("subtitle/save"))(context.get()); cmd::call("subtitle/save", context.get());
// If it fails saving, return cancel anyway // If it fails saving, return cancel anyway
return context->ass->IsModified() ? wxCANCEL : wxYES; return context->ass->IsModified() ? wxCANCEL : wxYES;
} }

View file

@ -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. /// The bottom line should be removed after all the hotkey commands are fixed.
/// This is to avoid pointless exceptions. /// This is to avoid pointless exceptions.
if (command.find("/") != std::string::npos) { if (command.find("/") != std::string::npos) {
(*cmd::get(command))(c); cmd::call(command, c);
return true; return true;
} }
} }

View file

@ -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) 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) : wxControl(parent, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER)
, context(context) , context(context)
, command(cmd::get(cmd_name)) , command(*cmd::get(cmd_name))
, img(command->Icon(icon_size)) , img(command.Icon(icon_size))
{ {
int w = size.GetWidth() != -1 ? size.GetWidth() : img.GetWidth(); int w = size.GetWidth() != -1 ? size.GetWidth() : img.GetWidth();
int h = size.GetHeight() != -1 ? size.GetHeight() : img.GetHeight(); 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); 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_PAINT, &ToggleBitmap::OnPaint, this);
Bind(wxEVT_LEFT_DOWN, &ToggleBitmap::OnMouseEvent, this); Bind(wxEVT_LEFT_DOWN, &ToggleBitmap::OnMouseEvent, this);
} }
void ToggleBitmap::OnMouseEvent(wxMouseEvent &) { void ToggleBitmap::OnMouseEvent(wxMouseEvent &) {
(*command)(context); if (command.Validate(context))
command(context);
Refresh(false); Refresh(false);
} }
@ -76,7 +77,7 @@ void ToggleBitmap::OnPaint(wxPaintEvent &) {
wxAutoBufferedPaintDC dc(this); wxAutoBufferedPaintDC dc(this);
// Get background color // 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); wxColor sysCol = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT);
bgColor.Set( bgColor.Set(
(sysCol.Red() + bgColor.Red()) / 2, (sysCol.Red() + bgColor.Red()) / 2,

View file

@ -49,7 +49,7 @@ namespace cmd { class Command; }
/// DOCME /// DOCME
class ToggleBitmap : public wxControl { class ToggleBitmap : public wxControl {
agi::Context *context; agi::Context *context;
cmd::Command *command; cmd::Command &command;
wxBitmap img; wxBitmap img;
void OnMouseEvent(wxMouseEvent &evt); void OnMouseEvent(wxMouseEvent &evt);