[gnome-builder] libide/gui: move various workbench session code into new file



commit 797d86ce917613778c24042b872cb74223f11941
Author: Christian Hergert <chergert redhat com>
Date:   Thu Sep 15 19:37:00 2022 -0700

    libide/gui: move various workbench session code into new file

 src/libide/gui/ide-workbench-private.h |  20 +++--
 src/libide/gui/ide-workbench-session.c | 143 +++++++++++++++++++++++++++++++++
 src/libide/gui/ide-workbench.c         | 104 ++----------------------
 src/libide/gui/meson.build             |   1 +
 4 files changed, 164 insertions(+), 104 deletions(-)
---
diff --git a/src/libide/gui/ide-workbench-private.h b/src/libide/gui/ide-workbench-private.h
index d3fd8992c..1cca682cb 100644
--- a/src/libide/gui/ide-workbench-private.h
+++ b/src/libide/gui/ide-workbench-private.h
@@ -20,15 +20,25 @@
 
 #pragma once
 
+#include <libpeas/peas.h>
+
+#include "ide-session.h"
 #include "ide-workbench.h"
 #include "ide-workspace.h"
 
 G_BEGIN_DECLS
 
-gboolean      _ide_workbench_is_last_workspace (IdeWorkbench *self,
-                                                IdeWorkspace *workspace);
-IdeWorkspace *_ide_workbench_create_secondary  (IdeWorkbench *self);
-void          _ide_workbench_set_session       (IdeWorkbench *self,
-                                                IdeSession   *session);
+gboolean      _ide_workbench_is_last_workspace      (IdeWorkbench     *self,
+                                                     IdeWorkspace     *workspace);
+IdeWorkspace *_ide_workbench_create_secondary       (IdeWorkbench     *self);
+void          _ide_workbench_addins_restore_session (IdeWorkbench     *self,
+                                                     PeasExtensionSet *addins,
+                                                     IdeSession       *session);
+gboolean      _ide_workbench_restore_workspaces     (IdeWorkbench     *self,
+                                                     IdeSession       *session,
+                                                     gint64            present_time,
+                                                     GType             expected_workspace);
+void          _ide_workbench_set_session            (IdeWorkbench     *self,
+                                                     IdeSession       *session);
 
 G_END_DECLS
