From aa40842848a60039c3978e0e7b8d0c3c4eb8f6e5 Mon Sep 17 00:00:00 2001 From: "mhm@mhm.com" Date: Tue, 21 Nov 2017 00:38:51 +0100 Subject: [PATCH] lazy sessions, docstring formatted, settings renamed, javascript notice changed, insert method changed --- doc/help/commands.asciidoc | 2 +- doc/help/settings.asciidoc | 6 +++--- qutebrowser/browser/qutescheme.py | 8 +++++--- qutebrowser/config/configdata.yml | 8 +++++--- qutebrowser/html/back.html | 16 +++------------- qutebrowser/misc/sessions.py | 27 ++++++++++++++++++--------- tests/unit/misc/test_sessions.py | 2 +- 7 files changed, 36 insertions(+), 33 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 04377c055..aa94de305 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -1070,7 +1070,7 @@ Syntax: +:session-save [*--current*] [*--quiet*] [*--force*] [*--only-active-win Save a session. ==== positional arguments -* +'name'+: The name of the session. If not given, the session configured in session_default_name is saved. +* +'name'+: The name of the session. If not given, the session configured in session.default_name is saved. ==== optional arguments diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 64881f619..9f694c184 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -222,7 +222,7 @@ |<>|Turn on Qt HighDPI scaling. |<>|Show a scrollbar. |<>|Enable smooth scrolling for web pages. -|<>|Name of the session to save by default. +|<>|Name of the session to save by default. |<>|Languages to use for spell checking. |<>|Hide the statusbar unless a message is shown. |<>|Padding (in pixels) for the statusbar. @@ -2554,8 +2554,8 @@ Type: <> Default: +pass:[false]+ -[[session_default_name]] -=== session_default_name +[[session.default_name]] +=== session.default_name Name of the session to save by default. If this is set to null, the session which was last loaded is saved. diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 3881a0d2e..4db7bdc84 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -427,10 +427,12 @@ def qute_settings(url): @add_handler('back') def qute_back(url): - """Handler for qute://back. Simple page to free ram / lazy load a site, - goes back on focusing the tab.""" + """Handler for qute://back. - html = jinja.render('back.html', title='Suspended') + Simple page to free ram / lazy load a site, goes back on focusing the tab. + """ + html = jinja.render('back.html', + title='Suspended: ' + url.url().split('#')[-1]) return 'text/html', html diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 7284d98d5..7f362daa4 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -79,6 +79,9 @@ new_instance_open_target_window: When `new_instance_open_target` is not set to `window`, this is ignored. session_default_name: + renamed: session.default_name + +session.default_name: type: name: SessionName none_ok: true @@ -88,13 +91,12 @@ session_default_name: If this is set to null, the session which was last loaded is saved. -session_lazy_restore: +session.lazy_restore: type: name: Bool none_ok: true default: false - desc: >- - Load a restored tab as soon as it takes focus. + desc: Load a restored tab as soon as it takes focus. backend: type: diff --git a/qutebrowser/html/back.html b/qutebrowser/html/back.html index c28419a64..0d06158f2 100644 --- a/qutebrowser/html/back.html +++ b/qutebrowser/html/back.html @@ -1,26 +1,16 @@ {% extends "base.html" %} {% block script %} -window.onload = function() { - var title = 'Suspended: ' + document.location.hash.substr(1); - var node = document.getElementsByTagName('h1')[0]; - node.innerText = document.title = title; -}; setTimeout(function() { /* drop first focus event, to avoid problems (allow to go easily to newer history entries) */ - var triggered = false; window.onfocus = function() { - if (! triggered) { - triggered = true; - window.history.back(); - } + window.onfocus = null; + window.history.back(); }; }, 1000); {% endblock %} {% block content %} - -

{{ title }}

- + {% endblock %} diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py index c3634a64a..faee99c99 100644 --- a/qutebrowser/misc/sessions.py +++ b/qutebrowser/misc/sessions.py @@ -22,6 +22,8 @@ import os import os.path +from itertools import chain, dropwhile, takewhile + import sip from PyQt5.QtCore import QUrl, QObject, QPoint, QTimer from PyQt5.QtWidgets import QApplication @@ -205,8 +207,8 @@ class SessionManager(QObject): for idx, item in enumerate(tab.history): qtutils.ensure_valid(item) item_data = self._save_tab_item(tab, idx, item) - if item_data['url'].startswith('qute://back'): - # dont add qute://back to the session file + if item.url().url().startswith('qute://back'): + # don't add qute://back to the session file if item_data.get('active', False) and data['history']: # mark entry before qute://back as active data['history'][-1]['active'] = True @@ -257,7 +259,7 @@ class SessionManager(QObject): object. """ if name is default: - name = config.val.session_default_name + name = config.val.session.default_name if name is None: if self._current is not None: name = self._current @@ -329,8 +331,16 @@ class SessionManager(QObject): def _load_tab(self, new_tab, data): """Load yaml data into a newly opened tab.""" entries = [] + lazy_load = [] + # use len(data['history']) + # -> dropwhile empty if not session.lazy_session + lazy_index = len(data['history']) + gen = chain( + takewhile(lambda _: not lazy_load, enumerate(data['history'])), + enumerate(lazy_load), + dropwhile(lambda i: i[0] < lazy_index, enumerate(data['history']))) - for i, histentry in enumerate(data['history']): + for i, histentry in gen: user_data = {} if 'zoom' in data: @@ -354,13 +364,12 @@ class SessionManager(QObject): if 'pinned' in histentry: new_tab.data.pinned = histentry['pinned'] - if (config.val.session_lazy_restore and + if (config.val.session.lazy_restore and histentry.get('active', False) and not histentry['url'].startswith('qute://back')): # remove "active" mark and insert back page marked as active - data['history'].insert( - i + 1, - { + lazy_index = i + 1 + lazy_load.append({ 'title': histentry['title'], 'url': 'qute://back#' + histentry['title'], 'active': True @@ -481,7 +490,7 @@ class SessionManager(QObject): Args: name: The name of the session. If not given, the session configured - in session_default_name is saved. + in session.default_name is saved. current: Save the current session instead of the default. quiet: Don't show confirmation message. force: Force saving internal sessions (starting with an underline). diff --git a/tests/unit/misc/test_sessions.py b/tests/unit/misc/test_sessions.py index 771430d5b..b2cb8a3dd 100644 --- a/tests/unit/misc/test_sessions.py +++ b/tests/unit/misc/test_sessions.py @@ -170,7 +170,7 @@ class TestSaveAll: ]) def test_get_session_name(config_stub, sess_man, arg, config, current, expected): - config_stub.val.session_default_name = config + config_stub.val.session.default_name = config sess_man._current = current assert sess_man._get_session_name(arg) == expected