Added bookmarks command.

This commit is contained in:
Antoni Boucher 2015-05-24 19:07:57 -04:00
parent aaf35536a7
commit ece32e930c
4 changed files with 18 additions and 8 deletions

View File

@ -30,8 +30,8 @@ import collections
from PyQt5.QtCore import pyqtSignal, QUrl, QObject from PyQt5.QtCore import pyqtSignal, QUrl, QObject
from qutebrowser.utils import message, usertypes, urlutils, standarddir, objreg from qutebrowser.utils import message, urlutils, standarddir, objreg
from qutebrowser.commands import cmdexc, cmdutils from qutebrowser.commands import cmdexc
from qutebrowser.misc import lineparser from qutebrowser.misc import lineparser

View File

@ -996,6 +996,20 @@ class CommandDispatcher:
bookmark_manager.bookmark_add(self._win_id, self._current_url(), bookmark_manager.bookmark_add(self._win_id, self._current_url(),
self._current_title()) self._current_title())
@cmdutils.register(instance='command-dispatcher', scope='window',
maxsplit=0,
completion=[usertypes.Completion.bookmark_by_url])
def bookmarks(self, url, tab=False, bg=False, window=False):
"""Load a bookmark.
Args:
url: The url of the bookmark to load.
tab: Load the bookmark in a new tab.
bg: Load the bookmark in a new background tab.
window: Load the bookmark in a new window.
"""
self._open(QUrl(url), tab, bg, window)
@cmdutils.register(instance='command-dispatcher', name='inspector', @cmdutils.register(instance='command-dispatcher', name='inspector',
scope='window') scope='window')
def toggle_inspector(self): def toggle_inspector(self):

View File

@ -113,13 +113,11 @@ def init_bookmark_completions():
log.completion.debug("Initializing bookmark completion.") log.completion.debug("Initializing bookmark completion.")
try: try:
_instances[usertypes.Completion.bookmark_by_url].deleteLater() _instances[usertypes.Completion.bookmark_by_url].deleteLater()
_instances[usertypes.Completion.bookmark_by_title].deleteLater()
except KeyError: except KeyError:
pass pass
model = _init_model(miscmodels.BookmarkCompletionModel, 'url') model = _init_model(miscmodels.BookmarkCompletionModel, 'url')
_instances[usertypes.Completion.bookmark_by_url] = model _instances[usertypes.Completion.bookmark_by_url] = model
model = _init_model(miscmodels.BookmarkCompletionModel, 'title') model = _init_model(miscmodels.BookmarkCompletionModel, 'title')
_instances[usertypes.Completion.bookmark_by_title] = model
@pyqtSlot() @pyqtSlot()
@ -144,7 +142,6 @@ INITIALIZERS = {
usertypes.Completion.quickmark_by_url: init_quickmark_completions, usertypes.Completion.quickmark_by_url: init_quickmark_completions,
usertypes.Completion.quickmark_by_name: init_quickmark_completions, usertypes.Completion.quickmark_by_name: init_quickmark_completions,
usertypes.Completion.bookmark_by_url: init_bookmark_completions, usertypes.Completion.bookmark_by_url: init_bookmark_completions,
usertypes.Completion.bookmark_by_title: init_bookmark_completions,
usertypes.Completion.sessions: init_session_completion, usertypes.Completion.sessions: init_session_completion,
} }
@ -184,8 +181,7 @@ def init():
usertypes.Completion.quickmark_by_name])) usertypes.Completion.quickmark_by_name]))
bookmark_manager = objreg.get('bookmark-manager') bookmark_manager = objreg.get('bookmark-manager')
bookmark_manager.changed.connect( bookmark_manager.changed.connect(
functools.partial(update, [usertypes.Completion.bookmark_by_url, functools.partial(update, [usertypes.Completion.bookmark_by_url]))
usertypes.Completion.bookmark_by_title]))
session_manager = objreg.get('session-manager') session_manager = objreg.get('session-manager')
session_manager.update_completion.connect( session_manager.update_completion.connect(
functools.partial(update, [usertypes.Completion.sessions])) functools.partial(update, [usertypes.Completion.sessions]))

View File

@ -238,7 +238,7 @@ KeyMode = enum('KeyMode', ['normal', 'hint', 'command', 'yesno', 'prompt',
Completion = enum('Completion', ['command', 'section', 'option', 'value', Completion = enum('Completion', ['command', 'section', 'option', 'value',
'helptopic', 'quickmark_by_url', 'helptopic', 'quickmark_by_url',
'quickmark_by_name', 'bookmark_by_url', 'quickmark_by_name', 'bookmark_by_url',
'bookmark_by_title', 'url', 'sessions']) 'url', 'sessions'])
# Exit statuses for errors. Needs to be an int for sys.exit. # Exit statuses for errors. Needs to be an int for sys.exit.