Fix key-config usage

This commit is contained in:
Florian Bruhin 2017-06-16 13:28:51 +02:00
parent aa75262fe4
commit 30f1970850
6 changed files with 30 additions and 22 deletions

View File

@ -277,7 +277,7 @@ def _get_cmd_completions(include_hidden, include_aliases, prefix=''):
""" """
assert cmdutils.cmd_dict assert cmdutils.cmd_dict
cmdlist = [] cmdlist = []
cmd_to_keys = objreg.get('key-config').get_reverse_bindings_for('normal') cmd_to_keys = config.key_instance.get_reverse_bindings_for('normal')
for obj in set(cmdutils.cmd_dict.values()): for obj in set(cmdutils.cmd_dict.values()):
hide_debug = obj.debug and not objreg.get('args').debug hide_debug = obj.debug and not objreg.get('args').debug
hide_hidden = obj.hide and not include_hidden hide_hidden = obj.hide and not include_hidden

View File

@ -56,6 +56,7 @@ UNSET = object()
# FIXME:conf for new config # FIXME:conf for new config
val = None val = None
instance = None instance = None
key_instance = None
def _init_main_config(parent=None): def _init_main_config(parent=None):
@ -171,12 +172,13 @@ def init(parent=None):
Args: Args:
parent: The parent to pass to QObjects which get initialized. parent: The parent to pass to QObjects which get initialized.
""" """
global val, instance global val, instance, key_instance
# _init_main_config(parent) # _init_main_config(parent)
configdata.init() configdata.init()
newconfig.init(parent) newconfig.init(parent)
val = newconfig.val val = newconfig.val
instance = newconfig.instance instance = newconfig.instance
key_instance = newconfig.key_instance
# _init_key_config(parent) # _init_key_config(parent)
_init_misc() _init_misc()

View File

@ -110,6 +110,26 @@ class change_filter: # pylint: disable=invalid-name
return wrapper return wrapper
class NewKeyConfig:
def get_reverse_bindings_for(self, section):
"""Get a dict of commands to a list of bindings for the section."""
cmd_to_keys = {}
bindings = val.bindings.commands[section]
if bindings is None:
return cmd_to_keys
for key, full_cmd in bindings.items():
for cmd in full_cmd.split(';;'):
cmd = cmd.strip()
cmd_to_keys.setdefault(cmd, [])
# put special bindings last
if utils.is_special_key(key):
cmd_to_keys[cmd].append(key)
else:
cmd_to_keys[cmd].insert(0, key)
return cmd_to_keys
class NewConfigManager(QObject): class NewConfigManager(QObject):
changed = pyqtSignal(str) # FIXME:conf stub... changed = pyqtSignal(str) # FIXME:conf stub...
@ -200,9 +220,10 @@ def init(parent):
new_config.read_defaults() new_config.read_defaults()
objreg.register('config', new_config) objreg.register('config', new_config)
global val, instance global val, instance, key_instance
val = ConfigContainer(new_config) val = ConfigContainer(new_config)
instance = new_config instance = new_config
key_instance = NewKeyConfig()
for cf in _change_filters: for cf in _change_filters:
cf.validate() cf.validate()

View File

@ -439,17 +439,3 @@ class KeyConfigParser(QObject):
bindings = {k: v for k, v in bindings.items() bindings = {k: v for k, v in bindings.items()
if v != self.UNBOUND_COMMAND} if v != self.UNBOUND_COMMAND}
return bindings return bindings
def get_reverse_bindings_for(self, section):
"""Get a dict of commands to a list of bindings for the section."""
cmd_to_keys = {}
for key, full_cmd in self.get_bindings_for(section).items():
for cmd in full_cmd.split(';;'):
cmd = cmd.strip()
cmd_to_keys.setdefault(cmd, [])
# put special bindings last
if utils.is_special_key(key):
cmd_to_keys[cmd].append(key)
else:
cmd_to_keys[cmd].insert(0, key)
return cmd_to_keys

View File

@ -482,9 +482,8 @@ class _BasePrompt(QWidget):
self._key_grid = QGridLayout() self._key_grid = QGridLayout()
self._key_grid.setVerticalSpacing(0) self._key_grid.setVerticalSpacing(0)
key_config = objreg.get('key-config')
# The bindings are all in the 'prompt' mode, even for yesno prompts # The bindings are all in the 'prompt' mode, even for yesno prompts
all_bindings = key_config.get_reverse_bindings_for('prompt') all_bindings = config.key_instance.get_reverse_bindings_for('prompt')
labels = [] labels = []
for cmd, text in self._allowed_commands(): for cmd, text in self._allowed_commands():

View File

@ -24,7 +24,8 @@ from PyQt5.QtWidgets import (QLineEdit, QWidget, QHBoxLayout, QLabel,
QStyleOption, QStyle, QLayout, QApplication) QStyleOption, QStyle, QLayout, QApplication)
from PyQt5.QtGui import QValidator, QPainter from PyQt5.QtGui import QValidator, QPainter
from qutebrowser.utils import utils, objreg, qtutils, log, usertypes from qutebrowser.config import config
from qutebrowser.utils import utils, qtutils, log, usertypes
from qutebrowser.misc import cmdhistory, objects from qutebrowser.misc import cmdhistory, objects
@ -289,8 +290,7 @@ class FullscreenNotification(QLabel):
padding: 30px; padding: 30px;
""") """)
key_config = objreg.get('key-config') all_bindings = config.key_instance.get_reverse_bindings_for('normal')
all_bindings = key_config.get_reverse_bindings_for('normal')
bindings = all_bindings.get('fullscreen --leave') bindings = all_bindings.get('fullscreen --leave')
if bindings: if bindings:
key = bindings[0] key = bindings[0]