From 93c6d8ea2ffca34075d12692388bc00694fcbcd1 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 4 Jun 2014 06:44:07 +0200 Subject: [PATCH] Add current value to completions for settings --- TODO | 1 - qutebrowser/models/completion.py | 15 ++++++++++++++- qutebrowser/utils/completer.py | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 25687e91a..c6f30a2a2 100644 --- a/TODO +++ b/TODO @@ -42,7 +42,6 @@ New big features Improvements / minor features ============================= -- Add current value as completion item for settings - Reimplement tabbar to paint it by ourselves to look like dwb - Save cookies in Netscape format so it can be used by wget. http://www.cookiecentral.com/faq/#3.5 diff --git a/qutebrowser/models/completion.py b/qutebrowser/models/completion.py index ffc3340d2..9f356f838 100644 --- a/qutebrowser/models/completion.py +++ b/qutebrowser/models/completion.py @@ -89,6 +89,11 @@ class SettingValueCompletionModel(BaseCompletionModel): def __init__(self, section, option=None, parent=None): super().__init__(parent) + cur_cat = self.new_category("Current") + value = config.get(section, option, raw=True) + if not value: + value = '""' + self.cur_item = self.new_item(cur_cat, value, "Current value") if hasattr(configdata.DATA[section], 'valtype'): # Same type for all values (ValueList) vals = configdata.DATA[section].valtype.complete() @@ -99,10 +104,18 @@ class SettingValueCompletionModel(BaseCompletionModel): # Different type for each value (KeyValue) vals = configdata.DATA[section][option].typ.complete() if vals is not None: - cat = self.new_category(section) + cat = self.new_category("Allowed") for (val, desc) in vals: self.new_item(cat, val, desc) + @pyqtSlot(str, str) + def on_config_changed(self, section, option): + """Update current value when config changed.""" + value = config.get(section, option) + if not value: + value = '""' + self.setData(self.cur_item.index(), value, Qt.DisplayRole) + class CommandCompletionModel(BaseCompletionModel): diff --git a/qutebrowser/utils/completer.py b/qutebrowser/utils/completer.py index 439458420..d84f02b99 100644 --- a/qutebrowser/utils/completer.py +++ b/qutebrowser/utils/completer.py @@ -80,6 +80,7 @@ class Completer(QObject): for opt in configdata.DATA[sectname].keys(): model = SettingValueCompletionModel(sectname, opt, self) self._models['value'][sectname][opt] = CFM(model) + config.instance().changed.connect(model.on_config_changed) def _get_new_completion(self, parts, cursor_part): """Get a new completion model.