Handle completions for ValueList sections correctly
This commit is contained in:
parent
379a6219ec
commit
b74a97580f
1
TODO
1
TODO
@ -37,7 +37,6 @@ handle completion for aliases
|
|||||||
keybind should have completion for commands/arguments
|
keybind should have completion for commands/arguments
|
||||||
Hiding scrollbars
|
Hiding scrollbars
|
||||||
Ctrl+A/X to increase/decrease last number in URL
|
Ctrl+A/X to increase/decrease last number in URL
|
||||||
command completion gets hidden when doing a new ValueList value
|
|
||||||
logging contexts
|
logging contexts
|
||||||
catch import errors for PyQt and QtWebKit
|
catch import errors for PyQt and QtWebKit
|
||||||
- Add more element-selection-detection code (with options?) based on:
|
- Add more element-selection-detection code (with options?) based on:
|
||||||
|
@ -61,10 +61,20 @@ class SettingValueCompletionModel(BaseCompletionModel):
|
|||||||
|
|
||||||
# pylint: disable=abstract-method
|
# pylint: disable=abstract-method
|
||||||
|
|
||||||
def __init__(self, section, option, parent=None):
|
def __init__(self, section, option=None, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
cat = self.new_category("Setting values for {}".format(option))
|
if hasattr(configdata.DATA[section], 'valtype'):
|
||||||
vals = configdata.DATA[section][option].typ.complete()
|
# Same type for all values (ValueList)
|
||||||
|
cat = self.new_category("Setting values for {} options".format(
|
||||||
|
section))
|
||||||
|
vals = configdata.DATA[section].valtype.complete()
|
||||||
|
else:
|
||||||
|
if option is None:
|
||||||
|
raise ValueError("option may only be None for ValueList "
|
||||||
|
"sections, but {} is not!".format(section))
|
||||||
|
# Different type for each value (KeyValue)
|
||||||
|
cat = self.new_category("Setting values for {}".format(option))
|
||||||
|
vals = configdata.DATA[section][option].typ.complete()
|
||||||
if vals is None:
|
if vals is None:
|
||||||
raise NoCompletionsError
|
raise NoCompletionsError
|
||||||
for (val, desc) in vals:
|
for (val, desc) in vals:
|
||||||
|
@ -140,3 +140,18 @@ class NeighborList:
|
|||||||
else:
|
else:
|
||||||
self.idx = self._items.index(self._default)
|
self.idx = self._items.index(self._default)
|
||||||
return self.curitem()
|
return self.curitem()
|
||||||
|
|
||||||
|
|
||||||
|
class FakeDict:
|
||||||
|
|
||||||
|
"""A fake dictionary which always returns the same value.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
_val: The value to return.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, val):
|
||||||
|
self._val = val
|
||||||
|
|
||||||
|
def __getitem__(self, _key):
|
||||||
|
return self._val
|
||||||
|
@ -41,6 +41,7 @@ from qutebrowser.models.completionfilter import CompletionFilterModel
|
|||||||
from qutebrowser.models.completion import (
|
from qutebrowser.models.completion import (
|
||||||
CommandCompletionModel, SettingSectionCompletionModel,
|
CommandCompletionModel, SettingSectionCompletionModel,
|
||||||
SettingOptionCompletionModel, SettingValueCompletionModel)
|
SettingOptionCompletionModel, SettingValueCompletionModel)
|
||||||
|
from qutebrowser.utils.usertypes import FakeDict
|
||||||
|
|
||||||
|
|
||||||
class CompletionView(QTreeView):
|
class CompletionView(QTreeView):
|
||||||
@ -114,17 +115,7 @@ class CompletionView(QTreeView):
|
|||||||
'option': {},
|
'option': {},
|
||||||
'value': {},
|
'value': {},
|
||||||
}
|
}
|
||||||
for sect in configdata.DATA.keys():
|
self._init_completions()
|
||||||
self._models['option'][sect] = CompletionFilterModel(
|
|
||||||
SettingOptionCompletionModel(sect, self))
|
|
||||||
self._models['value'][sect] = {}
|
|
||||||
for opt in configdata.DATA[sect].keys():
|
|
||||||
try:
|
|
||||||
self._models['value'][sect][opt] = (
|
|
||||||
CompletionFilterModel(SettingValueCompletionModel(
|
|
||||||
sect, opt, self)))
|
|
||||||
except NoCompletionsError:
|
|
||||||
pass
|
|
||||||
self._completing = False
|
self._completing = False
|
||||||
|
|
||||||
self._delegate = _CompletionItemDelegate(self)
|
self._delegate = _CompletionItemDelegate(self)
|
||||||
@ -144,6 +135,29 @@ class CompletionView(QTreeView):
|
|||||||
self.hide()
|
self.hide()
|
||||||
# FIXME set elidemode
|
# FIXME set elidemode
|
||||||
|
|
||||||
|
def _init_completions(self):
|
||||||
|
"""Initialize completion models."""
|
||||||
|
for sectname, sect in configdata.DATA.items():
|
||||||
|
self._models['option'][sectname] = CompletionFilterModel(
|
||||||
|
SettingOptionCompletionModel(sectname, self))
|
||||||
|
if hasattr(sect, 'valtype'):
|
||||||
|
# Same type for all values (ValueList)
|
||||||
|
try:
|
||||||
|
model = CompletionFilterModel(
|
||||||
|
SettingValueCompletionModel(sectname, parent=self))
|
||||||
|
self._models['value'][sectname] = FakeDict(model)
|
||||||
|
except NoCompletionsError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self._models['value'][sectname] = {}
|
||||||
|
for opt in configdata.DATA[sectname].keys():
|
||||||
|
try:
|
||||||
|
self._models['value'][sectname][opt] = (
|
||||||
|
CompletionFilterModel(SettingValueCompletionModel(
|
||||||
|
sectname, opt, self)))
|
||||||
|
except NoCompletionsError:
|
||||||
|
pass
|
||||||
|
|
||||||
def _next_idx(self, upwards):
|
def _next_idx(self, upwards):
|
||||||
"""Get the previous/next QModelIndex displayed in the view.
|
"""Get the previous/next QModelIndex displayed in the view.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user