summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2023-08-10 14:27:39 +0200
committerFlorian Bruhin <me@the-compiler.org>2023-08-10 15:30:26 +0200
commit0b200207dd01d1e6e806ce4e6b91cb4327437d6b (patch)
tree2c159c213d271861c6671ea8d3cd09b728692729
parent9e21e2e86bee5b0de42fe28153dd1bcb0aa51d27 (diff)
downloadqutebrowser-0b200207dd01d1e6e806ce4e6b91cb4327437d6b.tar.gz
qutebrowser-0b200207dd01d1e6e806ce4e6b91cb4327437d6b.zip
Add --all to :{quick,book}mark-del
Needed mostly for urlmarks BDD tests so they can clear things between tests. Hopefully with --all, this won't be accidentally triggered by users. Preparation for #7815
-rw-r--r--doc/changelog.asciidoc2
-rw-r--r--doc/help/commands.asciidoc10
-rw-r--r--qutebrowser/browser/commands.py24
-rw-r--r--qutebrowser/browser/urlmarks.py5
-rw-r--r--tests/end2end/features/test_urlmarks_bdd.py9
-rw-r--r--tests/end2end/features/urlmarks.feature29
6 files changed, 74 insertions, 5 deletions
diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc
index b2b392a4c..5deb381f7 100644
--- a/doc/changelog.asciidoc
+++ b/doc/changelog.asciidoc
@@ -67,6 +67,8 @@ Added
- New `colors.webpage.darkmode.increase_text_contrast` setting for Qt 6.3+
- New `fonts.tooltip`, `colors.tooltip.bg` and `colors.tooltip.fg` settings.
- New `log-qt-events` debug flag for `-D`
+- New `--all` flags for `:bookmark-del` and `:quickmark-del` to delete all
+ quickmarks/bookmarks.
Removed
~~~~~~~
diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc
index 7f0abc71d..6577a9ddf 100644
--- a/doc/help/commands.asciidoc
+++ b/doc/help/commands.asciidoc
@@ -204,7 +204,7 @@ If no url and title are provided, then save the current page as a bookmark. If a
[[bookmark-del]]
=== bookmark-del
-Syntax: +:bookmark-del ['url']+
+Syntax: +:bookmark-del [*--all*] ['url']+
Delete a bookmark.
@@ -212,6 +212,9 @@ Delete a bookmark.
* +'url'+: The url of the bookmark to delete. If not given, use the current page's url.
+==== optional arguments
+* +*-a*+, +*--all*+: If given, delete all bookmarks.
+
==== note
* This command does not split arguments after the last argument and handles quotes literally.
@@ -998,7 +1001,7 @@ You can view all saved quickmarks on the link:qute://bookmarks[bookmarks page].
[[quickmark-del]]
=== quickmark-del
-Syntax: +:quickmark-del ['name']+
+Syntax: +:quickmark-del [*--all*] ['name']+
Delete a quickmark.
@@ -1007,6 +1010,9 @@ Delete a quickmark.
if there are more than one).
+==== optional arguments
+* +*-a*+, +*--all*+: Delete all quickmarks.
+
==== note
* This command does not split arguments after the last argument and handles quotes literally.
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
index 7efb69511..2889b630c 100644
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -1235,21 +1235,30 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window',
maxsplit=0)
@cmdutils.argument('name', completion=miscmodels.quickmark)
- def quickmark_del(self, name=None):
+ def quickmark_del(self, name=None, all_=False):
"""Delete a quickmark.
Args:
name: The name of the quickmark to delete. If not given, delete the
quickmark for the current page (choosing one arbitrarily
if there are more than one).
+ all_: Delete all quickmarks.
"""
quickmark_manager = objreg.get('quickmark-manager')
+
+ if all_:
+ if name is not None:
+ raise cmdutils.CommandError("Cannot specify name and --all")
+ quickmark_manager.clear()
+ return
+
if name is None:
url = self._current_url()
try:
name = quickmark_manager.get_by_qurl(url)
except urlmarks.DoesNotExistError as e:
raise cmdutils.CommandError(str(e))
+
try:
quickmark_manager.delete(name)
except KeyError:
@@ -1320,18 +1329,27 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window',
maxsplit=0)
@cmdutils.argument('url', completion=miscmodels.bookmark)
- def bookmark_del(self, url=None):
+ def bookmark_del(self, url=None, all_=False):
"""Delete a bookmark.
Args:
url: The url of the bookmark to delete. If not given, use the
current page's url.
+ all_: If given, delete all bookmarks.
"""
+ bookmark_manager = objreg.get('bookmark-manager')
+ if all_:
+ if url is not None:
+ raise cmdutils.CommandError("Cannot specify url and --all")
+ bookmark_manager.clear()
+ return
+
if url is None:
url = self._current_url().toString(QUrl.UrlFormattingOption.RemovePassword |
QUrl.ComponentFormattingOption.FullyEncoded)
+
try:
- objreg.get('bookmark-manager').delete(url)
+ bookmark_manager.delete(url)
except KeyError:
raise cmdutils.CommandError("Bookmark '{}' not found!".format(url))
message.info("Removed bookmark {}".format(url))
diff --git a/qutebrowser/browser/urlmarks.py b/qutebrowser/browser/urlmarks.py
index 2a060f5ef..2d2563a1a 100644
--- a/qutebrowser/browser/urlmarks.py
+++ b/qutebrowser/browser/urlmarks.py
@@ -98,6 +98,11 @@ class UrlMarkManager(QObject):
del self.marks[key]
self.changed.emit()
+ def clear(self):
+ """Delete all marks."""
+ self.marks.clear()
+ self.changed.emit()
+
class QuickmarkManager(UrlMarkManager):
diff --git a/tests/end2end/features/test_urlmarks_bdd.py b/tests/end2end/features/test_urlmarks_bdd.py
index 1b21098cd..6d4172085 100644
--- a/tests/end2end/features/test_urlmarks_bdd.py
+++ b/tests/end2end/features/test_urlmarks_bdd.py
@@ -4,6 +4,7 @@
import os.path
+import pytest
import pytest_bdd as bdd
from helpers import testutils
@@ -11,6 +12,14 @@ from helpers import testutils
bdd.scenarios('urlmarks.feature')
+@pytest.fixture(autouse=True)
+def clear_marks(quteproc):
+ """Clear all existing marks between tests."""
+ yield
+ quteproc.send_cmd(':quickmark-del --all')
+ quteproc.send_cmd(':bookmark-del --all')
+
+
def _check_marks(quteproc, quickmarks, expected, contains):
"""Make sure the given line does (not) exist in the bookmarks.
diff --git a/tests/end2end/features/urlmarks.feature b/tests/end2end/features/urlmarks.feature
index 00fd14fb6..e8f4a9e77 100644
--- a/tests/end2end/features/urlmarks.feature
+++ b/tests/end2end/features/urlmarks.feature
@@ -86,6 +86,22 @@ Feature: quickmarks and bookmarks
And I run :bookmark-del http://localhost:(port)/data/numbers/5.txt
Then the bookmark file should not contain "http://localhost:*/data/numbers/5.txt "
+ Scenario: Deleting all bookmarks
+ When I open data/numbers/1.txt
+ And I run :bookmark-add
+ And I open data/numbers/2.txt
+ And I run :bookmark-add
+ And I run :bookmark-del --all
+ Then the bookmark file should not contain "http://localhost:*/data/numbers/1.txt"
+ And the bookmark file should not contain "http://localhost:*/data/numbers/2.txt"
+
+ Scenario: Deleting all bookmarks with url
+ When I open data/numbers/1.txt
+ And I run :bookmark-add
+ And I run :bookmark-del --all https://example.org
+ Then the error "Cannot specify url and --all" should be shown
+ And the bookmark file should contain "http://localhost:*/data/numbers/1.txt"
+
Scenario: Deleting the current page's bookmark if it doesn't exist
When I open data/hello.txt
And I run :bookmark-del
@@ -210,6 +226,19 @@ Feature: quickmarks and bookmarks
And I run :quickmark-del eighteen
Then the quickmark file should not contain "eighteen http://localhost:*/data/numbers/18.txt "
+ Scenario: Deleting all quickmarks
+ When I run :quickmark-add http://localhost:(port)/data/numbers/1.txt one
+ When I run :quickmark-add http://localhost:(port)/data/numbers/2.txt two
+ And I run :quickmark-del --all
+ Then the quickmark file should not contain "one http://localhost:*/data/numbers/1.txt"
+ And the quickmark file should not contain "two http://localhost:*/data/numbers/2.txt"
+
+ Scenario: Deleting all quickmarks with name
+ When I run :quickmark-add http://localhost:(port)/data/numbers/1.txt one
+ And I run :quickmark-del --all invalid
+ Then the error "Cannot specify name and --all" should be shown
+ And the quickmark file should contain "one http://localhost:*/data/numbers/1.txt"
+
Scenario: Deleting the current page's quickmark if it has none
When I open data/hello.txt
And I run :quickmark-del