[gtk+/parasite2: 13/38] parasite: Use template for object hierarchy



commit ced243c852a0d6f8b5cf945b9077d232263d1405
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun May 4 12:06:06 2014 -0400

    parasite: Use template for object hierarchy

 modules/other/parasite/object-hierarchy.c     |   64 +++++++------------------
 modules/other/parasite/object-hierarchy.h     |   40 ++++++++-------
 modules/other/parasite/object-hierarchy.ui    |   36 ++++++++++++++
 modules/other/parasite/parasite.gresource.xml |    1 +
 modules/other/parasite/window.c               |    4 +-
 5 files changed, 77 insertions(+), 68 deletions(-)
---
diff --git a/modules/other/parasite/object-hierarchy.c b/modules/other/parasite/object-hierarchy.c
index 3dba5af..921fc76 100644
--- a/modules/other/parasite/object-hierarchy.c
+++ b/modules/other/parasite/object-hierarchy.c
@@ -25,8 +25,7 @@
 
 enum
 {
-  COLUMN_OBJECT_NAME,
-  NUM_COLUMNS
+  COLUMN_OBJECT_NAME
 };
 
 struct _ParasiteObjectHierarchyPrivate
@@ -35,62 +34,34 @@ struct _ParasiteObjectHierarchyPrivate
   GtkTreeView *tree;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (ParasiteObjectHierarchy, parasite_objecthierarchy, GTK_TYPE_BOX)
+G_DEFINE_TYPE_WITH_PRIVATE (ParasiteObjectHierarchy, parasite_object_hierarchy, GTK_TYPE_BOX)
 
 static void
-parasite_objecthierarchy_init (ParasiteObjectHierarchy *oh)
+parasite_object_hierarchy_init (ParasiteObjectHierarchy *oh)
 {
-  oh->priv = parasite_objecthierarchy_get_instance_private (oh);
+  oh->priv = parasite_object_hierarchy_get_instance_private (oh);
+  gtk_widget_init_template (GTK_WIDGET (oh));
 }
 
 static void
-constructed (GObject *object)
+parasite_object_hierarchy_class_init (ParasiteObjectHierarchyClass *klass)
 {
-  ParasiteObjectHierarchy *oh = PARASITE_OBJECTHIERARCHY (object);
-  GtkWidget *sw;
-  GtkCellRenderer *renderer;
-  GtkTreeViewColumn *column;
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
-  g_object_set (object,
-                "orientation", GTK_ORIENTATION_VERTICAL,
-                NULL);
-
-  sw = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
-                     "expand", TRUE,
-                     NULL);
-  gtk_container_add (GTK_CONTAINER (object), sw);
-
-  oh->priv->model = gtk_tree_store_new (NUM_COLUMNS,
-                                        G_TYPE_STRING);   // COLUMN_OBJECT_NAME
-  oh->priv->tree = GTK_TREE_VIEW (gtk_tree_view_new_with_model (GTK_TREE_MODEL (oh->priv->model)));
-  gtk_container_add (GTK_CONTAINER (sw), GTK_WIDGET (oh->priv->tree));
-
-
-  renderer = gtk_cell_renderer_text_new ();
-  g_object_set (renderer, "scale", TREE_TEXT_SCALE, NULL);
-  column = gtk_tree_view_column_new_with_attributes ("Object Hierarchy", renderer,
-                                                     "text", COLUMN_OBJECT_NAME,
-                                                     NULL);
-  gtk_tree_view_append_column (GTK_TREE_VIEW (oh->priv->tree), column);
-}
-
-static void
-parasite_objecthierarchy_class_init (ParasiteObjectHierarchyClass *klass)
-{
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-  object_class->constructed  = constructed;
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/parasite/object-hierarchy.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, ParasiteObjectHierarchy, model);
+  gtk_widget_class_bind_template_child_private (widget_class, ParasiteObjectHierarchy, tree);
 }
 
 GtkWidget *
