Make get_hotkey_str_first more likely to return the desired hotkey when multiple are available

Originally committed to SVN as r5508.
This commit is contained in:
Thomas Goyne 2011-07-26 19:52:57 +00:00
parent dd38e1f07f
commit af484a469d
3 changed files with 19 additions and 2 deletions

View File

@ -160,6 +160,18 @@ std::vector<std::string> 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;

View File

@ -107,6 +107,12 @@ public:
/// @return A vector of all hotkeys for that command in the context
std::vector<std::string> 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<std::string, Combo> HotkeyMap; ///< Map to hold Combo instances.
HotkeyMap str_map; ///< String representation -> Combo

View File

@ -85,8 +85,7 @@ std::vector<std::string> 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<std::string> strs = get_hotkey_strs(context, command);
return strs.empty() ? "" : strs.front();
return agi::hotkey::hotkey->GetHotkey(context, command);
}