From e693fa97ba7fdd8d9d5e96b2b3281606111bda73 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 8 Jun 2013 18:24:50 -0700 Subject: [PATCH] Clean up the hotkey code a bit --- aegisub/src/hotkey.cpp | 23 +++++++++-------------- aegisub/src/include/aegisub/hotkey.h | 2 +- aegisub/src/preferences.cpp | 2 +- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/aegisub/src/hotkey.cpp b/aegisub/src/hotkey.cpp index 76cc4227d..fc9071182 100644 --- a/aegisub/src/hotkey.cpp +++ b/aegisub/src/hotkey.cpp @@ -47,15 +47,14 @@ namespace { void migrate_hotkeys(const char *removed[], const char *added[][4]) { agi::hotkey::Hotkey::HotkeyMap hk_map = hotkey::inst->GetHotkeyMap(); - for (size_t i = 0; removed[i]; ++i) { + for (size_t i = 0; removed[i]; ++i) hk_map.erase(removed[i]); - } for (size_t i = 0; added[i] && added[i][0]; ++i) { std::vector keys; - keys.push_back(added[i][2]); + keys.emplace_back(added[i][2]); if (added[i][3]) - keys.push_back(added[i][3]); + keys.emplace_back(added[i][3]); hk_map.insert(make_pair( std::string(added[i][0]), agi::hotkey::Combo(added[i][1], added[i][0], keys))); @@ -100,7 +99,7 @@ static std::string const& keycode_name(int code) { return keycode_names[code]; } -std::string keypress_to_str(int key_code, wchar_t key_char, int modifier) { +std::string keypress_to_str(int key_code, int modifier) { std::string combo; if ((modifier != wxMOD_NONE)) { if ((modifier & wxMOD_CMD) != 0) combo.append("Ctrl-"); @@ -113,24 +112,20 @@ std::string keypress_to_str(int key_code, wchar_t key_char, int modifier) { return combo; } -bool check(std::string const& context, agi::Context *c, int key_code, wchar_t key_char, int modifier) { - std::string combo = keypress_to_str(key_code, key_char, modifier); +bool check(std::string const& context, agi::Context *c, int key_code, int modifier) { + std::string combo = keypress_to_str(key_code, modifier); if (combo.empty()) return false; std::string command = inst->Scan(context, combo, OPT_GET("Audio/Medusa Timing Hotkeys")->GetBool()); if (!command.empty()) { - /// 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::call(command, c); - return true; - } + cmd::call(command, c); + return true; } return false; } bool check(std::string const& context, agi::Context *c, wxKeyEvent &evt) { - if (!hotkey::check(context, c, evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) { + if (!hotkey::check(context, c, evt.GetKeyCode(), evt.GetModifiers())) { evt.Skip(); return false; } diff --git a/aegisub/src/include/aegisub/hotkey.h b/aegisub/src/include/aegisub/hotkey.h index 2779d5757..f27644028 100644 --- a/aegisub/src/include/aegisub/hotkey.h +++ b/aegisub/src/include/aegisub/hotkey.h @@ -35,7 +35,7 @@ void clear(); bool check(std::string const& context, agi::Context *c, wxKeyEvent &evt); bool check(std::string const& context, agi::Context *c, int key_code, wchar_t key_char, int modifier); -std::string keypress_to_str(int key_code, wchar_t key_char, int modifier); +std::string keypress_to_str(int key_code, int modifier); std::string get_hotkey_str_first(std::string const& context, std::string const& command); std::vector get_hotkey_strs(std::string const& context, std::string const& command); diff --git a/aegisub/src/preferences.cpp b/aegisub/src/preferences.cpp index 90bb0425a..07363610b 100644 --- a/aegisub/src/preferences.cpp +++ b/aegisub/src/preferences.cpp @@ -342,7 +342,7 @@ public: } void OnKeyDown(wxKeyEvent &evt) { - ctrl->ChangeValue(to_wx(hotkey::keypress_to_str(evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers()))); + ctrl->ChangeValue(to_wx(hotkey::keypress_to_str(evt.GetKeyCode(), evt.GetModifiers()))); } bool SetValue(wxVariant const& var) {