Merge branch 'add-bookmark-by-url' of https://github.com/ismail-s/qutebrowser into ismail-s-add-bookmark-by-url
This commit is contained in:
commit
4f9be56d7d
@ -1081,12 +1081,33 @@ class CommandDispatcher:
|
|||||||
self._open(url, tab, bg, window)
|
self._open(url, tab, bg, window)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
def bookmark_add(self):
|
def bookmark_add(self, url=None, title=None):
|
||||||
"""Save the current page as a bookmark."""
|
"""Save the current page as a bookmark, or a specific url.
|
||||||
|
|
||||||
|
If no url and title are provided, then save the current page as a
|
||||||
|
bookmark.
|
||||||
|
If a url and title have been provided, then save the given url as
|
||||||
|
a bookmark with the provided title.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url: url to save as a bookmark. If None, use url of current page.
|
||||||
|
title: title of the new bookmark.
|
||||||
|
"""
|
||||||
|
if url and not title:
|
||||||
|
raise cmdexc.CommandError('Title must be provided if url has '
|
||||||
|
'been provided')
|
||||||
bookmark_manager = objreg.get('bookmark-manager')
|
bookmark_manager = objreg.get('bookmark-manager')
|
||||||
url = self._current_url()
|
if url is None:
|
||||||
|
url = self._current_url()
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
url = urlutils.fuzzy_url(url)
|
||||||
|
except urlutils.InvalidUrlError as e:
|
||||||
|
raise cmdexc.CommandError(e)
|
||||||
|
if not title:
|
||||||
|
title = self._current_title()
|
||||||
try:
|
try:
|
||||||
bookmark_manager.add(url, self._current_title())
|
bookmark_manager.add(url, title)
|
||||||
except urlmarks.Error as e:
|
except urlmarks.Error as e:
|
||||||
raise cmdexc.CommandError(str(e))
|
raise cmdexc.CommandError(str(e))
|
||||||
else:
|
else:
|
||||||
|
@ -8,6 +8,20 @@ Feature: quickmarks and bookmarks
|
|||||||
Then the message "Bookmarked http://localhost:*/data/title.html!" should be shown
|
Then the message "Bookmarked http://localhost:*/data/title.html!" should be shown
|
||||||
And the bookmark file should contain "http://localhost:*/data/title.html Test title"
|
And the bookmark file should contain "http://localhost:*/data/title.html Test title"
|
||||||
|
|
||||||
|
Scenario: Saving a bookmark with a provided url and title
|
||||||
|
When I run :bookmark-add http://example.com "some example title"
|
||||||
|
Then the message "Bookmarked http://example.com!" should be shown
|
||||||
|
And the bookmark file should contain "http://example.com some example title"
|
||||||
|
|
||||||
|
Scenario: Saving a bookmark with a url but no title
|
||||||
|
When I run :bookmark-add http://example.com
|
||||||
|
Then the error "Title must be provided if url has been provided" should be shown
|
||||||
|
|
||||||
|
Scenario: Saving a bookmark with an invalid url
|
||||||
|
When I set general -> auto-search to false
|
||||||
|
And I run :bookmark-add foo! "some example title"
|
||||||
|
Then the error "Invalid URL" should be shown
|
||||||
|
|
||||||
Scenario: Saving a duplicate bookmark
|
Scenario: Saving a duplicate bookmark
|
||||||
Given I have a fresh instance
|
Given I have a fresh instance
|
||||||
When I open data/title.html
|
When I open data/title.html
|
||||||
|
Loading…
Reference in New Issue
Block a user