Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate redundant terminal spawning #2020

Merged
merged 1 commit into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = []
gsemet marked this conversation as resolved.
Show resolved Hide resolved
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