forked from mia/Aegisub
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:
parent
dd38e1f07f
commit
af484a469d
3 changed files with 19 additions and 2 deletions
|
@ -160,6 +160,18 @@ std::vector<std::string> Hotkey::GetHotkeys(const std::string &context, const st
|
||||||
return ret;
|
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() {
|
void Hotkey::Flush() {
|
||||||
json::Object root;
|
json::Object root;
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,12 @@ public:
|
||||||
/// @return A vector of all hotkeys for that command in the context
|
/// @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;
|
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:
|
private:
|
||||||
typedef std::multimap<std::string, Combo> HotkeyMap; ///< Map to hold Combo instances.
|
typedef std::multimap<std::string, Combo> HotkeyMap; ///< Map to hold Combo instances.
|
||||||
HotkeyMap str_map; ///< String representation -> Combo
|
HotkeyMap str_map; ///< String representation -> Combo
|
||||||
|
|
|
@ -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::string get_hotkey_str_first(std::string const& context, std::string const& command) {
|
||||||
std::vector<std::string> strs = get_hotkey_strs(context, command);
|
return agi::hotkey::hotkey->GetHotkey(context, command);
|
||||||
return strs.empty() ? "" : strs.front();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue