Simplify setting value completion models.
This commit is contained in:
parent
e55174793a
commit
062b7b177b
@ -91,19 +91,17 @@ class SettingValueCompletionModel(BaseCompletionModel):
|
||||
super().__init__(parent)
|
||||
if hasattr(configdata.DATA[section], 'valtype'):
|
||||
# Same type for all values (ValueList)
|
||||
cat = self.new_category(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(option)
|
||||
vals = configdata.DATA[section][option].typ.complete()
|
||||
if vals is None:
|
||||
raise NoCompletionsError
|
||||
for (val, desc) in vals:
|
||||
self.new_item(cat, val, desc)
|
||||
if vals is not None:
|
||||
cat = self.new_category(section)
|
||||
for (val, desc) in vals:
|
||||
self.new_item(cat, val, desc)
|
||||
|
||||
|
||||
class CommandCompletionModel(BaseCompletionModel):
|
||||
|
@ -73,26 +73,13 @@ class Completer(QObject):
|
||||
self._models['option'] = {}
|
||||
self._models['value'] = {}
|
||||
for sectname, sect in configdata.DATA.items():
|
||||
optmodel = CFM(SettingOptionCompletionModel(sectname, self))
|
||||
self._models['option'][sectname] = optmodel
|
||||
config.instance().changed.connect(
|
||||
optmodel.srcmodel.on_config_changed)
|
||||
if hasattr(sect, 'valtype'):
|
||||
# Same type for all values (ValueList)
|
||||
try:
|
||||
model = CFM(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] = CFM(
|
||||
SettingValueCompletionModel(sectname, opt, self))
|
||||
except NoCompletionsError:
|
||||
pass
|
||||
model = SettingOptionCompletionModel(sectname, self)
|
||||
self._models['option'][sectname] = CFM(model)
|
||||
config.instance().changed.connect(model.on_config_changed)
|
||||
self._models['value'][sectname] = {}
|
||||
for opt in configdata.DATA[sectname].keys():
|
||||
model = SettingValueCompletionModel(sectname, opt, self)
|
||||
self._models['value'][sectname][opt] = CFM(model)
|
||||
|
||||
def _get_new_completion(self, parts, cursor_part):
|
||||
"""Get a new completion model.
|
||||
|
Loading…
Reference in New Issue
Block a user