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 40ddfa8e59
commit 46315d872f
4 changed files with 17 additions and 11 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); }
@ -72,6 +67,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

@ -97,7 +97,7 @@ public:
if (icon_bmp.IsOk())
icon.CopyFromBitmap(icon_bmp);
}
catch (agi::Exception const& e) {
catch (agi::Exception const&) {
// Just use no icon; error is reported in the description column
}
variant << wxDataViewIconText(to_wx(combo.CmdName()), icon);

View File

@ -129,7 +129,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;
}