[gnome-builder/wip/gtk4-port] libide/gui: cleanup workspace disposal



commit 5535e9331544e09ba3357a87431d6748eef8fdb0
Author: Christian Hergert <chergert redhat com>
Date:   Fri Apr 1 19:50:44 2022 -0700

    libide/gui: cleanup workspace disposal

 src/libide/gui/ide-workspace.c | 47 ++++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 18 deletions(-)
---
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index 8e44984bf..8782455a1 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -203,24 +203,6 @@ ide_workspace_close_request (GtkWindow *window)
   return TRUE;
 }
 
-static void
-ide_workspace_dispose (GObject *object)
-{
-  IdeWorkspace *self = (IdeWorkspace *)object;
-  IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
-  GtkWindowGroup *group;
-
-  g_assert (IDE_IS_WORKSPACE (self));
-
-  ide_clear_and_destroy_object (&priv->addins);
-
-  group = gtk_window_get_group (GTK_WINDOW (self));
-  if (IDE_IS_WORKBENCH (group))
-    ide_workbench_remove_workspace (IDE_WORKBENCH (group), self);
-
-  G_OBJECT_CLASS (ide_workspace_parent_class)->dispose (object);
-}
-
 /**
  * ide_workspace_class_set_kind:
  * @klass: a #IdeWorkspaceClass
@@ -356,6 +338,35 @@ ide_workspace_realize (GtkWidget *widget)
     gtk_window_maximize (GTK_WINDOW (self));
 }
 
+static void
+ide_workspace_dispose (GObject *object)
+{
+  IdeWorkspace *self = (IdeWorkspace *)object;
+  IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
+  GtkWindowGroup *group;
+
+  g_assert (IDE_IS_WORKSPACE (self));
+
+  /* Unload addins immediately */
+  ide_clear_and_destroy_object (&priv->addins);
+
+  /* Remove the workspace from the workbench MRU/etc */
+  group = gtk_window_get_group (GTK_WINDOW (self));
+  if (IDE_IS_WORKBENCH (group))
+    ide_workbench_remove_workspace (IDE_WORKBENCH (group), self);
+
+  /* Chain up to ensure the GtkWindow cleans up any widgets or other
+   * state attached to the workspace. We keep the context alive during
+   * this process.
+   */
+  G_OBJECT_CLASS (ide_workspace_parent_class)->dispose (object);
+
+  /* A reference is held during this so it is safe to run code after
+   * chaining up to dispose. Force release teh context now.
+   */
+  g_clear_object (&self->context);
+}
+
 static void
 ide_workspace_finalize (GObject *object)
 {


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