[gnome-builder] editor: handle empty restoration



commit f058bb476d48acf45bf32251fe71ffc0e849d325
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 3 12:26:17 2018 -0700

    editor: handle empty restoration
    
    We failed to change the view in a couple scenarios, and this fixes that
    by using the task:completion notification to ensure we transition.
    
    Related to #656

 src/libide/editor/ide-editor-perspective.c   |  3 +++
 src/libide/editor/ide-editor-session-addin.c | 35 ++++++++++++++++++++--------
 2 files changed, 28 insertions(+), 10 deletions(-)
---
diff --git a/src/libide/editor/ide-editor-perspective.c b/src/libide/editor/ide-editor-perspective.c
index b5e43a3a9..d9c7aae28 100644
--- a/src/libide/editor/ide-editor-perspective.c
+++ b/src/libide/editor/ide-editor-perspective.c
@@ -360,6 +360,9 @@ ide_editor_perspective_init (IdeEditorPerspective *self)
   _ide_editor_perspective_init_actions (self);
   _ide_editor_perspective_init_shortcuts (self);
 
+  /* ensure we default to the grid visible */
+  _ide_editor_perspective_set_loading (self, FALSE);
+
   g_signal_connect_swapped (self->grid,
                             "notify::current-view",
                             G_CALLBACK (ide_editor_perspective_notify_current_view),
diff --git a/src/libide/editor/ide-editor-session-addin.c b/src/libide/editor/ide-editor-session-addin.c
index f330ee73a..1391b1360 100644
--- a/src/libide/editor/ide-editor-session-addin.c
+++ b/src/libide/editor/ide-editor-session-addin.c
@@ -273,8 +273,6 @@ load_state_finish (IdeEditorSessionAddin *self,
 
       gtk_container_add (GTK_CONTAINER (stack), GTK_WIDGET (view));
     }
-
-  _ide_editor_perspective_set_loading (IDE_EDITOR_PERSPECTIVE (editor), FALSE);
 }
 
 static void
@@ -364,6 +362,18 @@ restore_file (GObject      *source,
     }
 }
 
+static void
+load_task_completed_cb (IdeTask              *task,
+                        GParamSpec           *pspec,
+                        IdeEditorPerspective *perspective)
+{
+  g_assert (IDE_IS_TASK (task));
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (perspective));
+
+  /* Always show the grid after the task completes */
+  _ide_editor_perspective_set_loading (perspective, FALSE);
+}
+
 static void
 ide_editor_session_addin_restore_async (IdeSessionAddin     *addin,
                                         GVariant            *state,
@@ -385,8 +395,17 @@ ide_editor_session_addin_restore_async (IdeSessionAddin     *addin,
   g_assert (IDE_IS_EDITOR_SESSION_ADDIN (addin));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
+  context = ide_object_get_context (IDE_OBJECT (addin));
+  workbench = IDE_WORKBENCH (ide_context_get_workbench (context));
+  editor = ide_workbench_get_perspective_by_name (workbench, "editor");
+
   task = ide_task_new (addin, cancellable, callback, user_data);
   ide_task_set_source_tag (task, ide_editor_session_addin_restore_async);
+  g_signal_connect_object (task,
+                           "notify::completed",
+                           G_CALLBACK (load_task_completed_cb),
+                           editor,
+                           0);
 
   settings = g_settings_new ("org.gnome.builder");
 
@@ -396,13 +415,6 @@ ide_editor_session_addin_restore_async (IdeSessionAddin     *addin,
       return;
     }
 
-  context = ide_object_get_context (IDE_OBJECT (addin));
-  workbench = IDE_WORKBENCH (ide_context_get_workbench (context));
-  editor = ide_workbench_get_perspective_by_name (workbench, "editor");
-
-  /* Hide the grid until we've loaded */
-  _ide_editor_perspective_set_loading (IDE_EDITOR_PERSPECTIVE (editor), TRUE);
-
   uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 
   load_state = g_slice_new0 (LoadState);
@@ -449,9 +461,12 @@ ide_editor_session_addin_restore_async (IdeSessionAddin     *addin,
 
   if (load_state->active == 0)
     {
-      _ide_editor_perspective_set_loading (IDE_EDITOR_PERSPECTIVE (editor), FALSE);
       ide_task_return_boolean (task, TRUE);
+      return;
     }
+
+  /* Hide the grid until we've loaded */
+  _ide_editor_perspective_set_loading (IDE_EDITOR_PERSPECTIVE (editor), TRUE);
 }
 
 static gboolean


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