[gnome-builder] omnibar: Update display name when runtimes are added



commit 22c09e7ffe8f9c4e21db107e2f14f9baf486736f
Author: Matthew Leeds <mleeds redhat com>
Date:   Mon Nov 14 18:18:53 2016 -0600

    omnibar: Update display name when runtimes are added
    
    Previously, runtimes were loaded strictly before a project was opened so
    the IdeOmniBarRow appended "(missing)" to the end of the selected
    runtime name if it wasn't found in the IdeConfiguration. But now that
    GbpFlatpakRuntimeProvider treats a flatpak manifest file in a project's
    source tree as a runtime, we need to be able to update the runtime's
    display name whenever it might be discovered asynchronously, so that it
    doesn't erroneously appear to be missing to the user. This commit
    accomplishes that by connecting to the IdeRuntimeManager's
    "items-changed" signal, which is fired whenever the list of runtimes is
    modified.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=773764

 libide/workbench/ide-omni-bar-row.c |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)
---
diff --git a/libide/workbench/ide-omni-bar-row.c b/libide/workbench/ide-omni-bar-row.c
index 1989a00..08a923c 100644
--- a/libide/workbench/ide-omni-bar-row.c
+++ b/libide/workbench/ide-omni-bar-row.c
@@ -20,9 +20,11 @@
 
 #include <glib/gi18n.h>
 
+#include "ide-context.h"
 #include "devices/ide-device.h"
 #include "runtimes/ide-runtime.h"
 #include "workbench/ide-omni-bar-row.h"
+#include "runtimes/ide-runtime-manager.h"
 
 struct _IdeOmniBarRow
 {
@@ -108,6 +110,20 @@ on_device_changed (IdeOmniBarRow    *self,
 }
 
 static void
+on_runtime_manager_items_changed (IdeOmniBarRow     *self,
+                                  guint              position,
+                                  guint              added,
+                                  guint              removed,
+                                  IdeRuntimeManager *runtime_manager)
+{
+  g_assert (IDE_IS_OMNI_BAR_ROW (self));
+  g_assert (IDE_IS_RUNTIME_MANAGER (runtime_manager));
+
+  if (self->item)
+    on_runtime_changed (self, NULL, self->item);
+}
+
+static void
 ide_omni_bar_row_set_item (IdeOmniBarRow    *self,
                            IdeConfiguration *item)
 {
@@ -116,6 +132,14 @@ ide_omni_bar_row_set_item (IdeOmniBarRow    *self,
 
   if (g_set_object (&self->item, item))
     {
+      IdeContext *context;
+      IdeRuntimeManager *runtime_manager;
+
+      context = ide_object_get_context (IDE_OBJECT (item));
+      g_assert (IDE_IS_CONTEXT (context));
+      runtime_manager = ide_context_get_runtime_manager (context);
+      g_assert (IDE_IS_RUNTIME_MANAGER (runtime_manager));
+
       g_object_bind_property (self->item, "display-name",
                               self->title, "label",
                               G_BINDING_SYNC_CREATE);
@@ -132,7 +156,13 @@ ide_omni_bar_row_set_item (IdeOmniBarRow    *self,
                                self,
                                G_CONNECT_SWAPPED);
 
-      on_runtime_changed (self, NULL, item);
+      g_signal_connect_object (runtime_manager,
+                               "items-changed",
+                               G_CALLBACK (on_runtime_manager_items_changed),
+                               self,
+                               G_CONNECT_SWAPPED);
+
+      on_runtime_manager_items_changed (self, 0, 0, 0, runtime_manager);
       on_device_changed (self, NULL, item);
     }
 }


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