Skip to content

Commit 2613e02

Browse files
Davidy22gsemet
authored andcommitted
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.
1 parent b769b3a commit 2613e02

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

guake/guake_app.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -1346,16 +1346,15 @@ def save_tabs(self, filename="session.json"):
13461346
for index in range(nb.get_n_pages()):
13471347
try:
13481348
page = nb.get_nth_page(index)
1349-
if page.child:
1350-
panes = []
1351-
page.save_box_layout(page.child, panes)
1352-
tabs.append(
1353-
{
1354-
"panes": panes,
1355-
"label": nb.get_tab_text_index(index),
1356-
"custom_label_set": getattr(page, "custom_label_set", False),
1357-
}
1358-
)
1349+
panes = []
1350+
page.save_box_layout(page.child, panes)
1351+
tabs.append(
1352+
{
1353+
"panes": panes,
1354+
"label": nb.get_tab_text_index(index),
1355+
"custom_label_set": getattr(page, "custom_label_set", False),
1356+
}
1357+
)
13591358
except FileNotFoundError:
13601359
# discard same broken tabs
13611360
pass
@@ -1440,16 +1439,18 @@ def restore_tabs(self, filename="session.json", suppress_notify=False):
14401439
# NOTE: If frame implement in future, we will need to update this code
14411440
for tabs in frames:
14421441
for index, tab in enumerate(tabs):
1443-
directory = (
1444-
tab["panes"][0]["directory"]
1445-
if len(tab.get("panes", [])) == 1
1446-
else tab.get("directory", None)
1447-
)
1448-
box, page_num, term = nb.new_page_with_focus(
1449-
directory, tab["label"], tab["custom_label_set"]
1450-
)
14511442
if tab.get("panes", False):
1443+
box, page_num, term = nb.new_page_with_focus(
1444+
label=tab["label"], empty=True
1445+
)
14521446
box.restore_box_layout(box.child, tab["panes"])
1447+
else:
1448+
directory = (
1449+
tab["panes"][0]["directory"]
1450+
if len(tab.get("panes", [])) == 1
1451+
else tab.get("directory", None)
1452+
)
1453+
nb.new_page_with_focus(directory, tab["label"], tab["custom_label_set"])
14531454

14541455
# Remove original pages in notebook
14551456
for i in range(current_pages):

guake/notebook.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,13 @@ def delete_page_by_label(self, label, kill=True, prompt=0):
340340
def delete_page_current(self, kill=True, prompt=0):
341341
self.delete_page(self.get_current_page(), kill, prompt)
342342

343-
def new_page(self, directory=None, position=None):
344-
terminal = self.terminal_spawn(directory)
343+
def new_page(self, directory=None, position=None, empty=False):
345344
terminal_box = TerminalBox()
346-
terminal_box.set_terminal(terminal)
345+
if empty:
346+
terminal = None
347+
else:
348+
terminal = self.terminal_spawn(directory)
349+
terminal_box.set_terminal(terminal)
347350
root_terminal_box = RootTerminalBox(self.guake, self)
348351
root_terminal_box.set_child(terminal_box)
349352
page_num = self.insert_page(
@@ -358,7 +361,8 @@ def new_page(self, directory=None, position=None):
358361
)
359362
# this is needed to initially set the last_terminal_focused,
360363
# one could also call terminal.get_parent().on_terminal_focus()
361-
self.terminal_attached(terminal)
364+
if not empty:
365+
self.terminal_attached(terminal)
362366
self.hide_tabbar_if_one_tab()
363367

364368
if self.guake:
@@ -405,14 +409,17 @@ def terminal_attached(self, terminal):
405409
terminal.emit("focus", Gtk.DirectionType.TAB_FORWARD)
406410
self.emit("terminal-spawned", terminal, terminal.pid)
407411

408-
def new_page_with_focus(self, directory=None, label=None, user_set=False, position=None):
409-
box, page_num, terminal = self.new_page(directory, position=position)
412+
def new_page_with_focus(
413+
self, directory=None, label=None, user_set=False, position=None, empty=False
414+
):
415+
box, page_num, terminal = self.new_page(directory, position=position, empty=empty)
410416
self.set_current_page(page_num)
411417
if not label:
412418
self.rename_page(page_num, _("Terminal"), False)
413419
else:
414420
self.rename_page(page_num, label, user_set)
415-
terminal.grab_focus()
421+
if terminal is not None:
422+
terminal.grab_focus()
416423
return box, page_num, terminal
417424

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

0 commit comments

Comments
 (0)