From af484a469d361d6c9d7a08594d746b986d993a2d Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 26 Jul 2011 19:52:57 +0000 Subject: [PATCH] Make get_hotkey_str_first more likely to return the desired hotkey when multiple are available Originally committed to SVN as r5508. --- aegisub/libaegisub/common/hotkey.cpp | 12 ++++++++++++ aegisub/libaegisub/include/libaegisub/hotkey.h | 6 ++++++ aegisub/src/hotkey.cpp | 3 +-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/aegisub/libaegisub/common/hotkey.cpp b/aegisub/libaegisub/common/hotkey.cpp index 6e9c90b7c..0ae3dfc53 100644 --- a/aegisub/libaegisub/common/hotkey.cpp +++ b/aegisub/libaegisub/common/hotkey.cpp @@ -160,6 +160,18 @@ std::vector Hotkey::GetHotkeys(const std::string &context, const st return ret; } +std::string Hotkey::GetHotkey(const std::string &context, const std::string &command) const { + std::string ret; + HotkeyMap::const_iterator it, end; + for (std::tr1::tie(it, end) = cmd_map.equal_range(command); it != end; ++it) { + std::string ctext = it->second.Context(); + if (ctext == context) return it->second.StrMenu(); + if (ctext == "Default") ret = it->second.StrMenu(); + else if (ret.empty() && ctext == "Always") it->second.StrMenu(); + } + return ret; +} + void Hotkey::Flush() { json::Object root; diff --git a/aegisub/libaegisub/include/libaegisub/hotkey.h b/aegisub/libaegisub/include/libaegisub/hotkey.h index 8bd4e0d4d..170bb0b65 100644 --- a/aegisub/libaegisub/include/libaegisub/hotkey.h +++ b/aegisub/libaegisub/include/libaegisub/hotkey.h @@ -107,6 +107,12 @@ public: /// @return A vector of all hotkeys for that command in the context std::vector GetHotkeys(const std::string &context, const std::string &command) const; + /// Get a string representation of a hotkeys for the given command + /// @param context Context requested + /// @param command Command name + /// @return A hotkey for the given command or "" if there are none + std::string GetHotkey(const std::string &context, const std::string &command) const; + private: typedef std::multimap HotkeyMap; ///< Map to hold Combo instances. HotkeyMap str_map; ///< String representation -> Combo diff --git a/aegisub/src/hotkey.cpp b/aegisub/src/hotkey.cpp index 1f27396ed..bc1108b6b 100644 --- a/aegisub/src/hotkey.cpp +++ b/aegisub/src/hotkey.cpp @@ -85,8 +85,7 @@ std::vector get_hotkey_strs(std::string const& context, std::string } std::string get_hotkey_str_first(std::string const& context, std::string const& command) { - std::vector strs = get_hotkey_strs(context, command); - return strs.empty() ? "" : strs.front(); + return agi::hotkey::hotkey->GetHotkey(context, command); }