More keyconfig work
This commit is contained in:
parent
67afc06d79
commit
056edcfed3
@ -160,9 +160,3 @@ def init():
|
|||||||
history = objreg.get('web-history')
|
history = objreg.get('web-history')
|
||||||
history.async_read_done.connect(
|
history.async_read_done.connect(
|
||||||
functools.partial(update, [usertypes.Completion.url]))
|
functools.partial(update, [usertypes.Completion.url]))
|
||||||
|
|
||||||
keyconf = objreg.get('key-config')
|
|
||||||
keyconf.changed.connect(
|
|
||||||
functools.partial(update, [usertypes.Completion.command]))
|
|
||||||
keyconf.changed.connect(
|
|
||||||
functools.partial(update, [usertypes.Completion.bind]))
|
|
||||||
|
@ -97,6 +97,7 @@ class BaseKeyParser(QObject):
|
|||||||
self._warn_on_keychains = True
|
self._warn_on_keychains = True
|
||||||
self.bindings = {}
|
self.bindings = {}
|
||||||
self.special_bindings = {}
|
self.special_bindings = {}
|
||||||
|
config.instance.changed.connect(self._on_config_changed)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self, supports_count=self._supports_count,
|
return utils.get_repr(self, supports_count=self._supports_count,
|
||||||
@ -127,6 +128,7 @@ class BaseKeyParser(QObject):
|
|||||||
self._debug_log("Ignoring only-modifier keyeevent.")
|
self._debug_log("Ignoring only-modifier keyeevent.")
|
||||||
return False
|
return False
|
||||||
binding = binding.lower()
|
binding = binding.lower()
|
||||||
|
binding = config.val.bindings.key_mappings.get(binding, binding)
|
||||||
try:
|
try:
|
||||||
cmdstr = self.special_bindings[binding]
|
cmdstr = self.special_bindings[binding]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@ -183,6 +185,7 @@ class BaseKeyParser(QObject):
|
|||||||
return self.Match.none
|
return self.Match.none
|
||||||
|
|
||||||
self._stop_timers()
|
self._stop_timers()
|
||||||
|
txt = config.val.bindings.key_mappings.get(txt, txt)
|
||||||
self._keystring += txt
|
self._keystring += txt
|
||||||
|
|
||||||
count, cmd_input = self._split_count()
|
count, cmd_input = self._split_count()
|
||||||
@ -314,7 +317,11 @@ class BaseKeyParser(QObject):
|
|||||||
self.keystring_updated.emit(self._keystring)
|
self.keystring_updated.emit(self._keystring)
|
||||||
return match != self.Match.none
|
return match != self.Match.none
|
||||||
|
|
||||||
def read_config(self, modename=None):
|
@config.change_filter('bindings')
|
||||||
|
def _on_config_changed(self):
|
||||||
|
self._read_config()
|
||||||
|
|
||||||
|
def _read_config(self, modename=None):
|
||||||
"""Read the configuration.
|
"""Read the configuration.
|
||||||
|
|
||||||
Config format: key = command, e.g.:
|
Config format: key = command, e.g.:
|
||||||
@ -332,8 +339,8 @@ class BaseKeyParser(QObject):
|
|||||||
self._modename = modename
|
self._modename = modename
|
||||||
self.bindings = {}
|
self.bindings = {}
|
||||||
self.special_bindings = {}
|
self.special_bindings = {}
|
||||||
keyconfparser = objreg.get('key-config')
|
|
||||||
for (key, cmd) in keyconfparser.get_bindings_for(modename).items():
|
for key, cmd in config.val.bindings.commands[modename].items():
|
||||||
assert cmd
|
assert cmd
|
||||||
self._parse_key_command(modename, key, cmd)
|
self._parse_key_command(modename, key, cmd)
|
||||||
|
|
||||||
@ -359,15 +366,6 @@ class BaseKeyParser(QObject):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@pyqtSlot(str)
|
|
||||||
def on_keyconfig_changed(self, mode):
|
|
||||||
"""Re-read the config if a key binding was changed."""
|
|
||||||
if self._modename is None:
|
|
||||||
raise AssertionError("on_keyconfig_changed called but no section "
|
|
||||||
"defined!")
|
|
||||||
if mode == self._modename:
|
|
||||||
self.read_config()
|
|
||||||
|
|
||||||
def clear_keystring(self):
|
def clear_keystring(self):
|
||||||
"""Clear the currently entered key sequence."""
|
"""Clear the currently entered key sequence."""
|
||||||
if self._keystring:
|
if self._keystring:
|
||||||
|
@ -69,7 +69,7 @@ class PassthroughKeyParser(CommandKeyParser):
|
|||||||
"""
|
"""
|
||||||
super().__init__(win_id, parent, supports_chains=False)
|
super().__init__(win_id, parent, supports_chains=False)
|
||||||
self._warn_on_keychains = warn
|
self._warn_on_keychains = warn
|
||||||
self.read_config(mode)
|
self._read_config(mode)
|
||||||
self._mode = mode
|
self._mode = mode
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -48,7 +48,7 @@ class NormalKeyParser(keyparser.CommandKeyParser):
|
|||||||
def __init__(self, win_id, parent=None):
|
def __init__(self, win_id, parent=None):
|
||||||
super().__init__(win_id, parent, supports_count=True,
|
super().__init__(win_id, parent, supports_count=True,
|
||||||
supports_chains=True)
|
supports_chains=True)
|
||||||
self.read_config('normal')
|
self._read_config('normal')
|
||||||
self._partial_timer = usertypes.Timer(self, 'partial-match')
|
self._partial_timer = usertypes.Timer(self, 'partial-match')
|
||||||
self._partial_timer.setSingleShot(True)
|
self._partial_timer.setSingleShot(True)
|
||||||
self._inhibited = False
|
self._inhibited = False
|
||||||
@ -130,7 +130,7 @@ class PromptKeyParser(keyparser.CommandKeyParser):
|
|||||||
supports_chains=True)
|
supports_chains=True)
|
||||||
# We don't want an extra section for this in the config, so we just
|
# We don't want an extra section for this in the config, so we just
|
||||||
# abuse the prompt section.
|
# abuse the prompt section.
|
||||||
self.read_config('prompt')
|
self._read_config('prompt')
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self)
|
return utils.get_repr(self)
|
||||||
@ -150,7 +150,7 @@ class HintKeyParser(keyparser.CommandKeyParser):
|
|||||||
supports_chains=True)
|
supports_chains=True)
|
||||||
self._filtertext = ''
|
self._filtertext = ''
|
||||||
self._last_press = LastPress.none
|
self._last_press = LastPress.none
|
||||||
self.read_config('hint')
|
self._read_config('hint')
|
||||||
self.keystring_updated.connect(self.on_keystring_updated)
|
self.keystring_updated.connect(self.on_keystring_updated)
|
||||||
|
|
||||||
def _handle_special_key(self, e):
|
def _handle_special_key(self, e):
|
||||||
@ -264,7 +264,7 @@ class CaretKeyParser(keyparser.CommandKeyParser):
|
|||||||
def __init__(self, win_id, parent=None):
|
def __init__(self, win_id, parent=None):
|
||||||
super().__init__(win_id, parent, supports_count=True,
|
super().__init__(win_id, parent, supports_count=True,
|
||||||
supports_chains=True)
|
supports_chains=True)
|
||||||
self.read_config('caret')
|
self._read_config('caret')
|
||||||
|
|
||||||
|
|
||||||
class RegisterKeyParser(keyparser.CommandKeyParser):
|
class RegisterKeyParser(keyparser.CommandKeyParser):
|
||||||
@ -280,7 +280,7 @@ class RegisterKeyParser(keyparser.CommandKeyParser):
|
|||||||
super().__init__(win_id, parent, supports_count=False,
|
super().__init__(win_id, parent, supports_count=False,
|
||||||
supports_chains=False)
|
supports_chains=False)
|
||||||
self._mode = mode
|
self._mode = mode
|
||||||
self.read_config('register')
|
self._read_config('register')
|
||||||
|
|
||||||
def handle(self, e):
|
def handle(self, e):
|
||||||
"""Override handle to always match the next key and use the register.
|
"""Override handle to always match the next key and use the register.
|
||||||
|
@ -411,8 +411,6 @@ class MainWindow(QWidget):
|
|||||||
|
|
||||||
def _connect_signals(self):
|
def _connect_signals(self):
|
||||||
"""Connect all mainwindow signals."""
|
"""Connect all mainwindow signals."""
|
||||||
key_config = objreg.get('key-config')
|
|
||||||
|
|
||||||
status = self._get_object('statusbar')
|
status = self._get_object('statusbar')
|
||||||
keyparsers = self._get_object('keyparsers')
|
keyparsers = self._get_object('keyparsers')
|
||||||
completion_obj = self._get_object('completion')
|
completion_obj = self._get_object('completion')
|
||||||
@ -442,10 +440,6 @@ class MainWindow(QWidget):
|
|||||||
parser.keystring_updated.connect(functools.partial(
|
parser.keystring_updated.connect(functools.partial(
|
||||||
self._keyhint.update_keyhint, mode.name))
|
self._keyhint.update_keyhint, mode.name))
|
||||||
|
|
||||||
# config
|
|
||||||
for obj in keyparsers.values():
|
|
||||||
key_config.changed.connect(obj.on_keyconfig_changed)
|
|
||||||
|
|
||||||
# messages
|
# messages
|
||||||
message.global_bridge.show_message.connect(
|
message.global_bridge.show_message.connect(
|
||||||
self._messageview.show_message)
|
self._messageview.show_message)
|
||||||
|
Loading…
Reference in New Issue
Block a user