Make quickmark_del with no argument delete the current page's mark (fixes #1661)
This commit is contained in:
parent
83005bc072
commit
19949101c6
@ -1095,6 +1095,29 @@ class CommandDispatcher:
|
||||
raise cmdexc.CommandError(str(e))
|
||||
self._open(url, tab, bg, window)
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||
maxsplit=0)
|
||||
@cmdutils.argument('name',
|
||||
completion=usertypes.Completion.quickmark_by_name)
|
||||
def quickmark_del(self, name=None):
|
||||
"""Delete a quickmark.
|
||||
|
||||
Args:
|
||||
name: The name of the quickmark to delete. If none, delete the
|
||||
quickmark for the current page (choosing one arbitrarily
|
||||
if there are more than one).
|
||||
"""
|
||||
quickmark_manager = objreg.get('quickmark-manager')
|
||||
if name is None:
|
||||
url = self._current_url()
|
||||
try:
|
||||
name = quickmark_manager.get_by_qurl(url)
|
||||
except ValueError:
|
||||
urlutils.invalid_url_error(self._win_id, url,
|
||||
"delete quickmark")
|
||||
return
|
||||
quickmark_manager.quickmark_del(name)
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||
def bookmark_add(self, url=None, title=None):
|
||||
"""Save the current page as a bookmark, or a specific url.
|
||||
|
@ -204,9 +204,6 @@ class QuickmarkManager(UrlMarkManager):
|
||||
else:
|
||||
set_mark()
|
||||
|
||||
@cmdutils.register(instance='quickmark-manager', maxsplit=0)
|
||||
@cmdutils.argument('name',
|
||||
completion=usertypes.Completion.quickmark_by_name)
|
||||
def quickmark_del(self, name):
|
||||
"""Delete a quickmark.
|
||||
|
||||
@ -218,6 +215,24 @@ class QuickmarkManager(UrlMarkManager):
|
||||
except KeyError:
|
||||
raise cmdexc.CommandError("Quickmark '{}' not found!".format(name))
|
||||
|
||||
def get_by_qurl(self, url):
|
||||
"""Look up a quickmark by QUrl, returning its name.
|
||||
|
||||
Takes O(n) time, where n is the number of quickmarks.
|
||||
Use a name instead where possible.
|
||||
"""
|
||||
if not url.isValid():
|
||||
raise ValueError("Invalid URL: {}".format(url.errorString()))
|
||||
urlstr = url.toString(QUrl.RemovePassword | QUrl.FullyEncoded)
|
||||
|
||||
try:
|
||||
index = list(self.marks.values()).index(urlstr)
|
||||
key = list(self.marks.keys())[index]
|
||||
except ValueError:
|
||||
raise cmdexc.CommandError(
|
||||
"Quickmark for '{}' not found!".format(urlstr))
|
||||
return key
|
||||
|
||||
def get(self, name):
|
||||
"""Get the URL of the quickmark named name as a QUrl."""
|
||||
if name not in self.marks:
|
||||
|
Loading…
Reference in New Issue
Block a user