[libdazzle] tree: add support for expanded icon-names
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] tree: add support for expanded icon-names
- Date: Sat, 22 Jul 2017 06:22:31 +0000 (UTC)
commit 06131c2f3212691cb2c2f9d33225dc2fe7eebe24
Author: Christian Hergert <chergert redhat com>
Date: Fri Jul 21 23:21:55 2017 -0700
tree: add support for expanded icon-names
src/tree/dzl-tree-node.c | 25 ++++++++++++++++++++++++-
src/tree/dzl-tree-private.h | 1 +
src/tree/dzl-tree.c | 22 +++++++++++++++++++++-
3 files changed, 46 insertions(+), 2 deletions(-)
---
diff --git a/src/tree/dzl-tree-node.c b/src/tree/dzl-tree-node.c
index c3225af..bef6a21 100644
--- a/src/tree/dzl-tree-node.c
+++ b/src/tree/dzl-tree-node.c
@@ -33,6 +33,7 @@ struct _DzlTreeNode
gchar *text;
DzlTree *tree;
GQuark icon_name;
+ GQuark expanded_icon_name;
GIcon *gicon;
GList *emblems;
guint use_markup : 1;
@@ -53,6 +54,7 @@ G_DEFINE_TYPE (DzlTreeNode, dzl_tree_node, G_TYPE_INITIALLY_UNOWNED)
enum {
PROP_0,
PROP_CHILDREN_POSSIBLE,
+ PROP_EXPANDED_ICON_NAME,
PROP_ICON_NAME,
PROP_GICON,
PROP_ITEM,
@@ -710,6 +712,10 @@ dzl_tree_node_get_property (GObject *object,
g_value_set_boolean (value, dzl_tree_node_get_children_possible (node));
break;
+ case PROP_EXPANDED_ICON_NAME:
+ g_value_set_string (value, _dzl_tree_node_get_expanded_icon (node));
+ break;
+
case PROP_ICON_NAME:
g_value_set_string (value, g_quark_to_string (node->icon_name));
break;
@@ -761,6 +767,10 @@ dzl_tree_node_set_property (GObject *object,
dzl_tree_node_set_children_possible (node, g_value_get_boolean (value));
break;
+ case PROP_EXPANDED_ICON_NAME:
+ node->expanded_icon_name = g_quark_from_string (g_value_get_string (value));
+ break;
+
case PROP_ICON_NAME:
dzl_tree_node_set_icon_name (node, g_value_get_string (value));
break;
@@ -815,7 +825,12 @@ dzl_tree_node_class_init (DzlTreeNodeClass *klass)
FALSE,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
+ properties [PROP_EXPANDED_ICON_NAME] =
+ g_param_spec_string ("expanded-icon-name",
+ "Expanded Icon Name",
+ "The icon-name to use when the row is expanded",
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* DzlTreeNode:icon-name:
@@ -1157,3 +1172,11 @@ dzl_tree_node_is_root (DzlTreeNode *node)
return node->parent == NULL;
}
+
+const gchar *
+_dzl_tree_node_get_expanded_icon (DzlTreeNode *node)
+{
+ g_return_val_if_fail (DZL_IS_TREE_NODE (node), NULL);
+
+ return g_quark_to_string (node->expanded_icon_name);
+}
diff --git a/src/tree/dzl-tree-private.h b/src/tree/dzl-tree-private.h
index 99122f3..22ce170 100644
--- a/src/tree/dzl-tree-private.h
+++ b/src/tree/dzl-tree-private.h
@@ -51,6 +51,7 @@ void _dzl_tree_node_set_tree (DzlTreeNode *node,
DzlTree *tree);
void _dzl_tree_node_set_parent (DzlTreeNode *node,
DzlTreeNode *parent);
+const gchar *_dzl_tree_node_get_expanded_icon (DzlTreeNode *node);
gboolean _dzl_tree_node_get_needs_build (DzlTreeNode *node);
void _dzl_tree_node_set_needs_build (DzlTreeNode *node,
gboolean needs_build);
diff --git a/src/tree/dzl-tree.c b/src/tree/dzl-tree.c
index cc287b0..d16c25b 100644
--- a/src/tree/dzl-tree.c
+++ b/src/tree/dzl-tree.c
@@ -364,14 +364,34 @@ pixbuf_func (GtkCellLayout *cell_layout,
{
g_autoptr(DzlTreeNode) node = NULL;
g_autoptr(GIcon) old_icon = NULL;
+ DzlTree *self = data;
+ GtkTreePath *tree_path;
+ gboolean expanded;
GIcon *icon;
g_assert (GTK_IS_CELL_LAYOUT (cell_layout));
g_assert (GTK_IS_CELL_RENDERER_PIXBUF (cell));
g_assert (GTK_IS_TREE_MODEL (tree_model));
+ g_assert (DZL_IS_TREE (self));
g_assert (iter != NULL);
gtk_tree_model_get (tree_model, iter, 0, &node, -1);
+
+ tree_path = gtk_tree_model_get_path (tree_model, iter);
+ expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (self), tree_path);
+ gtk_tree_path_free (tree_path);
+
+ if (expanded)
+ {
+ const gchar *icon_name = _dzl_tree_node_get_expanded_icon (node);
+
+ if (icon_name != NULL)
+ {
+ g_object_set (cell, "icon-name", icon_name, NULL);
+ return;
+ }
+ }
+
icon = dzl_tree_node_get_gicon (node);
g_object_get (cell, "gicon", &old_icon, NULL);
if (icon != old_icon)
@@ -972,7 +992,7 @@ dzl_tree_init (DzlTree *self)
priv->cell_pixbuf = cell;
g_object_bind_property (self, "show-icons", cell, "visible", 0);
gtk_cell_layout_pack_start (column, cell, FALSE);
- gtk_cell_layout_set_cell_data_func (column, cell, pixbuf_func, NULL, NULL);
+ gtk_cell_layout_set_cell_data_func (column, cell, pixbuf_func, self, NULL);
cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
"ellipsize", PANGO_ELLIPSIZE_NONE,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]