Skip to content

Commit

Permalink
Eliminate redundant terminal spawning
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Davidy22 committed Jan 25, 2022
1 parent c3ea8fe commit 47ec9c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
35 changes: 17 additions & 18 deletions guake/guake_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 8 additions & 4 deletions guake/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down

0 comments on commit 47ec9c0

Please sign in to comment.