Allow multiple contexts to be specified when adding keybindings

develop
lethosor 2015-08-06 20:41:54 -04:00
parent afce8d810b
commit f46d3d137f
3 changed files with 26 additions and 6 deletions

@ -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()

@ -212,7 +212,7 @@ Possible ways to call the command:
The *<key>* 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
================

@ -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<std::string> 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<std::string> 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<std::string> known_class_names;
static std::map<std::string, void*> known_vptrs;