Ask for confirmation with :history-clear

This commit is contained in:
Florian Bruhin 2017-02-09 13:19:42 +01:00
parent 92c3ec6435
commit 85d8d45e19
4 changed files with 26 additions and 3 deletions

View File

@ -40,6 +40,7 @@ Changed
- When yanking a mailto: link via hints, the mailto: prefix is now stripped
- Zoom level messages are now not stacked on top of each other anymore.
- qutebrowser now automatically uses QtWebEngine if QtWebKit is unavailable
- :history-clear now asks for a confirmation, unless it's run with --force.
Fixed
-----

View File

@ -420,10 +420,15 @@ Start hinting.
[[history-clear]]
=== history-clear
Syntax: +:history-clear [*--force*]+
Clear all browsing history.
Note this only clears the global history (e.g. `~/.local/share/qutebrowser/history` on Linux) but not cookies, the back/forward history of a tab, cache or other persistent data.
==== optional arguments
* +*-f*+, +*--force*+: Don't ask for confirmation.
[[home]]
=== home
Open main startpage in current tab.

View File

@ -26,7 +26,7 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject
from qutebrowser.commands import cmdutils
from qutebrowser.utils import (utils, objreg, standarddir, log, qtutils,
usertypes)
usertypes, message)
from qutebrowser.config import config
from qutebrowser.misc import lineparser, objects
@ -230,13 +230,23 @@ class WebHistory(QObject):
self._saved_count = len(self._new_history)
@cmdutils.register(name='history-clear', instance='web-history')
def clear(self):
def clear(self, force=False):
"""Clear all browsing history.
Note this only clears the global history
(e.g. `~/.local/share/qutebrowser/history` on Linux) but not cookies,
the back/forward history of a tab, cache or other persistent data.
Args:
force: Don't ask for confirmation.
"""
if force:
self._do_clear()
else:
message.confirm_async(self._do_clear, title="Clear all browsing "
"history?")
def _do_clear(self):
self._lineparser.clear()
self.history_dict.clear()
self._temp_history.clear()

View File

@ -4,7 +4,7 @@ Feature: Page history
Background:
Given I open about:blank
And I run :history-clear
And I run :history-clear --force
Scenario: Simple history saving
When I open data/numbers/1.txt
@ -56,8 +56,15 @@ Feature: Page history
Then "Changing title for idx 1 to 'about:blank'" should be logged
Scenario: Clearing history
When I open data/title.html
And I run :history-clear --force
Then the history file should be empty
Scenario: Clearing history with confirmation
When I open data/title.html
And I run :history-clear
And I wait for "Asking question <* title='Clear all browsing history?'>, *" in the log
And I run :prompt-accept yes
Then the history file should be empty
Scenario: History with yanked URL and 'add to history' flag