From 7bb749b51f5ca4b54d97f0ebe32c477424a296d0 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 22 Dec 2011 21:27:06 +0000 Subject: [PATCH] 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. --- aegisub/libaegisub/common/hotkey.cpp | 16 ++++++---------- aegisub/libaegisub/include/libaegisub/hotkey.h | 4 ++-- aegisub/src/hotkey.cpp | 4 ++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/aegisub/libaegisub/common/hotkey.cpp b/aegisub/libaegisub/common/hotkey.cpp index 71cf476f3..190677b2f 100644 --- a/aegisub/libaegisub/common/hotkey.cpp +++ b/aegisub/libaegisub/common/hotkey.cpp @@ -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; 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(); if (always && ctext == "Always") { - cmd = index->second.CmdName(); - LOG_D("agi/hotkey/found") << "Found: " << str << " Context (req/found): " << context << "/Always Command: " << cmd; - return true; + LOG_D("agi/hotkey/found") << "Found: " << str << " Context (req/found): " << context << "/Always Command: " << index->second.CmdName(); + return index->second.CmdName(); } if (ctext == "Default") dfault = index->second.CmdName(); @@ -110,18 +109,15 @@ bool Hotkey::Scan(const std::string &context, const std::string &str, bool alway } if (!local.empty()) { - cmd = local; LOG_D("agi/hotkey/found") << "Found: " << str << " Context: " << context << " Command: " << local; - return true; + return local; } if (!dfault.empty()) { - cmd = dfault; LOG_D("agi/hotkey/found") << "Found: " << str << " Context (req/found): " << context << "/Default Command: " << dfault; - return true; + return dfault; } - cmd.clear(); - return false; + return ""; } std::vector Hotkey::GetHotkeys(const std::string &context, const std::string &command) const { diff --git a/aegisub/libaegisub/include/libaegisub/hotkey.h b/aegisub/libaegisub/include/libaegisub/hotkey.h index 9afc22d3d..416f6938f 100644 --- a/aegisub/libaegisub/include/libaegisub/hotkey.h +++ b/aegisub/libaegisub/include/libaegisub/hotkey.h @@ -107,8 +107,8 @@ public: /// @param context Context requested. /// @param str Hyphen separated key sequence. /// @param always Enable the "Always" override context - /// @param[out] cmd Command found. - bool Scan(const std::string &context, const std::string &str, bool always, std::string &cmd) const; + /// @return Name of command or "" if none match + 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 /// @param context Context requested diff --git a/aegisub/src/hotkey.cpp b/aegisub/src/hotkey.cpp index fbb9c4b7a..059f03019 100644 --- a/aegisub/src/hotkey.cpp +++ b/aegisub/src/hotkey.cpp @@ -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); if (combo.empty()) return false; - std::string command; - if (inst->Scan(context, combo, OPT_GET("Audio/Medusa Timing Hotkeys")->GetBool(), command)) { + std::string command = inst->Scan(context, combo, OPT_GET("Audio/Medusa Timing Hotkeys")->GetBool()); + if (!command.empty()) { /// The bottom line should be removed after all the hotkey commands are fixed. /// This is to avoid pointless exceptions. if (command.find("/") != std::string::npos) {