[gnome-builder] tree: add support for rendering with error squiggles
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tree: add support for rendering with error squiggles
- Date: Wed, 16 Jan 2019 20:54:33 +0000 (UTC)
commit a4dc776f6f2be714f16cd4dbdea826f7d5165833
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 16 12:53:33 2019 -0800
tree: add support for rendering with error squiggles
src/libide/tree/ide-tree-node.c | 51 +++++++++++++++++++++++++++++++++++++++++
src/libide/tree/ide-tree-node.h | 5 ++++
src/libide/tree/ide-tree.c | 25 ++++++++++++++++++++
3 files changed, 81 insertions(+)
---
diff --git a/src/libide/tree/ide-tree-node.c b/src/libide/tree/ide-tree-node.c
index 6ef03280c..2c48ba724 100644
--- a/src/libide/tree/ide-tree-node.c
+++ b/src/libide/tree/ide-tree-node.c
@@ -96,6 +96,9 @@ struct _IdeTreeNode
/* If this is a synthesized empty node */
guint is_empty : 1;
+ /* If there are errors associated with the node's item */
+ guint has_error : 1;
+
/* If the node maybe has children */
guint children_possible : 1;
@@ -122,6 +125,7 @@ enum {
PROP_DISPLAY_NAME,
PROP_EXPANDED_ICON,
PROP_EXPANDED_ICON_NAME,
+ PROP_HAS_ERROR,
PROP_ICON,
PROP_ICON_NAME,
PROP_IS_HEADER,
@@ -250,6 +254,10 @@ ide_tree_node_get_property (GObject *object,
g_value_set_string (value, ide_tree_node_get_display_name (self));
break;
+ case PROP_HAS_ERROR:
+ g_value_set_boolean (value, ide_tree_node_get_has_error (self));
+ break;
+
case PROP_ICON:
g_value_set_object (value, ide_tree_node_get_icon (self));
break;
@@ -305,6 +313,10 @@ ide_tree_node_set_property (GObject *object,
ide_tree_node_set_expanded_icon_name (self, g_value_get_string (value));
break;
+ case PROP_HAS_ERROR:
+ ide_tree_node_set_has_error (self, g_value_get_boolean (value));
+ break;
+
case PROP_ICON:
ide_tree_node_set_icon (self, g_value_get_object (value));
break;
@@ -420,6 +432,22 @@ ide_tree_node_class_init (IdeTreeNodeClass *klass)
NULL,
(G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
+ /**
+ * IdeTreeNode:has-error:
+ *
+ * The "has-error" property is true if the node should be rendered with
+ * an error styling. This is useful when errors are known by the diagnostics
+ * manager for a given file or folder.
+ *
+ * Since: 3.32
+ */
+ properties [PROP_HAS_ERROR] =
+ g_param_spec_boolean ("has-error",
+ "Has Error",
+ "If the node has an error associated with it's item",
+ FALSE,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
/**
* IdeTreeNode:icon:
*
@@ -1892,3 +1920,26 @@ ide_tree_node_is_selected (IdeTreeNode *self)
return FALSE;
}
+
+gboolean
+ide_tree_node_get_has_error (IdeTreeNode *self)
+{
+ g_return_val_if_fail (IDE_IS_TREE_NODE (self), FALSE);
+
+ return self->has_error;
+}
+
+void
+ide_tree_node_set_has_error (IdeTreeNode *self,
+ gboolean has_error)
+{
+ g_return_if_fail (IDE_IS_TREE_NODE (self));
+
+ has_error = !!has_error;
+
+ if (has_error != self->has_error)
+ {
+ self->has_error = has_error;
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_HAS_ERROR]);
+ }
+}
diff --git a/src/libide/tree/ide-tree-node.h b/src/libide/tree/ide-tree-node.h
index 02ce2cb5a..7c8ffcc8d 100644
--- a/src/libide/tree/ide-tree-node.h
+++ b/src/libide/tree/ide-tree-node.h
@@ -69,6 +69,11 @@ typedef int (*IdeTreeNodeCompare) (IdeTreeNode *node,
IDE_AVAILABLE_IN_3_32
IdeTreeNode *ide_tree_node_new (void);
IDE_AVAILABLE_IN_3_32
+gboolean ide_tree_node_get_has_error (IdeTreeNode *self);
+IDE_AVAILABLE_IN_3_32
+void ide_tree_node_set_has_error (IdeTreeNode *self,
+ gboolean has_error);
+IDE_AVAILABLE_IN_3_32
const gchar *ide_tree_node_get_tag (IdeTreeNode *self);
IDE_AVAILABLE_IN_3_32
void ide_tree_node_set_tag (IdeTreeNode *self,
diff --git a/src/libide/tree/ide-tree.c b/src/libide/tree/ide-tree.c
index 24d557da1..6f97f63c3 100644
--- a/src/libide/tree/ide-tree.c
+++ b/src/libide/tree/ide-tree.c
@@ -161,6 +161,31 @@ text_cell_func (GtkCellLayout *layout,
}
}
+ if (ide_tree_node_get_has_error (node))
+ {
+ PangoAttrList *attrs = NULL;
+ PangoAttrList *copy = NULL;
+
+ g_object_get (cell,
+ "attributes", &attrs,
+ NULL);
+
+ if (attrs != NULL)
+ copy = pango_attr_list_copy (attrs);
+ else
+ copy = pango_attr_list_new ();
+
+ pango_attr_list_insert (copy, pango_attr_underline_new (PANGO_UNDERLINE_ERROR));
+ pango_attr_list_insert (copy, pango_attr_underline_color_new (65535, 0, 0));
+
+ g_object_set (cell,
+ "attributes", copy,
+ NULL);
+
+ g_clear_pointer (&attrs, pango_attr_list_unref);
+ g_clear_pointer (©, pango_attr_list_unref);
+ }
+
/* Only apply styling if the node isn't selected */
if (!ide_tree_node_is_selected (node))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]