Add a better error message when a hotkey is set for an invalid command

This commit is contained in:
Thomas Goyne 2014-01-03 16:56:18 -08:00
parent 0b205e8019
commit 924c63103f
3 changed files with 16 additions and 10 deletions

View File

@ -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,

View File

@ -24,6 +24,7 @@
#include "libresrc/libresrc.h"
#include "command/command.h"
#include "compat.h"
#include "options.h"
#include <libaegisub/path.h>
@ -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<std::string> get_hotkey_strs(std::string const& context, std::string const& command) {

View File

@ -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;
}