From 85be6565fcdf8d4006ded9b10250d1a9229e6502 Mon Sep 17 00:00:00 2001 From: David Vogt Date: Sat, 23 Jul 2016 12:09:49 +0200 Subject: [PATCH 1/5] Implement feature request #1033: Bookmark display There is a new page now, qute:bookmarks that will display all bookmarks and quickmarks. It's still missing a search / filter feature, but you can use the built-in search / navigation just as easily for now. --- .../browser/webkit/network/qutescheme.py | 14 ++++++ qutebrowser/html/bookmarks.html | 48 +++++++++++++++++++ tests/end2end/features/urlmarks.feature | 13 +++++ 3 files changed, 75 insertions(+) create mode 100644 qutebrowser/html/bookmarks.html diff --git a/qutebrowser/browser/webkit/network/qutescheme.py b/qutebrowser/browser/webkit/network/qutescheme.py index bfa722d43..272f97dfa 100644 --- a/qutebrowser/browser/webkit/network/qutescheme.py +++ b/qutebrowser/browser/webkit/network/qutescheme.py @@ -261,3 +261,17 @@ def qute_pdfjs(_win_id, request): "pdfjs resource requested but not found: {}".format(e.path)) raise QuteSchemeError("Can't find pdfjs resource '{}'".format(e.path), QNetworkReply.ContentNotFoundError) + + +@add_handler('bookmarks') +def qute_bookmarks(_win_id, request): + """Handler for qute:bookmarks. Show a list of all quickmarks / bookmarks""" + + bookmarks = objreg.get('bookmark-manager').marks.items() + quickmarks = objreg.get('quickmark-manager').marks.items() + + html = jinja.render('bookmarks.html', + title='Bookmarks', + bookmarks=bookmarks, + quickmarks=quickmarks) + return html.encode('UTF-8', errors='xmlcharrefreplace') diff --git a/qutebrowser/html/bookmarks.html b/qutebrowser/html/bookmarks.html new file mode 100644 index 000000000..c3a874785 --- /dev/null +++ b/qutebrowser/html/bookmarks.html @@ -0,0 +1,48 @@ +{% extends "base.html" %} + +{% block script %} +var win_id = {{ win_id }}; +var cset = function(section, option, el) { + value = el.value; + window.qute.set(win_id, section, option, value); +} +{% endblock %} + +{% block style %} +table { border: 1px solid grey; border-collapse: collapse; width: 100%;} +pre { margin: 2px; } +th, td { border: 1px solid grey; padding: 0px 5px; } +th { background: lightgrey; } +th pre { color: grey; text-align: left; } +.noscript, .noscript-text { color:red; } +.noscript-text { margin-bottom: 5cm; } +h4 { line-height: 1.2em; } +{% endblock %} + +{% block content %} + + + + + + + + {% for url, title in bookmarks %} + + + + + {% endfor %} + + + + + {% for name, url in quickmarks %} + + + + + {% endfor %} +

Bookmark

URL

{{title}}{{url}}

Quickmark

URL

