[gnome-builder] Support for GEmblem in IdeTreeNode
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] Support for GEmblem in IdeTreeNode
- Date: Tue, 27 Sep 2016 21:17:50 +0000 (UTC)
commit 077fb446fff3c34f54f02fa7630eb0caad357c3a
Author: Johan Svensson <johan svensson692 gmail com>
Date: Wed Sep 14 21:45:54 2016 +0200
Support for GEmblem in IdeTreeNode
Signed-off-by: Johan Svensson <johan svensson692 gmail com>
https://bugzilla.gnome.org/show_bug.cgi?id=768753
libide/tree/ide-tree-node.c | 136 +++++++++++++++++++++++++++++++++++++++++++
libide/tree/ide-tree-node.h | 10 +++
libide/tree/ide-tree.c | 11 +++-
3 files changed, 154 insertions(+), 3 deletions(-)
---
diff --git a/libide/tree/ide-tree-node.c b/libide/tree/ide-tree-node.c
index e96fc13..2dc846b 100644
--- a/libide/tree/ide-tree-node.c
+++ b/libide/tree/ide-tree-node.c
@@ -35,6 +35,8 @@ struct _IdeTreeNode
gchar *text;
IdeTree *tree;
GQuark icon_name;
+ GIcon *icon;
+ GList *emblems;
guint use_markup : 1;
guint needs_build : 1;
guint is_dummy : 1;
@@ -55,6 +57,7 @@ enum {
PROP_0,
PROP_CHILDREN_POSSIBLE,
PROP_ICON_NAME,
+ PROP_ICON,
PROP_ITEM,
PROP_PARENT,
PROP_TEXT,
@@ -267,6 +270,42 @@ ide_tree_node_get_parent (IdeTreeNode *node)
}
/**
+ * ide_tree_node_get_gicon:
+ *
+ * Fetch the GIcon, re-render if necessary
+ */
+GIcon *
+ide_tree_node_get_gicon (IdeTreeNode *node)
+{
+ const gchar *icon_name;
+ GIcon *icon;
+ GList *element;
+
+ g_return_val_if_fail (IDE_IS_TREE_NODE (node), NULL);
+
+ icon_name = node ? ide_tree_node_get_icon_name (node) : NULL;
+ if (!(node->icon) && icon_name)
+ {
+ icon = g_themed_icon_new (icon_name);
+ node->icon = g_emblemed_icon_new (icon, NULL);
+ element = node->emblems;
+ while (element)
+ {
+ GIcon *emblem_icon = g_themed_icon_new (element->data);
+ GEmblem *emblem = g_emblem_new (emblem_icon);
+ g_emblemed_icon_add_emblem (node->icon, emblem);
+ g_object_unref (&emblem);
+ g_object_unref (&emblem_icon);
+ element = element->next;
+ }
+ g_object_notify_by_pspec (G_OBJECT (node), properties [PROP_ICON]);
+ g_clear_object (&icon);
+ }
+
+ return node->icon;
+}
+
+/**
* ide_tree_node_get_icon_name:
*
* Fetches the icon-name of the icon to display, or NULL for no icon.
@@ -301,10 +340,90 @@ ide_tree_node_set_icon_name (IdeTreeNode *node,
if (value != node->icon_name)
{
node->icon_name = value;
+ g_clear_object (&node->icon);
g_object_notify_by_pspec (G_OBJECT (node), properties [PROP_ICON_NAME]);
}
}
+void
+ide_tree_node_add_emblem (IdeTreeNode *node,
+ const gchar *emblem_name)
+{
+ GList *elem;
+ GList *elem_tmp;
+ g_return_if_fail (IDE_IS_TREE_NODE (node));
+
+ elem_tmp = node->emblems;
+ elem = elem_tmp;
+ while (elem_tmp != NULL)
+ {
+ if (!g_strcmp0 (emblem_name, elem_tmp->data))
+ return;
+ elem = elem_tmp;
+ elem_tmp = elem_tmp->next;
+ }
+ gchar *data = g_strdup (emblem_name);
+ if(!data)
+ return;
+ elem = g_list_append (elem, g_strdup(emblem_name));
+ if (!node->emblems)
+ node->emblems = elem;
+
+ g_clear_object (&node->icon);
+
+}
+
+void
+ide_tree_node_remove_emblem (IdeTreeNode *node,
+ const gchar *emblem_name)
+{
+ GList *elem;
+ g_return_if_fail (IDE_IS_TREE_NODE (node));
+
+ elem = g_list_find_custom (node->emblems, emblem_name, g_strcmp0);
+ if (elem)
+ {
+ g_free (elem->data);
+ node->emblems = g_list_remove (node->emblems, elem->data);
+ g_clear_object (&node->icon);
+ }
+}
+
+void
+ide_tree_node_clear_emblems (IdeTreeNode *node)
+{
+ g_return_if_fail (IDE_IS_TREE_NODE (node));
+
+ g_list_free_full (node->emblems, g_free);
+ node->emblems = NULL;
+ g_clear_object (&node->icon);
+}
+
+gboolean
+ide_tree_node_has_emblem (IdeTreeNode *node,
+ const gchar *emblem_name)
+{
+ g_return_val_if_fail (IDE_IS_TREE_NODE (node), FALSE);
+
+ return g_list_find_custom (node->emblems, emblem_name, g_strcmp0) != NULL;
+}
+
+void
+ide_tree_node_set_emblems (IdeTreeNode *node,
+ GList *emblems)
+{
+ g_return_if_fail (IDE_IS_TREE_NODE (node));
+ g_return_if_fail (emblems);
+
+ if (emblems != node->emblems)
+ {
+ if (node->emblems)
+ g_list_free_full (node->emblems, g_free);
+ node->emblems = g_list_copy_deep (emblems, (GCopyFunc) g_strdup, NULL);
+ g_clear_object (&node->icon);
+ }
+}
+
/**
* ide_tree_node_set_item:
* @node: (in): A #IdeTreeNode.
@@ -556,6 +675,10 @@ ide_tree_node_get_property (GObject *object,
g_value_set_string (value, g_quark_to_string (node->icon_name));
break;
+ case PROP_ICON:
+ g_value_set_object (value, node->icon);
+ break;
+
case PROP_ITEM:
g_value_set_object (value, node->item);
break;
@@ -653,6 +776,8 @@ ide_tree_node_class_init (IdeTreeNodeClass *klass)
FALSE,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+
/**
* IdeTreeNode:icon-name:
*
@@ -664,6 +789,17 @@ ide_tree_node_class_init (IdeTreeNodeClass *klass)
"The icon name to display.",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ /**
+ * IdeTreeNode:icon:
+ *
+ * The cached GIcon to display.
+ */
+ properties[PROP_ICON] =
+ g_param_spec_object ("icon",
+ "Icon",
+ "The GIcon object",
+ G_TYPE_ICON,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* IdeTreeNode:item:
diff --git a/libide/tree/ide-tree-node.h b/libide/tree/ide-tree-node.h
index ebafaee..3015404 100644
--- a/libide/tree/ide-tree-node.h
+++ b/libide/tree/ide-tree-node.h
@@ -65,6 +65,16 @@ void ide_tree_node_set_children_possible (IdeTreeNode *sel
gboolean ide_tree_node_get_use_markup (IdeTreeNode *self);
void ide_tree_node_set_use_markup (IdeTreeNode *self,
gboolean use_markup);
+GIcon *ide_tree_node_get_gicon (IdeTreeNode *self);
+void ide_tree_node_add_emblem (IdeTreeNode *node,
+ const gchar *emblem_name);
+void ide_tree_node_remove_emblem (IdeTreeNode *node,
+ const gchar *emblem_name);
+void ide_tree_node_clear_emblems (IdeTreeNode *node);
+gboolean ide_tree_node_has_emblem (IdeTreeNode *node,
+ const gchar *emblem_name);
+void ide_tree_node_set_emblems (IdeTreeNode *node,
+ GList *emblems);
gboolean ide_tree_node_get_use_dim_label (IdeTreeNode *self);
void ide_tree_node_set_use_dim_label (IdeTreeNode *self,
gboolean use_dim_label);
diff --git a/libide/tree/ide-tree.c b/libide/tree/ide-tree.c
index f332ec3..63925fe 100644
--- a/libide/tree/ide-tree.c
+++ b/libide/tree/ide-tree.c
@@ -467,8 +467,9 @@ pixbuf_func (GtkCellLayout *cell_layout,
GtkTreeIter *iter,
gpointer data)
{
- const gchar *icon_name;
IdeTreeNode *node;
+ GIcon *icon;
+ GIcon *old_icon;
g_assert (GTK_IS_CELL_LAYOUT (cell_layout));
g_assert (GTK_IS_CELL_RENDERER_PIXBUF (cell));
@@ -476,8 +477,12 @@ pixbuf_func (GtkCellLayout *cell_layout,
g_assert (iter != NULL);
gtk_tree_model_get (tree_model, iter, 0, &node, -1);
- icon_name = node ? ide_tree_node_get_icon_name (node) : NULL;
- g_object_set (cell, "icon-name", icon_name, NULL);
+ icon = ide_tree_node_get_gicon (node);
+ g_object_get (cell, "gicon", &old_icon, NULL);
+ if (icon != old_icon)
+ g_object_set (cell, "gicon", icon, NULL);
+
+ g_clear_object (&old_icon);
g_clear_object (&node);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]