allow hotkeys to be invoked as a hotkey

also ensure keybindings are always cleaned up
develop
myk002 2022-11-07 12:18:08 -08:00
parent 234919ffe1
commit 2b73d6e8e9
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 22 additions and 6 deletions

@ -124,11 +124,6 @@ static bool invoke_command(color_ostream &out, const size_t index)
}
Screen::dismiss(screen);
std::for_each(sorted_keys.begin(), sorted_keys.end(), [](const string &sym){
Core::getInstance().ClearKeyBindings(sym + "@" + MENU_SCREEN_FOCUS_STRING);
});
sorted_keys.clear();
return true;
}
@ -152,11 +147,27 @@ static int getHotkeys(lua_State *L) {
return 2;
}
static int cleanupHotkeys(lua_State *) {
std::for_each(sorted_keys.begin(), sorted_keys.end(), [](const string &sym) {
string keyspec = sym + "@" + MENU_SCREEN_FOCUS_STRING;
DEBUG(log).print("clearing keybinding: %s\n", keyspec.c_str());
Core::getInstance().ClearKeyBindings(keyspec);
});
sorted_keys.clear();
current_bindings.clear();
return 0;
}
DFHACK_PLUGIN_LUA_COMMANDS {
DFHACK_LUA_COMMAND(getHotkeys),
DFHACK_LUA_COMMAND(cleanupHotkeys),
DFHACK_LUA_END
};
// allow "hotkeys" to be invoked as a hotkey from any screen
static bool hotkeys_anywhere(df::viewscreen *) {
return true;
}
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{
@ -164,7 +175,8 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <Plug
PluginCommand(
"hotkeys",
"Invoke hotkeys from the interactive menu.",
hotkeys_cmd));
hotkeys_cmd,
hotkeys_anywhere));
return CR_OK;
}

@ -117,6 +117,10 @@ function MenuScreen:init()
}
end
function MenuScreen:onDismiss()
cleanupHotkeys()
end
function MenuScreen:onSelect(_, choice)
if not choice or #self.subviews == 0 then return end
local first_word = choice.command:trim():split(' +')[1]