{{name}}{{url}}
+ +{% endblock %} diff --git a/tests/end2end/features/urlmarks.feature b/tests/end2end/features/urlmarks.feature index 8f0136e59..2f965169f 100644 --- a/tests/end2end/features/urlmarks.feature +++ b/tests/end2end/features/urlmarks.feature @@ -186,3 +186,16 @@ Feature: quickmarks and bookmarks When I run :quickmark-add http://localhost:(port)/data/numbers/15.txt fifteen And I run :quickmark-del fifteen Then the quickmark file should not contain "fourteen http://localhost:*/data/numbers/15.txt " + + Scenario: Listing quickmarks + When I run :quickmark-add http://localhost:(port)/data/numbers/15.txt fifteen + And I run :quickmark-add http://localhost:(port)/data/numbers/14.txt fourteen + And I open qute:bookmarks + Then the page should contain the plaintext "fifteen" + And the page should contain the plaintext "fourteen" + + Scenario: Listing bookmarks + When I open data/title.html + And I run :bookmark-add + And I open qute:bookmarks + Then the page should contain the plaintext "Test title" From 12e7b4f244a4a4e8bd726d47fbebc59dbfc00645 Mon Sep 17 00:00:00 2001 From: David Vogt Date: Sat, 23 Jul 2016 12:23:37 +0200 Subject: [PATCH 2/5] Extend command documentation regarding bookmarks page Add links to the qute:bookmarks page in the documentation for `:bookmark-add` and `:quickmark-add` commands. --- doc/help/commands.asciidoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 4c64c9068..cc9d7d031 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -122,6 +122,8 @@ 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. +You can view all saved bookmarks on the link:qute://bookmarks[bookmarks page]. + ==== positional arguments * +'url'+: url to save as a bookmark. If None, use url of current page. * +'title'+: title of the new bookmark. @@ -512,6 +514,8 @@ Syntax: +:quickmark-add 'url' 'name'+ Add a new quickmark. +You can view all saved quickmarks on the link:qute://bookmarks[bookmarks page]. + ==== positional arguments * +'url'+: The url to add as quickmark. * +'name'+: The name for the new quickmark. From 8bbfcc01be4b6e425dffbc1e73a55a63e4067da6 Mon Sep 17 00:00:00 2001 From: David Vogt Date: Sat, 23 Jul 2016 12:32:05 +0200 Subject: [PATCH 3/5] Sort bookmarks / quickmarks by title or name respectively. --- qutebrowser/browser/webkit/network/qutescheme.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/webkit/network/qutescheme.py b/qutebrowser/browser/webkit/network/qutescheme.py index 272f97dfa..bb6833cc8 100644 --- a/qutebrowser/browser/webkit/network/qutescheme.py +++ b/qutebrowser/browser/webkit/network/qutescheme.py @@ -267,8 +267,10 @@ def qute_pdfjs(_win_id, request): def qute_bookmarks(_win_id, request): """Handler for qute:bookmarks. Show a list of all quickmarks / bookmarks""" - bookmarks = objreg.get('bookmark-manager').marks.items() - quickmarks = objreg.get('quickmark-manager').marks.items() + bookmarks = sorted(objreg.get('bookmark-manager').marks.items(), + key=lambda x: x[1]) # Sort by title + quickmarks = sorted(objreg.get('quickmark-manager').marks.items(), + key=lambda x: x[0]) # Sort by name html = jinja.render('bookmarks.html', title='Bookmarks', From 11bf5c8809154bc47833360d40d23e8099472b1a Mon Sep 17 00:00:00 2001 From: David Vogt Date: Sat, 23 Jul 2016 13:06:56 +0200 Subject: [PATCH 4/5] Minor cleanups. Whitespace / indentation CSS. There were some CSS classes that were not used in the bookmarks page. Also, fixes a small indentation / code alignment issue --- qutebrowser/browser/webkit/network/qutescheme.py | 4 ++-- qutebrowser/html/bookmarks.html | 14 -------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/qutebrowser/browser/webkit/network/qutescheme.py b/qutebrowser/browser/webkit/network/qutescheme.py index bb6833cc8..a659395f5 100644 --- a/qutebrowser/browser/webkit/network/qutescheme.py +++ b/qutebrowser/browser/webkit/network/qutescheme.py @@ -267,8 +267,8 @@ def qute_pdfjs(_win_id, request): def qute_bookmarks(_win_id, request): """Handler for qute:bookmarks. Show a list of all quickmarks / bookmarks""" - bookmarks = sorted(objreg.get('bookmark-manager').marks.items(), - key=lambda x: x[1]) # Sort by title + bookmarks = sorted(objreg.get('bookmark-manager').marks.items(), + key=lambda x: x[1]) # Sort by title quickmarks = sorted(objreg.get('quickmark-manager').marks.items(), key=lambda x: x[0]) # Sort by name diff --git a/qutebrowser/html/bookmarks.html b/qutebrowser/html/bookmarks.html index c3a874785..2f82453ab 100644 --- a/qutebrowser/html/bookmarks.html +++ b/qutebrowser/html/bookmarks.html @@ -1,26 +1,12 @@ {% extends "base.html" %} -{% block script %} -var win_id = {{ win_id }}; -var cset = function(section, option, el) { - value = el.value; - window.qute.set(win_id, section, option, value); -} -{% endblock %} - {% block style %} table { border: 1px solid grey; border-collapse: collapse; width: 100%;} -pre { margin: 2px; } th, td { border: 1px solid grey; padding: 0px 5px; } th { background: lightgrey; } -th pre { color: grey; text-align: left; } -.noscript, .noscript-text { color:red; } -.noscript-text { margin-bottom: 5cm; } -h4 { line-height: 1.2em; } {% endblock %} {% block content %} - From 1f320b86869fa23111fcdb54f30105ba0a86d1a1 Mon Sep 17 00:00:00 2001 From: David Vogt Date: Sat, 23 Jul 2016 14:27:42 +0200 Subject: [PATCH 5/5] Various fixes after code review. * Move documentation changes of bookmark / quickmarks to docstrings, as the asciidoc is autogenerated from those * Fix some whitespaces in the BDD test cases * Improved docstring in qute_bookmarks handler --- doc/help/commands.asciidoc | 4 ---- qutebrowser/browser/commands.py | 3 +++ qutebrowser/browser/urlmarks.py | 3 +++ qutebrowser/browser/webkit/network/qutescheme.py | 5 ++--- tests/end2end/features/urlmarks.feature | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index cc9d7d031..4c64c9068 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -122,8 +122,6 @@ 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. -You can view all saved bookmarks on the link:qute://bookmarks[bookmarks page]. - ==== positional arguments * +'url'+: url to save as a bookmark. If None, use url of current page. * +'title'+: title of the new bookmark. @@ -514,8 +512,6 @@ Syntax: +:quickmark-add 'url' 'name'+ Add a new quickmark. -You can view all saved quickmarks on the link:qute://bookmarks[bookmarks page]. - ==== positional arguments * +'url'+: The url to add as quickmark. * +'name'+: The name for the new quickmark. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 5192ac895..42b91f737 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1104,6 +1104,9 @@ class CommandDispatcher: If a url and title have been provided, then save the given url as a bookmark with the provided title. + You can view all saved bookmarks on the + link:qute://bookmarks[bookmarks page]. + Args: url: url to save as a bookmark. If None, use url of current page. title: title of the new bookmark. diff --git a/qutebrowser/browser/urlmarks.py b/qutebrowser/browser/urlmarks.py index df1302535..e7b78c310 100644 --- a/qutebrowser/browser/urlmarks.py +++ b/qutebrowser/browser/urlmarks.py @@ -178,6 +178,9 @@ class QuickmarkManager(UrlMarkManager): def quickmark_add(self, win_id, url, name): """Add a new quickmark. + You can view all saved quickmarks on the + link:qute://bookmarks[bookmarks page]. + Args: win_id: The window ID to display the errors in. url: The url to add as quickmark. diff --git a/qutebrowser/browser/webkit/network/qutescheme.py b/qutebrowser/browser/webkit/network/qutescheme.py index a659395f5..85be4ceff 100644 --- a/qutebrowser/browser/webkit/network/qutescheme.py +++ b/qutebrowser/browser/webkit/network/qutescheme.py @@ -264,9 +264,8 @@ def qute_pdfjs(_win_id, request): @add_handler('bookmarks') -def qute_bookmarks(_win_id, request): - """Handler for qute:bookmarks. Show a list of all quickmarks / bookmarks""" - +def qute_bookmarks(_win_id, _request): + """Handler for qute:bookmarks. Display all quickmarks / bookmarks.""" bookmarks = sorted(objreg.get('bookmark-manager').marks.items(), key=lambda x: x[1]) # Sort by title quickmarks = sorted(objreg.get('quickmark-manager').marks.items(), diff --git a/tests/end2end/features/urlmarks.feature b/tests/end2end/features/urlmarks.feature index 2f965169f..010d87f90 100644 --- a/tests/end2end/features/urlmarks.feature +++ b/tests/end2end/features/urlmarks.feature @@ -189,10 +189,10 @@ Feature: quickmarks and bookmarks Scenario: Listing quickmarks When I run :quickmark-add http://localhost:(port)/data/numbers/15.txt fifteen - And I run :quickmark-add http://localhost:(port)/data/numbers/14.txt fourteen + And I run :quickmark-add http://localhost:(port)/data/numbers/14.txt fourteen And I open qute:bookmarks Then the page should contain the plaintext "fifteen" - And the page should contain the plaintext "fourteen" + And the page should contain the plaintext "fourteen" Scenario: Listing bookmarks When I open data/title.html