[easytag/wip/future-gtk: 2/15] Convert EtLogArea to a template widget



commit 81947cba8852c1e7e36a1a9f0a2ad588c418e306
Author: David King <amigadave amigadave com>
Date:   Tue Apr 28 19:14:33 2015 +0100

    Convert EtLogArea to a template widget

 data/log_area.ui |  100 ++++++++++++++++++++++++++++-------------------------
 src/log.c        |   32 ++++++-----------
 2 files changed, 64 insertions(+), 68 deletions(-)
---
diff --git a/data/log_area.ui b/data/log_area.ui
index 70c22c6..5d92ede 100644
--- a/data/log_area.ui
+++ b/data/log_area.ui
@@ -1,58 +1,57 @@
 <interface domain="easytag">
-    <requires lib="gtk+" version="3.4"/>
-    <object class="GtkListStore" id="log_model">
-        <columns>
-            <column type="gchararray"/>
-            <column type="gchararray"/>
-            <column type="gchararray"/>
-        </columns>
-    </object>
-    <object class="GtkGrid" id="log_grid">
-        <property name="orientation">vertical</property>
-        <property name="row-spacing">6</property>
+    <requires lib="gtk+" version="3.10"/>
+    <template class="EtLogArea" parent="GtkBin">
+        <property name="border-width">2</property>
         <property name="visible">True</property>
         <child>
-            <object class="GtkLabel" id="log_label">
-                <property name="halign">start</property>
-                <property name="label" translatable="yes">Log</property>
-                <property name="visible">True</property>
-                <attributes>
-                    <attribute name="weight" value="bold"/>
-                </attributes>
-            </object>
-        </child>
-        <child>
-            <object class="GtkScrolledWindow" id="log_scrolled">
-                <property name="expand">True</property>
-                <property name="margin-left">12</property>
-                <property name="min-content-height">20</property>
-                <property name="shadow-type">etched-in</property>
+            <object class="GtkGrid" id="log_grid">
+                <property name="orientation">vertical</property>
+                <property name="row-spacing">6</property>
                 <property name="visible">True</property>
                 <child>
-                    <object class="GtkTreeView" id="log_view">
-                        <property name="model">log_model</property>
-                        <property name="headers-visible">False</property>
+                    <object class="GtkLabel" id="log_label">
+                        <property name="halign">start</property>
+                        <property name="label" translatable="yes">Log</property>
+                        <property name="visible">True</property>
+                        <attributes>
+                            <attribute name="weight" value="bold"/>
+                        </attributes>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkScrolledWindow" id="log_scrolled">
+                        <property name="expand">True</property>
+                        <property name="margin-left">12</property>
+                        <property name="min-content-height">20</property>
+                        <property name="shadow-type">etched-in</property>
                         <property name="visible">True</property>
                         <child>
-                            <object class="GtkTreeViewColumn" id="log_icon_column">
-                                <property name="sizing">autosize</property>
-                                <child>
-                                    <object class="GtkCellRendererPixbuf" id="log_icon_renderer"/>
-                                    <attributes>
-                                        <attribute name="icon-name">0</attribute>
-                                    </attributes>
-                                </child>
-                                <child>
-                                    <object class="GtkCellRendererText" id="log_time_renderer"/>
-                                    <attributes>
-                                        <attribute name="text">1</attribute>
-                                    </attributes>
-                                </child>
+                            <object class="GtkTreeView" id="log_view">
+                                <property name="model">log_model</property>
+                                <property name="headers-visible">False</property>
+                                <property name="visible">True</property>
                                 <child>
-                                    <object class="GtkCellRendererText" id="log_text_renderer"/>
-                                    <attributes>
-                                        <attribute name="text">2</attribute>
-                                    </attributes>
+                                    <object class="GtkTreeViewColumn" id="log_icon_column">
+                                        <property name="sizing">autosize</property>
+                                        <child>
+                                            <object class="GtkCellRendererPixbuf" id="log_icon_renderer"/>
+                                            <attributes>
+                                                <attribute name="icon-name">0</attribute>
+                                            </attributes>
+                                        </child>
+                                        <child>
+                                            <object class="GtkCellRendererText" id="log_time_renderer"/>
+                                            <attributes>
+                                                <attribute name="text">1</attribute>
+                                            </attributes>
+                                        </child>
+                                        <child>
+                                            <object class="GtkCellRendererText" id="log_text_renderer"/>
+                                            <attributes>
+                                                <attribute name="text">2</attribute>
+                                            </attributes>
+                                        </child>
+                                    </object>
                                 </child>
                             </object>
                         </child>
@@ -60,5 +59,12 @@
                 </child>
             </object>
         </child>
+    </template>
+    <object class="GtkListStore" id="log_model">
+        <columns>
+            <column type="gchararray"/>
+            <column type="gchararray"/>
+            <column type="gchararray"/>
+        </columns>
     </object>
 </interface>
diff --git a/src/log.c b/src/log.c
index d64d9af..6f0b59d 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,5 +1,5 @@
 /* EasyTAG - Tag editor for audio files
- * Copyright (C) 2014  David King <amigadave amigadave com>
+ * Copyright (C) 2014-2015  David King <amigadave amigadave com>
  * Copyright (C) 2000-2007  Jerome Couderc <easytag gmail com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -122,40 +122,30 @@ on_button_press_event (GtkWidget *treeview,
 static void
 et_log_area_class_init (EtLogAreaClass *klass)
 {
+    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+    gtk_widget_class_set_template_from_resource (widget_class,
+                                                 "/org/gnome/EasyTAG/log_area.ui");
+    gtk_widget_class_bind_template_child_private (widget_class, EtLogArea,
+                                                  log_view);
+    gtk_widget_class_bind_template_child_private (widget_class, EtLogArea,
+                                                  log_model);
 }
 
 static void
 et_log_area_init (EtLogArea *self)
 {
     EtLogAreaPrivate *priv;
-    GtkWidget *grid;
     GtkBuilder *builder;
     GError *error = NULL;
     GMenuModel *menu_model;
 
     priv = et_log_area_get_instance_private (self);
 
-    gtk_container_set_border_width (GTK_CONTAINER (self), 2);
-
-    builder = gtk_builder_new ();
-    gtk_builder_add_from_resource (builder, "/org/gnome/EasyTAG/log_area.ui",
-                                   &error);
-
-    if (error != NULL)
-    {
-        g_error ("Unable to get log area from resource: %s",
-                 error->message);
-    }
-
-    grid = GTK_WIDGET (gtk_builder_get_object (builder, "log_grid"));
-    gtk_container_add (GTK_CONTAINER (self), grid);
-
-    /* The list. */
-    priv->log_model = GTK_LIST_STORE (gtk_builder_get_object (builder,
-                                                              "log_model"));
-    priv->log_view = GTK_WIDGET (gtk_builder_get_object (builder, "log_view"));
+    gtk_widget_init_template (GTK_WIDGET (self));
 
     /* Create popup menu. */
+    builder = gtk_builder_new ();
     gtk_builder_add_from_resource (builder, "/org/gnome/EasyTAG/menus.ui",
                                    &error);
 


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