Don't overwrite existing hotkeys in migrations

This commit is contained in:
Thomas Goyne 2013-06-08 18:41:55 -07:00
parent 9809b66f61
commit cff5afbb08
3 changed files with 19 additions and 3 deletions

View file

@ -110,6 +110,17 @@ std::string Hotkey::Scan(const std::string &context, const std::string &str, boo
return ""; return "";
} }
bool Hotkey::HasHotkey(const std::string &context, const std::string &str) const {
HotkeyMap::const_iterator index, end;
for (std::tie(index, end) = str_map.equal_range(str); index != end; ++index) {
std::string const& ctext = index->second.Context();
if (ctext == context)
return true;
}
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 {
std::vector<std::string> ret; std::vector<std::string> ret;

View file

@ -108,6 +108,8 @@ public:
/// @return Name of command or "" if none match /// @return Name of command or "" if none match
std::string Scan(const std::string &context, const std::string &str, bool always) const; std::string Scan(const std::string &context, const std::string &str, bool always) const;
bool HasHotkey(const std::string &context, const std::string &str) 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
/// @param command Command name /// @param command Command name

View file

@ -57,9 +57,12 @@ namespace {
keys.emplace_back(added[i][2]); keys.emplace_back(added[i][2]);
if (added[i][3]) if (added[i][3])
keys.emplace_back(added[i][3]); keys.emplace_back(added[i][3]);
hk_map.insert(make_pair( agi::hotkey::Combo combo(added[i][1], added[i][0], keys);
std::string(added[i][0]),
agi::hotkey::Combo(added[i][1], added[i][0], keys))); if (hotkey::inst->HasHotkey(combo.Context(), combo.Str()))
continue;
hk_map.insert(make_pair(std::string(added[i][0]), combo));
} }
hotkey::inst->SetHotkeyMap(hk_map); hotkey::inst->SetHotkeyMap(hk_map);