[gnome-builder/wip/chergert/headerbar] omnibar: allow attaching a build result



commit 8eb11e4cbf76b819ccd2c7d8b5637c8c201f06d5
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 22 18:30:17 2016 -0700

    omnibar: allow attaching a build result
    
    The omnibar will allow us to see build status and cancel an active build.
    We could certainly use a cleaner abstraction here, but this at least gets
    things wired up.

 libide/workbench/ide-omni-bar.c  |  124 +++++++++++++++++++++++++++++++++++++-
 libide/workbench/ide-omni-bar.h  |    7 ++-
 libide/workbench/ide-omni-bar.ui |   25 +++++---
 3 files changed, 142 insertions(+), 14 deletions(-)
---
diff --git a/libide/workbench/ide-omni-bar.c b/libide/workbench/ide-omni-bar.c
index d52a845..aeec086 100644
--- a/libide/workbench/ide-omni-bar.c
+++ b/libide/workbench/ide-omni-bar.c
@@ -18,9 +18,12 @@
 
 #define G_LOG_DOMAIN "ide-omni-bar"
 
+#include <egg-signal-group.h>
+
 #include "ide-context.h"
 #include "ide-debug.h"
 
+#include "buildsystem/ide-build-result.h"
 #include "projects/ide-project.h"
 #include "util/ide-gtk.h"
 #include "vcs/ide-vcs.h"
@@ -28,10 +31,16 @@
 
 struct _IdeOmniBar
 {
-  GtkBox    parent_instance;
+  GtkBox          parent_instance;
+
+  EggSignalGroup *build_result_signals;
 
-  GtkLabel *branch_label;
-  GtkLabel *project_label;
+  GtkLabel       *branch_label;
+  GtkLabel       *project_label;
+  GtkLabel       *build_result_mode_label;
+  GtkImage       *build_result_diagnostics_image;
+  GtkButton      *build_button;
+  GtkImage       *build_button_image;
 };
 
 G_DEFINE_TYPE (IdeOmniBar, ide_omni_bar, GTK_TYPE_BOX)
@@ -91,8 +100,69 @@ ide_omni_bar_context_set (GtkWidget  *widget,
 }
 
 static void
+ide_omni_bar_build_result_notify_mode (IdeOmniBar     *self,
+                                       GParamSpec     *pspec,
+                                       IdeBuildResult *result)
+{
+  g_autofree gchar *mode = NULL;
+
+  g_assert (IDE_IS_OMNI_BAR (self));
+  g_assert (pspec != NULL);
+  g_assert (IDE_IS_BUILD_RESULT (result));
+
+  mode = ide_build_result_get_mode (result);
+
+  gtk_label_set_label (self->build_result_mode_label, mode);
+}
+
+static void
+ide_omni_bar_build_result_notify_running (IdeOmniBar     *self,
+                                          GParamSpec     *pspec,
+                                          IdeBuildResult *result)
+{
+  g_assert (IDE_IS_OMNI_BAR (self));
+  g_assert (pspec != NULL);
+  g_assert (IDE_IS_BUILD_RESULT (result));
+
+  if (ide_build_result_get_running (result))
+    {
+      g_object_set (self->build_button_image,
+                    "icon-name", "process-stop-symbolic",
+                    NULL);
+      g_object_set (self->build_button,
+                    "action-name", "build-tools.cancel-build",
+                    NULL);
+    }
+  else
+    {
+      g_object_set (self->build_button_image,
+                    "icon-name", "system-run-symbolic",
+                    NULL);
+      g_object_set (self->build_button,
+                    "action-name", "build-tools.build",
+                    NULL);
+    }
+}
+
+static void
+ide_omni_bar_build_result_diagnostic (IdeOmniBar     *self,
+                                      IdeDiagnostic  *diagnostic,
+                                      IdeBuildResult *result)
+{
+  g_assert (IDE_IS_OMNI_BAR (self));
+  g_assert (diagnostic != NULL);
+  g_assert (IDE_IS_BUILD_RESULT (result));
+
+  gtk_widget_show (GTK_WIDGET (self->build_result_diagnostics_image));
+}
+
+static void
 ide_omni_bar_finalize (GObject *object)
 {
+  IdeOmniBar *self = (IdeOmniBar *)object;
+
+  g_clear_object (&self->build_result_signals);
+
   G_OBJECT_CLASS (ide_omni_bar_parent_class)->finalize (object);
 }
 
@@ -107,6 +177,10 @@ ide_omni_bar_class_init (IdeOmniBarClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/ui/ide-omni-bar.ui");
   gtk_widget_class_set_css_name (widget_class, "omnibar");
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, branch_label);
+  gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, build_button);
+  gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, build_button_image);
+  gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, build_result_diagnostics_image);
+  gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, build_result_mode_label);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, project_label);
 }
 
