From 3c22fc4ef6798be1dab8256b8adf5af679ba62c1 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 4 May 2014 12:06:06 -0400 Subject: [PATCH] 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(-) create mode 100644 modules/other/parasite/object-hierarchy.ui diff --git a/modules/other/parasite/object-hierarchy.c b/modules/other/parasite/object-hierarchy.c index 3dba5af95b..921fc762e7 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 6eab63a7ba..0bc18a8494 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 -#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 0000000000..808dbfc340 --- /dev/null +++ b/modules/other/parasite/object-hierarchy.ui @@ -0,0 +1,36 @@ + + + + + + + + + diff --git a/modules/other/parasite/parasite.gresource.xml b/modules/other/parasite/parasite.gresource.xml index ec422dfa25..d89a36a69d 100644 --- a/modules/other/parasite/parasite.gresource.xml +++ b/modules/other/parasite/parasite.gresource.xml @@ -2,5 +2,6 @@ button-path.ui + object-hierarchy.ui diff --git a/modules/other/parasite/window.c b/modules/other/parasite/window.c index bc6868d9af..668c95c4bc 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"));