Merge branch 'separate_completion_filters' of git://github.com/acogneau/qutebrowser into acogneau-separate_completion_filters
This commit is contained in:
commit
2a5d352c7b
@ -25,6 +25,7 @@ from qutebrowser.config import config
|
||||
from qutebrowser.commands import cmdexc, cmdutils, runners
|
||||
from qutebrowser.utils import usertypes, log, objreg, utils
|
||||
from qutebrowser.completion.models import instances
|
||||
from qutebrowser.completion.models.sortfilter import CompletionFilterModel
|
||||
|
||||
|
||||
class Completer(QObject):
|
||||
@ -153,7 +154,19 @@ class Completer(QObject):
|
||||
model = None
|
||||
else:
|
||||
model = instances.get(completion)
|
||||
return model
|
||||
return self._get_filter_completion_model(model)
|
||||
|
||||
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):
|
||||
"""Filter a list of commandline parts to exclude flags.
|
||||
@ -202,7 +215,8 @@ class Completer(QObject):
|
||||
"{}".format(parts, cursor_part))
|
||||
if cursor_part == 0:
|
||||
# '|' or 'set|'
|
||||
return instances.get(usertypes.Completion.command)
|
||||
model = instances.get(usertypes.Completion.command)
|
||||
return self._get_filter_completion_model(model)
|
||||
# delegate completion to command
|
||||
try:
|
||||
completions = cmdutils.cmd_dict[parts[0]].completion
|
||||
|
@ -43,9 +43,11 @@ class BaseCompletionModel(QStandardItemModel):
|
||||
Class Attributes:
|
||||
COLUMN_WIDTHS: The width percentages of the columns used in the
|
||||
completion view.
|
||||
DUMB_SORT: the dumb sorting used by the model
|
||||
"""
|
||||
|
||||
COLUMN_WIDTHS = (30, 70, 0)
|
||||
DUMB_SORT = None
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
@ -27,10 +27,9 @@ Module attributes:
|
||||
|
||||
import functools
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot, Qt
|
||||
from PyQt5.QtCore import pyqtSlot
|
||||
|
||||
from qutebrowser.completion.models import miscmodels, urlmodel, configmodel
|
||||
from qutebrowser.completion.models.sortfilter import CompletionFilterModel
|
||||
from qutebrowser.utils import objreg, usertypes, log, debug
|
||||
from qutebrowser.config import configdata
|
||||
|
||||
@ -38,7 +37,7 @@ from qutebrowser.config import configdata
|
||||
_instances = {}
|
||||
|
||||
|
||||
def _init_model(klass, *args, dumb_sort=None, **kwargs):
|
||||
def _init_model(klass, *args, **kwargs):
|
||||
"""Helper to initialize a model.
|
||||
|
||||
Args:
|
||||
@ -48,8 +47,7 @@ def _init_model(klass, *args, dumb_sort=None, **kwargs):
|
||||
dumb_sort: Passed to CompletionFilterModel.
|
||||
"""
|
||||
app = objreg.get('app')
|
||||
return CompletionFilterModel(klass(*args, parent=app, **kwargs),
|
||||
dumb_sort=dumb_sort, parent=app)
|
||||
return klass(*args, parent=app, **kwargs)
|
||||
|
||||
|
||||
def _init_command_completion():
|
||||
@ -70,8 +68,7 @@ def _init_url_completion():
|
||||
"""Initialize the URL completion model."""
|
||||
log.completion.debug("Initializing URL completion.")
|
||||
with debug.log_time(log.completion, 'URL completion init'):
|
||||
model = _init_model(urlmodel.UrlCompletionModel,
|
||||
dumb_sort=Qt.DescendingOrder)
|
||||
model = _init_model(urlmodel.UrlCompletionModel)
|
||||
_instances[usertypes.Completion.url] = model
|
||||
|
||||
|
||||
|
@ -41,11 +41,13 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
||||
_sort_order: The order to use for sorting if using dumb_sort.
|
||||
"""
|
||||
|
||||
def __init__(self, source, parent=None, *, dumb_sort=None):
|
||||
def __init__(self, source, parent=None):
|
||||
super().__init__(parent)
|
||||
super().setSourceModel(source)
|
||||
self.srcmodel = source
|
||||
self.pattern = ''
|
||||
|
||||
dumb_sort = self.srcmodel.DUMB_SORT
|
||||
if dumb_sort is None:
|
||||
# pylint: disable=invalid-name
|
||||
self.lessThan = self.intelligentLessThan
|
||||
|
@ -41,6 +41,7 @@ class UrlCompletionModel(base.BaseCompletionModel):
|
||||
TIME_COLUMN = 2
|
||||
|
||||
COLUMN_WIDTHS = (40, 50, 10)
|
||||
DUMB_SORT = Qt.DescendingOrder
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
Loading…
Reference in New Issue
Block a user