Add completion for settings values
This commit is contained in:
parent
44ce804bdf
commit
f959c0c137
@ -263,7 +263,7 @@ class Config(QObject):
|
||||
return newval
|
||||
|
||||
@cmdutils.register(name='set', instance='config',
|
||||
completion=['section', 'option'])
|
||||
completion=['section', 'option', 'value'])
|
||||
def set_wrapper(self, section, option, value):
|
||||
"""Set an option.
|
||||
|
||||
@ -279,7 +279,7 @@ class Config(QObject):
|
||||
message.error("set: {} - {}".format(e.__class__.__name__, e))
|
||||
|
||||
@cmdutils.register(name='set_temp', instance='config',
|
||||
completion=['section', 'option'])
|
||||
completion=['section', 'option', 'value'])
|
||||
def set_temp_wrapper(self, section, option, value):
|
||||
"""Set a temporary option.
|
||||
|
||||
|
@ -100,6 +100,10 @@ class KeyValue:
|
||||
"""Get dict item tuples."""
|
||||
return self.values.items()
|
||||
|
||||
def keys(self):
|
||||
"""Get value keys."""
|
||||
return self.values.keys()
|
||||
|
||||
def from_cp(self, sect):
|
||||
"""Initialize the values from a configparser section.
|
||||
|
||||
@ -211,6 +215,10 @@ class ValueList:
|
||||
self.update_valdict()
|
||||
return self.valdict.items()
|
||||
|
||||
def keys(self):
|
||||
"""Get value keys."""
|
||||
return self.values.keys()
|
||||
|
||||
def from_cp(self, sect):
|
||||
"""Initialize the values from a configparser section."""
|
||||
keytype = self.keytype()
|
||||
|
@ -23,6 +23,13 @@ from PyQt5.QtCore import Qt, QVariant, QAbstractItemModel, QModelIndex
|
||||
ROLE_MARKS = Qt.UserRole
|
||||
|
||||
|
||||
class NoCompletionsError(Exception):
|
||||
|
||||
"""Gets raised when there are no completions available."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class CompletionModel(QAbstractItemModel):
|
||||
|
||||
"""A simple tree model based on Python OrderdDict containing tuples.
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
"""CompletionModels for settings/sections."""
|
||||
|
||||
from qutebrowser.models.completion import CompletionModel
|
||||
from qutebrowser.models.completion import CompletionModel, NoCompletionsError
|
||||
from qutebrowser.config.configdata import configdata
|
||||
|
||||
|
||||
@ -50,3 +50,23 @@ class SettingOptionCompletionModel(CompletionModel):
|
||||
except (KeyError, AttributeError):
|
||||
desc = ""
|
||||
self.new_item(cat, name, desc)
|
||||
|
||||
|
||||
class SettingValueCompletionModel(CompletionModel):
|
||||
|
||||
"""A CompletionModel filled with setting values."""
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
|
||||
def __init__(self, section, option, parent=None):
|
||||
super().__init__(parent)
|
||||
cat = self.new_category("Setting values for {}".format(option))
|
||||
vals = configdata()[section][option].typ.valid_values
|
||||
if vals is None:
|
||||
raise NoCompletionsError
|
||||
for val in vals:
|
||||
try:
|
||||
desc = vals.descriptions[val]
|
||||
except KeyError:
|
||||
desc = ""
|
||||
self.new_item(cat, val, desc)
|
||||
|
@ -34,13 +34,14 @@ from PyQt5.QtGui import (QIcon, QPalette, QTextDocument, QTextOption,
|
||||
import qutebrowser.config.config as config
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
from qutebrowser.config.configdata import configdata
|
||||
from qutebrowser.models.completion import ROLE_MARKS
|
||||
from qutebrowser.models.completion import ROLE_MARKS, NoCompletionsError
|
||||
from qutebrowser.config.style import set_register_stylesheet, get_stylesheet
|
||||
from qutebrowser.commands.parsers import split_cmdline
|
||||
from qutebrowser.models.completionfilter import CompletionFilterModel
|
||||
from qutebrowser.models.commandcompletion import CommandCompletionModel
|
||||
from qutebrowser.models.settingcompletion import (
|
||||
SettingSectionCompletionModel, SettingOptionCompletionModel)
|
||||
SettingSectionCompletionModel, SettingOptionCompletionModel,
|
||||
SettingValueCompletionModel)
|
||||
|
||||
|
||||
class CompletionView(QTreeView):
|
||||
@ -112,6 +113,13 @@ class CompletionView(QTreeView):
|
||||
for sect in configdata().keys():
|
||||
self._completion_models['option_' + sect] = CompletionFilterModel(
|
||||
SettingOptionCompletionModel(sect, self))
|
||||
for opt in configdata()[sect].keys():
|
||||
try:
|
||||
self._completion_models['value_{}_{}'.format(sect,opt)] = (
|
||||
CompletionFilterModel(SettingValueCompletionModel(sect,
|
||||
opt, self)))
|
||||
except NoCompletionsError:
|
||||
pass
|
||||
self._ignore_next = False
|
||||
self._completing = False
|
||||
|
||||
@ -178,9 +186,12 @@ class CompletionView(QTreeView):
|
||||
return None
|
||||
if compl == 'option':
|
||||
compl = 'option_' + parts[-2]
|
||||
elif compl == 'value':
|
||||
compl = 'value_{}_{}'.format(parts[-3], parts[-2])
|
||||
if compl in self._completion_models:
|
||||
return compl
|
||||
else:
|
||||
logging.debug("No completion model for {}.".format(compl))
|
||||
return None
|
||||
|
||||
def set_model(self, model):
|
||||
|
Loading…
Reference in New Issue
Block a user