-parasite_objecthierarchy_new (void)
+parasite_object_hierarchy_new (void)
 {
-  return GTK_WIDGET (g_object_new (PARASITE_TYPE_OBJECTHIERARCHY,
-                                   NULL));
+  return GTK_WIDGET (g_object_new (PARASITE_TYPE_OBJECT_HIERARCHY, NULL));
 }
 
 void
-parasite_objecthierarchy_set_object (ParasiteObjectHierarchy *oh, GObject *object)
+parasite_object_hierarchy_set_object (ParasiteObjectHierarchy *oh,
+                                      GObject                 *object)
 {
   GObjectClass *klass = G_OBJECT_GET_CLASS (object);
   const gchar *class_name;
@@ -104,7 +75,7 @@ parasite_objecthierarchy_set_object (ParasiteObjectHierarchy *oh, GObject *objec
       class_name = G_OBJECT_CLASS_NAME (klass);
       list = g_slist_append (list, (gpointer)class_name);
     }
-  while ((klass = g_type_class_peek_parent (klass))) ;
+  while ((klass = g_type_class_peek_parent (klass)));
   list = g_slist_reverse (list);
 
   for (l = list; l; l = l->next)
@@ -119,8 +90,7 @@ parasite_objecthierarchy_set_object (ParasiteObjectHierarchy *oh, GObject *objec
   g_slist_free (list);
 
   gtk_tree_view_expand_all (oh->priv->tree);
-  gtk_tree_selection_select_iter (gtk_tree_view_get_selection (oh->priv->tree),
-                                  &iter);
+  gtk_tree_selection_select_iter (gtk_tree_view_get_selection (oh->priv->tree), &iter);
 }
 
-// vim: set et sw=4 ts=4:
+// vim: set et sw=2 ts=2:
diff --git a/modules/other/parasite/object-hierarchy.h b/modules/other/parasite/object-hierarchy.h
index 6eab63a..0bc18a8 100644
--- a/modules/other/parasite/object-hierarchy.h
+++ b/modules/other/parasite/object-hierarchy.h
@@ -20,39 +20,41 @@
  * THE SOFTWARE.
  */
 
-#ifndef _GTKPARASITE_OBJECTHIERARCHY_H_
-#define _GTKPARASITE_OBJECTHIERARCHY_H_
+#ifndef _GTKPARASITE_OBJECT_HIERARCHY_H_
+#define _GTKPARASITE_OBJECT_HIERARCHY_H_
 
 #include <gtk/gtk.h>
 
-#define PARASITE_TYPE_OBJECTHIERARCHY            (parasite_objecthierarchy_get_type())
-#define PARASITE_OBJECTHIERARCHY(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), 
PARASITE_TYPE_OBJECTHIERARCHY, ParasiteObjectHierarchy))
-#define PARASITE_OBJECTHIERARCHY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), 
PARASITE_TYPE_OBJECTHIERARCHY, ParasiteObjectHierarchyClass))
-#define PARASITE_IS_OBJECTHIERARCHY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
PARASITE_TYPE_OBJECTHIERARCHY))
-#define PARASITE_IS_OBJECTHIERARCHY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), 
PARASITE_TYPE_OBJECTHIERARCHY))
-#define PARASITE_OBJECTHIERARCHY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), 
PARASITE_TYPE_OBJECTHIERARCHY, ParasiteObjectHierarchyClass))
+#define PARASITE_TYPE_OBJECT_HIERARCHY            (parasite_object_hierarchy_get_type())
+#define PARASITE_OBJECT_HIERARCHY(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), 
PARASITE_TYPE_OBJECT_HIERARCHY, ParasiteObjectHierarchy))
+#define PARASITE_OBJECT_HIERARCHY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), 
PARASITE_TYPE_OBJECT_HIERARCHY, ParasiteObjectHierarchyClass))
+#define PARASITE_IS_OBJECT_HIERARCHY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
PARASITE_TYPE_OBJECT_HIERARCHY))
+#define PARASITE_IS_OBJECT_HIERARCHY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), 
PARASITE_TYPE_OBJECT_HIERARCHY))
+#define PARASITE_OBJECT_HIERARCHY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), 
PARASITE_TYPE_OBJECT_HIERARCHY, ParasiteObjectHierarchyClass))
 
 
 typedef struct _ParasiteObjectHierarchyPrivate ParasiteObjectHierarchyPrivate;
 
