console: add console.key.edit.focus, bind to "enter"

This commit is contained in:
Aldo Cortesi 2017-06-14 09:48:07 +12:00
parent e5f79abb4f
commit 2108bfb106
2 changed files with 23 additions and 4 deletions

View File

@ -425,16 +425,16 @@ class ConsoleAddon:
return list(sorted(keymap.Contexts))
@command.command("console.key.bind")
def key_bind(self, context: str, key: str, command: str) -> None:
def key_bind(self, contexts: typing.Sequence[str], key: str, *command: str) -> None:
"""
Bind a shortcut key.
"""
try:
self.master.keymap.add(
key,
command,
[context],
command
" ".join(command),
contexts,
""
)
except ValueError as v:
raise exceptions.CommandError(v)
@ -477,6 +477,19 @@ class ConsoleAddon:
b = self._keyfocus()
self.console_command(b.command)
@command.command("console.key.edit.focus")
def key_edit_focus(self) -> None:
"""
Execute the currently focused key binding.
"""
b = self._keyfocus()
self.console_command(
"console.key.bind",
",".join(b.contexts),
b.key,
b.command,
)
def running(self):
self.started = True

View File

@ -170,3 +170,9 @@ def map(km):
["keybindings"],
"Execute the currently focused key binding"
)
km.add(
"enter",
"console.key.edit.focus",
["keybindings"],
"Edit the currently focused key binding"
)