Cleanup
This commit is contained in:
parent
17f971344d
commit
fc6c49f57c
@ -24,8 +24,7 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QTimer
|
|||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.commands import cmdexc, cmdutils, runners
|
from qutebrowser.commands import cmdexc, cmdutils, runners
|
||||||
from qutebrowser.utils import usertypes, log, objreg, utils
|
from qutebrowser.utils import usertypes, log, objreg, utils
|
||||||
from qutebrowser.completion.models import instances
|
from qutebrowser.completion.models import instances, sortfilter
|
||||||
from qutebrowser.completion.models.sortfilter import CompletionFilterModel
|
|
||||||
|
|
||||||
|
|
||||||
class Completer(QObject):
|
class Completer(QObject):
|
||||||
@ -154,19 +153,7 @@ class Completer(QObject):
|
|||||||
model = None
|
model = None
|
||||||
else:
|
else:
|
||||||
model = instances.get(completion)
|
model = instances.get(completion)
|
||||||
return self._get_filter_completion_model(model)
|
return sortfilter.CompletionFilterModel(source=model, parent=self)
|
||||||
|
|
||||||
def _get_filter_completion_model(self, model):
|
|
||||||
"""Wrap the argument model with a CompletionFilterModel.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
model: the source model.
|
|
||||||
|
|
||||||
Return:
|
|
||||||
A completion filter model.
|
|
||||||
"""
|
|
||||||
filtermodel = CompletionFilterModel(source=model, parent=self)
|
|
||||||
return filtermodel
|
|
||||||
|
|
||||||
def _filter_cmdline_parts(self, parts, cursor_part):
|
def _filter_cmdline_parts(self, parts, cursor_part):
|
||||||
"""Filter a list of commandline parts to exclude flags.
|
"""Filter a list of commandline parts to exclude flags.
|
||||||
@ -216,7 +203,7 @@ class Completer(QObject):
|
|||||||
if cursor_part == 0:
|
if cursor_part == 0:
|
||||||
# '|' or 'set|'
|
# '|' or 'set|'
|
||||||
model = instances.get(usertypes.Completion.command)
|
model = instances.get(usertypes.Completion.command)
|
||||||
return self._get_filter_completion_model(model)
|
return sortfilter.CompletionFilterModel(source=model, parent=self)
|
||||||
# delegate completion to command
|
# delegate completion to command
|
||||||
try:
|
try:
|
||||||
completions = cmdutils.cmd_dict[parts[0]].completion
|
completions = cmdutils.cmd_dict[parts[0]].completion
|
||||||
|
@ -37,30 +37,17 @@ from qutebrowser.config import configdata
|
|||||||
_instances = {}
|
_instances = {}
|
||||||
|
|
||||||
|
|
||||||
def _init_model(klass, *args, **kwargs):
|
|
||||||
"""Helper to initialize a model.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
klass: The class of the model to initialize.
|
|
||||||
*args: Arguments to pass to the model.
|
|
||||||
**kwargs: Keyword arguments to pass to the model.
|
|
||||||
dumb_sort: Passed to CompletionFilterModel.
|
|
||||||
"""
|
|
||||||
app = objreg.get('app')
|
|
||||||
return klass(*args, parent=app, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def _init_command_completion():
|
def _init_command_completion():
|
||||||
"""Initialize the command completion model."""
|
"""Initialize the command completion model."""
|
||||||
log.completion.debug("Initializing command completion.")
|
log.completion.debug("Initializing command completion.")
|
||||||
model = _init_model(miscmodels.CommandCompletionModel)
|
model = miscmodels.CommandCompletionModel()
|
||||||
_instances[usertypes.Completion.command] = model
|
_instances[usertypes.Completion.command] = model
|
||||||
|
|
||||||
|
|
||||||
def _init_helptopic_completion():
|
def _init_helptopic_completion():
|
||||||
"""Initialize the helptopic completion model."""
|
"""Initialize the helptopic completion model."""
|
||||||
log.completion.debug("Initializing helptopic completion.")
|
log.completion.debug("Initializing helptopic completion.")
|
||||||
model = _init_model(miscmodels.HelpCompletionModel)
|
model = miscmodels.HelpCompletionModel()
|
||||||
_instances[usertypes.Completion.helptopic] = model
|
_instances[usertypes.Completion.helptopic] = model
|
||||||
|
|
||||||
|
|
||||||
@ -68,24 +55,23 @@ def _init_url_completion():
|
|||||||
"""Initialize the URL completion model."""
|
"""Initialize the URL completion model."""
|
||||||
log.completion.debug("Initializing URL completion.")
|
log.completion.debug("Initializing URL completion.")
|
||||||
with debug.log_time(log.completion, 'URL completion init'):
|
with debug.log_time(log.completion, 'URL completion init'):
|
||||||
model = _init_model(urlmodel.UrlCompletionModel)
|
model = urlmodel.UrlCompletionModel()
|
||||||
_instances[usertypes.Completion.url] = model
|
_instances[usertypes.Completion.url] = model
|
||||||
|
|
||||||
|
|
||||||
def _init_setting_completions():
|
def _init_setting_completions():
|
||||||
"""Initialize setting completion models."""
|
"""Initialize setting completion models."""
|
||||||
log.completion.debug("Initializing setting completion.")
|
log.completion.debug("Initializing setting completion.")
|
||||||
_instances[usertypes.Completion.section] = _init_model(
|
_instances[usertypes.Completion.section] = (
|
||||||
configmodel.SettingSectionCompletionModel)
|
configmodel.SettingSectionCompletionModel())
|
||||||
_instances[usertypes.Completion.option] = {}
|
_instances[usertypes.Completion.option] = {}
|
||||||
_instances[usertypes.Completion.value] = {}
|
_instances[usertypes.Completion.value] = {}
|
||||||
for sectname in configdata.DATA:
|
for sectname in configdata.DATA:
|
||||||
model = _init_model(configmodel.SettingOptionCompletionModel, sectname)
|
model = configmodel.SettingOptionCompletionModel(sectname)
|
||||||
_instances[usertypes.Completion.option][sectname] = model
|
_instances[usertypes.Completion.option][sectname] = model
|
||||||
_instances[usertypes.Completion.value][sectname] = {}
|
_instances[usertypes.Completion.value][sectname] = {}
|
||||||
for opt in configdata.DATA[sectname].keys():
|
for opt in configdata.DATA[sectname].keys():
|
||||||
model = _init_model(configmodel.SettingValueCompletionModel,
|
model = configmodel.SettingValueCompletionModel(sectname, opt)
|
||||||
sectname, opt)
|
|
||||||
_instances[usertypes.Completion.value][sectname][opt] = model
|
_instances[usertypes.Completion.value][sectname][opt] = model
|
||||||
|
|
||||||
|
|
||||||
@ -97,7 +83,7 @@ def init_quickmark_completions():
|
|||||||
_instances[usertypes.Completion.quickmark_by_name].deleteLater()
|
_instances[usertypes.Completion.quickmark_by_name].deleteLater()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
model = _init_model(miscmodels.QuickmarkCompletionModel)
|
model = miscmodels.QuickmarkCompletionModel()
|
||||||
_instances[usertypes.Completion.quickmark_by_name] = model
|
_instances[usertypes.Completion.quickmark_by_name] = model
|
||||||
|
|
||||||
|
|
||||||
@ -109,7 +95,7 @@ def init_bookmark_completions():
|
|||||||
_instances[usertypes.Completion.bookmark_by_url].deleteLater()
|
_instances[usertypes.Completion.bookmark_by_url].deleteLater()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
model = _init_model(miscmodels.BookmarkCompletionModel)
|
model = miscmodels.BookmarkCompletionModel()
|
||||||
_instances[usertypes.Completion.bookmark_by_url] = model
|
_instances[usertypes.Completion.bookmark_by_url] = model
|
||||||
|
|
||||||
|
|
||||||
@ -121,7 +107,7 @@ def init_session_completion():
|
|||||||
_instances[usertypes.Completion.sessions].deleteLater()
|
_instances[usertypes.Completion.sessions].deleteLater()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
model = _init_model(miscmodels.SessionCompletionModel)
|
model = miscmodels.SessionCompletionModel()
|
||||||
_instances[usertypes.Completion.sessions] = model
|
_instances[usertypes.Completion.sessions] = model
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user