[gedit/wip/tablabel: 27/27] Make the TabLabel a template and use GtkBox center widget



commit 7d8448f5feef5b27b63850bf75b3fe307c35c267
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Jan 29 13:18:50 2014 +0100

    Make the TabLabel a template and use GtkBox center widget

 gedit/gedit-tab-label.c   |   72 ++++++++++-----------------------------------
 gedit/gedit-tab-label.ui  |   39 ++++++++++++++++++++++++
 gedit/gedit.gresource.xml |    1 +
 3 files changed, 56 insertions(+), 56 deletions(-)
---
diff --git a/gedit/gedit-tab-label.c b/gedit/gedit-tab-label.c
index c5cf75f..ff8aebd 100644
--- a/gedit/gedit-tab-label.c
+++ b/gedit/gedit-tab-label.c
@@ -44,7 +44,6 @@ struct _GeditTabLabelPrivate
 {
        GeditTab *tab;
 
-       GtkWidget *ebox;
        GtkWidget *close_button;
        GtkWidget *spinner;
        GtkWidget *icon;
@@ -119,7 +118,7 @@ sync_tip (GeditTab *tab,
        str = _gedit_tab_get_tooltip (tab);
        g_return_if_fail (str != NULL);
 
-       gtk_widget_set_tooltip_markup (tab_label->priv->ebox, str);
+       gtk_widget_set_tooltip_markup (GTK_WIDGET (tab_label), str);
        g_free (str);
 }
 
@@ -229,6 +228,7 @@ static void
 gedit_tab_label_class_init (GeditTabLabelClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
        object_class->finalize = gedit_tab_label_finalize;
        object_class->set_property = gedit_tab_label_set_property;
@@ -253,68 +253,29 @@ gedit_tab_label_class_init (GeditTabLabelClass *klass)
                                                              GEDIT_TYPE_TAB,
                                                              G_PARAM_READWRITE |
                                                              G_PARAM_CONSTRUCT_ONLY));
+
+       /* Bind class to template */
+       gtk_widget_class_set_template_from_resource (widget_class,
+                                                    "/org/gnome/gedit/ui/gedit-tab-label.ui");
+       gtk_widget_class_bind_template_child_private (widget_class, GeditTabLabel, spinner);
+       gtk_widget_class_bind_template_child_private (widget_class, GeditTabLabel, close_button);
+       gtk_widget_class_bind_template_child_private (widget_class, GeditTabLabel, icon);
+       gtk_widget_class_bind_template_child_private (widget_class, GeditTabLabel, label);
 }
 
 static void
 gedit_tab_label_init (GeditTabLabel *tab_label)
 {
-       GtkWidget *ebox;
-       GtkWidget *hbox;
-       GtkWidget *close_button;
-       GtkWidget *spinner;
-       GtkWidget *icon;
-       GtkWidget *label;
-       GtkWidget *dummy_label;
-
        tab_label->priv = gedit_tab_label_get_instance_private (tab_label);
 
        tab_label->priv->close_button_sensitive = TRUE;
 
-       gtk_orientable_set_orientation (GTK_ORIENTABLE (tab_label),
-                                       GTK_ORIENTATION_HORIZONTAL);
-
-       ebox = gtk_event_box_new ();
-       gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
-       gtk_box_pack_start (GTK_BOX (tab_label), ebox, TRUE, TRUE, 0);
-       tab_label->priv->ebox = ebox;
-
-       hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
-       gtk_container_add (GTK_CONTAINER (ebox), hbox);
-
-       close_button = gedit_close_button_new ();
-       gtk_widget_set_tooltip_text (close_button, _("Close document"));
-       gtk_box_pack_start (GTK_BOX (tab_label), close_button, FALSE, FALSE, 0);
-       tab_label->priv->close_button = close_button;
-
-       g_signal_connect (close_button,
-                         "clicked",
-                         G_CALLBACK (close_button_clicked_cb),
-                         tab_label);
-
-       spinner = gtk_spinner_new ();
-       gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
-       tab_label->priv->spinner = spinner;
-
-       /* setup icon, empty by default */
-       icon = gtk_image_new ();
-       gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
-       tab_label->priv->icon = icon;
-
-       dummy_label = gtk_label_new ("  ");
-       gtk_box_pack_start (GTK_BOX (hbox), dummy_label, FALSE, FALSE, 0);
-
-       label = gtk_label_new ("");
-       gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
-       gtk_misc_set_padding (GTK_MISC (label), 0, 0);
-       gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
-       tab_label->priv->label = label;
-
-       gtk_widget_show (ebox);
-       gtk_widget_show (hbox);
-       gtk_widget_show (close_button);
-       gtk_widget_show (icon);
-       gtk_widget_show (label);
-       gtk_widget_show (dummy_label);
+       gtk_widget_init_template (GTK_WIDGET (tab_label));
+
+       g_signal_connect (tab_label->priv->close_button,
+                         "clicked",
+                         G_CALLBACK (close_button_clicked_cb),
+                         tab_label);
 }
 
 void
@@ -358,7 +319,6 @@ gedit_tab_label_new (GeditTab *tab)
        GeditTabLabel *tab_label;
 
        tab_label = g_object_new (GEDIT_TYPE_TAB_LABEL,
-                                 "homogeneous", FALSE,
                                  "tab", tab,
                                  NULL);
 
diff --git a/gedit/gedit-tab-label.ui b/gedit/gedit-tab-label.ui
new file mode 100644
index 0000000..2ccf0a8
--- /dev/null
+++ b/gedit/gedit-tab-label.ui
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="GeditTabLabel" parent="GtkBox">
+    <property name="can_focus">False</property>
+    <property name="has_focus">False</property>
+    <property name="orientation">horizontal</property>
+    <child type="center">
+      <object class="GtkLabel" id="label">
+        <property name="visible">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkImage" id="icon">
+        <property name="visible">False</property>
+      </object>
+      <packing>
+        <property name="pack_type">start</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkSpinner" id="spinner">
+        <property name="visible">False</property>
+      </object>
+      <packing>
+        <property name="pack_type">start</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GeditCloseButton" id="close_button">
+        <property name="visible">True</property>
+        <property name="tooltip_text" translatable="yes">Close Document</property>
+      </object>
+      <packing>
+        <property name="pack_type">end</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/gedit/gedit.gresource.xml b/gedit/gedit.gresource.xml
index d0ac1ca..7ac35b0 100644
--- a/gedit/gedit.gresource.xml
+++ b/gedit/gedit.gresource.xml
@@ -9,6 +9,7 @@
     <file preprocess="xml-stripblanks">gedit-print-preferences.ui</file>
     <file preprocess="xml-stripblanks">gedit-progress-info-bar.ui</file>
     <file preprocess="xml-stripblanks">gedit-status-menu-button.ui</file>
+    <file preprocess="xml-stripblanks">gedit-tab-label.ui</file>
     <file preprocess="xml-stripblanks">gedit-view-frame.ui</file>
     <file preprocess="xml-stripblanks">gedit-highlight-mode-dialog.ui</file>
     <file preprocess="xml-stripblanks">gedit-highlight-mode-selector.ui</file>


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