@@ -115,6 +189,24 @@ ide_omni_bar_init (IdeOmniBar *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  self->build_result_signals = egg_signal_group_new (IDE_TYPE_BUILD_RESULT);
+
+  egg_signal_group_connect_object (self->build_result_signals,
+                                   "notify::mode",
+                                   G_CALLBACK (ide_omni_bar_build_result_notify_mode),
+                                   self,
+                                   G_CONNECT_SWAPPED);
+  egg_signal_group_connect_object (self->build_result_signals,
+                                   "notify::running",
+                                   G_CALLBACK (ide_omni_bar_build_result_notify_running),
+                                   self,
+                                   G_CONNECT_SWAPPED);
+  egg_signal_group_connect_object (self->build_result_signals,
+                                   "diagnostic",
+                                   G_CALLBACK (ide_omni_bar_build_result_diagnostic),
+                                   self,
+                                   G_CONNECT_SWAPPED);
+
   ide_widget_set_context_handler (self, ide_omni_bar_context_set);
 }
 
@@ -123,3 +215,29 @@ ide_omni_bar_new (void)
 {
   return g_object_new (IDE_TYPE_OMNI_BAR, NULL);
 }
+
+/**
+ * ide_omni_bar_get_build_result:
+ *
+ * Gets the current build result that is being visualized in the omni bar.
+ *
+ * Returns: (nullable) (transfer none): An #IdeBuildResult or %NULL.
+ */
+IdeBuildResult *
+ide_omni_bar_get_build_result (IdeOmniBar *self)
+{
+  g_return_val_if_fail (IDE_IS_OMNI_BAR (self), NULL);
+
+  return egg_signal_group_get_target (self->build_result_signals);
+}
+
+void
+ide_omni_bar_set_build_result (IdeOmniBar     *self,
+                               IdeBuildResult *build_result)
+{
+  g_return_if_fail (IDE_IS_OMNI_BAR (self));
+  g_return_if_fail (!build_result || IDE_IS_BUILD_RESULT (build_result));
+
+  gtk_widget_hide (GTK_WIDGET (self->build_result_diagnostics_image));
+  egg_signal_group_set_target (self->build_result_signals, build_result);
+}
diff --git a/libide/workbench/ide-omni-bar.h b/libide/workbench/ide-omni-bar.h
index 0bca17f..956a37c 100644
--- a/libide/workbench/ide-omni-bar.h
+++ b/libide/workbench/ide-omni-bar.h
@@ -21,13 +21,18 @@
 
 #include <gtk/gtk.h>
 
+#include "ide-types.h"
+
 G_BEGIN_DECLS
 
 #define IDE_TYPE_OMNI_BAR (ide_omni_bar_get_type())
 
 G_DECLARE_FINAL_TYPE (IdeOmniBar, ide_omni_bar, IDE, OMNI_BAR, GtkBox)
 
-GtkWidget *ide_omni_bar_new (void);
+GtkWidget      *ide_omni_bar_new              (void);
+IdeBuildResult *ide_omni_bar_get_build_result (IdeOmniBar     *self);
+void            ide_omni_bar_set_build_result (IdeOmniBar     *self,
+                                               IdeBuildResult *build_result);
 
 G_END_DECLS
 
diff --git a/libide/workbench/ide-omni-bar.ui b/libide/workbench/ide-omni-bar.ui
index 2236727..b4126e7 100644
--- a/libide/workbench/ide-omni-bar.ui
+++ b/libide/workbench/ide-omni-bar.ui
@@ -34,23 +34,28 @@
           </object>
         </child>
         <child>
-          <object class="GtkLabel">
-            <property name="label">Target: host OS</property>
+          <object class="GtkImage" id="build_result_diagnostics_image">
+            <property name="icon-name">dialog-warning</property>
+          </object>
+          <packing>
+            <property name="pack-type">end</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="build_result_mode_label">
             <property name="visible">true</property>
+            <property name="ellipsize">end</property>
           </object>
           <packing>
             <property name="pack-type">end</property>
+            <property name="position">0</property>
           </packing>
         </child>
       </object>
     </child>
     <child>
-      <object class="GtkButton" id="button">
-        <!--
-          action-name is sort of a layer violation, since it requires
-          knowledge of the build plugin. But until we figure out
-          a good way to make this extensible, just put it here.
-        -->
+      <object class="GtkButton" id="build_button">
         <property name="action-name">build-tools.build</property>
         <property name="focus-on-click">false</property>
         <property name="visible">true</property>
@@ -58,7 +63,7 @@
           <class name="linked"/>
         </style>
         <child>
-          <object class="GtkImage">
+          <object class="GtkImage" id="build_button_image">
             <property name="icon-name">system-run-symbolic</property>
             <property name="visible">true</property>
           </object>
@@ -74,7 +79,7 @@
     <property name="mode">GTK_SIZE_GROUP_VERTICAL</property>
     <widgets>
       <widget name="frame"/>
-      <widget name="button"/>
+      <widget name="build_button"/>
     </widgets>
   </object>
 </interface>


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