From 28caf457072036ba8cdda7399133fa9358759b1a Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Thu, 21 May 2015 18:17:22 -0400 Subject: [PATCH 01/28] First version of bookmarks. --- .gitignore | 1 + qutebrowser/app.py | 5 +- qutebrowser/browser/bookmarks.py | 136 +++++++++++++++++++++ qutebrowser/browser/commands.py | 10 ++ qutebrowser/completion/models/instances.py | 20 +++ qutebrowser/completion/models/urlmodel.py | 47 +++++-- qutebrowser/utils/usertypes.py | 3 +- 7 files changed, 213 insertions(+), 9 deletions(-) create mode 100644 qutebrowser/browser/bookmarks.py diff --git a/.gitignore b/.gitignore index f3ff3652a..ee9b26169 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ __pycache__ *.pyc +*.swp /build /dist /qutebrowser.egg-info diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 64c277c9f..867a24d52 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -44,7 +44,7 @@ import qutebrowser.resources # pylint: disable=unused-import from qutebrowser.completion.models import instances as completionmodels from qutebrowser.commands import cmdutils, runners, cmdexc from qutebrowser.config import style, config, websettings, configexc -from qutebrowser.browser import quickmarks, cookies, cache, adblock, history +from qutebrowser.browser import bookmarks, quickmarks, cookies, cache, adblock, history from qutebrowser.browser.network import qutescheme, proxy, networkmanager from qutebrowser.mainwindow import mainwindow from qutebrowser.misc import readline, ipc, savemanager, sessions, crashsignal @@ -413,6 +413,9 @@ def _init_modules(args, crash_handler): log.init.debug("Initializing quickmarks...") quickmark_manager = quickmarks.QuickmarkManager(qApp) objreg.register('quickmark-manager', quickmark_manager) + log.init.debug("Initializing bookmarks...") + bookmark_manager = bookmarks.BookmarkManager(qApp) + objreg.register('bookmark-manager', bookmark_manager) log.init.debug("Initializing proxy...") proxy.init() log.init.debug("Initializing cookies...") diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py new file mode 100644 index 000000000..d1693b358 --- /dev/null +++ b/qutebrowser/browser/bookmarks.py @@ -0,0 +1,136 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2014-2015 Florian Bruhin (The Compiler) +# Copyright 2015 Antoni Boucher +# +# 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 . + +"""Manager for bookmarks. + +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 sense to keep them as strings here. +""" + +import os.path +import functools +import collections + +from PyQt5.QtCore import pyqtSignal, QUrl, QObject + +from qutebrowser.utils import message, usertypes, urlutils, standarddir, objreg +from qutebrowser.commands import cmdexc, cmdutils +from qutebrowser.misc import lineparser + + +class BookmarkManager(QObject): + + """Manager for bookmarks. + + Attributes: + marks: An OrderedDict of all bookmarks. + _lineparser: The LineParser used for the bookmarks, or None + (when qutebrowser is started with -c ''). + + Signals: + changed: Emitted when anything changed. + added: Emitted when a new bookmark was added. + arg 0: The name of the bookmark. + arg 1: The URL of the bookmark, as string. + removed: Emitted when an existing bookmark was removed. + arg 0: The name of the bookmark. + """ + + changed = pyqtSignal() + added = pyqtSignal(str, str) + removed = pyqtSignal(str) + + def __init__(self, parent=None): + """Initialize and read bookmarks.""" + super().__init__(parent) + + self.marks = collections.OrderedDict() + + if standarddir.config() is None: + self._lineparser = None + else: + self._lineparser = lineparser.LineParser( + standarddir.config(), 'bookmarks', parent=self) + for line in self._lineparser: + if not line.strip(): + # Ignore empty or whitespace-only lines. + continue + try: + key, url = line.rsplit(maxsplit=1) + except ValueError: + message.error(0, "Invalid bookmark '{}'".format(line)) + else: + self.marks[key] = url + filename = os.path.join(standarddir.config(), 'bookmarks') + objreg.get('save-manager').add_saveable( + 'bookmark-manager', self.save, self.changed, + filename=filename) + + def save(self): + """Save the bookmarks to disk.""" + if self._lineparser is not None: + self._lineparser.data = [' '.join(tpl) + for tpl in self.marks.items()] + self._lineparser.save() + + @cmdutils.register(instance='bookmark-manager', win_id='win_id') + def bookmark_add(self, win_id, url, name): + """Add a new bookmark. + + Args: + win_id: The window ID to display the errors in. + url: The url to add as bookmark. + name: The name for the new bookmark. + """ + if not url.isValid(): + urlutils.invalid_url_error(win_id, url, "save quickmark") + return + urlstr = url.toString(QUrl.RemovePassword | QUrl.FullyEncoded) + + # We don't raise cmdexc.CommandError here as this can be called async + # via prompt_save. + if not name: + message.error(win_id, "Can't set mark with empty name!") + return + if not urlstr: + message.error(win_id, "Can't set mark with empty URL!") + return + + self.marks[name] = urlstr + self.changed.emit() + self.added.emit(name, urlstr) + message.info(win_id, "Bookmarks added") + + @cmdutils.register(instance='bookmark-manager', maxsplit=0, + completion=[usertypes.Completion.bookmark_by_name]) + def bookmark_del(self, name): + """Delete a bookmark. + + Args: + name: The name of the bookmark to delete. + """ + try: + del self.marks[name] + except KeyError: + raise cmdexc.CommandError("Bookmark '{}' not found!".format(name)) + else: + self.changed.emit() + self.removed.emit(name) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 0c01260d7..41b379c51 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -99,6 +99,10 @@ class CommandDispatcher: msg += "!" raise cmdexc.CommandError(msg) + def _current_title(self): + """Convenience method to get the current title.""" + return self._tabbed_browser.page_title(self._current_index()) + def _current_widget(self): """Get the currently active widget from a command.""" widget = self._tabbed_browser.currentWidget() @@ -985,6 +989,12 @@ class CommandDispatcher: url = objreg.get('quickmark-manager').get(name) self._open(url, tab, bg, window) + @cmdutils.register(instance='command-dispatcher', scope='window') + def bookmark_save(self): + """Save the current page as a bookmark.""" + bookmark_manager = objreg.get('bookmark-manager') + bookmark_manager.bookmark_add(self._win_id, self._current_url(), self._current_title()) + @cmdutils.register(instance='command-dispatcher', name='inspector', scope='window') def toggle_inspector(self): diff --git a/qutebrowser/completion/models/instances.py b/qutebrowser/completion/models/instances.py index 85998357f..50e73cab5 100644 --- a/qutebrowser/completion/models/instances.py +++ b/qutebrowser/completion/models/instances.py @@ -106,6 +106,20 @@ def init_quickmark_completions(): model = _init_model(miscmodels.QuickmarkCompletionModel, 'name') _instances[usertypes.Completion.quickmark_by_name] = model +@pyqtSlot() +def init_bookmark_completions(): + """Initialize bookmark completion models.""" + log.completion.debug("Initializing bookmark completion.") + try: + _instances[usertypes.Completion.bookmark_by_url].deleteLater() + _instances[usertypes.Completion.bookmark_by_name].deleteLater() + except KeyError: + pass + model = _init_model(miscmodels.BookmarkCompletionModel, 'url') + _instances[usertypes.Completion.bookmark_by_url] = model + model = _init_model(miscmodels.BookmarkCompletionModel, 'name') + _instances[usertypes.Completion.bookmark_by_name] = model + @pyqtSlot() def init_session_completion(): @@ -128,6 +142,8 @@ INITIALIZERS = { usertypes.Completion.value: _init_setting_completions, usertypes.Completion.quickmark_by_url: init_quickmark_completions, usertypes.Completion.quickmark_by_name: init_quickmark_completions, + usertypes.Completion.bookmark_by_url: init_bookmark_completions, + usertypes.Completion.bookmark_by_name: init_bookmark_completions, usertypes.Completion.sessions: init_session_completion, } @@ -165,6 +181,10 @@ def init(): quickmark_manager.changed.connect( functools.partial(update, [usertypes.Completion.quickmark_by_url, usertypes.Completion.quickmark_by_name])) + bookmark_manager = objreg.get('bookmark-manager') + bookmark_manager.changed.connect( + functools.partial(update, [usertypes.Completion.bookmark_by_url, + usertypes.Completion.bookmark_by_name])) session_manager = objreg.get('session-manager') session_manager.update_completion.connect( functools.partial(update, [usertypes.Completion.sessions])) diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index e8898ec85..4927ec65a 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -30,7 +30,7 @@ from qutebrowser.config import config class UrlCompletionModel(base.BaseCompletionModel): - """A model which combines quickmarks and web history URLs. + """A model which combines bookmarks, quickmarks and web history URLs. Used for the `open` command.""" @@ -40,14 +40,15 @@ class UrlCompletionModel(base.BaseCompletionModel): super().__init__(parent) self._quickmark_cat = self.new_category("Quickmarks") + self._bookmark_cat = self.new_category("Bookmarks") self._history_cat = self.new_category("History") - quickmark_manager = objreg.get('quickmark-manager') - quickmarks = quickmark_manager.marks.items() - for qm_name, qm_url in quickmarks: - self._add_quickmark_entry(qm_name, qm_url) - quickmark_manager.added.connect(self.on_quickmark_added) - quickmark_manager.removed.connect(self.on_quickmark_removed) + bookmark_manager = objreg.get('bookmark-manager') + bookmarks = bookmark_manager.marks.items() + for bm_name, bm_url in bookmarks: + self._add_bookmark_entry(bm_name, bm_url) + bookmark_manager.added.connect(self.on_bookmark_added) + bookmark_manager.removed.connect(self.on_bookmark_removed) self._history = objreg.get('web-history') max_history = config.get('completion', 'web-history-max-items') @@ -81,6 +82,15 @@ class UrlCompletionModel(base.BaseCompletionModel): """ self.new_item(self._quickmark_cat, url, name) + def _add_bookmark_entry(self, name, url): + """Add a new bookmark entry to the completion. + + Args: + name: The name of the new bookmark. + url: The URL of the new bookmark. + """ + self.new_item(self._bookmark_cat, url, name) + @config.change_filter('completion', 'timestamp-format') def reformat_timestamps(self): """Reformat the timestamps if the config option was changed.""" @@ -126,3 +136,26 @@ class UrlCompletionModel(base.BaseCompletionModel): if name_item.data(Qt.DisplayRole) == name: self._quickmark_cat.removeRow(i) break + + @pyqtSlot(str, str) + def on_bookmark_added(self, name, url): + """Called when a bookmark has been added by the user. + + Args: + name: The name of the new bookmark. + url: The url of the new bookmark, as string. + """ + self._add_bookmark_entry(name, url) + + @pyqtSlot(str) + def on_bookmark_removed(self, name): + """Called when a bookmark has been removed by the user. + + Args: + name: The name of the bookmark which has been removed. + """ + for i in range(self._bookmark_cat.rowCount()): + name_item = self._bookmark_cat.child(i, 1) + if name_item.data(Qt.DisplayRole) == name: + self._bookmark_cat.removeRow(i) + break diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index 5d19ad515..3de7012f4 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -237,7 +237,8 @@ KeyMode = enum('KeyMode', ['normal', 'hint', 'command', 'yesno', 'prompt', # Available command completions Completion = enum('Completion', ['command', 'section', 'option', 'value', 'helptopic', 'quickmark_by_url', - 'quickmark_by_name', 'url', 'sessions']) + 'quickmark_by_name', 'bookmark_by_url', + 'bookmark_by_name', 'url', 'sessions']) # Exit statuses for errors. Needs to be an int for sys.exit. From 2c0c2e220e127bedea0136ed669e5994359ac925 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Thu, 21 May 2015 19:38:30 -0400 Subject: [PATCH 02/28] Fixed style issue. --- qutebrowser/app.py | 3 +- qutebrowser/browser/bookmarks.py | 41 ++++++++++----------- qutebrowser/browser/commands.py | 3 +- qutebrowser/completion/models/instances.py | 11 +++--- qutebrowser/completion/models/miscmodels.py | 21 +++++++++++ qutebrowser/completion/models/urlmodel.py | 26 ++++++------- qutebrowser/utils/usertypes.py | 2 +- 7 files changed, 65 insertions(+), 42 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 867a24d52..b755b0239 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -44,7 +44,8 @@ import qutebrowser.resources # pylint: disable=unused-import from qutebrowser.completion.models import instances as completionmodels from qutebrowser.commands import cmdutils, runners, cmdexc from qutebrowser.config import style, config, websettings, configexc -from qutebrowser.browser import bookmarks, quickmarks, cookies, cache, adblock, history +from qutebrowser.browser import (bookmarks, quickmarks, cookies, cache, + adblock, history) from qutebrowser.browser.network import qutescheme, proxy, networkmanager from qutebrowser.mainwindow import mainwindow from qutebrowser.misc import readline, ipc, savemanager, sessions, crashsignal diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py index d1693b358..aac331015 100644 --- a/qutebrowser/browser/bookmarks.py +++ b/qutebrowser/browser/bookmarks.py @@ -20,13 +20,12 @@ """Manager for bookmarks. -Note we violate our general QUrl rule by storing url strings in the marks +Note we violate our general QUrl rule by storing url strings in the bookmarks OrderedDict. This is because we read them from a file at start and write them to a file on shutdown, so it makes sense to keep them as strings here. """ import os.path -import functools import collections from PyQt5.QtCore import pyqtSignal, QUrl, QObject @@ -41,17 +40,17 @@ class BookmarkManager(QObject): """Manager for bookmarks. Attributes: - marks: An OrderedDict of all bookmarks. + bookmarks: An OrderedDict of all bookmarks. _lineparser: The LineParser used for the bookmarks, or None (when qutebrowser is started with -c ''). Signals: changed: Emitted when anything changed. added: Emitted when a new bookmark was added. - arg 0: The name of the bookmark. + arg 0: The title of the bookmark. arg 1: The URL of the bookmark, as string. removed: Emitted when an existing bookmark was removed. - arg 0: The name of the bookmark. + arg 0: The title of the bookmark. """ changed = pyqtSignal() @@ -62,7 +61,7 @@ class BookmarkManager(QObject): """Initialize and read bookmarks.""" super().__init__(parent) - self.marks = collections.OrderedDict() + self.bookmarks = collections.OrderedDict() if standarddir.config() is None: self._lineparser = None @@ -74,11 +73,11 @@ class BookmarkManager(QObject): # Ignore empty or whitespace-only lines. continue try: - key, url = line.rsplit(maxsplit=1) + url, title = line.split(maxsplit=1) except ValueError: message.error(0, "Invalid bookmark '{}'".format(line)) else: - self.marks[key] = url + self.bookmarks[url] = title filename = os.path.join(standarddir.config(), 'bookmarks') objreg.get('save-manager').add_saveable( 'bookmark-manager', self.save, self.changed, @@ -88,17 +87,17 @@ class BookmarkManager(QObject): """Save the bookmarks to disk.""" if self._lineparser is not None: self._lineparser.data = [' '.join(tpl) - for tpl in self.marks.items()] + for tpl in self.bookmarks.items()] self._lineparser.save() @cmdutils.register(instance='bookmark-manager', win_id='win_id') - def bookmark_add(self, win_id, url, name): + def bookmark_add(self, win_id, url, title): """Add a new bookmark. Args: win_id: The window ID to display the errors in. url: The url to add as bookmark. - name: The name for the new bookmark. + title: The title for the new bookmark. """ if not url.isValid(): urlutils.invalid_url_error(win_id, url, "save quickmark") @@ -107,30 +106,30 @@ class BookmarkManager(QObject): # We don't raise cmdexc.CommandError here as this can be called async # via prompt_save. - if not name: - message.error(win_id, "Can't set mark with empty name!") + if not title: + message.error(win_id, "Can't set mark with empty title!") return if not urlstr: message.error(win_id, "Can't set mark with empty URL!") return - self.marks[name] = urlstr + self.bookmarks[urlstr] = title self.changed.emit() - self.added.emit(name, urlstr) + self.added.emit(title, urlstr) message.info(win_id, "Bookmarks added") @cmdutils.register(instance='bookmark-manager', maxsplit=0, - completion=[usertypes.Completion.bookmark_by_name]) - def bookmark_del(self, name): + completion=[usertypes.Completion.bookmark_by_title]) + def bookmark_del(self, url): """Delete a bookmark. Args: - name: The name of the bookmark to delete. + url: The url of the bookmark to delete. """ try: - del self.marks[name] + del self.bookmarks[url] except KeyError: - raise cmdexc.CommandError("Bookmark '{}' not found!".format(name)) + raise cmdexc.CommandError("Bookmark '{}' not found!".format(url)) else: self.changed.emit() - self.removed.emit(name) + self.removed.emit(url) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 41b379c51..42400f38a 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -993,7 +993,8 @@ class CommandDispatcher: def bookmark_save(self): """Save the current page as a bookmark.""" bookmark_manager = objreg.get('bookmark-manager') - bookmark_manager.bookmark_add(self._win_id, self._current_url(), self._current_title()) + bookmark_manager.bookmark_add(self._win_id, self._current_url(), + self._current_title()) @cmdutils.register(instance='command-dispatcher', name='inspector', scope='window') diff --git a/qutebrowser/completion/models/instances.py b/qutebrowser/completion/models/instances.py index 50e73cab5..2277cf5b9 100644 --- a/qutebrowser/completion/models/instances.py +++ b/qutebrowser/completion/models/instances.py @@ -106,19 +106,20 @@ def init_quickmark_completions(): model = _init_model(miscmodels.QuickmarkCompletionModel, 'name') _instances[usertypes.Completion.quickmark_by_name] = model + @pyqtSlot() def init_bookmark_completions(): """Initialize bookmark completion models.""" log.completion.debug("Initializing bookmark completion.") try: _instances[usertypes.Completion.bookmark_by_url].deleteLater() - _instances[usertypes.Completion.bookmark_by_name].deleteLater() + _instances[usertypes.Completion.bookmark_by_title].deleteLater() except KeyError: pass model = _init_model(miscmodels.BookmarkCompletionModel, 'url') _instances[usertypes.Completion.bookmark_by_url] = model - model = _init_model(miscmodels.BookmarkCompletionModel, 'name') - _instances[usertypes.Completion.bookmark_by_name] = model + model = _init_model(miscmodels.BookmarkCompletionModel, 'title') + _instances[usertypes.Completion.bookmark_by_title] = model @pyqtSlot() @@ -143,7 +144,7 @@ INITIALIZERS = { usertypes.Completion.quickmark_by_url: init_quickmark_completions, usertypes.Completion.quickmark_by_name: init_quickmark_completions, usertypes.Completion.bookmark_by_url: init_bookmark_completions, - usertypes.Completion.bookmark_by_name: init_bookmark_completions, + usertypes.Completion.bookmark_by_title: init_bookmark_completions, usertypes.Completion.sessions: init_session_completion, } @@ -184,7 +185,7 @@ def init(): bookmark_manager = objreg.get('bookmark-manager') bookmark_manager.changed.connect( functools.partial(update, [usertypes.Completion.bookmark_by_url, - usertypes.Completion.bookmark_by_name])) + usertypes.Completion.bookmark_by_title])) session_manager = objreg.get('session-manager') session_manager.update_completion.connect( functools.partial(update, [usertypes.Completion.sessions])) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index f9af679ce..faea69269 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -111,6 +111,27 @@ class QuickmarkCompletionModel(base.BaseCompletionModel): match_field)) +class BookmarkCompletionModel(base.BaseCompletionModel): + + """A CompletionModel filled with all bookmarks.""" + + # pylint: disable=abstract-method + + def __init__(self, match_field='url', parent=None): + super().__init__(parent) + cat = self.new_category("Bookmarks") + bookmarks = objreg.get('bookmark-manager').bookmarks.items() + if match_field == 'url': + for bm_url, bm_title in bookmarks: + self.new_item(cat, bm_url, bm_title) + elif match_field == 'title': + for bm_url, bm_title in bookmarks: + self.new_item(cat, bm_title, bm_url) + else: + raise ValueError("Invalid value '{}' for match_field!".format( + match_field)) + + class SessionCompletionModel(base.BaseCompletionModel): """A CompletionModel filled with session names.""" diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 4927ec65a..eacd1aebd 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -44,9 +44,9 @@ class UrlCompletionModel(base.BaseCompletionModel): self._history_cat = self.new_category("History") bookmark_manager = objreg.get('bookmark-manager') - bookmarks = bookmark_manager.marks.items() - for bm_name, bm_url in bookmarks: - self._add_bookmark_entry(bm_name, bm_url) + bookmarks = bookmark_manager.bookmarks.items() + for bm_url, bm_title in bookmarks: + self._add_bookmark_entry(bm_title, bm_url) bookmark_manager.added.connect(self.on_bookmark_added) bookmark_manager.removed.connect(self.on_bookmark_removed) @@ -82,14 +82,14 @@ class UrlCompletionModel(base.BaseCompletionModel): """ self.new_item(self._quickmark_cat, url, name) - def _add_bookmark_entry(self, name, url): + def _add_bookmark_entry(self, title, url): """Add a new bookmark entry to the completion. Args: - name: The name of the new bookmark. + title: The title of the new bookmark. url: The URL of the new bookmark. """ - self.new_item(self._bookmark_cat, url, name) + self.new_item(self._bookmark_cat, url, title) @config.change_filter('completion', 'timestamp-format') def reformat_timestamps(self): @@ -138,24 +138,24 @@ class UrlCompletionModel(base.BaseCompletionModel): break @pyqtSlot(str, str) - def on_bookmark_added(self, name, url): + def on_bookmark_added(self, title, url): """Called when a bookmark has been added by the user. Args: - name: The name of the new bookmark. + title: The title of the new bookmark. url: The url of the new bookmark, as string. """ - self._add_bookmark_entry(name, url) + self._add_bookmark_entry(title, url) @pyqtSlot(str) - def on_bookmark_removed(self, name): + def on_bookmark_removed(self, url): """Called when a bookmark has been removed by the user. Args: - name: The name of the bookmark which has been removed. + url: The url of the bookmark which has been removed. """ for i in range(self._bookmark_cat.rowCount()): - name_item = self._bookmark_cat.child(i, 1) - if name_item.data(Qt.DisplayRole) == name: + url_item = self._bookmark_cat.child(i, 1) + if url_item.data(Qt.DisplayRole) == url: self._bookmark_cat.removeRow(i) break diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index 3de7012f4..2ee55e96f 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -238,7 +238,7 @@ KeyMode = enum('KeyMode', ['normal', 'hint', 'command', 'yesno', 'prompt', Completion = enum('Completion', ['command', 'section', 'option', 'value', 'helptopic', 'quickmark_by_url', 'quickmark_by_name', 'bookmark_by_url', - 'bookmark_by_name', 'url', 'sessions']) + 'bookmark_by_title', 'url', 'sessions']) # Exit statuses for errors. Needs to be an int for sys.exit. From 0ee7e40e69fa922bb5a0b2ac3a0595b5be721893 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 23 May 2015 15:57:52 -0400 Subject: [PATCH 03/28] Fixed broken quickmarks completion. --- qutebrowser/completion/models/urlmodel.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index eacd1aebd..55b7c4ddb 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -43,6 +43,13 @@ class UrlCompletionModel(base.BaseCompletionModel): self._bookmark_cat = self.new_category("Bookmarks") self._history_cat = self.new_category("History") + quickmark_manager = objreg.get('quickmark-manager') + quickmarks = quickmark_manager.marks.items() + for qm_name, qm_url in quickmarks: + self._add_quickmark_entry(qm_name, qm_url) + quickmark_manager.added.connect(self.on_quickmark_added) + quickmark_manager.removed.connect(self.on_quickmark_removed) + bookmark_manager = objreg.get('bookmark-manager') bookmarks = bookmark_manager.bookmarks.items() for bm_url, bm_title in bookmarks: From aaf35536a7714478c451635413bf22966a4a8bbc Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 23 May 2015 16:02:02 -0400 Subject: [PATCH 04/28] Removed unused commands and renamed bookmark-save command. --- qutebrowser/browser/bookmarks.py | 3 --- qutebrowser/browser/commands.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py index aac331015..dd0fb3439 100644 --- a/qutebrowser/browser/bookmarks.py +++ b/qutebrowser/browser/bookmarks.py @@ -90,7 +90,6 @@ class BookmarkManager(QObject): for tpl in self.bookmarks.items()] self._lineparser.save() - @cmdutils.register(instance='bookmark-manager', win_id='win_id') def bookmark_add(self, win_id, url, title): """Add a new bookmark. @@ -118,8 +117,6 @@ class BookmarkManager(QObject): self.added.emit(title, urlstr) message.info(win_id, "Bookmarks added") - @cmdutils.register(instance='bookmark-manager', maxsplit=0, - completion=[usertypes.Completion.bookmark_by_title]) def bookmark_del(self, url): """Delete a bookmark. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 42400f38a..6238e549c 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -990,7 +990,7 @@ class CommandDispatcher: self._open(url, tab, bg, window) @cmdutils.register(instance='command-dispatcher', scope='window') - def bookmark_save(self): + def bookmark(self): """Save the current page as a bookmark.""" bookmark_manager = objreg.get('bookmark-manager') bookmark_manager.bookmark_add(self._win_id, self._current_url(), From ece32e930c35693b93fa91d0c7e2ba17c98f23cb Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 24 May 2015 19:07:57 -0400 Subject: [PATCH 05/28] Added bookmarks command. --- qutebrowser/browser/bookmarks.py | 4 ++-- qutebrowser/browser/commands.py | 14 ++++++++++++++ qutebrowser/completion/models/instances.py | 6 +----- qutebrowser/utils/usertypes.py | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py index dd0fb3439..d92ad2bb2 100644 --- a/qutebrowser/browser/bookmarks.py +++ b/qutebrowser/browser/bookmarks.py @@ -30,8 +30,8 @@ import collections from PyQt5.QtCore import pyqtSignal, QUrl, QObject -from qutebrowser.utils import message, usertypes, urlutils, standarddir, objreg -from qutebrowser.commands import cmdexc, cmdutils +from qutebrowser.utils import message, urlutils, standarddir, objreg +from qutebrowser.commands import cmdexc from qutebrowser.misc import lineparser diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 6238e549c..9f5d5e210 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -996,6 +996,20 @@ class CommandDispatcher: bookmark_manager.bookmark_add(self._win_id, self._current_url(), 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', scope='window') def toggle_inspector(self): diff --git a/qutebrowser/completion/models/instances.py b/qutebrowser/completion/models/instances.py index 2277cf5b9..31654c295 100644 --- a/qutebrowser/completion/models/instances.py +++ b/qutebrowser/completion/models/instances.py @@ -113,13 +113,11 @@ def init_bookmark_completions(): log.completion.debug("Initializing bookmark completion.") try: _instances[usertypes.Completion.bookmark_by_url].deleteLater() - _instances[usertypes.Completion.bookmark_by_title].deleteLater() except KeyError: pass model = _init_model(miscmodels.BookmarkCompletionModel, 'url') _instances[usertypes.Completion.bookmark_by_url] = model model = _init_model(miscmodels.BookmarkCompletionModel, 'title') - _instances[usertypes.Completion.bookmark_by_title] = model @pyqtSlot() @@ -144,7 +142,6 @@ INITIALIZERS = { usertypes.Completion.quickmark_by_url: init_quickmark_completions, usertypes.Completion.quickmark_by_name: init_quickmark_completions, usertypes.Completion.bookmark_by_url: init_bookmark_completions, - usertypes.Completion.bookmark_by_title: init_bookmark_completions, usertypes.Completion.sessions: init_session_completion, } @@ -184,8 +181,7 @@ def init(): usertypes.Completion.quickmark_by_name])) bookmark_manager = objreg.get('bookmark-manager') bookmark_manager.changed.connect( - functools.partial(update, [usertypes.Completion.bookmark_by_url, - usertypes.Completion.bookmark_by_title])) + functools.partial(update, [usertypes.Completion.bookmark_by_url])) session_manager = objreg.get('session-manager') session_manager.update_completion.connect( functools.partial(update, [usertypes.Completion.sessions])) diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index 2ee55e96f..cabfdc979 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -238,7 +238,7 @@ KeyMode = enum('KeyMode', ['normal', 'hint', 'command', 'yesno', 'prompt', Completion = enum('Completion', ['command', 'section', 'option', 'value', 'helptopic', 'quickmark_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. From ad763685e56fdf72b2e0b0903eb1ad1e02140633 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 24 May 2015 19:26:23 -0400 Subject: [PATCH 06/28] Added bookmark command default key binding. --- qutebrowser/config/configdata.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index cb3a47be7..f6f038ee1 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -1195,6 +1195,7 @@ KEY_DATA = collections.OrderedDict([ ('set-cmd-text -s :quickmark-load', ['b']), ('set-cmd-text -s :quickmark-load -t', ['B']), ('set-cmd-text -s :quickmark-load -w', ['wb']), + ('bookmark', ['M']), ('save', ['sf']), ('set-cmd-text -s :set', ['ss']), ('set-cmd-text -s :set -t', ['sl']), From cbc4ec6531f648201a8240e917d3929ad7e9ed37 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Thu, 28 May 2015 19:50:36 -0400 Subject: [PATCH 07/28] Added filter bookmarks by name as well as url. --- qutebrowser/completion/models/base.py | 10 ++++++++++ qutebrowser/completion/models/sortfilter.py | 12 ++++++++---- qutebrowser/completion/models/urlmodel.py | 9 +++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/qutebrowser/completion/models/base.py b/qutebrowser/completion/models/base.py index b56444013..8c79910db 100644 --- a/qutebrowser/completion/models/base.py +++ b/qutebrowser/completion/models/base.py @@ -121,3 +121,13 @@ class BaseCompletionModel(QStandardItemModel): Override QAbstractItemModel::sort. """ raise NotImplementedError + + def custom_filter(self, pattern, row, parent): + """Custom filter. + + Args: + pattern: The current filter pattern. + row: The row to accept or reject in the filter. + parent: The parent item QModelIndex. + """ + raise NotImplementedError diff --git a/qutebrowser/completion/models/sortfilter.py b/qutebrowser/completion/models/sortfilter.py index 19802fa96..2310d73d1 100644 --- a/qutebrowser/completion/models/sortfilter.py +++ b/qutebrowser/completion/models/sortfilter.py @@ -137,12 +137,16 @@ class CompletionFilterModel(QSortFilterProxyModel): # No entries in parent model return False data = self.srcmodel.data(idx) - # TODO more sophisticated filtering if not self.pattern: return True - if not data: - return False - return self.pattern.casefold() in data.casefold() + + pattern = self.pattern.casefold() + try: + return self.srcmodel.custom_filter(pattern, row, parent) + except NotImplementedError: + if not data: + return False + return pattern in data.casefold() def intelligentLessThan(self, lindex, rindex): """Custom sorting implementation. diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 55b7c4ddb..27ff67e39 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -98,6 +98,15 @@ class UrlCompletionModel(base.BaseCompletionModel): """ self.new_item(self._bookmark_cat, url, title) + def custom_filter(self, pattern, row, parent): + """Filter by url and title. + """ + index0 = self.index(row, 0, parent) + index1 = self.index(row, 1, parent) + url = self.data(index0) + title = self.data(index1) + return pattern in url.casefold() or pattern in title.casefold() + @config.change_filter('completion', 'timestamp-format') def reformat_timestamps(self): """Reformat the timestamps if the config option was changed.""" From e92c493b07cabbdb0db4b0f5162cc87d74f9008b Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 30 May 2015 12:37:21 -0400 Subject: [PATCH 08/28] Fixed bug making the application crash. --- qutebrowser/completion/models/urlmodel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 27ff67e39..10d4fb9fd 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -103,8 +103,8 @@ class UrlCompletionModel(base.BaseCompletionModel): """ index0 = self.index(row, 0, parent) index1 = self.index(row, 1, parent) - url = self.data(index0) - title = self.data(index1) + url = self.data(index0) or '' + title = self.data(index1) or '' return pattern in url.casefold() or pattern in title.casefold() @config.change_filter('completion', 'timestamp-format') From 958216292717a60ff3d659a162ee1d8501b66155 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Mon, 1 Jun 2015 17:52:23 -0400 Subject: [PATCH 09/28] Fixed bookmarks command names. --- qutebrowser/browser/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 239307560..170ab5127 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1014,7 +1014,7 @@ class CommandDispatcher: self._open(url, tab, bg, window) @cmdutils.register(instance='command-dispatcher', scope='window') - def bookmark(self): + def bookmark_add(self): """Save the current page as a bookmark.""" bookmark_manager = objreg.get('bookmark-manager') bookmark_manager.bookmark_add(self._win_id, self._current_url(), @@ -1023,7 +1023,7 @@ class CommandDispatcher: @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): + def bookmark_load(self, url, tab=False, bg=False, window=False): """Load a bookmark. Args: From 508584455004bcb4e72e529206315a3bb0796541 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Mon, 1 Jun 2015 17:55:09 -0400 Subject: [PATCH 10/28] Added highlighting for completion in name column. --- qutebrowser/completion/completiondelegate.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/qutebrowser/completion/completiondelegate.py b/qutebrowser/completion/completiondelegate.py index 03caa5158..56bf18d34 100644 --- a/qutebrowser/completion/completiondelegate.py +++ b/qutebrowser/completion/completiondelegate.py @@ -196,13 +196,10 @@ class CompletionItemDelegate(QStyledItemDelegate): if index.parent().isValid(): pattern = index.model().pattern - if index.column() == 0 and pattern: - repl = r'\g<0>' - text = re.sub(re.escape(pattern), repl, self._opt.text, - flags=re.IGNORECASE) - self._doc.setHtml(text) - else: - self._doc.setPlainText(self._opt.text) + repl = r'\g<0>' + text = re.sub(re.escape(pattern), repl, self._opt.text, + flags=re.IGNORECASE) + self._doc.setHtml(text) else: self._doc.setHtml('{}'.format(html.escape(self._opt.text))) From c8bbef0ab0c039359065537f05feb992cfee2521 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Mon, 1 Jun 2015 19:49:32 -0400 Subject: [PATCH 11/28] Fixed bookmark command name in config. --- qutebrowser/config/configdata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index dbad5c66a..6afbdf5e9 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -1203,7 +1203,7 @@ KEY_DATA = collections.OrderedDict([ ('set-cmd-text -s :quickmark-load', ['b']), ('set-cmd-text -s :quickmark-load -t', ['B']), ('set-cmd-text -s :quickmark-load -w', ['wb']), - ('bookmark', ['M']), + ('bookmark-add', ['M']), ('save', ['sf']), ('set-cmd-text -s :set', ['ss']), ('set-cmd-text -s :set -t', ['sl']), From f1874ff44f0d7d96153690f4c22c9557a7a6dea3 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Mon, 1 Jun 2015 20:00:21 -0400 Subject: [PATCH 12/28] Added possibility to remove bookmarks and quickmarks. --- qutebrowser/completion/models/urlmodel.py | 2 +- qutebrowser/mainwindow/statusbar/command.py | 27 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 10d4fb9fd..80cae22e9 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -171,7 +171,7 @@ class UrlCompletionModel(base.BaseCompletionModel): url: The url of the bookmark which has been removed. """ for i in range(self._bookmark_cat.rowCount()): - url_item = self._bookmark_cat.child(i, 1) + url_item = self._bookmark_cat.child(i, 0) if url_item.data(Qt.DisplayRole) == url: self._bookmark_cat.removeRow(i) break diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index 1d8105c2f..93035d36f 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -26,7 +26,7 @@ from qutebrowser.keyinput import modeman, modeparsers from qutebrowser.commands import cmdexc, cmdutils from qutebrowser.misc import cmdhistory from qutebrowser.misc import miscwidgets as misc -from qutebrowser.utils import usertypes, log, objreg, qtutils +from qutebrowser.utils import message, usertypes, log, objreg, qtutils class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): @@ -211,7 +211,30 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): e.ignore() return else: - super().keyPressEvent(e) + if e.key() == Qt.Key_D and e.modifiers() & Qt.ControlModifier == Qt.ControlModifier: + self.delete_current_item() + else: + super().keyPressEvent(e) + + def delete_current_item(self): + completer_obj = objreg.get('completer', scope='window', + window=self._win_id) + completion = objreg.get('completion', scope='window', + window=self._win_id) + index = completion.currentIndex() + model = completion.model() + url = model.data(index) + category = index.parent() + if category.isValid(): + if category.data() == 'Bookmarks': + bookmark_manager = objreg.get('bookmark-manager') + bookmark_manager.bookmark_del(url) + message.info(self._win_id, "Bookmarks deleted") + elif category.data() == 'Quickmarks': + quickmark_manager = objreg.get('quickmark-manager') + name = model.data(index.sibling(index.row(), index.column() + 1)) + quickmark_manager.quickmark_del(name) + message.info(self._win_id, "Quickmarks deleted") def sizeHint(self): """Dynamically calculate the needed size.""" From 8b14145a4d63699ce10a80154642102d6d531d6a Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Wed, 3 Jun 2015 19:31:31 -0400 Subject: [PATCH 13/28] Fixed style. --- qutebrowser/completion/models/urlmodel.py | 3 +-- qutebrowser/mainwindow/statusbar/command.py | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 80cae22e9..d0d603c19 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -99,8 +99,7 @@ class UrlCompletionModel(base.BaseCompletionModel): self.new_item(self._bookmark_cat, url, title) def custom_filter(self, pattern, row, parent): - """Filter by url and title. - """ + """Filter by url and title.""" index0 = self.index(row, 0, parent) index1 = self.index(row, 1, parent) url = self.data(index0) or '' diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index 93035d36f..86b761fdc 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -211,16 +211,16 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): e.ignore() return else: - if e.key() == Qt.Key_D and e.modifiers() & Qt.ControlModifier == Qt.ControlModifier: + if e.key() == Qt.Key_D and (e.modifiers() & Qt.ControlModifier == + Qt.ControlModifier): self.delete_current_item() else: super().keyPressEvent(e) def delete_current_item(self): - completer_obj = objreg.get('completer', scope='window', - window=self._win_id) + """Delete the selected bookmark/quickmark.""" completion = objreg.get('completion', scope='window', - window=self._win_id) + window=self._win_id) index = completion.currentIndex() model = completion.model() url = model.data(index) @@ -232,7 +232,8 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): message.info(self._win_id, "Bookmarks deleted") elif category.data() == 'Quickmarks': quickmark_manager = objreg.get('quickmark-manager') - name = model.data(index.sibling(index.row(), index.column() + 1)) + name = model.data(index.sibling(index.row(), + index.column() + 1)) quickmark_manager.quickmark_del(name) message.info(self._win_id, "Quickmarks deleted") From 57a72a7120da8542135f871d5b7e77f927c47abc Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 7 Jun 2015 19:36:19 -0400 Subject: [PATCH 14/28] Refactored bookmark removal to use a command. --- qutebrowser/completion/completionwidget.py | 11 +++++++- qutebrowser/completion/models/base.py | 4 +++ qutebrowser/completion/models/urlmodel.py | 26 ++++++++++++++++++- qutebrowser/config/configdata.py | 1 + qutebrowser/mainwindow/statusbar/command.py | 28 ++------------------- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/qutebrowser/completion/completionwidget.py b/qutebrowser/completion/completionwidget.py index 0bd6b04c9..0ad17fa7e 100644 --- a/qutebrowser/completion/completionwidget.py +++ b/qutebrowser/completion/completionwidget.py @@ -26,7 +26,7 @@ subclasses to provide completions. from PyQt5.QtWidgets import QStyle, QTreeView, QSizePolicy from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QItemSelectionModel -from qutebrowser.commands import cmdutils +from qutebrowser.commands import cmdexc, cmdutils from qutebrowser.config import config, style from qutebrowser.completion import completiondelegate, completer from qutebrowser.utils import usertypes, qtutils, objreg, utils @@ -245,6 +245,15 @@ class CompletionView(QTreeView): """Select the next completion item.""" self._next_prev_item(prev=False) + @cmdutils.register(instance='completion', hide=True, + modes=[usertypes.KeyMode.command], scope='window') + def completion_item_del(self): + """Delete the current completion item.""" + try: + self.model().srcmodel.delete_cur_item(self._win_id) + except NotImplementedError: + raise cmdexc.CommandError("Cannot delete this item.") + def selectionChanged(self, selected, deselected): """Extend selectionChanged to call completers selection_changed.""" super().selectionChanged(selected, deselected) diff --git a/qutebrowser/completion/models/base.py b/qutebrowser/completion/models/base.py index 8c79910db..7f1e0c7d6 100644 --- a/qutebrowser/completion/models/base.py +++ b/qutebrowser/completion/models/base.py @@ -95,6 +95,10 @@ class BaseCompletionModel(QStandardItemModel): nameitem.setData(userdata, Role.userdata) return nameitem, descitem, miscitem + def delete_cur_item(self, win_id): + """Delete the selected item.""" + raise NotImplementedError + def flags(self, index): """Return the item flags for index. diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index d0d603c19..46db1d54c 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -23,7 +23,7 @@ import datetime from PyQt5.QtCore import pyqtSlot, Qt -from qutebrowser.utils import objreg, utils +from qutebrowser.utils import message, objreg, utils from qutebrowser.completion.models import base from qutebrowser.config import config @@ -174,3 +174,27 @@ class UrlCompletionModel(base.BaseCompletionModel): if url_item.data(Qt.DisplayRole) == url: self._bookmark_cat.removeRow(i) break + + def delete_cur_item(self, win_id): + """Delete the selected item. + + Args: + win_id: The current windows id. + """ + completion = objreg.get('completion', scope='window', + window=win_id) + index = completion.currentIndex() + model = completion.model() + url = model.data(index) + category = index.parent() + if category.isValid(): + if category.data() == 'Bookmarks': + bookmark_manager = objreg.get('bookmark-manager') + bookmark_manager.bookmark_del(url) + message.info(win_id, "Bookmarks deleted") + elif category.data() == 'Quickmarks': + quickmark_manager = objreg.get('quickmark-manager') + name = model.data(index.sibling(index.row(), + index.column() + 1)) + quickmark_manager.quickmark_del(name) + message.info(win_id, "Quickmarks deleted") diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 6149ba577..3f4fdb690 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -1280,6 +1280,7 @@ KEY_DATA = collections.OrderedDict([ ('command-history-next', ['']), ('completion-item-prev', ['', '']), ('completion-item-next', ['', '']), + ('completion-item-del', ['']), ('command-accept', RETURN_KEYS), ])), diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index 86b761fdc..1d8105c2f 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -26,7 +26,7 @@ from qutebrowser.keyinput import modeman, modeparsers from qutebrowser.commands import cmdexc, cmdutils from qutebrowser.misc import cmdhistory from qutebrowser.misc import miscwidgets as misc -from qutebrowser.utils import message, usertypes, log, objreg, qtutils +from qutebrowser.utils import usertypes, log, objreg, qtutils class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): @@ -211,31 +211,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): e.ignore() return else: - if e.key() == Qt.Key_D and (e.modifiers() & Qt.ControlModifier == - Qt.ControlModifier): - self.delete_current_item() - else: - super().keyPressEvent(e) - - def delete_current_item(self): - """Delete the selected bookmark/quickmark.""" - completion = objreg.get('completion', scope='window', - window=self._win_id) - index = completion.currentIndex() - model = completion.model() - url = model.data(index) - category = index.parent() - if category.isValid(): - if category.data() == 'Bookmarks': - bookmark_manager = objreg.get('bookmark-manager') - bookmark_manager.bookmark_del(url) - message.info(self._win_id, "Bookmarks deleted") - elif category.data() == 'Quickmarks': - quickmark_manager = objreg.get('quickmark-manager') - name = model.data(index.sibling(index.row(), - index.column() + 1)) - quickmark_manager.quickmark_del(name) - message.info(self._win_id, "Quickmarks deleted") + super().keyPressEvent(e) def sizeHint(self): """Dynamically calculate the needed size.""" From c4fc5c0c43dca026accebcb8a8203fa7404283af Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 7 Jun 2015 19:51:46 -0400 Subject: [PATCH 15/28] Fixed to use the title "(null)" when the page does not have any title. --- qutebrowser/browser/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index c0f19c0b2..fb539ab10 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -103,7 +103,8 @@ class CommandDispatcher: def _current_title(self): """Convenience method to get the current title.""" - return self._tabbed_browser.page_title(self._current_index()) + title = self._current_widget().title() + return title if title else "(null)" def _current_widget(self): """Get the currently active widget from a command.""" From d93732a6b37546474883abaf868da71ca8e32653 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 7 Jun 2015 20:04:42 -0400 Subject: [PATCH 16/28] Fixed to use 'bookmarks/urls' file instead of bookmarks. --- qutebrowser/browser/bookmarks.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py index d92ad2bb2..5d7cd7530 100644 --- a/qutebrowser/browser/bookmarks.py +++ b/qutebrowser/browser/bookmarks.py @@ -25,6 +25,7 @@ OrderedDict. This is because we read them from a file at start and write them to a file on shutdown, so it makes sense to keep them as strings here. """ +import os import os.path import collections @@ -66,8 +67,11 @@ class BookmarkManager(QObject): if standarddir.config() is None: self._lineparser = None else: + bookmarks_directory = os.path.join(standarddir.config(), 'bookmarks') + if not os.path.isdir(bookmarks_directory): + os.makedirs(bookmarks_directory) self._lineparser = lineparser.LineParser( - standarddir.config(), 'bookmarks', parent=self) + standarddir.config(), 'bookmarks/urls', parent=self) for line in self._lineparser: if not line.strip(): # Ignore empty or whitespace-only lines. @@ -78,7 +82,7 @@ class BookmarkManager(QObject): message.error(0, "Invalid bookmark '{}'".format(line)) else: self.bookmarks[url] = title - filename = os.path.join(standarddir.config(), 'bookmarks') + filename = os.path.join(standarddir.config(), 'bookmarks/urls') objreg.get('save-manager').add_saveable( 'bookmark-manager', self.save, self.changed, filename=filename) From 31eed6c9a6a90c8d302ca5abcd1da2000bd084d1 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 7 Jun 2015 20:16:45 -0400 Subject: [PATCH 17/28] Fixed to avoid having duplicate bookmarks. --- qutebrowser/browser/bookmarks.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py index 5d7cd7530..c982160f4 100644 --- a/qutebrowser/browser/bookmarks.py +++ b/qutebrowser/browser/bookmarks.py @@ -116,10 +116,13 @@ class BookmarkManager(QObject): message.error(win_id, "Can't set mark with empty URL!") return - self.bookmarks[urlstr] = title - self.changed.emit() - self.added.emit(title, urlstr) - message.info(win_id, "Bookmarks added") + if urlstr in self.bookmarks: + message.error(win_id, "Bookmark already exists!") + else: + self.bookmarks[urlstr] = title + self.changed.emit() + self.added.emit(title, urlstr) + message.info(win_id, "Bookmark added") def bookmark_del(self, url): """Delete a bookmark. From c2eabb13b031058f32d4769b9d4c4e04a2e2a68d Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 7 Jun 2015 20:25:04 -0400 Subject: [PATCH 18/28] Fixed style. --- qutebrowser/browser/bookmarks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py index c982160f4..1634f4f2e 100644 --- a/qutebrowser/browser/bookmarks.py +++ b/qutebrowser/browser/bookmarks.py @@ -67,7 +67,8 @@ class BookmarkManager(QObject): if standarddir.config() is None: self._lineparser = None else: - bookmarks_directory = os.path.join(standarddir.config(), 'bookmarks') + bookmarks_directory = os.path.join(standarddir.config(), + 'bookmarks') if not os.path.isdir(bookmarks_directory): os.makedirs(bookmarks_directory) self._lineparser = lineparser.LineParser( From 8159c5f56703b8f0fc6323763f0109131c604566 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 11 Jul 2015 18:56:19 -0400 Subject: [PATCH 19/28] Fixed last merge. --- qutebrowser/completion/completer.py | 11 ++++++++++- qutebrowser/completion/completionwidget.py | 22 ---------------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/qutebrowser/completion/completer.py b/qutebrowser/completion/completer.py index 2d4165bbf..d1bc962f6 100644 --- a/qutebrowser/completion/completer.py +++ b/qutebrowser/completion/completer.py @@ -22,7 +22,7 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QTimer from qutebrowser.config import config -from qutebrowser.commands import cmdutils, runners +from qutebrowser.commands import cmdexc, cmdutils, runners from qutebrowser.utils import usertypes, log, objreg, utils from qutebrowser.completion.models import instances @@ -481,3 +481,12 @@ class Completer(QObject): """Select the next completion item.""" self._open_completion_if_needed() self.next_prev_item.emit(False) + + @cmdutils.register(instance='completion', hide=True, + modes=[usertypes.KeyMode.command], scope='window') + def completion_item_del(self): + """Delete the current completion item.""" + try: + self.model().srcmodel.delete_cur_item(self._win_id) + except NotImplementedError: + raise cmdexc.CommandError("Cannot delete this item.") diff --git a/qutebrowser/completion/completionwidget.py b/qutebrowser/completion/completionwidget.py index 5db383a64..a3bea931a 100644 --- a/qutebrowser/completion/completionwidget.py +++ b/qutebrowser/completion/completionwidget.py @@ -26,7 +26,6 @@ subclasses to provide completions. from PyQt5.QtWidgets import QStyle, QTreeView, QSizePolicy from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QItemSelectionModel -from qutebrowser.commands import cmdexc, cmdutils from qutebrowser.config import config, style from qutebrowser.completion import completiondelegate, completer from qutebrowser.utils import qtutils, objreg, utils @@ -237,27 +236,6 @@ class CompletionView(QTreeView): selmod.clearSelection() selmod.clearCurrentIndex() - @cmdutils.register(instance='completion', hide=True, - modes=[usertypes.KeyMode.command], scope='window') - def completion_item_prev(self): - """Select the previous completion item.""" - self._next_prev_item(prev=True) - - @cmdutils.register(instance='completion', hide=True, - modes=[usertypes.KeyMode.command], scope='window') - def completion_item_next(self): - """Select the next completion item.""" - self._next_prev_item(prev=False) - - @cmdutils.register(instance='completion', hide=True, - modes=[usertypes.KeyMode.command], scope='window') - def completion_item_del(self): - """Delete the current completion item.""" - try: - self.model().srcmodel.delete_cur_item(self._win_id) - except NotImplementedError: - raise cmdexc.CommandError("Cannot delete this item.") - def selectionChanged(self, selected, deselected): """Extend selectionChanged to call completers selection_changed.""" super().selectionChanged(selected, deselected) From 4bc2f63608afc314d30c3bc4ef50ad0e977e6d25 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 11 Jul 2015 19:12:18 -0400 Subject: [PATCH 20/28] Renamed bookmark_add to add in bookmark manager. --- .gitignore | 1 + qutebrowser/browser/bookmarks.py | 2 +- qutebrowser/browser/commands.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 696cdc775..6d95e92f4 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ __pycache__ /.tox /testresults.html /.cache +TODO diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py index 1634f4f2e..0343af924 100644 --- a/qutebrowser/browser/bookmarks.py +++ b/qutebrowser/browser/bookmarks.py @@ -95,7 +95,7 @@ class BookmarkManager(QObject): for tpl in self.bookmarks.items()] self._lineparser.save() - def bookmark_add(self, win_id, url, title): + def add(self, win_id, url, title): """Add a new bookmark. Args: diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 4335dd1de..a15ad79dd 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1062,8 +1062,8 @@ class CommandDispatcher: def bookmark_add(self): """Save the current page as a bookmark.""" bookmark_manager = objreg.get('bookmark-manager') - bookmark_manager.bookmark_add(self._win_id, self._current_url(), - self._current_title()) + bookmark_manager.add(self._win_id, self._current_url(), + self._current_title()) @cmdutils.register(instance='command-dispatcher', scope='window', maxsplit=0, From 96a2178a25a95bb222459fc6b5cb6d58efa5c548 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 11 Jul 2015 19:23:21 -0400 Subject: [PATCH 21/28] Renamed bookmark_del to delete in bookmark manager. --- qutebrowser/browser/bookmarks.py | 2 +- qutebrowser/completion/models/urlmodel.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py index 0343af924..35a1b9bf4 100644 --- a/qutebrowser/browser/bookmarks.py +++ b/qutebrowser/browser/bookmarks.py @@ -125,7 +125,7 @@ class BookmarkManager(QObject): self.added.emit(title, urlstr) message.info(win_id, "Bookmark added") - def bookmark_del(self, url): + def delete(self, url): """Delete a bookmark. Args: diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index ef2b548d6..bf66abb0d 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -190,7 +190,7 @@ class UrlCompletionModel(base.BaseCompletionModel): if category.isValid(): if category.data() == 'Bookmarks': bookmark_manager = objreg.get('bookmark-manager') - bookmark_manager.bookmark_del(url) + bookmark_manager.delete(url) message.info(win_id, "Bookmarks deleted") elif category.data() == 'Quickmarks': quickmark_manager = objreg.get('quickmark-manager') From 5e8129788a05f473ef7fe5fb2a2be4d98280011b Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 11 Jul 2015 19:44:01 -0400 Subject: [PATCH 22/28] Removed try/except. --- qutebrowser/browser/bookmarks.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py index 35a1b9bf4..2c1558f84 100644 --- a/qutebrowser/browser/bookmarks.py +++ b/qutebrowser/browser/bookmarks.py @@ -32,7 +32,6 @@ import collections from PyQt5.QtCore import pyqtSignal, QUrl, QObject from qutebrowser.utils import message, urlutils, standarddir, objreg -from qutebrowser.commands import cmdexc from qutebrowser.misc import lineparser @@ -131,10 +130,6 @@ class BookmarkManager(QObject): Args: url: The url of the bookmark to delete. """ - try: - del self.bookmarks[url] - except KeyError: - raise cmdexc.CommandError("Bookmark '{}' not found!".format(url)) - else: - self.changed.emit() - self.removed.emit(url) + del self.bookmarks[url] + self.changed.emit() + self.removed.emit(url) From 1e354a797e8edf5530e1880925997617a00db1ac Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 11 Jul 2015 19:52:48 -0400 Subject: [PATCH 23/28] Removed useless checks. --- qutebrowser/browser/bookmarks.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py index 2c1558f84..c57d0c23e 100644 --- a/qutebrowser/browser/bookmarks.py +++ b/qutebrowser/browser/bookmarks.py @@ -31,7 +31,7 @@ import collections from PyQt5.QtCore import pyqtSignal, QUrl, QObject -from qutebrowser.utils import message, urlutils, standarddir, objreg +from qutebrowser.utils import message, standarddir, objreg from qutebrowser.misc import lineparser @@ -102,20 +102,8 @@ class BookmarkManager(QObject): url: The url to add as bookmark. title: The title for the new bookmark. """ - if not url.isValid(): - urlutils.invalid_url_error(win_id, url, "save quickmark") - return urlstr = url.toString(QUrl.RemovePassword | QUrl.FullyEncoded) - # We don't raise cmdexc.CommandError here as this can be called async - # via prompt_save. - if not title: - message.error(win_id, "Can't set mark with empty title!") - return - if not urlstr: - message.error(win_id, "Can't set mark with empty URL!") - return - if urlstr in self.bookmarks: message.error(win_id, "Bookmark already exists!") else: From 5dbaea7a83e6a92a49dbf668c7bc5c39b16ed70e Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 11 Jul 2015 20:28:31 -0400 Subject: [PATCH 24/28] Fixed empty title. --- qutebrowser/browser/bookmarks.py | 13 +++++++------ qutebrowser/browser/commands.py | 3 +-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/qutebrowser/browser/bookmarks.py b/qutebrowser/browser/bookmarks.py index c57d0c23e..966584c04 100644 --- a/qutebrowser/browser/bookmarks.py +++ b/qutebrowser/browser/bookmarks.py @@ -76,12 +76,13 @@ class BookmarkManager(QObject): if not line.strip(): # Ignore empty or whitespace-only lines. continue - try: - url, title = line.split(maxsplit=1) - except ValueError: - message.error(0, "Invalid bookmark '{}'".format(line)) - else: - self.bookmarks[url] = title + + parts = line.split(maxsplit=1) + if len(parts) == 2: + self.bookmarks[parts[0]] = parts[1] + elif len(parts) == 1: + self.bookmarks[parts[0]] = '' + filename = os.path.join(standarddir.config(), 'bookmarks/urls') objreg.get('save-manager').add_saveable( 'bookmark-manager', self.save, self.changed, diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index a15ad79dd..4ccab7e24 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -102,8 +102,7 @@ class CommandDispatcher: def _current_title(self): """Convenience method to get the current title.""" - title = self._current_widget().title() - return title if title else "(null)" + return self._current_widget().title() def _current_widget(self): """Get the currently active widget from a command.""" From d4c91f7b0ca1d58f5eb950eda36413d0b2e60a7b Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 12 Jul 2015 20:18:32 -0400 Subject: [PATCH 25/28] Fixed completion highlighting. --- qutebrowser/completion/completiondelegate.py | 12 ++++++++---- qutebrowser/completion/models/base.py | 1 + qutebrowser/completion/models/configmodel.py | 3 +++ qutebrowser/completion/models/miscmodels.py | 5 +++++ qutebrowser/completion/models/urlmodel.py | 3 +++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/qutebrowser/completion/completiondelegate.py b/qutebrowser/completion/completiondelegate.py index aae84992e..130454229 100644 --- a/qutebrowser/completion/completiondelegate.py +++ b/qutebrowser/completion/completiondelegate.py @@ -195,10 +195,14 @@ class CompletionItemDelegate(QStyledItemDelegate): if index.parent().isValid(): pattern = index.model().pattern - repl = r'\g<0>' - text = re.sub(re.escape(pattern), repl, self._opt.text, - flags=re.IGNORECASE) - self._doc.setHtml(text) + if(index.column() in index.model().srcmodel.columns_to_highlight + and pattern): + repl = r'\g<0>' + text = re.sub(re.escape(pattern), repl, self._opt.text, + flags=re.IGNORECASE) + self._doc.setHtml(text) + else: + self._doc.setPlainText(self._opt.text) else: self._doc.setHtml('{}'.format(html.escape(self._opt.text))) diff --git a/qutebrowser/completion/models/base.py b/qutebrowser/completion/models/base.py index 7f1e0c7d6..b7c5223d7 100644 --- a/qutebrowser/completion/models/base.py +++ b/qutebrowser/completion/models/base.py @@ -44,6 +44,7 @@ class BaseCompletionModel(QStandardItemModel): def __init__(self, parent=None): super().__init__(parent) self.setColumnCount(3) + self.columns_to_highlight = [] def new_category(self, name, sort=None): """Add a new category to the model. diff --git a/qutebrowser/completion/models/configmodel.py b/qutebrowser/completion/models/configmodel.py index 6d39fed7b..a44387a17 100644 --- a/qutebrowser/completion/models/configmodel.py +++ b/qutebrowser/completion/models/configmodel.py @@ -34,6 +34,7 @@ class SettingSectionCompletionModel(base.BaseCompletionModel): def __init__(self, parent=None): super().__init__(parent) + self.columns_to_highlight.append(0) cat = self.new_category("Sections") for name in configdata.DATA.keys(): desc = configdata.SECTION_DESC[name].splitlines()[0].strip() @@ -53,6 +54,7 @@ class SettingOptionCompletionModel(base.BaseCompletionModel): def __init__(self, section, parent=None): super().__init__(parent) + self.columns_to_highlight.append(0) cat = self.new_category(section) sectdata = configdata.DATA[section] self._misc_items = {} @@ -106,6 +108,7 @@ class SettingValueCompletionModel(base.BaseCompletionModel): def __init__(self, section, option, parent=None): super().__init__(parent) + self.columns_to_highlight.append(0) self._section = section self._option = option objreg.get('config').changed.connect(self.update_current_value) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index faea69269..2ce9cd147 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -33,6 +33,7 @@ class CommandCompletionModel(base.BaseCompletionModel): def __init__(self, parent=None): super().__init__(parent) + self.columns_to_highlight.append(0) assert cmdutils.cmd_dict cmdlist = [] for obj in set(cmdutils.cmd_dict.values()): @@ -56,6 +57,7 @@ class HelpCompletionModel(base.BaseCompletionModel): def __init__(self, parent=None): super().__init__(parent) + self.columns_to_highlight.append(0) self._init_commands() self._init_settings() @@ -98,6 +100,7 @@ class QuickmarkCompletionModel(base.BaseCompletionModel): def __init__(self, match_field='url', parent=None): super().__init__(parent) + self.columns_to_highlight.append(0) cat = self.new_category("Quickmarks") quickmarks = objreg.get('quickmark-manager').marks.items() if match_field == 'url': @@ -119,6 +122,7 @@ class BookmarkCompletionModel(base.BaseCompletionModel): def __init__(self, match_field='url', parent=None): super().__init__(parent) + self.columns_to_highlight.append(0) cat = self.new_category("Bookmarks") bookmarks = objreg.get('bookmark-manager').bookmarks.items() if match_field == 'url': @@ -140,6 +144,7 @@ class SessionCompletionModel(base.BaseCompletionModel): def __init__(self, parent=None): super().__init__(parent) + self.columns_to_highlight.append(0) cat = self.new_category("Sessions") try: for name in objreg.get('session-manager').list_sessions(): diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index bf66abb0d..f89b2cf48 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -39,6 +39,9 @@ class UrlCompletionModel(base.BaseCompletionModel): def __init__(self, parent=None): super().__init__(parent) + self.columns_to_highlight.append(0) + self.columns_to_highlight.append(1) + self._quickmark_cat = self.new_category("Quickmarks") self._bookmark_cat = self.new_category("Bookmarks") self._history_cat = self.new_category("History") From 1b24cfd618d7d9e1d0cc6fc1ba52f39ead538f8e Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 12 Jul 2015 20:21:49 -0400 Subject: [PATCH 26/28] Removed useless bookmark by title model. --- qutebrowser/completion/models/instances.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qutebrowser/completion/models/instances.py b/qutebrowser/completion/models/instances.py index 7fa53d6d9..f8e89137c 100644 --- a/qutebrowser/completion/models/instances.py +++ b/qutebrowser/completion/models/instances.py @@ -117,7 +117,6 @@ def init_bookmark_completions(): pass model = _init_model(miscmodels.BookmarkCompletionModel, 'url') _instances[usertypes.Completion.bookmark_by_url] = model - model = _init_model(miscmodels.BookmarkCompletionModel, 'title') @pyqtSlot() From 5bca951c21db7dab8c8e2e21c0545d2f82224afa Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 12 Jul 2015 20:29:40 -0400 Subject: [PATCH 27/28] Removed casefold() function call when using a custom filter. --- qutebrowser/completion/models/sortfilter.py | 5 ++--- qutebrowser/completion/models/urlmodel.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/qutebrowser/completion/models/sortfilter.py b/qutebrowser/completion/models/sortfilter.py index 2310d73d1..be9199153 100644 --- a/qutebrowser/completion/models/sortfilter.py +++ b/qutebrowser/completion/models/sortfilter.py @@ -140,13 +140,12 @@ class CompletionFilterModel(QSortFilterProxyModel): if not self.pattern: return True - pattern = self.pattern.casefold() try: - return self.srcmodel.custom_filter(pattern, row, parent) + return self.srcmodel.custom_filter(self.pattern, row, parent) except NotImplementedError: if not data: return False - return pattern in data.casefold() + return self.pattern.casefold() in data.casefold() def intelligentLessThan(self, lindex, rindex): """Custom sorting implementation. diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index f89b2cf48..4500d66cc 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -107,7 +107,7 @@ class UrlCompletionModel(base.BaseCompletionModel): index1 = self.index(row, 1, parent) url = self.data(index0) or '' title = self.data(index1) or '' - return pattern in url.casefold() or pattern in title.casefold() + return pattern.casefold() in url.casefold() or pattern.casefold() in title.casefold() @config.change_filter('completion', 'timestamp-format') def reformat_timestamps(self): From 91561e2c5b50de23b140e2b19843687ea853f536 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 12 Jul 2015 20:46:40 -0400 Subject: [PATCH 28/28] Fixed style. --- qutebrowser/completion/models/urlmodel.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 4500d66cc..14d8b5252 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -107,7 +107,8 @@ class UrlCompletionModel(base.BaseCompletionModel): index1 = self.index(row, 1, parent) url = self.data(index0) or '' title = self.data(index1) or '' - return pattern.casefold() in url.casefold() or pattern.casefold() in title.casefold() + return (pattern.casefold() in url.casefold() or pattern.casefold() in + title.casefold()) @config.change_filter('completion', 'timestamp-format') def reformat_timestamps(self):