Implement quickmarks
This commit is contained in:
parent
e7da95a3b1
commit
8cddbec9e3
9
TODO
9
TODO
@ -160,15 +160,6 @@ Show Bookmarks (command bookmarks, aliases: bmarks, bmas).
|
|||||||
gB
|
gB
|
||||||
Show Bookmarks, open bookmark in a new tab (command tab_bookmarks, aliases: tabmarks).
|
Show Bookmarks, open bookmark in a new tab (command tab_bookmarks, aliases: tabmarks).
|
||||||
|
|
||||||
m
|
|
||||||
Add a quickmark (command save_quickmark, aliases: quickmark, qmark).
|
|
||||||
|
|
||||||
b
|
|
||||||
Open quickmark (command quickmark, aliases: qmarks).
|
|
||||||
|
|
||||||
B
|
|
||||||
Open quickmark in a new tab (command tab_quickmark, aliases: tabqmarks).
|
|
||||||
|
|
||||||
tab-handling
|
tab-handling
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ import qutebrowser.network.qutescheme as qutescheme
|
|||||||
import qutebrowser.config.websettings as websettings
|
import qutebrowser.config.websettings as websettings
|
||||||
import qutebrowser.network.proxy as proxy
|
import qutebrowser.network.proxy as proxy
|
||||||
import qutebrowser.utils.message as message
|
import qutebrowser.utils.message as message
|
||||||
|
import qutebrowser.browser.quickmarks as quickmarks
|
||||||
from qutebrowser.network.networkmanager import NetworkManager
|
from qutebrowser.network.networkmanager import NetworkManager
|
||||||
from qutebrowser.config.config import ConfigManager
|
from qutebrowser.config.config import ConfigManager
|
||||||
from qutebrowser.keyinput.modeman import ModeManager
|
from qutebrowser.keyinput.modeman import ModeManager
|
||||||
@ -133,6 +134,7 @@ class QuteBrowser(QApplication):
|
|||||||
self._handle_segfault()
|
self._handle_segfault()
|
||||||
self._init_modes()
|
self._init_modes()
|
||||||
websettings.init()
|
websettings.init()
|
||||||
|
quickmarks.init()
|
||||||
proxy.init()
|
proxy.init()
|
||||||
self.cookiejar = CookieJar()
|
self.cookiejar = CookieJar()
|
||||||
self.networkmanager = NetworkManager(self.cookiejar)
|
self.networkmanager = NetworkManager(self.cookiejar)
|
||||||
@ -624,6 +626,11 @@ class QuteBrowser(QApplication):
|
|||||||
self.cookiejar.save()
|
self.cookiejar.save()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
logging.exception("Could not save cookies.")
|
logging.exception("Could not save cookies.")
|
||||||
|
# Save quickmarks
|
||||||
|
try:
|
||||||
|
quickmarks.save()
|
||||||
|
except AttributeError:
|
||||||
|
logging.exception("Could not save quickmarks.")
|
||||||
# Shut down tabs
|
# Shut down tabs
|
||||||
try:
|
try:
|
||||||
self.mainwindow.tabs.shutdown_complete.connect(partial(
|
self.mainwindow.tabs.shutdown_complete.connect(partial(
|
||||||
|
@ -33,6 +33,7 @@ import qutebrowser.browser.hints as hints
|
|||||||
import qutebrowser.utils.url as urlutils
|
import qutebrowser.utils.url as urlutils
|
||||||
import qutebrowser.utils.message as message
|
import qutebrowser.utils.message as message
|
||||||
import qutebrowser.utils.webelem as webelem
|
import qutebrowser.utils.webelem as webelem
|
||||||
|
import qutebrowser.browser.quickmarks as quickmarks
|
||||||
from qutebrowser.utils.misc import check_overflow, shell_escape
|
from qutebrowser.utils.misc import check_overflow, shell_escape
|
||||||
from qutebrowser.utils.editor import ExternalEditor
|
from qutebrowser.utils.editor import ExternalEditor
|
||||||
from qutebrowser.commands.exceptions import CommandError
|
from qutebrowser.commands.exceptions import CommandError
|
||||||
@ -601,6 +602,29 @@ class CommandDispatcher(QObject):
|
|||||||
runner.run(cmd, *args, env={'QUTE_URL': url})
|
runner.run(cmd, *args, env={'QUTE_URL': url})
|
||||||
self._userscript_runners.append(runner)
|
self._userscript_runners.append(runner)
|
||||||
|
|
||||||
|
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
||||||
|
def quickmark_save(self):
|
||||||
|
"""Save the current page as a quickmark."""
|
||||||
|
quickmarks.prompt_save(self._tabs.currentWidget().url())
|
||||||
|
|
||||||
|
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
||||||
|
def quickmark_load(self, name):
|
||||||
|
"""Load a quickmark."""
|
||||||
|
url = quickmarks.get(name)
|
||||||
|
self._tabs.currentWidget().openurl(url)
|
||||||
|
|
||||||
|
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
||||||
|
def quickmark_load_tab(self, name):
|
||||||
|
"""Load a quickmark in a new tab."""
|
||||||
|
url = quickmarks.get(name)
|
||||||
|
self._tabs.tabopen(url, background=False)
|
||||||
|
|
||||||
|
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
||||||
|
def quickmark_load_tab_bg(self, name):
|
||||||
|
"""Load a quickmark in a new background tab."""
|
||||||
|
url = quickmarks.get(name)
|
||||||
|
self._tabs.tabopen(url, background=True)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', modes=['insert'],
|
@cmdutils.register(instance='mainwindow.tabs.cmd', modes=['insert'],
|
||||||
hide=True)
|
hide=True)
|
||||||
def open_editor(self):
|
def open_editor(self):
|
||||||
|
87
qutebrowser/browser/quickmarks.py
Normal file
87
qutebrowser/browser/quickmarks.py
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
|
#
|
||||||
|
# This file is part of qutebrowser.
|
||||||
|
#
|
||||||
|
# qutebrowser is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# qutebrowser is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""Manager for quickmarks."""
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from PyQt5.QtCore import QStandardPaths
|
||||||
|
|
||||||
|
import qutebrowser.utils.message as message
|
||||||
|
import qutebrowser.commands.utils as cmdutils
|
||||||
|
from qutebrowser.utils.usertypes import PromptMode
|
||||||
|
from qutebrowser.config.lineparser import LineConfigParser
|
||||||
|
from qutebrowser.utils.misc import get_standard_dir
|
||||||
|
from qutebrowser.utils.url import urlstring
|
||||||
|
from qutebrowser.commands.exceptions import CommandError
|
||||||
|
|
||||||
|
|
||||||
|
marks = OrderedDict()
|
||||||
|
linecp = None
|
||||||
|
|
||||||
|
|
||||||
|
def init():
|
||||||
|
"""Read quickmarks from the config file."""
|
||||||
|
global marks, linecp
|
||||||
|
confdir = get_standard_dir(QStandardPaths.ConfigLocation)
|
||||||
|
linecp = LineConfigParser(confdir, 'quickmarks')
|
||||||
|
for line in linecp:
|
||||||
|
key, url = line.split(maxsplit=1)
|
||||||
|
marks[key] = url
|
||||||
|
|
||||||
|
|
||||||
|
def save():
|
||||||
|
"""Save the quickmarks to disk."""
|
||||||
|
linecp.data = [' '.join(tpl) for tpl in marks.items()]
|
||||||
|
linecp.save()
|
||||||
|
|
||||||
|
|
||||||
|
def prompt_save(url):
|
||||||
|
"""Prompt for a new quickmark name to be added and add it."""
|
||||||
|
message.question("Add quickmark:", PromptMode.text,
|
||||||
|
partial(quickmark_add, url))
|
||||||
|
|
||||||
|
|
||||||
|
@cmdutils.register()
|
||||||
|
def quickmark_add(url, name):
|
||||||
|
"""Add a new quickmark.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url: The url to add as quickmark.
|
||||||
|
name: The name for the new quickmark.
|
||||||
|
"""
|
||||||
|
if not name:
|
||||||
|
raise CommandError("Can't set mark with empty name!")
|
||||||
|
if not url:
|
||||||
|
raise CommandError("Can't set mark with empty URL!")
|
||||||
|
|
||||||
|
def set_mark():
|
||||||
|
marks[name] = urlstring(url)
|
||||||
|
|
||||||
|
if name in marks:
|
||||||
|
message.confirm_action("Override existing quickmark?", set_mark,
|
||||||
|
default=True)
|
||||||
|
else:
|
||||||
|
set_mark()
|
||||||
|
|
||||||
|
|
||||||
|
def get(name):
|
||||||
|
"""Get the URL of the quickmark named name."""
|
||||||
|
if name not in marks:
|
||||||
|
raise CommandError("Quickmark '{}' does not exist!".format(name))
|
||||||
|
return marks[name]
|
@ -627,6 +627,10 @@ DATA = OrderedDict([
|
|||||||
('pP', 'paste sel'),
|
('pP', 'paste sel'),
|
||||||
('Pp', 'paste-tab'),
|
('Pp', 'paste-tab'),
|
||||||
('PP', 'paste-tab sel'),
|
('PP', 'paste-tab sel'),
|
||||||
|
('m', 'quickmark-save'),
|
||||||
|
('b', 'quickmark-load'),
|
||||||
|
('B', 'quickmark-load-tab'),
|
||||||
|
(';b', 'quickmark-load-tab-bg'),
|
||||||
('sf', 'save'),
|
('sf', 'save'),
|
||||||
('ss', 'set'),
|
('ss', 'set'),
|
||||||
('sl', 'set-temp'),
|
('sl', 'set-temp'),
|
||||||
|
Loading…
Reference in New Issue
Block a user