From e0f4bf5d3523c65521a5ac0768c5770fb7836bd9 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 1 Nov 2015 02:34:41 +0100 Subject: [PATCH] inspector: Store the current node in the priv struct --- gtk/inspector/css-node-tree.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/gtk/inspector/css-node-tree.c b/gtk/inspector/css-node-tree.c index 80b88907e6..6d7cfa96f4 100644 --- a/gtk/inspector/css-node-tree.c +++ b/gtk/inspector/css-node-tree.c @@ -72,6 +72,7 @@ struct _GtkInspectorCssNodeTreePrivate GtkWidget *prop_tree; GtkTreeViewColumn *prop_name_column; GHashTable *prop_iters; + GtkCssNode *node; }; G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorCssNodeTree, gtk_inspector_css_node_tree, GTK_TYPE_BOX) @@ -127,11 +128,25 @@ selection_changed (GtkTreeSelection *selection, GtkInspectorCssNodeTree *cnt) populate_properties (cnt); } +static void +gtk_inspector_css_node_tree_unset_node (GtkInspectorCssNodeTree *cnt) +{ + GtkInspectorCssNodeTreePrivate *priv = cnt->priv; + + if (priv->node) + { + g_object_unref (priv->node); + priv->node = NULL; + } +} + static void gtk_inspector_css_node_tree_finalize (GObject *object) { GtkInspectorCssNodeTree *cnt = GTK_INSPECTOR_CSS_NODE_TREE (object); + gtk_inspector_css_node_tree_unset_node (cnt); + g_hash_table_unref (cnt->priv->prop_iters); G_OBJECT_CLASS (gtk_inspector_css_node_tree_parent_class)->finalize (object); @@ -341,6 +356,20 @@ static void gtk_inspector_css_node_tree_set_node (GtkInspectorCssNodeTree *cnt, GtkCssNode *node) { + GtkInspectorCssNodeTreePrivate *priv = cnt->priv; + GtkCssStyle *style; + gint i; + + if (priv->node == node) + return; + + if (node) + g_object_ref (node); + + gtk_inspector_css_node_tree_unset_node (cnt); + + priv->node = node; + style = gtk_css_node_get_style (node); for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++) @@ -383,8 +412,6 @@ populate_properties (GtkInspectorCssNodeTree *cnt) GtkTreeSelection *selection; GtkTreeIter titer; GtkCssNode *node; - GtkCssStyle *style; - gint i; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->node_tree)); if (!gtk_tree_selection_get_selected (selection, NULL, &titer))