summaryrefslogtreecommitdiff
path: root/qutebrowser/misc/sessions.py
diff options
context:
space:
mode:
Diffstat (limited to 'qutebrowser/misc/sessions.py')
-rw-r--r--qutebrowser/misc/sessions.py72
1 files changed, 61 insertions, 11 deletions
diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py
index fe8e7ba24..35c36f203 100644
--- a/qutebrowser/misc/sessions.py
+++ b/qutebrowser/misc/sessions.py
@@ -321,15 +321,14 @@ class SessionManager(QObject):
win_data['private'] = True
win_data['tabs'] = []
- for i, tab in enumerate(tabbed_browser.widgets()):
- active = i == tabbed_browser.widget.currentIndex()
+ for tab in tabbed_browser.tabs(include_hidden=True):
+ active = tab == tabbed_browser.current_tab()
tab_data = self._save_tab(tab,
active,
with_history=with_history)
if tabbed_browser.is_treetabbedbrowser:
node = tab.node
node_data = {
- 'node': node.uid,
'parent': node.parent.uid,
'children': [c.uid for c in node.children],
'collapsed': node.collapsed,
@@ -510,7 +509,7 @@ class SessionManager(QObject):
except ValueError as e:
raise SessionError(e)
- def _load_tree(self, tabbed_browser, tree_data):
+ def _load_tree(self, tabbed_browser, tree_data, legacy=False):
tree_keys = list(tree_data.keys())
if not tree_keys:
return None
@@ -527,14 +526,22 @@ class SessionManager(QObject):
nonlocal tab_to_focus
nonlocal index
index += 1
- tab_data = tree_data[uid]
- node_data = tab_data['treetab_node_data']
+ if legacy:
+ node_data = tree_data[uid]
+ tab_data = node_data['tab']
+ else:
+ tab_data = tree_data[uid]
+ node_data = tab_data['treetab_node_data']
children_uids = node_data['children']
if tab_data.get('active'):
tab_to_focus = index
- new_tab = tabbed_browser.tabopen(background=False)
+ new_tab = tabbed_browser.tabopen(
+ background=False,
+ related=False,
+ idx=index,
+ )
self._load_tab(new_tab, tab_data)
new_tab.node.parent = root_node
@@ -547,8 +554,41 @@ class SessionManager(QObject):
child = recursive_load_node(child_uid)
child.parent = root_node
+ # Make sure any collapsed tabs are removed from the widget.
+ # Since we only set the "collapsed" attribute after loading the tab,
+ # and the tree only gets updated in the above loop on tab loads. So if
+ # the last set of tabs we load is a collapsed group this children
+ # won't know they are support to be hidden yet.
+ tabbed_browser.widget.tree_tab_update()
+
return tab_to_focus
+ def _load_legacy_tree_tabs(self, win, tabbed_browser):
+ """Load the "legacy" tree session format.
+
+ For a number of years (pull #4602) tree tabs used a session format
+ that wasn't backwards compatible with prior session formats. In that
+ tab data was a child of a tree node. Now it's been switched to the
+ other way around. This method (along with a conditional in
+ `_load_tree()`) handle loading the old format for early adopters who
+ have session they don't want to have to rebuild.
+
+ Returns:
+ a. `(None, None)` if tree tabs where loaded, or
+ b. or a tuple of the tab index to focus and a flat list of tabs that
+ need loading if tree tabs is turned off.
+ """
+ plain_tabs = None
+ tab_to_focus = None
+ tree_data = win.get('tree')
+ if tabbed_browser.is_treetabbedbrowser:
+ tab_to_focus = self._load_tree(tabbed_browser, tree_data, legacy=True)
+ tabbed_browser.widget.tree_tab_update()
+ else:
+ plain_tabs = [tree_data[i]['tab'] for i in tree_data if
+ tree_data[i]['tab']]
+ return tab_to_focus, plain_tabs
+
def _load_window(self, win):
"""Turn yaml data into windows."""
window = mainwindow.MainWindow(geometry=win['geometry'],
@@ -557,7 +597,13 @@ class SessionManager(QObject):
window=window.win_id)
tab_to_focus = None
- tabs = win['tabs']
+ legacy_tree_loaded = False
+ if win.get('tree'):
+ tab_to_focus, tabs = self._load_legacy_tree_tabs(win, tabbed_browser)
+ legacy_tree_loaded = not tabs
+ else:
+ tabs = win['tabs']
+
# restore a tab tree only if the session contains treetab
# data and tree tabs are enabled.
# Otherwise, restore tabs "flat"
@@ -565,10 +611,14 @@ class SessionManager(QObject):
tabbed_browser.is_treetabbedbrowser
if load_tree_tabs:
tree_data = reconstruct_tree_data(win)
- self._load_tree(tabbed_browser, tree_data)
- else:
+ tab_to_focus = self._load_tree(tabbed_browser, tree_data)
+ elif not legacy_tree_loaded:
for i, tab in enumerate(tabs):
- new_tab = tabbed_browser.tabopen(background=False)
+ new_tab = tabbed_browser.tabopen(
+ background=False,
+ related=False,
+ idx=i,
+ )
self._load_tab(new_tab, tab)
if tab.get('active', False):
tab_to_focus = i