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 10a92b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
37 changes: 19 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,18 @@ 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_with_focus(
label=tab["label"], 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
21 changes: 14 additions & 7 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 empty:
terminal = None
else:
terminal = self.terminal_spawn(directory)
terminal_box.set_terminal(terminal)
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 Expand Up @@ -405,14 +409,17 @@ def terminal_attached(self, terminal):
terminal.emit("focus", Gtk.DirectionType.TAB_FORWARD)
self.emit("terminal-spawned", terminal, terminal.pid)

def new_page_with_focus(self, directory=None, label=None, user_set=False, position=None):
box, page_num, terminal = self.new_page(directory, position=position)
def new_page_with_focus(
self, directory=None, label=None, user_set=False, position=None, empty=False
):
box, page_num, terminal = self.new_page(directory, position=position, empty=empty)
self.set_current_page(page_num)
if not label:
self.rename_page(page_num, _("Terminal"), False)
else:
self.rename_page(page_num, label, user_set)
terminal.grab_focus()
if terminal is not None:
terminal.grab_focus()
return box, page_num, terminal

def rename_page(self, page_index, new_text, user_set=False):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
release_summary: >
Eliminated redundant terminal spawning on startup

0 comments on commit 10a92b8

Please sign in to comment.