Merge branch 'quickmark-completion'
This commit is contained in:
commit
596c33fe1c
@ -274,7 +274,8 @@ class CommandDispatcher:
|
|||||||
tabbar.setSelectionBehaviorOnRemove(old_selection_behavior)
|
tabbar.setSelectionBehaviorOnRemove(old_selection_behavior)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', name='open',
|
@cmdutils.register(instance='command-dispatcher', name='open',
|
||||||
split=False, scope='window')
|
split=False, scope='window',
|
||||||
|
completion=[usertypes.Completion.quickmark_by_url])
|
||||||
def openurl(self, url, bg=False, tab=False, window=False,
|
def openurl(self, url, bg=False, tab=False, window=False,
|
||||||
count: {'special': 'count'}=None):
|
count: {'special': 'count'}=None):
|
||||||
"""Open a URL in the current/[count]th tab.
|
"""Open a URL in the current/[count]th tab.
|
||||||
@ -818,7 +819,8 @@ class CommandDispatcher:
|
|||||||
quickmark_manager = objreg.get('quickmark-manager')
|
quickmark_manager = objreg.get('quickmark-manager')
|
||||||
quickmark_manager.prompt_save(self._win_id, self._current_url())
|
quickmark_manager.prompt_save(self._win_id, self._current_url())
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
|
completion=[usertypes.Completion.quickmark_by_name])
|
||||||
def quickmark_load(self, name, tab=False, bg=False, window=False):
|
def quickmark_load(self, name, tab=False, bg=False, window=False):
|
||||||
"""Load a quickmark.
|
"""Load a quickmark.
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
Note we violate our general QUrl rule by storing url strings in the marks
|
Note we violate our general QUrl rule by storing url strings in the marks
|
||||||
OrderedDict. This is because we read them from a file at start and write them
|
OrderedDict. This is because we read them from a file at start and write them
|
||||||
to a file on shutdown, so it makes semse to keep them as strings here.
|
to a file on shutdown, so it makes sense to keep them as strings here.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
@ -207,3 +207,26 @@ class HelpCompletionModel(basecompletion.BaseCompletionModel):
|
|||||||
desc = desc.splitlines()[0]
|
desc = desc.splitlines()[0]
|
||||||
name = '{}->{}'.format(sectname, optname)
|
name = '{}->{}'.format(sectname, optname)
|
||||||
self.new_item(cat, name, desc)
|
self.new_item(cat, name, desc)
|
||||||
|
|
||||||
|
|
||||||
|
class QuickmarkCompletionModel(basecompletion.BaseCompletionModel):
|
||||||
|
|
||||||
|
"""A CompletionModel filled with all quickmarks."""
|
||||||
|
|
||||||
|
# pylint: disable=abstract-method
|
||||||
|
|
||||||
|
def __init__(self, match_field='url', parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
|
||||||
|
cat = self.new_category("Quickmarks")
|
||||||
|
quickmarks = objreg.get('quickmark-manager').marks.items()
|
||||||
|
|
||||||
|
if match_field == 'url':
|
||||||
|
for qm_name, qm_url in quickmarks:
|
||||||
|
self.new_item(cat, qm_url, qm_name)
|
||||||
|
elif match_field == 'name':
|
||||||
|
for qm_name, qm_url in quickmarks:
|
||||||
|
self.new_item(cat, qm_name, qm_url)
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid value '{}' for match_field!".format(
|
||||||
|
match_field))
|
||||||
|
@ -36,7 +36,7 @@ class Completer(QObject):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
_ignore_change: Whether to ignore the next completion update.
|
_ignore_change: Whether to ignore the next completion update.
|
||||||
_models: dict of available completion models.
|
models: dict of available completion models.
|
||||||
_win_id: The window ID this completer is in.
|
_win_id: The window ID this completer is in.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
@ -61,6 +61,7 @@ class Completer(QObject):
|
|||||||
}
|
}
|
||||||
self._init_static_completions()
|
self._init_static_completions()
|
||||||
self._init_setting_completions()
|
self._init_setting_completions()
|
||||||
|
self.init_quickmark_completions()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self)
|
return utils.get_repr(self)
|
||||||
@ -94,6 +95,19 @@ class Completer(QObject):
|
|||||||
self._models[usertypes.Completion.value][sectname][opt] = CFM(
|
self._models[usertypes.Completion.value][sectname][opt] = CFM(
|
||||||
model, self)
|
model, self)
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def init_quickmark_completions(self):
|
||||||
|
"""Initialize quickmark completion models."""
|
||||||
|
try:
|
||||||
|
self._models[usertypes.Completion.quickmark_by_url].deleteLater()
|
||||||
|
self._models[usertypes.Completion.quickmark_by_name].deleteLater()
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
self._models[usertypes.Completion.quickmark_by_url] = CFM(
|
||||||
|
models.QuickmarkCompletionModel('url', self), self)
|
||||||
|
self._models[usertypes.Completion.quickmark_by_name] = CFM(
|
||||||
|
models.QuickmarkCompletionModel('name', self), self)
|
||||||
|
|
||||||
def _get_new_completion(self, parts, cursor_part):
|
def _get_new_completion(self, parts, cursor_part):
|
||||||
"""Get a new completion model.
|
"""Get a new completion model.
|
||||||
|
|
||||||
|
@ -230,7 +230,8 @@ KeyMode = enum('KeyMode', ['normal', 'hint', 'command', 'yesno', 'prompt',
|
|||||||
|
|
||||||
# Available command completions
|
# Available command completions
|
||||||
Completion = enum('Completion', ['command', 'section', 'option', 'value',
|
Completion = enum('Completion', ['command', 'section', 'option', 'value',
|
||||||
'helptopic'])
|
'helptopic', 'quickmark_by_url',
|
||||||
|
'quickmark_by_name'])
|
||||||
|
|
||||||
|
|
||||||
class Question(QObject):
|
class Question(QObject):
|
||||||
|
@ -264,6 +264,11 @@ class MainWindow(QWidget):
|
|||||||
# downloads
|
# downloads
|
||||||
tabs.start_download.connect(download_manager.fetch)
|
tabs.start_download.connect(download_manager.fetch)
|
||||||
|
|
||||||
|
# quickmark completion
|
||||||
|
completer = self._get_object('completer')
|
||||||
|
quickmark_manager = objreg.get('quickmark-manager')
|
||||||
|
quickmark_manager.changed.connect(completer.init_quickmark_completions)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def resize_completion(self):
|
def resize_completion(self):
|
||||||
"""Adjust completion according to config."""
|
"""Adjust completion according to config."""
|
||||||
|
Loading…
Reference in New Issue
Block a user