From cff5afbb08346edbcf46aa665ad3cc0204b7ed52 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 8 Jun 2013 18:41:55 -0700 Subject: [PATCH] Don't overwrite existing hotkeys in migrations --- aegisub/libaegisub/common/hotkey.cpp | 11 +++++++++++ aegisub/libaegisub/include/libaegisub/hotkey.h | 2 ++ aegisub/src/hotkey.cpp | 9 ++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/aegisub/libaegisub/common/hotkey.cpp b/aegisub/libaegisub/common/hotkey.cpp index b42153ccf..d56438823 100644 --- a/aegisub/libaegisub/common/hotkey.cpp +++ b/aegisub/libaegisub/common/hotkey.cpp @@ -110,6 +110,17 @@ std::string Hotkey::Scan(const std::string &context, const std::string &str, boo return ""; } +bool Hotkey::HasHotkey(const std::string &context, const std::string &str) const { + HotkeyMap::const_iterator index, end; + for (std::tie(index, end) = str_map.equal_range(str); index != end; ++index) { + std::string const& ctext = index->second.Context(); + + if (ctext == context) + return true; + } + return false; +} + std::vector Hotkey::GetHotkeys(const std::string &context, const std::string &command) const { std::vector ret; diff --git a/aegisub/libaegisub/include/libaegisub/hotkey.h b/aegisub/libaegisub/include/libaegisub/hotkey.h index eaaa73dea..bf70771c6 100644 --- a/aegisub/libaegisub/include/libaegisub/hotkey.h +++ b/aegisub/libaegisub/include/libaegisub/hotkey.h @@ -108,6 +108,8 @@ public: /// @return Name of command or "" if none match std::string Scan(const std::string &context, const std::string &str, bool always) const; + bool HasHotkey(const std::string &context, const std::string &str) const; + /// Get the string representation of the hotkeys for the given command /// @param context Context requested /// @param command Command name diff --git a/aegisub/src/hotkey.cpp b/aegisub/src/hotkey.cpp index fb6960026..5535889f2 100644 --- a/aegisub/src/hotkey.cpp +++ b/aegisub/src/hotkey.cpp @@ -57,9 +57,12 @@ namespace { keys.emplace_back(added[i][2]); if (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))); + agi::hotkey::Combo combo(added[i][1], added[i][0], keys); + + if (hotkey::inst->HasHotkey(combo.Context(), combo.Str())) + continue; + + hk_map.insert(make_pair(std::string(added[i][0]), combo)); } hotkey::inst->SetHotkeyMap(hk_map);