[gnome-builder] libide/gui: add vfuncs to save/restore session state



commit 5ffbb00355166e6e78f63bf114ca51bb79f7752b
Author: Christian Hergert <chergert redhat com>
Date:   Wed Sep 14 16:56:47 2022 -0700

    libide/gui: add vfuncs to save/restore session state
    
    This will be used eventually by the IdeWorkbench to save/restore state as
    part of the project load/unload flow.

 src/libide/gui/ide-workbench-addin.c | 42 ++++++++++++++++++++++++++++++++++++
 src/libide/gui/ide-workbench-addin.h | 12 ++++++++++-
 2 files changed, 53 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/gui/ide-workbench-addin.c b/src/libide/gui/ide-workbench-addin.c
index 0e9a4700e..383f0faf3 100644
--- a/src/libide/gui/ide-workbench-addin.c
+++ b/src/libide/gui/ide-workbench-addin.c
@@ -325,6 +325,48 @@ ide_workbench_addin_project_loaded (IdeWorkbenchAddin *self,
     IDE_WORKBENCH_ADDIN_GET_IFACE (self)->project_loaded (self, project_info);
 }
 
+/**
+ * ide_workbench_addin_save_session:
+ * @self: an #IdeWorkbenchAddin
+ * @session: an #IdeSession
+ *
+ * Saves session state from @self into @session.
+ *
+ * This function is used for workbench addins that want to save state between
+ * application runs of Builder. You can add items to the session and then
+ * restore them when ide_workbench_addin_restore_session() is called as part
+ * of the project loading in a future Builder application instance.
+ */
+void
+ide_workbench_addin_save_session (IdeWorkbenchAddin *self,
+                                  IdeSession        *session)
+{
+  g_return_if_fail (IDE_IS_WORKBENCH_ADDIN (self));
+  g_return_if_fail (IDE_IS_SESSION (session));
+
+  if (IDE_WORKBENCH_ADDIN_GET_IFACE (self)->save_session)
+    IDE_WORKBENCH_ADDIN_GET_IFACE (self)->save_session (self, session);
+}
+
+/**
+ * ide_workbench_addin_restore_session:
+ * @self: an #IdeWorkbenchAddin
+ * @session: an #IdeSession
+ *
+ * Requests that the workbench restore any session state that was saved
+ * into the session object @session.
+ */
+void
+ide_workbench_addin_restore_session (IdeWorkbenchAddin *self,
+                                     IdeSession        *session)
+{
+  g_return_if_fail (IDE_IS_WORKBENCH_ADDIN (self));
+  g_return_if_fail (IDE_IS_SESSION (session));
+
+  if (IDE_WORKBENCH_ADDIN_GET_IFACE (self)->restore_session)
+    IDE_WORKBENCH_ADDIN_GET_IFACE (self)->restore_session (self, session);
+}
+
 /**
  * ide_workbench_addin_ref_action_group:
  * @self: a #IdeWorkbenchAddin
diff --git a/src/libide/gui/ide-workbench-addin.h b/src/libide/gui/ide-workbench-addin.h
index 250bbc425..57cdd50eb 100644
--- a/src/libide/gui/ide-workbench-addin.h
+++ b/src/libide/gui/ide-workbench-addin.h
@@ -24,7 +24,7 @@
 # error "Only <libide-gui.h> can be included directly."
 #endif
 
-#include "ide-panel-position.h"
+#include "ide-session.h"
 #include "ide-workbench.h"
 #include "ide-workspace.h"
 
@@ -85,6 +85,10 @@ struct _IdeWorkbenchAddinInterface
   void          (*vcs_changed)           (IdeWorkbenchAddin     *self,
                                           IdeVcs                *vcs);
   GActionGroup *(*ref_action_group)      (IdeWorkbenchAddin     *self);
+  void          (*save_session)          (IdeWorkbenchAddin     *self,
+                                          IdeSession            *session);
+  void          (*restore_session)       (IdeWorkbenchAddin     *self,
+                                          IdeSession            *session);
 };
 
 IDE_AVAILABLE_IN_ALL
@@ -148,6 +152,12 @@ void               ide_workbench_addin_vcs_changed           (IdeWorkbenchAddin
 IDE_AVAILABLE_IN_ALL
 GActionGroup      *ide_workbench_addin_ref_action_group      (IdeWorkbenchAddin    *self);
 IDE_AVAILABLE_IN_ALL
+void               ide_workbench_addin_save_session          (IdeWorkbenchAddin    *self,
+                                                              IdeSession           *session);
+IDE_AVAILABLE_IN_ALL
+void               ide_workbench_addin_restore_session       (IdeWorkbenchAddin    *self,
+                                                              IdeSession           *session);
+IDE_AVAILABLE_IN_ALL
 IdeWorkbenchAddin *ide_workbench_addin_find_by_module_name   (IdeWorkbench         *workbench,
                                                               const gchar          *module_name);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]