[gnome-builder] tree: add support for markup text for nodes



commit b9643ca83e4b11136379c81567383ceb3e10ddda
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 16 18:48:39 2019 -0800

    tree: add support for markup text for nodes

 src/libide/tree/ide-tree-node.c | 52 +++++++++++++++++++++++++++++++++++++++++
 src/libide/tree/ide-tree-node.h |  5 ++++
 src/libide/tree/ide-tree.c      |  7 +++---
 3 files changed, 61 insertions(+), 3 deletions(-)
---
diff --git a/src/libide/tree/ide-tree-node.c b/src/libide/tree/ide-tree-node.c
index 2c48ba724..5d823605d 100644
--- a/src/libide/tree/ide-tree-node.c
+++ b/src/libide/tree/ide-tree-node.c
@@ -108,6 +108,9 @@ struct _IdeTreeNode
   /* If true, we remove all children on collapse */
   guint reset_on_collapse : 1;
 
+  /* If pango markup should be used */
+  guint use_markup : 1;
+
   /* If true, we use ide_clear_and_destroy_object() */
   guint destroy_item : 1;
 
@@ -132,6 +135,7 @@ enum {
   PROP_ITEM,
   PROP_RESET_ON_COLLAPSE,
   PROP_TAG,
+  PROP_USE_MARKUP,
   N_PROPS
 };
 
@@ -278,6 +282,10 @@ ide_tree_node_get_property (GObject    *object,
       g_value_set_string (value, ide_tree_node_get_tag (self));
       break;
 
+    case PROP_USE_MARKUP:
+      g_value_set_boolean (value, ide_tree_node_get_use_markup (self));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -341,6 +349,10 @@ ide_tree_node_set_property (GObject      *object,
       ide_tree_node_set_tag (self, g_value_get_string (value));
       break;
 
+    case PROP_USE_MARKUP:
+      ide_tree_node_set_use_markup (self, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -541,6 +553,21 @@ ide_tree_node_class_init (IdeTreeNodeClass *klass)
                          NULL,
                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
 
+  /**
+   * IdeTreeNode:use-markup:
+   *
+   * If #TRUE, the "use-markup" property denotes that #IdeTreeNode:display-name
+   * contains pango markup.
+   *
+   * Since: 3.32
+   */
+  properties [PROP_USE_MARKUP] =
+    g_param_spec_boolean ("use-markup",
+                          "Use Markup",
+                          "If pango markup should be used",
+                          FALSE,
+                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, N_PROPS, properties);
 }
 
@@ -1940,6 +1967,31 @@ ide_tree_node_set_has_error (IdeTreeNode *self,
   if (has_error != self->has_error)
     {
       self->has_error = has_error;
+      ide_tree_node_emit_changed (self);
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_HAS_ERROR]);
     }
 }
+
+gboolean
+ide_tree_node_get_use_markup (IdeTreeNode *self)
+{
+  g_return_val_if_fail (IDE_IS_TREE_NODE (self), FALSE);
+
+  return self->use_markup;
+}
+
+void
+ide_tree_node_set_use_markup (IdeTreeNode *self,
+                              gboolean     use_markup)
+{
+  g_return_if_fail (IDE_IS_TREE_NODE (self));
+
+  use_markup = !!use_markup;
+
+  if (use_markup != self->use_markup)
+    {
+      self->use_markup = use_markup;
+      ide_tree_node_emit_changed (self);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_USE_MARKUP]);
+    }
+}
diff --git a/src/libide/tree/ide-tree-node.h b/src/libide/tree/ide-tree-node.h
index 7c8ffcc8d..0aa301b11 100644
--- a/src/libide/tree/ide-tree-node.h
+++ b/src/libide/tree/ide-tree-node.h
@@ -193,5 +193,10 @@ void           ide_tree_node_set_foreground_rgba    (IdeTreeNode         *self,
                                                      const GdkRGBA       *foreground_rgba);
 IDE_AVAILABLE_IN_3_32
 gboolean       ide_tree_node_is_selected            (IdeTreeNode         *self);
+IDE_AVAILABLE_IN_3_32
+gboolean       ide_tree_node_get_use_markup         (IdeTreeNode         *self);
+IDE_AVAILABLE_IN_3_32
+void           ide_tree_node_set_use_markup         (IdeTreeNode         *self,
+                                                     gboolean             use_markup);
 
 G_END_DECLS
diff --git a/src/libide/tree/ide-tree.c b/src/libide/tree/ide-tree.c
index 6f97f63c3..0fb074a01 100644
--- a/src/libide/tree/ide-tree.c
+++ b/src/libide/tree/ide-tree.c
@@ -198,9 +198,10 @@ text_cell_func (GtkCellLayout   *layout,
   display_name = ide_tree_node_get_display_name (node);
 
 set_props:
-  g_object_set (cell,
-                "text", display_name,
-                NULL);
+  if (ide_tree_node_get_use_markup (node))
+    g_object_set (cell, "markup", display_name, NULL);
+  else
+    g_object_set (cell, "text", display_name, NULL);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]