quickmarks completion
It works, but: * terrible performance (5s for ~1600 marks) * split and join operations in the loop - i want direct access to name + url in the marks dict! how?
This commit is contained in:
parent
da0d81e700
commit
777e93bd3f
@ -817,7 +817,8 @@ class CommandDispatcher:
|
|||||||
"""Save the current page as a quickmark."""
|
"""Save the current page as a quickmark."""
|
||||||
quickmarks.prompt_save(self._win_id, self._current_url())
|
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):
|
def quickmark_load(self, name, tab=False, bg=False, window=False):
|
||||||
"""Load a quickmark.
|
"""Load a quickmark.
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ from qutebrowser.config import config, configdata
|
|||||||
from qutebrowser.models import basecompletion
|
from qutebrowser.models import basecompletion
|
||||||
from qutebrowser.utils import log, qtutils, objreg
|
from qutebrowser.utils import log, qtutils, objreg
|
||||||
from qutebrowser.commands import cmdutils
|
from qutebrowser.commands import cmdutils
|
||||||
|
from qutebrowser.browser import quickmarks
|
||||||
|
|
||||||
|
|
||||||
class SettingSectionCompletionModel(basecompletion.BaseCompletionModel):
|
class SettingSectionCompletionModel(basecompletion.BaseCompletionModel):
|
||||||
@ -192,3 +193,30 @@ 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, 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)
|
||||||
|
|
||||||
|
@ -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,13 @@ class Completer(QObject):
|
|||||||
self._models[usertypes.Completion.value][sectname][opt] = CFM(
|
self._models[usertypes.Completion.value][sectname][opt] = CFM(
|
||||||
model, self)
|
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):
|
def _get_new_completion(self, parts, cursor_part):
|
||||||
"""Get a new completion model.
|
"""Get a new completion model.
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ 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'])
|
||||||
|
|
||||||
|
|
||||||
class Question(QObject):
|
class Question(QObject):
|
||||||
|
Loading…
Reference in New Issue
Block a user