lazy sessions, docstring formatted, settings renamed, javascript notice changed, insert method changed

This commit is contained in:
mhm@mhm.com 2017-11-21 00:38:51 +01:00
parent 13dc24f6ca
commit aa40842848
7 changed files with 36 additions and 33 deletions

View File

@ -1070,7 +1070,7 @@ Syntax: +:session-save [*--current*] [*--quiet*] [*--force*] [*--only-active-win
Save a session. Save a session.
==== positional arguments ==== 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 ==== optional arguments

View File

@ -222,7 +222,7 @@
|<<qt.highdpi,qt.highdpi>>|Turn on Qt HighDPI scaling. |<<qt.highdpi,qt.highdpi>>|Turn on Qt HighDPI scaling.
|<<scrolling.bar,scrolling.bar>>|Show a scrollbar. |<<scrolling.bar,scrolling.bar>>|Show a scrollbar.
|<<scrolling.smooth,scrolling.smooth>>|Enable smooth scrolling for web pages. |<<scrolling.smooth,scrolling.smooth>>|Enable smooth scrolling for web pages.
|<<session_default_name,session_default_name>>|Name of the session to save by default. |<<session.default_name,session.default_name>>|Name of the session to save by default.
|<<spellcheck.languages,spellcheck.languages>>|Languages to use for spell checking. |<<spellcheck.languages,spellcheck.languages>>|Languages to use for spell checking.
|<<statusbar.hide,statusbar.hide>>|Hide the statusbar unless a message is shown. |<<statusbar.hide,statusbar.hide>>|Hide the statusbar unless a message is shown.
|<<statusbar.padding,statusbar.padding>>|Padding (in pixels) for the statusbar. |<<statusbar.padding,statusbar.padding>>|Padding (in pixels) for the statusbar.
@ -2554,8 +2554,8 @@ Type: <<types,Bool>>
Default: +pass:[false]+ Default: +pass:[false]+
[[session_default_name]] [[session.default_name]]
=== session_default_name === session.default_name
Name of the session to save by default. Name of the session to save by default.
If this is set to null, the session which was last loaded is saved. If this is set to null, the session which was last loaded is saved.

View File

@ -427,10 +427,12 @@ def qute_settings(url):
@add_handler('back') @add_handler('back')
def qute_back(url): def qute_back(url):
"""Handler for qute://back. Simple page to free ram / lazy load a site, """Handler for qute://back.
goes back on focusing the tab."""
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 return 'text/html', html

View File

@ -79,6 +79,9 @@ new_instance_open_target_window:
When `new_instance_open_target` is not set to `window`, this is ignored. When `new_instance_open_target` is not set to `window`, this is ignored.
session_default_name: session_default_name:
renamed: session.default_name
session.default_name:
type: type:
name: SessionName name: SessionName
none_ok: true none_ok: true
@ -88,13 +91,12 @@ session_default_name:
If this is set to null, the session which was last loaded is saved. If this is set to null, the session which was last loaded is saved.
session_lazy_restore: session.lazy_restore:
type: type:
name: Bool name: Bool
none_ok: true none_ok: true
default: false default: false
desc: >- desc: Load a restored tab as soon as it takes focus.
Load a restored tab as soon as it takes focus.
backend: backend:
type: type:

View File

@ -1,26 +1,16 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block script %} {% 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() { setTimeout(function() {
/* drop first focus event, to avoid problems /* drop first focus event, to avoid problems
(allow to go easily to newer history entries) */ (allow to go easily to newer history entries) */
var triggered = false;
window.onfocus = function() { window.onfocus = function() {
if (! triggered) { window.onfocus = null;
triggered = true; window.history.back();
window.history.back();
}
}; };
}, 1000); }, 1000);
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<noscript><h1 class="noscript">View Only</h1><p class="noscript-text">Changing settings requires javascript to be enabled!</p></noscript> <noscript><p class="noscript-text">Javascript isn't enabled. So you need to manually go back in history to restore this tab.</p></noscript>
<header><h1>{{ title }}</h1></header>
{% endblock %} {% endblock %}

View File

@ -22,6 +22,8 @@
import os import os
import os.path import os.path
from itertools import chain, dropwhile, takewhile
import sip import sip
from PyQt5.QtCore import QUrl, QObject, QPoint, QTimer from PyQt5.QtCore import QUrl, QObject, QPoint, QTimer
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
@ -205,8 +207,8 @@ class SessionManager(QObject):
for idx, item in enumerate(tab.history): for idx, item in enumerate(tab.history):
qtutils.ensure_valid(item) qtutils.ensure_valid(item)
item_data = self._save_tab_item(tab, idx, item) item_data = self._save_tab_item(tab, idx, item)
if item_data['url'].startswith('qute://back'): if item.url().url().startswith('qute://back'):
# dont add qute://back to the session file # don't add qute://back to the session file
if item_data.get('active', False) and data['history']: if item_data.get('active', False) and data['history']:
# mark entry before qute://back as active # mark entry before qute://back as active
data['history'][-1]['active'] = True data['history'][-1]['active'] = True
@ -257,7 +259,7 @@ class SessionManager(QObject):
object. object.
""" """
if name is default: if name is default:
name = config.val.session_default_name name = config.val.session.default_name
if name is None: if name is None:
if self._current is not None: if self._current is not None:
name = self._current name = self._current
@ -329,8 +331,16 @@ class SessionManager(QObject):
def _load_tab(self, new_tab, data): def _load_tab(self, new_tab, data):
"""Load yaml data into a newly opened tab.""" """Load yaml data into a newly opened tab."""
entries = [] 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 = {} user_data = {}
if 'zoom' in data: if 'zoom' in data:
@ -354,13 +364,12 @@ class SessionManager(QObject):
if 'pinned' in histentry: if 'pinned' in histentry:
new_tab.data.pinned = histentry['pinned'] 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 histentry.get('active', False) and
not histentry['url'].startswith('qute://back')): not histentry['url'].startswith('qute://back')):
# remove "active" mark and insert back page marked as active # remove "active" mark and insert back page marked as active
data['history'].insert( lazy_index = i + 1
i + 1, lazy_load.append({
{
'title': histentry['title'], 'title': histentry['title'],
'url': 'qute://back#' + histentry['title'], 'url': 'qute://back#' + histentry['title'],
'active': True 'active': True
@ -481,7 +490,7 @@ class SessionManager(QObject):
Args: Args:
name: The name of the session. If not given, the session configured 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. current: Save the current session instead of the default.
quiet: Don't show confirmation message. quiet: Don't show confirmation message.
force: Force saving internal sessions (starting with an underline). force: Force saving internal sessions (starting with an underline).

View File

@ -170,7 +170,7 @@ class TestSaveAll:
]) ])
def test_get_session_name(config_stub, sess_man, arg, config, current, def test_get_session_name(config_stub, sess_man, arg, config, current,
expected): expected):
config_stub.val.session_default_name = config config_stub.val.session.default_name = config
sess_man._current = current sess_man._current = current
assert sess_man._get_session_name(arg) == expected assert sess_man._get_session_name(arg) == expected