-typedef struct _ParasiteObjectHierarchy {
-   GtkBox parent;
-   ParasiteObjectHierarchyPrivate *priv;
+typedef struct _ParasiteObjectHierarchy
+{
+  GtkBox parent;
+  ParasiteObjectHierarchyPrivate *priv;
 } ParasiteObjectHierarchy;
 
-typedef struct _ParasiteObjectHierarchyClass {
-   GtkBoxClass parent;
+typedef struct _ParasiteObjectHierarchyClass
+{
+  GtkBoxClass parent;
 } ParasiteObjectHierarchyClass;
 
 G_BEGIN_DECLS
 
-GType     parasite_objecthierarchy_get_type   (void);
-GtkWidget *parasite_objecthierarchy_new       (void);
-void      parasite_objecthierarchy_set_object (ParasiteObjectHierarchy *editor,
-                                               GObject                 *object);
+GType      parasite_object_hierarchy_get_type   (void);
+GtkWidget *parasite_object_hierarchy_new        (void);
+void       parasite_object_hierarchy_set_object (ParasiteObjectHierarchy *oh,
+                                                 GObject                 *object);
 
 G_END_DECLS
 
-#endif // _GTKPARASITE_OBJECTHIERARCHY_H_
+#endif // _GTKPARASITE_OBJECT_HIERARCHY_H_
 
-// vim: set et sw=4 ts=4:
+// vim: set et sw=2 ts=2:
diff --git a/modules/other/parasite/object-hierarchy.ui b/modules/other/parasite/object-hierarchy.ui
new file mode 100644
index 0000000..808dbfc
--- /dev/null
+++ b/modules/other/parasite/object-hierarchy.ui
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkTreeStore" id="model">
+    <columns>
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <template class="ParasiteObjectHierarchy" parent="GtkBox">
+    <property name="orientation">horizontal</property>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="visible">True</property>
+        <property name="expand">True</property>
+        <child>
+          <object class="GtkTreeView" id="tree">
+            <property name="visible">True</property>
+            <property name="model">model</property>
+            <child>
+              <object class="GtkTreeViewColumn">
+                <property name="title">Object Hierarchy</property>
+                <child>
+                  <object class="GtkCellRendererText">
+                    <property name="scale">0.8</property>
+                  </object>
+                  <attributes>
+                    <attribute name="text">0</attribute>
+                  </attributes> 
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/modules/other/parasite/parasite.gresource.xml b/modules/other/parasite/parasite.gresource.xml
index ec422df..d89a36a 100644
--- a/modules/other/parasite/parasite.gresource.xml
+++ b/modules/other/parasite/parasite.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/org/gtk/parasite">
     <file>button-path.ui</file>
+    <file>object-hierarchy.ui</file>
   </gresource>
 </gresources>
diff --git a/modules/other/parasite/window.c b/modules/other/parasite/window.c
index bc6868d..668c95c 100644
--- a/modules/other/parasite/window.c
+++ b/modules/other/parasite/window.c
@@ -46,7 +46,7 @@ on_widget_tree_selection_changed (ParasiteWidgetTree *widget_tree,
         return;
 
       parasite_proplist_set_object (PARASITE_PROPLIST (parasite->child_prop_list), selected);
-      parasite_objecthierarchy_set_object (PARASITE_OBJECTHIERARCHY (parasite->oh), selected);
+      parasite_object_hierarchy_set_object (PARASITE_OBJECT_HIERARCHY (parasite->oh), selected);
 
       if (GTK_IS_WIDGET (selected))
         {
@@ -288,7 +288,7 @@ gtkparasite_window_create()
                               create_prop_list_pane (window, TRUE),
                               gtk_label_new ("Child Properties"));
 
-    window->oh = parasite_objecthierarchy_new ();
+    window->oh = parasite_object_hierarchy_new ();
     gtk_notebook_append_page (GTK_NOTEBOOK (nb),
                               window->oh,
                               gtk_label_new ("Hierarchy"));


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