bool CKeyBindings::Bind(const string& keystr, const string& line) { CKeySet ks; if (!ParseKeySet(keystr, ks)) { LOG_L(L_WARNING, "Bind: could not parse key: %s", keystr.c_str()); return false; } Action action(line); action.boundWith = keystr; if (action.command.empty()) { LOG_L(L_WARNING, "Bind: empty action: %s", line.c_str()); return false; } // Try to be safe, force AnyMod mode for stateful commands if (statefulCommands.find(action.command) != statefulCommands.end()) { ks.SetAnyBit(); } KeyMap::iterator it = bindings.find(ks); if (it == bindings.end()) { // new entry, push it ActionList& al = bindings[ks]; al.push_back(action); } else { if (it->first != ks) { // not a match, push it ActionList& al = it->second; al.push_back(action); } else { // an exact keyset match, check the command ActionList& al = it->second; int i; for (i = 0; i < (int)al.size(); i++) { if (action.command == al[i].command) { break; } } if (i == (int)al.size()) { // not a match, push it al.push_back(action); } } } return true; }
bool CKeyBindings::UnBindKeyset(const string& keystr) { CKeySet ks; if (!ParseKeySet(keystr, ks)) { LOG_L(L_WARNING, "UnBindKeyset: could not parse key: %s", keystr.c_str()); return false; } bool success = false; KeyMap::iterator it = bindings.find(ks); if (it != bindings.end()) { bindings.erase(it); success = true; } return success; }
bool CKeyBindings::UnBind(const string& keystr, const string& command) { CKeySet ks; if (!ParseKeySet(keystr, ks)) { LOG_L(L_WARNING, "UnBind: could not parse key: %s", keystr.c_str()); return false; } bool success = false; KeyMap::iterator it = bindings.find(ks); if (it != bindings.end()) { ActionList& al = it->second; success = RemoveCommandFromList(al, command); if (al.empty()) { bindings.erase(it); } } return success; }
bool CKeyBindings::UnBind(const string& keystr, const string& command) { CKeySet ks; if (!ParseKeySet(keystr, ks)) { logOutput.Print("UnBind: could not parse key: %s\n", keystr.c_str()); return false; } bool success = false; KeyMap::iterator it = bindings.find(ks); if (it != bindings.end()) { ActionList& al = it->second; success = RemoveCommandFromList(al, command); if (al.size() <= 0) { bindings.erase(it); } } return success; }