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
This commit is contained in:
parent
9e21e2e86b
commit
0b200207dd
|
|
@ -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
|
||||
~~~~~~~
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue