Allow unbinding keys.
This commit is contained in:
parent
4fde56a942
commit
c0e8352c95
@ -123,11 +123,6 @@ class KeyConfigParser(QObject):
|
|||||||
def bind(self, key, command, mode=None):
|
def bind(self, key, command, mode=None):
|
||||||
"""Bind a key to a command.
|
"""Bind a key to a command.
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
FIXME: We should use the KeyMode enum here, and some argparser type for
|
|
||||||
a comma-separated list of enums.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
key: The keychain or special key (inside <...>) to bind.
|
key: The keychain or special key (inside <...>) to bind.
|
||||||
command: The command to execute.
|
command: The command to execute.
|
||||||
@ -136,6 +131,7 @@ class KeyConfigParser(QObject):
|
|||||||
"""
|
"""
|
||||||
if mode is None:
|
if mode is None:
|
||||||
mode = 'normal'
|
mode = 'normal'
|
||||||
|
mode = self._normalize_sectname(mode)
|
||||||
for m in mode.split(','):
|
for m in mode.split(','):
|
||||||
if m not in configdata.KEY_DATA:
|
if m not in configdata.KEY_DATA:
|
||||||
raise cmdexc.CommandError("Invalid mode {}!".format(m))
|
raise cmdexc.CommandError("Invalid mode {}!".format(m))
|
||||||
@ -148,6 +144,35 @@ class KeyConfigParser(QObject):
|
|||||||
for m in mode.split(','):
|
for m in mode.split(','):
|
||||||
self.changed.emit(m)
|
self.changed.emit(m)
|
||||||
|
|
||||||
|
@cmdutils.register(instance='keyconfig')
|
||||||
|
def unbind(self, key, mode=None):
|
||||||
|
"""Unbind a keychain.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key: The keychain or special key (inside <...>) to bind.
|
||||||
|
mode: A comma-separated list of modes to unbind the key in
|
||||||
|
(default: normal mode).
|
||||||
|
"""
|
||||||
|
if mode is None:
|
||||||
|
mode = 'normal'
|
||||||
|
mode = self._normalize_sectname(mode)
|
||||||
|
for m in mode.split(','):
|
||||||
|
if m not in configdata.KEY_DATA:
|
||||||
|
raise cmdexc.CommandError("Invalid mode {}!".format(m))
|
||||||
|
try:
|
||||||
|
sect = self.keybindings[mode]
|
||||||
|
except KeyError as e:
|
||||||
|
raise cmdexc.CommandError("Can't find mode section '{}'!".format(
|
||||||
|
sect))
|
||||||
|
try:
|
||||||
|
del sect[key]
|
||||||
|
except KeyError as e:
|
||||||
|
raise cmdexc.CommandError("Can't find binding '{}' in section "
|
||||||
|
"'{}'!".format(key, mode))
|
||||||
|
else:
|
||||||
|
for m in mode.split(','):
|
||||||
|
self.changed.emit(m)
|
||||||
|
|
||||||
def _normalize_sectname(self, s):
|
def _normalize_sectname(self, s):
|
||||||
"""Normalize a section string like 'foo, bar,baz' to 'bar,baz,foo'."""
|
"""Normalize a section string like 'foo, bar,baz' to 'bar,baz,foo'."""
|
||||||
return ','.join(sorted(s.split(',')))
|
return ','.join(sorted(s.split(',')))
|
||||||
|
Loading…
Reference in New Issue
Block a user