[gtk+] parasite: Use a template for prop list
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] parasite: Use a template for prop list
- Date: Sun, 11 May 2014 02:21:48 +0000 (UTC)
commit ee7cc6d189e1359af2a51508497b00223ffd4259
Author: Matthias Clasen <mclasen redhat com>
Date: Sun May 4 21:08:36 2014 -0400
parasite: Use a template for prop list
modules/other/parasite/parasite.gresource.xml | 1 +
modules/other/parasite/prop-list.c | 232 ++++++-------------------
modules/other/parasite/prop-list.h | 42 +++--
modules/other/parasite/prop-list.ui | 66 +++++++
modules/other/parasite/window.c | 6 +-
5 files changed, 144 insertions(+), 203 deletions(-)
---
diff --git a/modules/other/parasite/parasite.gresource.xml b/modules/other/parasite/parasite.gresource.xml
index 5f121be..91e074b 100644
--- a/modules/other/parasite/parasite.gresource.xml
+++ b/modules/other/parasite/parasite.gresource.xml
@@ -6,5 +6,6 @@
<file>css-editor.ui</file>
<file>classes-list.ui</file>
<file>widget-tree.ui</file>
+ <file>prop-list.ui</file>
</gresource>
</gresources>
diff --git a/modules/other/parasite/prop-list.c b/modules/other/parasite/prop-list.c
index b5370d8..16c41ed 100644
--- a/modules/other/parasite/prop-list.c
+++ b/modules/other/parasite/prop-list.c
@@ -32,8 +32,7 @@ enum
COLUMN_DEFINED_AT,
COLUMN_OBJECT,
COLUMN_TOOLTIP,
- COLUMN_RO,
- NUM_COLUMNS
+ COLUMN_WRITABLE
};
enum
@@ -50,174 +49,46 @@ struct _ParasitePropListPrivate
GHashTable *prop_iters;
GList *signal_cnxs;
GtkWidget *widget_tree;
- GtkTreeViewColumn *property_column;
- GtkTreeViewColumn *value_column;
+ GtkCellRenderer *value_renderer;
gboolean child_properties;
};
-G_DEFINE_TYPE_WITH_PRIVATE (ParasitePropList, parasite_proplist, GTK_TYPE_TREE_VIEW)
+G_DEFINE_TYPE_WITH_PRIVATE (ParasitePropList, parasite_prop_list, GTK_TYPE_TREE_VIEW)
static void
-parasite_proplist_init (ParasitePropList *pl)
+parasite_prop_list_init (ParasitePropList *pl)
{
- pl->priv = parasite_proplist_get_instance_private (pl);
-}
-
-static gboolean
-query_tooltip_cb (GtkWidget *widget,
- gint x,
- gint y,
- gboolean keyboard_tip,
- GtkTooltip *tooltip,
- ParasitePropList *pl)
-{
- GtkTreeIter iter;
- GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
- GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
- GtkTreePath *path = NULL;
- gchar *tooltip_text;
-
- if (!gtk_tree_view_get_tooltip_context (tree_view,
- &x,
- &y,
- keyboard_tip,
- &model,
- &path,
- &iter))
- return FALSE;
-
- gtk_tree_model_get (model, &iter, COLUMN_TOOLTIP, &tooltip_text, -1);
- gtk_tooltip_set_text (tooltip, tooltip_text);
-
- gtk_tree_view_set_tooltip_cell (tree_view,
- tooltip,
- path,
- pl->priv->property_column,
- NULL);
-
- gtk_tree_path_free (path);
- g_free (tooltip_text);
-
- return TRUE;
-}
-
-static void
-draw_columns (GtkTreeViewColumn *column,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- ParasitePropList *pl)
-{
- gboolean ro;
-
- gtk_tree_model_get (model, iter, COLUMN_RO, &ro, -1);
- if (ro)
- {
- g_object_set (renderer, "foreground", "#a7aba7", NULL);
- }
- else
- {
- g_object_set (renderer, "foreground-set", FALSE, NULL);
- }
-}
-
-static void
-constructed (GObject *object)
-{
- ParasitePropList *pl = PARASITE_PROPLIST (object);
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
-
+ pl->priv = parasite_prop_list_get_instance_private (pl);
+ gtk_widget_init_template (GTK_WIDGET (pl));
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (pl->priv->model),
+ COLUMN_NAME,
+ GTK_SORT_ASCENDING);
pl->priv->prop_iters = g_hash_table_new_full (g_str_hash,
g_str_equal,
NULL,
(GDestroyNotify) gtk_tree_iter_free);
-
- pl->priv->model = gtk_list_store_new(NUM_COLUMNS,
- G_TYPE_STRING, // COLUMN_NAME
- G_TYPE_STRING, // COLUMN_VALUE
- G_TYPE_STRING, // COLUMN_DEFINED_AT
- G_TYPE_OBJECT, // COLUMN_OBJECT
- G_TYPE_STRING, // COLUMN_TOOLTIP
- G_TYPE_BOOLEAN);// COLUMN_RO
- gtk_tree_view_set_model (GTK_TREE_VIEW (pl),
- GTK_TREE_MODEL (pl->priv->model));
-
- renderer = gtk_cell_renderer_text_new();
- g_object_set (renderer, "scale", TREE_TEXT_SCALE, NULL);
- pl->priv->property_column = gtk_tree_view_column_new_with_attributes ("Property",
- renderer,
- "text", COLUMN_NAME,
- NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (pl), pl->priv->property_column);
- g_object_set (pl->priv->property_column,
- "resizable", TRUE,
- "sort-order", GTK_SORT_ASCENDING,
- "sort-column-id", COLUMN_NAME,
- NULL);
- gtk_tree_view_column_set_cell_data_func (pl->priv->property_column,
- renderer,
- (GtkTreeCellDataFunc) draw_columns,
- pl,
- NULL);
-
- renderer = parasite_property_cell_renderer_new ();
- g_object_set_data (G_OBJECT (renderer), "parasite-widget-tree", pl->priv->widget_tree);
- g_object_set (renderer,
- "scale", TREE_TEXT_SCALE,
- "editable", TRUE,
- "is-child-property", pl->priv->child_properties,
- NULL);
- pl->priv->value_column = gtk_tree_view_column_new_with_attributes ("Value", renderer,
- "text", COLUMN_VALUE,
- "object", COLUMN_OBJECT,
- "name", COLUMN_NAME,
- NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (pl), pl->priv->value_column);
- gtk_tree_view_column_set_resizable (pl->priv->value_column, TRUE);
-
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (pl->priv->model),
- COLUMN_NAME,
- GTK_SORT_ASCENDING);
- gtk_tree_view_column_set_cell_data_func (pl->priv->value_column,
- renderer,
- (GtkTreeCellDataFunc) draw_columns,
- pl,
- NULL);
-
- renderer = gtk_cell_renderer_text_new ();
- g_object_set (renderer, "scale", TREE_TEXT_SCALE, NULL);
- column = gtk_tree_view_column_new_with_attributes ("Defined at",
- renderer,
- "text", COLUMN_DEFINED_AT,
- NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (pl), column);
- gtk_tree_view_column_set_cell_data_func (column,
- renderer,
- (GtkTreeCellDataFunc) draw_columns,
- pl,
- NULL);
-
- g_object_set (object, "has-tooltip", TRUE, NULL);
- g_signal_connect (object, "query-tooltip", G_CALLBACK (query_tooltip_cb), pl);
}
static void
get_property (GObject *object,
- guint param_id,
+ guint param_id,
GValue *value,
GParamSpec *pspec)
{
- ParasitePropList *pl = PARASITE_PROPLIST (object);
+ ParasitePropList *pl = PARASITE_PROP_LIST (object);
switch (param_id)
{
case PROP_WIDGET_TREE:
g_value_take_object (value, pl->priv->widget_tree);
+ g_object_set_data (G_OBJECT (pl->priv->value_renderer), "parasite-widget-tree",
pl->priv->widget_tree);
break;
case PROP_CHILD_PROPERTIES:
g_value_set_boolean (value, pl->priv->child_properties);
+ g_object_set (pl->priv->value_renderer,
+ "is-child-property", pl->priv->child_properties,
+ NULL);
break;
default:
@@ -228,11 +99,11 @@ get_property (GObject *object,
static void
set_property (GObject *object,
- guint param_id,
+ guint param_id,
const GValue *value,
GParamSpec *pspec)
{
- ParasitePropList *pl = PARASITE_PROPLIST (object);
+ ParasitePropList *pl = PARASITE_PROP_LIST (object);
switch (param_id)
{
@@ -251,33 +122,33 @@ set_property (GObject *object,
}
static void
-parasite_proplist_class_init (ParasitePropListClass *klass)
+parasite_prop_list_class_init (ParasitePropListClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->get_property = get_property;
object_class->set_property = set_property;
- object_class->constructed = constructed;
-
- g_object_class_install_property (object_class,
- PROP_WIDGET_TREE,
- g_param_spec_object ("widget-tree",
- "Widget Tree",
- "Widget tree",
- GTK_TYPE_WIDGET,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (object_class, PROP_WIDGET_TREE,
+ g_param_spec_object ("widget-tree", "Widget Tree", "Widget tree",
+ GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_CHILD_PROPERTIES,
g_param_spec_boolean ("child-properties", "Child properties", "Child properties",
FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/parasite/prop-list.ui");
+ gtk_widget_class_bind_template_child_private (widget_class, ParasitePropList, model);
+ gtk_widget_class_bind_template_child_private (widget_class, ParasitePropList, value_renderer);
}
static void
parasite_prop_list_update_prop (ParasitePropList *pl,
- GtkTreeIter *iter,
- GParamSpec *prop)
+ GtkTreeIter *iter,
+ GParamSpec *prop)
{
GValue gvalue = {0};
- char *value;
+ gchar *value;
g_value_init(&gvalue, prop->value_type);
if (pl->priv->child_properties)
@@ -294,8 +165,8 @@ parasite_prop_list_update_prop (ParasitePropList *pl,
if (G_VALUE_HOLDS_ENUM (&gvalue))
{
- GEnumClass *enum_class = G_PARAM_SPEC_ENUM(prop)->enum_class;
- GEnumValue *enum_value = g_enum_get_value(enum_class, g_value_get_enum(&gvalue));
+ GEnumClass *enum_class = G_PARAM_SPEC_ENUM (prop)->enum_class;
+ GEnumValue *enum_value = g_enum_get_value (enum_class, g_value_get_enum (&gvalue));
value = g_strdup (enum_value->value_name);
}
@@ -310,7 +181,7 @@ parasite_prop_list_update_prop (ParasitePropList *pl,
COLUMN_DEFINED_AT, g_type_name (prop->owner_type),
COLUMN_OBJECT, pl->priv->object,
COLUMN_TOOLTIP, g_param_spec_get_blurb (prop),
- COLUMN_RO, !(prop->flags & G_PARAM_WRITABLE),
+ COLUMN_WRITABLE, (prop->flags & G_PARAM_WRITABLE) != 0,
-1);
g_free (value);
@@ -318,9 +189,9 @@ parasite_prop_list_update_prop (ParasitePropList *pl,
}
static void
-parasite_proplist_prop_changed_cb (GObject *pspec,
- GParamSpec *prop,
- ParasitePropList *pl)
+parasite_prop_list_prop_changed_cb (GObject *pspec,
+ GParamSpec *prop,
+ ParasitePropList *pl)
{
GtkTreeIter *iter = g_hash_table_lookup(pl->priv->prop_iters, prop->name);
@@ -329,17 +200,20 @@ parasite_proplist_prop_changed_cb (GObject *pspec,
}
GtkWidget *
-parasite_proplist_new (GtkWidget *widget_tree,
- gboolean child_properties)
+parasite_prop_list_new (GtkWidget *widget_tree,
+ gboolean child_properties)
{
- return g_object_new (PARASITE_TYPE_PROPLIST,
- "widget-tree", widget_tree,
- "child-properties", child_properties,
- NULL);
+ g_type_ensure (PARASITE_TYPE_PROPERTY_CELL_RENDERER);
+
+ return g_object_new (PARASITE_TYPE_PROP_LIST,
+ "widget-tree", widget_tree,
+ "child-properties", child_properties,
+ NULL);
}
gboolean
-parasite_proplist_set_object (ParasitePropList* pl, GObject *object)
+parasite_prop_list_set_object (ParasitePropList *pl,
+ GObject *object)
{
GtkTreeIter iter;
GParamSpec **props;
@@ -388,7 +262,7 @@ parasite_proplist_set_object (ParasitePropList* pl, GObject *object)
for (i = 0; i < num_properties; i++)
{
GParamSpec *prop = props[i];
- char *signal_name;
+ gchar *signal_name;
if (! (prop->flags & G_PARAM_READABLE))
continue;
@@ -405,10 +279,9 @@ parasite_proplist_set_object (ParasitePropList* pl, GObject *object)
signal_name = g_strdup_printf ("notify::%s", prop->name);
pl->priv->signal_cnxs =
- g_list_prepend (pl->priv->signal_cnxs, GINT_TO_POINTER(
- g_signal_connect(object, signal_name,
- G_CALLBACK (parasite_proplist_prop_changed_cb),
- pl)));
+ g_list_prepend (pl->priv->signal_cnxs,
+ GINT_TO_POINTER (g_signal_connect(object, signal_name,
+ G_CALLBACK (parasite_prop_list_prop_changed_cb),
pl)));
g_free (signal_name);
}
@@ -416,5 +289,4 @@ parasite_proplist_set_object (ParasitePropList* pl, GObject *object)
return TRUE;
}
-
-// vim: set et sw=4 ts=4:
+// vim: set et sw=2 ts=2:
diff --git a/modules/other/parasite/prop-list.h b/modules/other/parasite/prop-list.h
index 2343988..04e3ba6 100644
--- a/modules/other/parasite/prop-list.h
+++ b/modules/other/parasite/prop-list.h
@@ -20,42 +20,44 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef _GTKPARASITE_PROPLIST_H_
-#define _GTKPARASITE_PROPLIST_H_
+#ifndef _GTKPARASITE_PROP_LIST_H_
+#define _GTKPARASITE_PROP_LIST_H_
#include <gtk/gtk.h>
-#define PARASITE_TYPE_PROPLIST (parasite_proplist_get_type())
-#define PARASITE_PROPLIST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PARASITE_TYPE_PROPLIST,
ParasitePropList))
-#define PARASITE_PROPLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PARASITE_TYPE_PROPLIST,
ParasitePropListClass))
-#define PARASITE_IS_PROPLIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PARASITE_TYPE_PROPLIST))
-#define PARASITE_IS_PROPLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PARASITE_TYPE_PROPLIST))
-#define PARASITE_PROPLIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PARASITE_TYPE_PROPLIST,
ParasitePropListClass))
+#define PARASITE_TYPE_PROP_LIST (parasite_prop_list_get_type())
+#define PARASITE_PROP_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PARASITE_TYPE_PROP_LIST,
ParasitePropList))
+#define PARASITE_PROP_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PARASITE_TYPE_PROP_LIST,
ParasitePropListClass))
+#define PARASITE_IS_PROP_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PARASITE_TYPE_PROP_LIST))
+#define PARASITE_IS_PROP_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PARASITE_TYPE_PROP_LIST))
+#define PARASITE_PROP_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PARASITE_TYPE_PROP_LIST,
ParasitePropListClass))
typedef struct _ParasitePropListPrivate ParasitePropListPrivate;
-typedef struct _ParasitePropList {
- GtkTreeView parent;
- ParasitePropListPrivate *priv;
+typedef struct _ParasitePropList
+{
+ GtkTreeView parent;
+ ParasitePropListPrivate *priv;
} ParasitePropList;
-typedef struct _ParasitePropListClass {
- GtkTreeViewClass parent;
+typedef struct _ParasitePropListClass
+{
+ GtkTreeViewClass parent;
} ParasitePropListClass;
G_BEGIN_DECLS
-GType parasite_proplist_get_type (void);
-GtkWidget *parasite_proplist_new (GtkWidget *widget_tree,
- gboolean child_properties);
-gboolean parasite_proplist_set_object (ParasitePropList *proplist,
- GObject *object);
+GType parasite_prop_list_get_type (void);
+GtkWidget *parasite_prop_list_new (GtkWidget *widget_tree,
+ gboolean child_properties);
+gboolean parasite_prop_list_set_object (ParasitePropList *pl,
+ GObject *object);
G_END_DECLS
-#endif // _GTKPARASITE_PROPLIST_H_
+#endif // _GTKPARASITE_PROP_LIST_H_
-// vim: set et sw=4 ts=4:
+// vim: set et sw=2 ts=2:
diff --git a/modules/other/parasite/prop-list.ui b/modules/other/parasite/prop-list.ui
new file mode 100644
index 0000000..a83953d
--- /dev/null
+++ b/modules/other/parasite/prop-list.ui
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkListStore" id="model">
+ <columns>
+ <column type="gchararray"/>
+ <column type="gchararray"/>
+ <column type="gchararray"/>
+ <column type="GObject"/>
+ <column type="gchararray"/>
+ <column type="gboolean"/>
+ </columns>
+ </object>
+ <template class="ParasitePropList" parent="GtkTreeView">
+ <property name="model">model</property>
+ <property name="tooltip-column">4</property>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title">Property</property>
+ <property name="resizable">True</property>
+ <property name="sort-order">ascending</property>
+ <property name="sort-column-id">0</property>
+ <child>
+ <object class="GtkCellRendererText">
+ <property name="scale">0.8</property>
+ </object>
+ <attributes>
+ <attribute name="text">0</attribute>
+ <attribute name="sensitive">5</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title">Value</property>
+ <property name="resizable">True</property>
+ <child>
+ <object class="ParasitePropertyCellRenderer" id="value_renderer">
+ <property name="scale">0.8</property>
+ <property name="editable">True</property>
+ </object>
+ <attributes>
+ <attribute name="text">1</attribute>
+ <attribute name="object">3</attribute>
+ <attribute name="name">0</attribute>
+ <attribute name="sensitive">5</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title">Defined At</property>
+ <child>
+ <object class="GtkCellRendererText">
+ <property name="scale">0.8</property>
+ </object>
+ <attributes>
+ <attribute name="text">2</attribute>
+ <attribute name="sensitive">5</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/modules/other/parasite/window.c b/modules/other/parasite/window.c
index dd28777..00c131f 100644
--- a/modules/other/parasite/window.c
+++ b/modules/other/parasite/window.c
@@ -42,10 +42,10 @@ on_widget_tree_selection_changed (ParasiteWidgetTree *widget_tree,
if (selected != NULL)
{
- if (!parasite_proplist_set_object (PARASITE_PROPLIST (parasite->prop_list), selected))
+ if (!parasite_prop_list_set_object (PARASITE_PROP_LIST (parasite->prop_list), selected))
return;
- parasite_proplist_set_object (PARASITE_PROPLIST (parasite->child_prop_list), selected);
+ parasite_prop_list_set_object (PARASITE_PROP_LIST (parasite->child_prop_list), selected);
parasite_object_hierarchy_set_object (PARASITE_OBJECT_HIERARCHY (parasite->oh), selected);
if (GTK_IS_WIDGET (selected))
@@ -149,7 +149,7 @@ create_prop_list_pane (ParasiteWindow *parasite,
"width-request", 250,
NULL);
- pl = parasite_proplist_new (parasite->widget_tree, child_properties);
+ pl = parasite_prop_list_new (parasite->widget_tree, child_properties);
gtk_container_add (GTK_CONTAINER (swin), pl);
if (child_properties)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]