parasite: Use template for object hierarchy

This commit is contained in:
Matthias Clasen 2014-05-04 12:06:06 -04:00
parent 3f5d21abec
commit 3c22fc4ef6
5 changed files with 77 additions and 68 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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>

View File

@ -2,5 +2,6 @@
<gresources>
<gresource prefix="/org/gtk/parasite">
<file>button-path.ui</file>
<file>object-hierarchy.ui</file>
</gresource>
</gresources>

View File

@ -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"));