MCPcopy Create free account
hub / github.com/DFHack/dfhack / addKeybind

Method addKeybind

library/modules/Hotkey.cpp:176–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174
175
176bool HotkeyManager::addKeybind(KeySpec spec, std::string_view cmd) {
177 // No point in a hotkey with no action
178 if (cmd.empty())
179 return false;
180
181 KeyBinding binding;
182 binding.spec = std::move(spec);
183 binding.cmdline = cmd;
184 size_t space_idx = cmd.find(' ');
185 binding.command = space_idx == std::string::npos ? cmd : cmd.substr(0, space_idx);
186
187 std::lock_guard<std::mutex> l(lock);
188 auto& bindings = this->bindings[binding.spec.sym];
189 for (auto& bind : bindings) {
190 // Don't set a keybind twice, but return true as there isn't an issue
191 if (bind == binding)
192 return true;
193 }
194
195 bindings.emplace_back(binding);
196 return true;
197}
198
199bool HotkeyManager::addKeybind(std::string keyspec, std::string_view cmd) {
200 std::optional<KeySpec> spec_opt = KeySpec::parse(std::move(keyspec));

Callers 3

keybindingMethod · 0.80
hotkey_addKeybindFunction · 0.80
add_binding_if_validFunction · 0.80

Calls 2

emptyMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected