Move on_update_completion
This commit is contained in:
parent
2648f283b9
commit
7d440426eb
@ -410,7 +410,8 @@ class QuteBrowser(QApplication):
|
||||
cmd.clear_completion_selection.connect(
|
||||
completion.on_clear_completion_selection)
|
||||
cmd.hide_completion.connect(completion.hide)
|
||||
cmd.update_completion.connect(completion.on_update_completion)
|
||||
cmd.update_completion.connect(
|
||||
completion.completer.on_update_completion)
|
||||
completion.change_completed_part.connect(cmd.on_change_completed_part)
|
||||
|
||||
def _recover_pages(self):
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
"""Completer attached to a CompletionView."""
|
||||
|
||||
from PyQt5.QtCore import QObject
|
||||
from PyQt5.QtCore import QObject, pyqtSlot
|
||||
|
||||
import qutebrowser.config.config as config
|
||||
import qutebrowser.config.configdata as configdata
|
||||
@ -37,11 +37,17 @@ class Completer(QObject):
|
||||
"""Completer which manages completions in a CompletionView.
|
||||
|
||||
Attributes:
|
||||
view: The CompletionView associated with this completer.
|
||||
ignore_change: Whether to ignore the next completion update.
|
||||
_models: dict of available completion models.
|
||||
_lastmodel: The model set in the last iteration.
|
||||
"""
|
||||
|
||||
def __init__(self, view):
|
||||
super().__init__(view)
|
||||
self.view = view
|
||||
self.ignore_change = False
|
||||
self._lastmodel = None
|
||||
|
||||
self._models = {
|
||||
'option': {},
|
||||
@ -122,3 +128,58 @@ class Completer(QObject):
|
||||
else:
|
||||
model = self._models.get(completion_name)
|
||||
return model
|
||||
|
||||
@pyqtSlot(str, list, int)
|
||||
def on_update_completion(self, prefix, parts, cursor_part):
|
||||
"""Check if completions are available and activate them.
|
||||
|
||||
Slot for the textChanged signal of the statusbar command widget.
|
||||
|
||||
Args:
|
||||
text: The new text
|
||||
cursor_part: The part the cursor is currently over.
|
||||
"""
|
||||
if self.ignore_change:
|
||||
logger.debug("Ignoring completion update")
|
||||
return
|
||||
|
||||
logger.debug("Updating completion, parts: {}, cursor_part {}".format(
|
||||
parts, cursor_part))
|
||||
|
||||
if prefix != ':':
|
||||
# This is a search or gibberish, so we don't need to complete
|
||||
# anything (yet)
|
||||
# FIXME complete searchs
|
||||
self.view.hide()
|
||||
return
|
||||
|
||||
model = self._get_new_completion(parts, cursor_part)
|
||||
if model is None:
|
||||
logger.debug("No completion model for {}.".format(parts))
|
||||
else:
|
||||
logger.debug("New completion: {} / last: {}".format(
|
||||
model.srcmodel.__class__.__name__,
|
||||
self._lastmodel.srcmodel.__class__.__name__ if self._lastmodel
|
||||
is not None else "None"))
|
||||
if model != self._lastmodel:
|
||||
self._lastmodel = model
|
||||
if model is None:
|
||||
self.view.hide()
|
||||
return
|
||||
self.view.set_model(model)
|
||||
|
||||
if model is None:
|
||||
return
|
||||
|
||||
pattern = parts[cursor_part] if parts else ''
|
||||
logger.debug("pattern: {}".format(pattern))
|
||||
self.view.model().pattern = pattern
|
||||
|
||||
if self.view.model().item_count == 0:
|
||||
self.view.hide()
|
||||
return
|
||||
|
||||
self.view.model().mark_all_items(pattern)
|
||||
if self.view._enabled:
|
||||
self.view.show()
|
||||
|
||||
|
@ -47,7 +47,6 @@ class CompletionView(QTreeView):
|
||||
|
||||
Attributes:
|
||||
completer: The Completer instance to use.
|
||||
_ignore_change: Whether to ignore the next completion update.
|
||||
_lastmodel: The model set in the last iteration.
|
||||
_enabled: Whether showing the CompletionView is enabled.
|
||||
_height: The height to use for the CompletionView.
|
||||
@ -103,7 +102,6 @@ class CompletionView(QTreeView):
|
||||
super().__init__(parent)
|
||||
self.completer = Completer(self)
|
||||
self._enabled = config.get('completion', 'show')
|
||||
self._ignore_change = False
|
||||
self._lastmodel = None
|
||||
|
||||
self._delegate = CompletionItemDelegate(self)
|
||||
@ -203,60 +201,6 @@ class CompletionView(QTreeView):
|
||||
elif section == 'aliases':
|
||||
self._init_command_completion()
|
||||
|
||||
@pyqtSlot(str, list, int)
|
||||
def on_update_completion(self, prefix, parts, cursor_part):
|
||||
"""Check if completions are available and activate them.
|
||||
|
||||
Slot for the textChanged signal of the statusbar command widget.
|
||||
|
||||
Args:
|
||||
text: The new text
|
||||
cursor_part: The part the cursor is currently over.
|
||||
"""
|
||||
if self._ignore_change:
|
||||
logger.debug("Ignoring completion update")
|
||||
return
|
||||
|
||||
logger.debug("Updating completion, parts: {}, cursor_part {}".format(
|
||||
parts, cursor_part))
|
||||
|
||||
if prefix != ':':
|
||||
# This is a search or gibberish, so we don't need to complete
|
||||
# anything (yet)
|
||||
# FIXME complete searchs
|
||||
self.hide()
|
||||
return
|
||||
|
||||
model = self.completer._get_new_completion(parts, cursor_part)
|
||||
if model is None:
|
||||
logger.debug("No completion model for {}.".format(parts))
|
||||
else:
|
||||
logger.debug("New completion: {} / last: {}".format(
|
||||
model.srcmodel.__class__.__name__,
|
||||
self._lastmodel.srcmodel.__class__.__name__ if self._lastmodel
|
||||
is not None else "None"))
|
||||
if model != self._lastmodel:
|
||||
self._lastmodel = model
|
||||
if model is None:
|
||||
self.hide()
|
||||
return
|
||||
self.set_model(model)
|
||||
|
||||
if model is None:
|
||||
return
|
||||
|
||||
pattern = parts[cursor_part] if parts else ''
|
||||
logger.debug("pattern: {}".format(pattern))
|
||||
self.model().pattern = pattern
|
||||
|
||||
if self.model().item_count == 0:
|
||||
self.hide()
|
||||
return
|
||||
|
||||
self.model().mark_all_items(pattern)
|
||||
if self._enabled:
|
||||
self.show()
|
||||
|
||||
@pyqtSlot()
|
||||
def on_clear_completion_selection(self):
|
||||
"""Clear the selection model when an item is activated."""
|
||||
@ -297,9 +241,9 @@ class CompletionView(QTreeView):
|
||||
# and go on to the next part.
|
||||
self.change_completed_part.emit(data, True)
|
||||
else:
|
||||
self._ignore_change = True
|
||||
self.completer.ignore_change = True
|
||||
self.change_completed_part.emit(data, False)
|
||||
self._ignore_change = False
|
||||
self.completer.ignore_change = False
|
||||
super().selectionChanged(selected, deselected)
|
||||
|
||||
def resizeEvent(self, e):
|
||||
|
Loading…
Reference in New Issue
Block a user