[gnome-builder/wip/chergert/headerbar] omnibar: render project name/branch name in the bar



commit 6295a5a6802f8fe7e21a801f6bf81539055f819f
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jun 21 18:08:48 2016 -0700

    omnibar: render project name/branch name in the bar

 libide/workbench/ide-omni-bar.c  |   94 ++++++++++++++++++++++++-------------
 libide/workbench/ide-omni-bar.ui |   22 ++++++++-
 2 files changed, 80 insertions(+), 36 deletions(-)
---
diff --git a/libide/workbench/ide-omni-bar.c b/libide/workbench/ide-omni-bar.c
index ae5760b..d52a845 100644
--- a/libide/workbench/ide-omni-bar.c
+++ b/libide/workbench/ide-omni-bar.c
@@ -16,58 +16,84 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "ide-omni-bar.h"
+#define G_LOG_DOMAIN "ide-omni-bar"
+
+#include "ide-context.h"
+#include "ide-debug.h"
+
+#include "projects/ide-project.h"
+#include "util/ide-gtk.h"
+#include "vcs/ide-vcs.h"
+#include "workbench/ide-omni-bar.h"
 
 struct _IdeOmniBar
 {
-  GtkBox parent_instance;
-};
+  GtkBox    parent_instance;
 
-G_DEFINE_TYPE (IdeOmniBar, ide_omni_bar, GTK_TYPE_BOX)
-
-enum {
-  PROP_0,
-  N_PROPS
+  GtkLabel *branch_label;
+  GtkLabel *project_label;
 };
 
-static GParamSpec *properties [N_PROPS];
+G_DEFINE_TYPE (IdeOmniBar, ide_omni_bar, GTK_TYPE_BOX)
 
 static void
-ide_omni_bar_finalize (GObject *object)
+ide_omni_bar_update (IdeOmniBar *self)
 {
-  IdeOmniBar *self = (IdeOmniBar *)object;
+  g_autofree gchar *branch_name = NULL;
+  const gchar *project_name = NULL;
+  IdeContext *context;
 
-  G_OBJECT_CLASS (ide_omni_bar_parent_class)->finalize (object);
-}
+  g_assert (IDE_IS_OMNI_BAR (self));
 
-static void
-ide_omni_bar_get_property (GObject    *object,
-                           guint       prop_id,
-                           GValue     *value,
-                           GParamSpec *pspec)
-{
-  IdeOmniBar *self = IDE_OMNI_BAR (object);
+  context = ide_widget_get_context (GTK_WIDGET (self));
 
-  switch (prop_id)
+  if (IDE_IS_CONTEXT (context))
     {
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      IdeProject *project;
+      IdeVcs *vcs;
+
+      project = ide_context_get_project (context);
+      project_name = ide_project_get_name (project);
+
+      vcs = ide_context_get_vcs (context);
+      branch_name = ide_vcs_get_branch_name (vcs);
     }
+
+  gtk_label_set_label (self->project_label, project_name);
+  gtk_label_set_label (self->branch_label, branch_name);
 }
 
 static void
-ide_omni_bar_set_property (GObject      *object,
-                           guint         prop_id,
-                           const GValue *value,
-                           GParamSpec   *pspec)
+ide_omni_bar_context_set (GtkWidget  *widget,
+                          IdeContext *context)
 {
-  IdeOmniBar *self = IDE_OMNI_BAR (object);
+  IdeOmniBar *self = (IdeOmniBar *)widget;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_OMNI_BAR (self));
+  g_assert (!context || IDE_IS_CONTEXT (context));
+
+  ide_omni_bar_update (self);
 
-  switch (prop_id)
+  if (context != NULL)
     {
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      IdeVcs *vcs = ide_context_get_vcs (context);
+
+      g_signal_connect_object (vcs,
+                               "changed",
+                               G_CALLBACK (ide_omni_bar_update),
+                               self,
+                               G_CONNECT_SWAPPED);
     }
+
+  IDE_EXIT;
+}
+
+static void
+ide_omni_bar_finalize (GObject *object)
+{
+  G_OBJECT_CLASS (ide_omni_bar_parent_class)->finalize (object);
 }
 
 static void
@@ -77,17 +103,19 @@ ide_omni_bar_class_init (IdeOmniBarClass *klass)
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   object_class->finalize = ide_omni_bar_finalize;
-  object_class->get_property = ide_omni_bar_get_property;
-  object_class->set_property = ide_omni_bar_set_property;
 
   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, project_label);
 }
 
 static void
 ide_omni_bar_init (IdeOmniBar *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
+
+  ide_widget_set_context_handler (self, ide_omni_bar_context_set);
 }
 
 GtkWidget *
diff --git a/libide/workbench/ide-omni-bar.ui b/libide/workbench/ide-omni-bar.ui
index d8d582a..2236727 100644
--- a/libide/workbench/ide-omni-bar.ui
+++ b/libide/workbench/ide-omni-bar.ui
@@ -7,12 +7,28 @@
     <child type="center">
       <object class="EggEntryBox" id="frame">
         <property name="max-width-chars">50</property>
-        <property name="spacing">10</property>
+        <property name="spacing">6</property>
         <property name="visible">true</property>
         <child>
           <object class="GtkLabel" id="project_label">
-            <property name="label">&lt;b&gt;gnome-builder&lt;/b&gt; / master</property>
-            <property name="use-markup">true</property>
+            <property name="ellipsize">end</property>
+            <property name="visible">true</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="label">/</property>
+            <property name="visible">true</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="branch_label">
             <property name="ellipsize">end</property>
             <property name="visible">true</property>
           </object>


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