lazy sessions, docstring formatted, settings renamed, javascript notice changed, insert method changed
This commit is contained in:
parent
13dc24f6ca
commit
aa40842848
@ -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
|
||||
|
@ -222,7 +222,7 @@
|
||||
|<<qt.highdpi,qt.highdpi>>|Turn on Qt HighDPI scaling.
|
||||
|<<scrolling.bar,scrolling.bar>>|Show a scrollbar.
|
||||
|<<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.
|
||||
|<<statusbar.hide,statusbar.hide>>|Hide the statusbar unless a message is shown.
|
||||
|<<statusbar.padding,statusbar.padding>>|Padding (in pixels) for the statusbar.
|
||||
@ -2554,8 +2554,8 @@ Type: <<types,Bool>>
|
||||
|
||||
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.
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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.onfocus = null;
|
||||
window.history.back();
|
||||
}
|
||||
};
|
||||
}, 1000);
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<noscript><h1 class="noscript">View Only</h1><p class="noscript-text">Changing settings requires javascript to be enabled!</p></noscript>
|
||||
<header><h1>{{ title }}</h1></header>
|
||||
|
||||
<noscript><p class="noscript-text">Javascript isn't enabled. So you need to manually go back in history to restore this tab.</p></noscript>
|
||||
{% endblock %}
|
||||
|
@ -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).
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user