Return the name of the command found or an empty string if none from Hotkey::Scan rather than using an out reference

Originally committed to SVN as r6112.
This commit is contained in:
Thomas Goyne 2011-12-22 21:27:06 +00:00
parent 022c711409
commit 7bb749b51f
3 changed files with 10 additions and 14 deletions

View File

@ -91,7 +91,7 @@ void Hotkey::BuildHotkey(std::string const& context, const json::Object& object)
} }
} }
bool Hotkey::Scan(const std::string &context, const std::string &str, bool always, std::string &cmd) const { std::string Hotkey::Scan(const std::string &context, const std::string &str, bool always) const {
std::string local, dfault; std::string local, dfault;
HotkeyMap::const_iterator index, end; HotkeyMap::const_iterator index, end;
@ -99,9 +99,8 @@ bool Hotkey::Scan(const std::string &context, const std::string &str, bool alway
std::string const& ctext = index->second.Context(); std::string const& ctext = index->second.Context();
if (always && ctext == "Always") { if (always && ctext == "Always") {
cmd = index->second.CmdName(); LOG_D("agi/hotkey/found") << "Found: " << str << " Context (req/found): " << context << "/Always Command: " << index->second.CmdName();
LOG_D("agi/hotkey/found") << "Found: " << str << " Context (req/found): " << context << "/Always Command: " << cmd; return index->second.CmdName();
return true;
} }
if (ctext == "Default") if (ctext == "Default")
dfault = index->second.CmdName(); dfault = index->second.CmdName();
@ -110,18 +109,15 @@ bool Hotkey::Scan(const std::string &context, const std::string &str, bool alway
} }
if (!local.empty()) { if (!local.empty()) {
cmd = local;
LOG_D("agi/hotkey/found") << "Found: " << str << " Context: " << context << " Command: " << local; LOG_D("agi/hotkey/found") << "Found: " << str << " Context: " << context << " Command: " << local;
return true; return local;
} }
if (!dfault.empty()) { if (!dfault.empty()) {
cmd = dfault;
LOG_D("agi/hotkey/found") << "Found: " << str << " Context (req/found): " << context << "/Default Command: " << dfault; LOG_D("agi/hotkey/found") << "Found: " << str << " Context (req/found): " << context << "/Default Command: " << dfault;
return true; return dfault;
} }
cmd.clear(); return "";
return false;
} }
std::vector<std::string> Hotkey::GetHotkeys(const std::string &context, const std::string &command) const { std::vector<std::string> Hotkey::GetHotkeys(const std::string &context, const std::string &command) const {

View File

@ -107,8 +107,8 @@ public:
/// @param context Context requested. /// @param context Context requested.
/// @param str Hyphen separated key sequence. /// @param str Hyphen separated key sequence.
/// @param always Enable the "Always" override context /// @param always Enable the "Always" override context
/// @param[out] cmd Command found. /// @return Name of command or "" if none match
bool Scan(const std::string &context, const std::string &str, bool always, std::string &cmd) const; std::string Scan(const std::string &context, const std::string &str, bool always) const;
/// Get the string representation of the hotkeys for the given command /// Get the string representation of the hotkeys for the given command
/// @param context Context requested /// @param context Context requested

View File

@ -76,8 +76,8 @@ bool check(std::string const& context, agi::Context *c, int key_code, wchar_t ke
std::string combo = keypress_to_str(key_code, key_char, modifier); std::string combo = keypress_to_str(key_code, key_char, modifier);
if (combo.empty()) return false; if (combo.empty()) return false;
std::string command; std::string command = inst->Scan(context, combo, OPT_GET("Audio/Medusa Timing Hotkeys")->GetBool());
if (inst->Scan(context, combo, OPT_GET("Audio/Medusa Timing Hotkeys")->GetBool(), command)) { if (!command.empty()) {
/// The bottom line should be removed after all the hotkey commands are fixed. /// The bottom line should be removed after all the hotkey commands are fixed.
/// This is to avoid pointless exceptions. /// This is to avoid pointless exceptions.
if (command.find("/") != std::string::npos) { if (command.find("/") != std::string::npos) {