Merge branch 'quickmark-completion'

This commit is contained in:
Florian Bruhin 2014-10-20 00:29:46 +02:00
commit 596c33fe1c
6 changed files with 50 additions and 5 deletions

View File

@ -274,7 +274,8 @@ class CommandDispatcher:
tabbar.setSelectionBehaviorOnRemove(old_selection_behavior)
@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,
count: {'special': 'count'}=None):
"""Open a URL in the current/[count]th tab.
@ -818,7 +819,8 @@ class CommandDispatcher:
quickmark_manager = objreg.get('quickmark-manager')
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):
"""Load a quickmark.

View File

@ -21,7 +21,7 @@
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
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

View File

@ -207,3 +207,26 @@ class HelpCompletionModel(basecompletion.BaseCompletionModel):
desc = desc.splitlines()[0]
name = '{}->{}'.format(sectname, optname)
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))

View File

@ -36,7 +36,7 @@ class Completer(QObject):
Attributes:
_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.
Signals:
@ -61,6 +61,7 @@ class Completer(QObject):
}
self._init_static_completions()
self._init_setting_completions()
self.init_quickmark_completions()
def __repr__(self):
return utils.get_repr(self)
@ -94,6 +95,19 @@ class Completer(QObject):
self._models[usertypes.Completion.value][sectname][opt] = CFM(
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):
"""Get a new completion model.

View File

@ -230,7 +230,8 @@ KeyMode = enum('KeyMode', ['normal', 'hint', 'command', 'yesno', 'prompt',
# Available command completions
Completion = enum('Completion', ['command', 'section', 'option', 'value',
'helptopic'])
'helptopic', 'quickmark_by_url',
'quickmark_by_name'])
class Question(QObject):

View File

@ -264,6 +264,11 @@ class MainWindow(QWidget):
# downloads
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()
def resize_completion(self):
"""Adjust completion according to config."""