diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 333195d6e..0fc7c4ea8 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -817,7 +817,8 @@ class CommandDispatcher: """Save the current page as a quickmark.""" quickmarks.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]) def quickmark_load(self, name, tab=False, bg=False, window=False): """Load a quickmark. diff --git a/qutebrowser/models/completion.py b/qutebrowser/models/completion.py index 98bf46635..e40a0bed7 100644 --- a/qutebrowser/models/completion.py +++ b/qutebrowser/models/completion.py @@ -25,6 +25,7 @@ from qutebrowser.config import config, configdata from qutebrowser.models import basecompletion from qutebrowser.utils import log, qtutils, objreg from qutebrowser.commands import cmdutils +from qutebrowser.browser import quickmarks class SettingSectionCompletionModel(basecompletion.BaseCompletionModel): @@ -192,3 +193,30 @@ 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, parent=None): + super().__init__(parent) + assert cmdutils.cmd_dict + + qmlist = [] + for qm in quickmarks.marks.items(): + # strange. in qm[0] is the first word of the quickmark, + # in qm[1] the rest. I have to split the url manually. + # omg help wtf bbq! FIXME + + qm_splitter = str(qm[0] + ' ' + qm[1]).split(' ') + qm_name = ' '.join(qm_splitter[:-1]) + qm_url = qm_splitter[-1] + qmlist.append((qm_url, qm_name)) + + cat = self.new_category("Quickmarks") + for (name, desc) in sorted(qmlist): + self.new_item(cat, name, desc) + diff --git a/qutebrowser/utils/completer.py b/qutebrowser/utils/completer.py index b3202bcf4..ec8add8c9 100644 --- a/qutebrowser/utils/completer.py +++ b/qutebrowser/utils/completer.py @@ -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,13 @@ class Completer(QObject): self._models[usertypes.Completion.value][sectname][opt] = CFM( model, self) + def _init_quickmark_completions(self): + """Initialize the quickmark completion models.""" + self._models[usertypes.Completion.quickmark] = CFM( + models.QuickmarkCompletionModel(self), self) + self._models[usertypes.Completion.helptopic] = CFM( + models.HelpCompletionModel(self), self) + def _get_new_completion(self, parts, cursor_part): """Get a new completion model. diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index 409fac36c..7bcb0ef7d 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -230,7 +230,7 @@ KeyMode = enum('KeyMode', ['normal', 'hint', 'command', 'yesno', 'prompt', # Available command completions Completion = enum('Completion', ['command', 'section', 'option', 'value', - 'helptopic']) + 'helptopic', 'quickmark']) class Question(QObject):