diff --git a/src/libide/gui/ide-workbench-session.c b/src/libide/gui/ide-workbench-session.c
new file mode 100644
index 000000000..bebb31e4c
--- /dev/null
+++ b/src/libide/gui/ide-workbench-session.c
@@ -0,0 +1,143 @@
+/* ide-workbench-session.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-workbench-session"
+
+#include "config.h"
+
+#include "ide-application.h"
+#include "ide-session.h"
+#include "ide-session-item.h"
+#include "ide-workbench-addin.h"
+#include "ide-workbench-private.h"
+#include "ide-workspace-private.h"
+
+static void
+ide_workbench_addin_restore_session_cb (PeasExtensionSet *set,
+                                        PeasPluginInfo   *plugin_info,
+                                        PeasExtension    *exten,
+                                        gpointer          user_data)
+{
+  IdeWorkbenchAddin *addin = (IdeWorkbenchAddin *)exten;
+  IdeSession *session = user_data;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (IDE_IS_WORKBENCH_ADDIN (addin));
+  g_assert (IDE_IS_SESSION (session));
+
+  ide_workbench_addin_restore_session (addin, session);
+}
+
+void
+_ide_workbench_addins_restore_session (IdeWorkbench     *self,
+                                       PeasExtensionSet *addins,
+                                       IdeSession       *session)
+{
+  IDE_ENTRY;
+
+  g_return_if_fail (IDE_IS_MAIN_THREAD ());
+  g_return_if_fail (IDE_IS_WORKBENCH (self));
+  g_return_if_fail (IDE_IS_SESSION (session));
+  g_return_if_fail (PEAS_IS_EXTENSION_SET (addins));
+
+  peas_extension_set_foreach (addins,
+                              ide_workbench_addin_restore_session_cb,
+                              session);
+
+  IDE_EXIT;
+}
+
+gboolean
+_ide_workbench_restore_workspaces (IdeWorkbench *self,
+                                   IdeSession   *session,
+                                   gint64        present_time,
+                                   GType         expected_workspace)
+{
+  IdeWorkspace *active_window = NULL;
+  gboolean ret = FALSE;
+  guint n_items;
+
+  IDE_ENTRY;
+
+  g_return_val_if_fail (IDE_IS_MAIN_THREAD (), FALSE);
+  g_return_val_if_fail (IDE_IS_WORKBENCH (self), FALSE);
+
+  n_items = ide_session_get_n_items (session);
+
+  for (guint i = 0; i < n_items; i++)
+    {
+      IdeSessionItem *item = ide_session_get_item (session, i);
+
+      if (g_strcmp0 (ide_session_item_get_module_name (item), "libide-gui") == 0)
+        {
+          const char *type_hint = ide_session_item_get_type_hint (item);
+          GType type = type_hint ? g_type_from_name (type_hint) : G_TYPE_INVALID;
+
+          if (type && g_type_is_a (type, IDE_TYPE_WORKSPACE))
+            {
+              IdeWorkspace *workspace;
+              const char *id;
+              gboolean is_active = FALSE;
+              gboolean is_maximized = FALSE;
+              int width = -1, height = -1;
+
+              if (type == expected_workspace)
+                ret = TRUE;
+
+              id = ide_session_item_get_id (item);
+
+              if (ide_session_item_has_metadata_with_type (item, "is-maximized", G_VARIANT_TYPE ("b")))
+                ide_session_item_get_metadata (item, "is-maximized", "b", &is_maximized);
+
+              if (ide_session_item_has_metadata_with_type (item, "is-active", G_VARIANT_TYPE ("b")))
+                ide_session_item_get_metadata (item, "is-active", "b", &is_active);
+
+              if (ide_session_item_has_metadata_with_type (item, "size", G_VARIANT_TYPE ("(ii)")))
+                ide_session_item_get_metadata (item, "size", "(ii)", &width, &height);
+
+              workspace = g_object_new (type,
+                                        "application", IDE_APPLICATION_DEFAULT,
+                                        "id", id,
+                                        NULL);
+              ide_workbench_add_workspace (self, workspace);
+
+              if (width > -1 && height > -1)
+                {
+                  gtk_window_set_default_size (GTK_WINDOW (workspace), width, height);
+                  _ide_workspace_set_ignore_size_setting (workspace, TRUE);
+                }
+
+              if (is_maximized)
+                gtk_window_maximize (GTK_WINDOW (workspace));
+
+              if (is_active)
+                active_window = workspace;
+              else
+                gtk_window_present_with_time (GTK_WINDOW (workspace), present_time);
+            }
+        }
+    }
+
+  if (active_window)
+    gtk_window_present_with_time (GTK_WINDOW (active_window), present_time);
+
+  IDE_RETURN (ret);
+}
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index 550d098e4..19041b484 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -958,98 +958,6 @@ ide_workbench_project_loaded_foreach_cb (PeasExtensionSet *set,
   ide_workbench_addin_project_loaded (addin, self->project_info);
 }
 
-static void
-ide_workbench_addin_restore_session_cb (PeasExtensionSet *set,
-                                        PeasPluginInfo   *plugin_info,
-                                        PeasExtension    *exten,
-                                        gpointer          user_data)
-{
-  IdeWorkbenchAddin *addin = (IdeWorkbenchAddin *)exten;
-  IdeSession *session = user_data;
-
-  g_assert (IDE_IS_MAIN_THREAD ());
-  g_assert (PEAS_IS_EXTENSION_SET (set));
-  g_assert (IDE_IS_WORKBENCH_ADDIN (addin));
-  g_assert (IDE_IS_SESSION (session));
-
-  ide_workbench_addin_restore_session (addin, session);
-}
-
-static gboolean
-ide_workbench_restore_workspaces (IdeWorkbench *self,
-                                  IdeSession   *session,
-                                  gint64        present_time,
-                                  GType         expected_workspace)
-{
-  IdeWorkspace *active_window = NULL;
-  gboolean ret = FALSE;
-  guint n_items;
-
-  g_assert (IDE_IS_MAIN_THREAD ());
-  g_assert (IDE_IS_SESSION (session));
-
-  n_items = ide_session_get_n_items (session);
-
-  for (guint i = 0; i < n_items; i++)
-    {
-      IdeSessionItem *item = ide_session_get_item (session, i);
-
-      if (g_strcmp0 (ide_session_item_get_module_name (item), "libide-gui") == 0)
-        {
-          const char *type_hint = ide_session_item_get_type_hint (item);
-          GType type = type_hint ? g_type_from_name (type_hint) : G_TYPE_INVALID;
-
-          if (type && g_type_is_a (type, IDE_TYPE_WORKSPACE))
-            {
-              IdeWorkspace *workspace;
-              const char *id;
-              gboolean is_active = FALSE;
-              gboolean is_maximized = FALSE;
-              int width = -1, height = -1;
-
-              if (type == expected_workspace)
-                ret = TRUE;
-
-              id = ide_session_item_get_id (item);
-
-              if (ide_session_item_has_metadata_with_type (item, "is-maximized", G_VARIANT_TYPE ("b")))
-                ide_session_item_get_metadata (item, "is-maximized", "b", &is_maximized);
-
-              if (ide_session_item_has_metadata_with_type (item, "is-active", G_VARIANT_TYPE ("b")))
-                ide_session_item_get_metadata (item, "is-active", "b", &is_active);
-
-              if (ide_session_item_has_metadata_with_type (item, "size", G_VARIANT_TYPE ("(ii)")))
-                ide_session_item_get_metadata (item, "size", "(ii)", &width, &height);
-
-              workspace = g_object_new (type,
-                                        "application", IDE_APPLICATION_DEFAULT,
-                                        "id", id,
-                                        NULL);
-              ide_workbench_add_workspace (self, workspace);
-
-              if (width > -1 && height > -1)
-                {
-                  gtk_window_set_default_size (GTK_WINDOW (workspace), width, height);
-                  _ide_workspace_set_ignore_size_setting (workspace, TRUE);
-                }
-
-              if (is_maximized)
-                gtk_window_maximize (GTK_WINDOW (workspace));
-
-              if (is_active)
-                active_window = workspace;
-              else
-                gtk_window_present_with_time (GTK_WINDOW (workspace), present_time);
-            }
-        }
-    }
-
-  if (active_window)
-    gtk_window_present_with_time (GTK_WINDOW (active_window), present_time);
-
-  return ret;
-}
-
 static void
 ide_workbench_load_project_completed (IdeWorkbench *self,
                                       IdeTask      *task)
@@ -1090,15 +998,13 @@ ide_workbench_load_project_completed (IdeWorkbench *self,
       /* Restore workspaces, and cancel our request to create a new one
        * if the workspace was likely created already.
        */
-      if (ide_workbench_restore_workspaces (self,
-                                            self->session,
-                                            lp->present_time,
-                                            lp->workspace_type))
+      if (_ide_workbench_restore_workspaces (self,
+                                             self->session,
+                                             lp->present_time,
+                                             lp->workspace_type))
         lp->workspace_type = G_TYPE_INVALID;
 
-      peas_extension_set_foreach (self->addins,
-                                  ide_workbench_addin_restore_session_cb,
-                                  self->session);
+      _ide_workbench_addins_restore_session (self, self->addins, self->session);
       g_clear_object (&self->session);
     }
 
diff --git a/src/libide/gui/meson.build b/src/libide/gui/meson.build
index 067ddaf12..51480a450 100644
--- a/src/libide/gui/meson.build
+++ b/src/libide/gui/meson.build
@@ -76,6 +76,7 @@ libide_gui_private_sources = [
   'ide-shortcut-window.c',
   'ide-support.c',
   'ide-style-variant-preview.c',
+  'ide-workbench-session.c',
 ]
 
 libide_gui_public_sources = [


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