[gnome-builder] workbench: use restore_state api from perspectives



commit dbe559e4464b63288d2ec50a6e9ee7117e4c3f2a
Author: Christian Hergert <chergert redhat com>
Date:   Sun Jun 18 03:38:35 2017 -0700

    workbench: use restore_state api from perspectives
    
    This allows the perspectives to restore state after the common work of
    loading extensions should have occurred. This fixes an issue where our
    panels were not being shown/hidden at startup properly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=783920

 libide/workbench/ide-workbench.c |   44 +++++++++++++++++++++++++------------
 1 files changed, 30 insertions(+), 14 deletions(-)
---
diff --git a/libide/workbench/ide-workbench.c b/libide/workbench/ide-workbench.c
index fe803ff..a264cdb 100644
--- a/libide/workbench/ide-workbench.c
+++ b/libide/workbench/ide-workbench.c
@@ -528,14 +528,37 @@ ide_workbench_get_context (IdeWorkbench *self)
   return self->context;
 }
 
+static void
+ide_workbench_restore_perspectives (IdePerspective *perspective,
+                                    IdeWorkbench   *self)
+{
+  g_assert (IDE_IS_PERSPECTIVE (perspective));
+  g_assert (IDE_IS_WORKBENCH (self));
+
+  ide_perspective_restore_state (perspective);
+}
+
 static gboolean
 restore_in_timeout (gpointer data)
 {
-  g_autoptr(IdeContext) context = data;
+  g_autoptr(IdeWorkbench) self = data;
+
+  g_assert (IDE_IS_WORKBENCH (self));
 
-  g_assert (IDE_IS_CONTEXT (context));
+  if (self->context != NULL)
+    {
+      g_autoptr(GSettings) settings = NULL;
 
-  ide_context_restore_async (context, NULL, NULL, NULL);
+      /* Ask perspectives to restore state */
+      gtk_container_foreach (GTK_CONTAINER (self->perspectives_stack),
+                             (GtkCallback) ide_workbench_restore_perspectives,
+                             self);
+
+      /* Restore previous files when needed */
+      settings = g_settings_new ("org.gnome.builder");
+      if (g_settings_get_boolean (settings, "restore-previous-files"))
+        ide_context_restore_async (self->context, NULL, NULL, NULL);
+    }
 
   return G_SOURCE_REMOVE;
 }
@@ -572,11 +595,11 @@ void
 ide_workbench_set_context (IdeWorkbench *self,
                            IdeContext   *context)
 {
-  g_autoptr(GSettings) settings = NULL;
   IdeBuildManager *build_manager;
   IdeRunManager *run_manager;
   IdeProject *project;
   guint delay_msec;
+  guint duration = 0;
 
   IDE_ENTRY;
 
@@ -584,8 +607,6 @@ ide_workbench_set_context (IdeWorkbench *self,
   g_return_if_fail (IDE_IS_CONTEXT (context));
   g_return_if_fail (self->context == NULL);
 
-  settings = g_settings_new ("org.gnome.builder");
-
   g_set_object (&self->context, context);
 
   project = ide_context_get_project (context);
@@ -636,14 +657,9 @@ ide_workbench_set_context (IdeWorkbench *self,
    * the stack transition results in non-smooth transitions. So instead,
    * we will delay until the transition has completed.
    */
-  if (g_settings_get_boolean (settings, "restore-previous-files"))
-    {
-      guint duration = 0;
-
-      if (!self->disable_greeter)
-        duration = gtk_stack_get_transition_duration (self->perspectives_stack);
-      g_timeout_add (delay_msec + duration, restore_in_timeout, g_object_ref (context));
-    }
+  if (!self->disable_greeter)
+    delay_msec = gtk_stack_get_transition_duration (self->perspectives_stack);
+  g_timeout_add (delay_msec + duration, restore_in_timeout, g_object_ref (self));
 
   IDE_EXIT;
 }


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