[gnome-builder] tabs: update tab-label when GbTab:dirty property changes.



commit 8846c00d2d95e6731db458afe09283d674fa5849
Author: Christian Hergert <christian hergert me>
Date:   Tue Sep 9 01:25:40 2014 -0700

    tabs: update tab-label when GbTab:dirty property changes.

 src/resources/ui/gb-tab-label.ui |   28 ++++++++++++++++----
 src/tabs/gb-tab-label.c          |   51 ++++++++++++++++++++++---------------
 2 files changed, 52 insertions(+), 27 deletions(-)
---
diff --git a/src/resources/ui/gb-tab-label.ui b/src/resources/ui/gb-tab-label.ui
index c59b133..f300a7c 100644
--- a/src/resources/ui/gb-tab-label.ui
+++ b/src/resources/ui/gb-tab-label.ui
@@ -9,13 +9,29 @@
         <property name="spacing">3</property>
         <property name="orientation">horizontal</property>
         <child>
-          <object class="GtkLabel" id="label">
-            <property name="ellipsize">end</property>
-            <property name="hexpand">True</property>
-            <property name="use-markup">False</property>
-            <property name="use-underline">False</property>
-            <property name="valign">baseline</property>
+          <object class="GtkBox" id="label_container">
             <property name="visible">True</property>
+            <property name="hexpand">True</property>
+            <property name="halign">center</property>
+            <property name="orientation">horizontal</property>
+            <child>
+              <object class="GtkLabel" id="modified_label">
+                <property name="use-markup">False</property>
+                <property name="use-underline">False</property>
+                <property name="valign">baseline</property>
+                <property name="visible">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label">
+                <property name="ellipsize">end</property>
+                <property name="hexpand">False</property>
+                <property name="use-markup">False</property>
+                <property name="use-underline">False</property>
+                <property name="valign">baseline</property>
+                <property name="visible">True</property>
+              </object>
+            </child>
           </object>
         </child>
         <child>
diff --git a/src/tabs/gb-tab-label.c b/src/tabs/gb-tab-label.c
index 2b9526c..0cf7ac5 100644
--- a/src/tabs/gb-tab-label.c
+++ b/src/tabs/gb-tab-label.c
@@ -27,15 +27,12 @@
 
 struct _GbTabLabelPrivate
 {
-  GbTab          *tab;
+  GbTab     *tab;
 
-  GBinding       *title_binding;
-
-  GtkWidget      *hbox;
-  GtkWidget      *label;
-  GtkWidget      *close_button;
-
-  guint           button_pressed : 1;
+  GtkWidget *close_button;
+  GtkWidget *hbox;
+  GtkWidget *label;
+  GtkWidget *modified_label;
 };
 
 enum {
@@ -69,6 +66,20 @@ _gb_tab_label_set_show_close_button (GbTabLabel *tab_label,
   gtk_widget_set_visible (tab_label->priv->close_button, show_close_button);
 }
 
+static gboolean
+transform_dirty_to_label (GBinding     *binding,
+                          const GValue *src_value,
+                          GValue       *dst_value,
+                          gpointer      user_data)
+{
+  if (g_value_get_boolean (src_value))
+    g_value_set_static_string (dst_value, "•");
+  else
+    g_value_set_static_string (dst_value, "");
+
+  return TRUE;
+}
+
 GbTab *
 gb_tab_label_get_tab (GbTabLabel *label)
 {
@@ -88,8 +99,6 @@ gb_tab_label_set_tab (GbTabLabel *label,
 
   priv = label->priv;
 
-  g_clear_object (&priv->title_binding);
-
   if (priv->tab)
     {
       g_object_remove_weak_pointer (G_OBJECT (priv->tab),
@@ -101,12 +110,13 @@ gb_tab_label_set_tab (GbTabLabel *label,
     {
       priv->tab = tab;
       g_object_add_weak_pointer (G_OBJECT (tab), (gpointer *) &priv->tab);
-
-      priv->title_binding =
-        g_object_bind_property (tab, "title", priv->label, "label",
-                                G_BINDING_SYNC_CREATE);
-      g_object_add_weak_pointer (G_OBJECT (priv->title_binding),
-                                 (gpointer *) &priv->title_binding);
+      g_object_bind_property_full (tab, "dirty",
+                                   priv->modified_label, "label",
+                                   G_BINDING_SYNC_CREATE,
+                                   transform_dirty_to_label,
+                                   NULL, NULL, NULL);
+      g_object_bind_property (tab, "title", priv->label, "label",
+                              G_BINDING_SYNC_CREATE);
     }
 }
 
@@ -143,8 +153,6 @@ gb_tab_label_finalize (GObject *object)
 {
   GbTabLabelPrivate *priv = GB_TAB_LABEL (object)->priv;
 
-  g_clear_object (&priv->title_binding);
-
   if (priv->tab)
     {
       g_object_remove_weak_pointer (G_OBJECT (priv->tab),
@@ -204,7 +212,7 @@ gb_tab_label_class_init (GbTabLabelClass *klass)
   object_class->get_property = gb_tab_label_get_property;
   object_class->set_property = gb_tab_label_set_property;
 
-  gParamSpecs[PROP_TAB] =
+  gParamSpecs [PROP_TAB] =
     g_param_spec_object ("tab",
                          _ ("Tab"),
                          _ ("The tab the label is observing."),
@@ -215,7 +223,7 @@ gb_tab_label_class_init (GbTabLabelClass *klass)
   g_object_class_install_property (object_class, PROP_TAB,
                                    gParamSpecs[PROP_TAB]);
 
-  gSignals[CLOSE_CLICKED] =
+  gSignals [CLOSE_CLICKED] =
     g_signal_new ("close-clicked",
                   GB_TYPE_TAB_LABEL,
                   G_SIGNAL_RUN_LAST,
@@ -228,9 +236,10 @@ gb_tab_label_class_init (GbTabLabelClass *klass)
 
   gtk_widget_class_set_template_from_resource (widget_class,
                                                "/org/gnome/builder/ui/gb-tab-label.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, GbTabLabel, close_button);
   gtk_widget_class_bind_template_child_private (widget_class, GbTabLabel, hbox);
   gtk_widget_class_bind_template_child_private (widget_class, GbTabLabel, label);
-  gtk_widget_class_bind_template_child_private (widget_class, GbTabLabel, close_button);
+  gtk_widget_class_bind_template_child_private (widget_class, GbTabLabel, modified_label);
 
   g_type_ensure (GEDIT_TYPE_CLOSE_BUTTON);
 }


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