[gnome-builder] plugins/terminal: store information when saving session
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/terminal: store information when saving session
- Date: Thu, 15 Sep 2022 08:12:49 +0000 (UTC)
commit 3e176b03f291e00d84ddc632f9cb55d620c581dc
Author: Christian Hergert <chergert redhat com>
Date: Thu Sep 15 01:12:21 2022 -0700
plugins/terminal: store information when saving session
We won't respawn the terminals, but it would be nice to be able to show
the contents that were there before we closed.
.../terminal/gbp-terminal-workspace-addin.c | 53 ++++++++++++++++++++++
1 file changed, 53 insertions(+)
---
diff --git a/src/plugins/terminal/gbp-terminal-workspace-addin.c
b/src/plugins/terminal/gbp-terminal-workspace-addin.c
index a0106d4fd..30db4fab2 100644
--- a/src/plugins/terminal/gbp-terminal-workspace-addin.c
+++ b/src/plugins/terminal/gbp-terminal-workspace-addin.c
@@ -335,11 +335,64 @@ gbp_terminal_workspace_addin_unload (IdeWorkspaceAddin *addin,
self->workspace = NULL;
}
+static void
+gbp_terminal_workspace_addin_save_session_page_cb (IdePage *page,
+ gpointer user_data)
+{
+ IdeSession *session = user_data;
+
+ g_assert (IDE_IS_PAGE (page));
+ g_assert (IDE_IS_SESSION (session));
+
+ if (IDE_IS_TERMINAL_PAGE (page))
+ {
+ g_autoptr(PanelPosition) position = ide_page_get_position (page);
+ g_autoptr(IdeSessionItem) item = ide_session_item_new ();
+ IdeTerminal *terminal = ide_terminal_page_get_terminal (IDE_TERMINAL_PAGE (page));
+ const char *title = panel_widget_get_title (PANEL_WIDGET (page));
+ g_autofree char *text = vte_terminal_get_text (VTE_TERMINAL (terminal), NULL, NULL, NULL);
+ IdeWorkspace *workspace = ide_widget_get_workspace (GTK_WIDGET (page));
+ const char *id = ide_workspace_get_id (workspace);
+
+ ide_session_item_set_module_name (item, "terminal");
+ ide_session_item_set_type_hint (item, "IdeTerminalPage");
+ ide_session_item_set_position (item, position);
+ ide_session_item_set_metadata (item, "title", "s", title);
+ ide_session_item_set_metadata (item, "workspace", "s", id);
+ ide_session_item_set_metadata (item, "text", "s", text);
+
+ if (page == ide_workspace_get_most_recent_page (workspace))
+ ide_session_item_set_metadata (item, "has-focus", "b", TRUE);
+
+ ide_session_append (session, item);
+ }
+}
+
+static void
+gbp_terminal_workspace_addin_save_session (IdeWorkspaceAddin *addin,
+ IdeSession *session)
+{
+ GbpTerminalWorkspaceAddin *self = (GbpTerminalWorkspaceAddin *)addin;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_TERMINAL_WORKSPACE_ADDIN (self));
+ g_assert (IDE_IS_SESSION (session));
+ g_assert (IDE_IS_WORKSPACE (self->workspace));
+
+ ide_workspace_foreach_page (self->workspace,
+ gbp_terminal_workspace_addin_save_session_page_cb,
+ session);
+
+ IDE_EXIT;
+}
+
static void
workspace_addin_iface_init (IdeWorkspaceAddinInterface *iface)
{
iface->load = gbp_terminal_workspace_addin_load;
iface->unload = gbp_terminal_workspace_addin_unload;
+ iface->save_session = gbp_terminal_workspace_addin_save_session;
}
G_DEFINE_FINAL_TYPE_WITH_CODE (GbpTerminalWorkspaceAddin, gbp_terminal_workspace_addin, G_TYPE_OBJECT,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]