From 47ec9c066a7a69b236086e2c19a5b13e3e102667 Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 24 Jan 2022 23:30:15 +0800 Subject: [PATCH] Eliminate redundant terminal spawning Panes are always stored even in single paned tabs, the condition gating restoring box layout is always true so the initial terminal spawned was always immediately overwritten. --- guake/guake_app.py | 35 +++++++++++++++++------------------ guake/notebook.py | 12 ++++++++---- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/guake/guake_app.py b/guake/guake_app.py index 5cf234dc0..4a2cc4f7e 100644 --- a/guake/guake_app.py +++ b/guake/guake_app.py @@ -1350,16 +1350,15 @@ def save_tabs(self, filename="session.json"): for index in range(nb.get_n_pages()): try: page = nb.get_nth_page(index) - if page.child: - panes = [] - page.save_box_layout(page.child, panes) - tabs.append( - { - "panes": panes, - "label": nb.get_tab_text_index(index), - "custom_label_set": getattr(page, "custom_label_set", False), - } - ) + panes = [] + page.save_box_layout(page.child, panes) + tabs.append( + { + "panes": panes, + "label": nb.get_tab_text_index(index), + "custom_label_set": getattr(page, "custom_label_set", False), + } + ) except FileNotFoundError: # discard same broken tabs pass @@ -1444,16 +1443,16 @@ def restore_tabs(self, filename="session.json", suppress_notify=False): # NOTE: If frame implement in future, we will need to update this code for tabs in frames: for index, tab in enumerate(tabs): - directory = ( - tab["panes"][0]["directory"] - if len(tab.get("panes", [])) == 1 - else tab.get("directory", None) - ) - box, page_num, term = nb.new_page_with_focus( - directory, tab["label"], tab["custom_label_set"] - ) if tab.get("panes", False): + box, page_num, term = nb.new_page(empty=True) box.restore_box_layout(box.child, tab["panes"]) + else: + directory = ( + tab["panes"][0]["directory"] + if len(tab.get("panes", [])) == 1 + else tab.get("directory", None) + ) + nb.new_page_with_focus(directory, tab["label"], tab["custom_label_set"]) # Remove original pages in notebook for i in range(current_pages): diff --git a/guake/notebook.py b/guake/notebook.py index 0719aec1a..605088281 100644 --- a/guake/notebook.py +++ b/guake/notebook.py @@ -340,10 +340,13 @@ def delete_page_by_label(self, label, kill=True, prompt=0): def delete_page_current(self, kill=True, prompt=0): self.delete_page(self.get_current_page(), kill, prompt) - def new_page(self, directory=None, position=None): - terminal = self.terminal_spawn(directory) + def new_page(self, directory=None, position=None, empty=False): terminal_box = TerminalBox() - terminal_box.set_terminal(terminal) + if not empty: + terminal = self.terminal_spawn(directory) + terminal_box.set_terminal(terminal) + else: + terminal = None root_terminal_box = RootTerminalBox(self.guake, self) root_terminal_box.set_child(terminal_box) page_num = self.insert_page( @@ -358,7 +361,8 @@ def new_page(self, directory=None, position=None): ) # this is needed to initially set the last_terminal_focused, # one could also call terminal.get_parent().on_terminal_focus() - self.terminal_attached(terminal) + if not empty: + self.terminal_attached(terminal) self.hide_tabbar_if_one_tab() if self.guake: