From f46d3d137f72c4e5c619033253f5045fa0212c88 Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 6 Aug 2015 20:41:54 -0400 Subject: [PATCH] Allow multiple contexts to be specified when adding keybindings --- NEWS | 1 + Readme.rst | 5 +++-- library/Core.cpp | 26 ++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 10178f501..5eee8c72e 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ DFHack Future Fixed a rare overflow issue that could cause crashes on Linux and OS X Stopped DF window from receiving input when unfocused on OS X Fixed issues with keybindings involving Ctrl-A and Ctrl-Z, as well as Alt-E/U/N on OS X + Multiple contexts can now be specified when adding keybindings Lua Scripts can be enabled with the built-in enable/disable commands A new function, reqscript(), is available as a safer alternative to script_environment() diff --git a/Readme.rst b/Readme.rst index 84fc475a5..fec765dd1 100644 --- a/Readme.rst +++ b/Readme.rst @@ -212,7 +212,7 @@ Possible ways to call the command: The ** parameter above has the following *case-sensitive* syntax:: - [Ctrl-][Alt-][Shift-]KEY[@context] + [Ctrl-][Alt-][Shift-]KEY[@context[|context...]] where the *KEY* part can be F1-F9 or A-Z, and [] denote optional parts. @@ -227,7 +227,8 @@ the ``keybinding`` command among other things prints the current context string. Only bindings with a *context* tag that either matches the current context fully, or is a prefix ending at a '/' boundary would be considered for execution, i.e. for context ``foo/bar/baz``, possible matches are any of ``@foo/bar/baz``, ``@foo/bar``, -``@foo`` or none. +``@foo`` or none. Multiple contexts can be specified by separating them with a +pipe (``|``) - for example, ``@foo|bar|baz/foo``. Enabling plugins ================ diff --git a/library/Core.cpp b/library/Core.cpp index 62b63411f..d48f45199 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -2105,6 +2105,23 @@ bool Core::ClearKeyBindings(std::string keyspec) bool Core::AddKeyBinding(std::string keyspec, std::string cmdline) { + size_t at_pos = keyspec.find('@'); + if (at_pos != std::string::npos) + { + std::string raw_spec = keyspec.substr(0, at_pos); + std::string raw_focus = keyspec.substr(at_pos + 1); + if (raw_focus.find('|') != std::string::npos) + { + std::vector focus_strings; + split_string(&focus_strings, raw_focus, "|"); + for (size_t i = 0; i < focus_strings.size(); i++) + { + if (!AddKeyBinding(raw_spec + "@" + focus_strings[i], cmdline)) + return false; + } + return true; + } + } int sym; KeyBinding binding; if (!parseKeySpec(keyspec, &sym, &binding.modifiers, &binding.focus)) @@ -2156,11 +2173,12 @@ std::vector Core::ListKeyBindings(std::string keyspec) return rv; } -//////////////// -// ClassNamCheck -//////////////// -// Since there is no Process.cpp, put ClassNamCheck stuff in Core.cpp +///////////////// +// ClassNameCheck +///////////////// + +// Since there is no Process.cpp, put ClassNameCheck stuff in Core.cpp static std::set known_class_names; static std::map known_vptrs;