history: Add clear() method and history-clear command
WebHistory now has a clear() method which is also a command (history-clear) which clears the qutebrowser history using the new lineparser clear() method and emits a cleared signal. The completion model urlmodel connects to the WebHistory.cleared signal and clears its history category completion list. I am adding this as a temporary fix before #58 or #1051 get implemented.
This commit is contained in:
parent
6894033f8d
commit
399aaa2b70
@ -25,6 +25,7 @@ import collections
|
||||
from PyQt5.QtCore import pyqtSignal, QUrl
|
||||
from PyQt5.QtWebKit import QWebHistoryInterface
|
||||
|
||||
from qutebrowser.commands import cmdutils
|
||||
from qutebrowser.utils import utils, objreg, standarddir, log
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.misc import lineparser
|
||||
@ -72,10 +73,12 @@ class WebHistory(QWebHistoryInterface):
|
||||
arg: The new HistoryEntry.
|
||||
item_added: Emitted after a new HistoryEntry is added.
|
||||
arg: The new HistoryEntry.
|
||||
cleared: Emitted after the history is cleared.
|
||||
"""
|
||||
|
||||
add_completion_item = pyqtSignal(HistoryEntry)
|
||||
item_added = pyqtSignal(HistoryEntry)
|
||||
cleared = pyqtSignal()
|
||||
async_read_done = pyqtSignal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
@ -169,6 +172,16 @@ class WebHistory(QWebHistoryInterface):
|
||||
self._lineparser.save()
|
||||
self._saved_count = len(self._new_history)
|
||||
|
||||
@cmdutils.register(name='history-clear', instance='web-history')
|
||||
def clear(self):
|
||||
"""Clear all history entries."""
|
||||
self._lineparser.clear()
|
||||
self._history_dict.clear()
|
||||
self._temp_history.clear()
|
||||
self._new_history.clear()
|
||||
self._saved_count = 0
|
||||
self.cleared.emit()
|
||||
|
||||
def addHistoryEntry(self, url_string):
|
||||
"""Called by WebKit when an URL should be added to the history.
|
||||
|
||||
|
@ -76,6 +76,7 @@ class UrlCompletionModel(base.BaseCompletionModel):
|
||||
self._add_history_entry(entry)
|
||||
self._history.add_completion_item.connect(
|
||||
self.on_history_item_added)
|
||||
self._history.cleared.connect(self.on_history_cleared)
|
||||
|
||||
objreg.get('config').changed.connect(self.reformat_timestamps)
|
||||
|
||||
@ -130,6 +131,10 @@ class UrlCompletionModel(base.BaseCompletionModel):
|
||||
else:
|
||||
self._add_history_entry(entry)
|
||||
|
||||
@pyqtSlot()
|
||||
def on_history_cleared(self):
|
||||
self._history_cat.removeRows(0, self._history_cat.rowCount())
|
||||
|
||||
def _remove_item(self, data, category, column):
|
||||
"""Helper function for on_quickmark_removed and on_bookmark_removed.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user