forked from mia/Aegisub
Call Validate before invoking commands via hotkeys
Originally committed to SVN as r6448.
This commit is contained in:
parent
51cbc353b3
commit
38c905d32a
6 changed files with 13 additions and 10 deletions
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue