From 924c63103f2b8d614940fb991cac954310877f0e Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 3 Jan 2014 16:56:18 -0800 Subject: [PATCH] Add a better error message when a hotkey is set for an invalid command --- aegisub/src/command/command.h | 8 +++----- aegisub/src/hotkey.cpp | 16 ++++++++++++---- aegisub/src/toolbar.cpp | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/aegisub/src/command/command.h b/aegisub/src/command/command.h index a67cade0c..3fb57bc60 100644 --- a/aegisub/src/command/command.h +++ b/aegisub/src/command/command.h @@ -28,11 +28,6 @@ namespace agi { struct Context; } -DEFINE_BASE_EXCEPTION_NOINNER(CommandError, agi::Exception) -DEFINE_SIMPLE_EXCEPTION_NOINNER(CommandNotFound, CommandError, "command/notfound") -DEFINE_SIMPLE_EXCEPTION_NOINNER(CommandIconNone, CommandError, "command/icon") -DEFINE_SIMPLE_EXCEPTION_NOINNER(CommandIconInvalid, CommandError, "command/icon/invalid") - #define CMD_NAME(a) const char* name() const { return a; } #define STR_MENU(a) wxString StrMenu(const agi::Context *) const { return _(a); } #define STR_DISP(a) wxString StrDisplay(const agi::Context *) const { return _(a); } @@ -50,6 +45,9 @@ struct cname : public Command { \ /// Commands namespace cmd { +DEFINE_BASE_EXCEPTION_NOINNER(CommandError, agi::Exception) +DEFINE_SIMPLE_EXCEPTION_NOINNER(CommandNotFound, CommandError, "command/notfound") + enum CommandFlags { /// Default command type COMMAND_NORMAL = 0, diff --git a/aegisub/src/hotkey.cpp b/aegisub/src/hotkey.cpp index 8eb36310b..bb60674e1 100644 --- a/aegisub/src/hotkey.cpp +++ b/aegisub/src/hotkey.cpp @@ -24,6 +24,7 @@ #include "libresrc/libresrc.h" #include "command/command.h" +#include "compat.h" #include "options.h" #include @@ -163,11 +164,18 @@ bool check(std::string const& context, agi::Context *c, int key_code, int modifi } bool check(std::string const& context, agi::Context *c, wxKeyEvent &evt) { - if (!hotkey::check(context, c, evt.GetKeyCode(), evt.GetModifiers())) { - evt.Skip(); - return false; + try { + if (!hotkey::check(context, c, evt.GetKeyCode(), evt.GetModifiers())) { + evt.Skip(); + return false; + } + return true; + } + catch (cmd::CommandNotFound const& e) { + wxMessageBox(to_wx(e.GetChainedMessage()), _("Invalid command name for hotkey"), + wxOK | wxICON_ERROR | wxCENTER | wxSTAY_ON_TOP); + return true; } - return true; } std::vector get_hotkey_strs(std::string const& context, std::string const& command) { diff --git a/aegisub/src/toolbar.cpp b/aegisub/src/toolbar.cpp index 0c99623ef..7d6311ab7 100644 --- a/aegisub/src/toolbar.cpp +++ b/aegisub/src/toolbar.cpp @@ -124,7 +124,7 @@ namespace { try { command = cmd::get(command_name); } - catch (CommandNotFound const&) { + catch (cmd::CommandNotFound const&) { LOG_W("toolbar/command/not_found") << "Command '" << command_name << "' not found; skipping"; continue; }