[gnome-builder] tree: cleanup and GObject Introspection fixes
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tree: cleanup and GObject Introspection fixes
- Date: Mon, 18 Jan 2016 05:20:24 +0000 (UTC)
commit 3ce98bf9f019e150f06252a11e175483652355e2
Author: Christian Hergert <chergert redhat com>
Date: Sun Jan 17 21:15:02 2016 -0800
tree: cleanup and GObject Introspection fixes
This makes things a bit easier to use from PyGObject and presumably other
language bindings.
libide/ide-tree-builder.c | 24 ++++++------
libide/ide-tree-node.c | 30 ++++++++++------
libide/ide-tree-node.h | 86 ++++++++++++++++++++++----------------------
libide/ide-tree-private.h | 1 +
libide/ide-tree.c | 53 +++++++++++++++++-----------
5 files changed, 107 insertions(+), 87 deletions(-)
---
diff --git a/libide/ide-tree-builder.c b/libide/ide-tree-builder.c
index 2e680e1..af8176e 100644
--- a/libide/ide-tree-builder.c
+++ b/libide/ide-tree-builder.c
@@ -52,7 +52,7 @@ static guint signals [LAST_SIGNAL];
gboolean
_ide_tree_builder_node_activated (IdeTreeBuilder *builder,
- IdeTreeNode *node)
+ IdeTreeNode *node)
{
gboolean ret = FALSE;
@@ -66,8 +66,8 @@ _ide_tree_builder_node_activated (IdeTreeBuilder *builder,
void
_ide_tree_builder_node_popup (IdeTreeBuilder *builder,
- IdeTreeNode *node,
- GMenu *menu)
+ IdeTreeNode *node,
+ GMenu *menu)
{
g_return_if_fail (IDE_IS_TREE_BUILDER (builder));
g_return_if_fail (IDE_IS_TREE_NODE (node));
@@ -78,7 +78,7 @@ _ide_tree_builder_node_popup (IdeTreeBuilder *builder,
void
_ide_tree_builder_node_selected (IdeTreeBuilder *builder,
- IdeTreeNode *node)
+ IdeTreeNode *node)
{
g_return_if_fail (IDE_IS_TREE_BUILDER (builder));
g_return_if_fail (IDE_IS_TREE_NODE (node));
@@ -88,7 +88,7 @@ _ide_tree_builder_node_selected (IdeTreeBuilder *builder,
void
_ide_tree_builder_node_unselected (IdeTreeBuilder *builder,
- IdeTreeNode *node)
+ IdeTreeNode *node)
{
g_return_if_fail (IDE_IS_TREE_BUILDER (builder));
g_return_if_fail (IDE_IS_TREE_NODE (node));
@@ -98,7 +98,7 @@ _ide_tree_builder_node_unselected (IdeTreeBuilder *builder,
void
_ide_tree_builder_build_node (IdeTreeBuilder *builder,
- IdeTreeNode *node)
+ IdeTreeNode *node)
{
g_return_if_fail (IDE_IS_TREE_BUILDER (builder));
g_return_if_fail (IDE_IS_TREE_NODE (node));
@@ -108,7 +108,7 @@ _ide_tree_builder_build_node (IdeTreeBuilder *builder,
void
_ide_tree_builder_added (IdeTreeBuilder *builder,
- IdeTree *tree)
+ IdeTree *tree)
{
g_return_if_fail (IDE_IS_TREE_BUILDER (builder));
g_return_if_fail (IDE_IS_TREE (tree));
@@ -118,7 +118,7 @@ _ide_tree_builder_added (IdeTreeBuilder *builder,
void
_ide_tree_builder_removed (IdeTreeBuilder *builder,
- IdeTree *tree)
+ IdeTree *tree)
{
g_return_if_fail (IDE_IS_TREE_BUILDER (builder));
g_return_if_fail (IDE_IS_TREE (tree));
@@ -128,7 +128,7 @@ _ide_tree_builder_removed (IdeTreeBuilder *builder,
void
_ide_tree_builder_set_tree (IdeTreeBuilder *builder,
- IdeTree *tree)
+ IdeTree *tree)
{
IdeTreeBuilderPrivate *priv = ide_tree_builder_get_instance_private (builder);
@@ -189,9 +189,9 @@ ide_tree_builder_finalize (GObject *object)
static void
ide_tree_builder_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
IdeTreeBuilder *builder = IDE_TREE_BUILDER (object);
IdeTreeBuilderPrivate *priv = ide_tree_builder_get_instance_private (builder);
diff --git a/libide/ide-tree-node.c b/libide/ide-tree-node.c
index 71d5f5e..f1d63d8 100644
--- a/libide/ide-tree-node.c
+++ b/libide/ide-tree-node.c
@@ -281,20 +281,28 @@ ide_tree_node_get_icon_name (IdeTreeNode *node)
/**
* ide_tree_node_set_icon_name:
- * @node: (in): A #IdeTreeNode.
- * @icon_name: (in): The icon name.
+ * @node: A #IdeTreeNode.
+ * @icon_name: (nullable): The icon name.
*
* Sets the icon name of the node. This is displayed in the pixbuf
* cell of the IdeTree.
*/
void
-ide_tree_node_set_icon_name (IdeTreeNode *node,
- const gchar *icon_name)
+ide_tree_node_set_icon_name (IdeTreeNode *node,
+ const gchar *icon_name)
{
+ GQuark value = 0;
+
g_return_if_fail (IDE_IS_TREE_NODE (node));
- node->icon_name = g_quark_from_string (icon_name);
- g_object_notify_by_pspec (G_OBJECT (node), properties [PROP_ICON_NAME]);
+ if (icon_name != NULL)
+ value = g_quark_from_string (icon_name);
+
+ if (value != node->icon_name)
+ {
+ node->icon_name = value;
+ g_object_notify_by_pspec (G_OBJECT (node), properties [PROP_ICON_NAME]);
+ }
}
/**
@@ -350,15 +358,15 @@ ide_tree_node_get_text (IdeTreeNode *node)
/**
* ide_tree_node_set_text:
- * @node: (in): A #IdeTreeNode.
- * @text: (in): The node text.
+ * @node: A #IdeTreeNode.
+ * @text: (nullable): The node text.
*
* Sets the text of the node. This is displayed in the text
* cell of the IdeTree.
*/
void
-ide_tree_node_set_text (IdeTreeNode *node,
- const gchar *text)
+ide_tree_node_set_text (IdeTreeNode *node,
+ const gchar *text)
{
g_return_if_fail (IDE_IS_TREE_NODE (node));
@@ -936,7 +944,7 @@ ide_tree_node_set_children_possible (IdeTreeNode *self,
{
self->children_possible = children_possible;
- if (self->needs_build)
+ if (self->tree && self->needs_build)
{
if (self->children_possible)
_ide_tree_node_add_dummy_child (self);
diff --git a/libide/ide-tree-node.h b/libide/ide-tree-node.h
index 0ebd3dc..7fd255b 100644
--- a/libide/ide-tree-node.h
+++ b/libide/ide-tree-node.h
@@ -24,49 +24,49 @@
G_BEGIN_DECLS
IdeTreeNode *ide_tree_node_new (void);
-void ide_tree_node_append (IdeTreeNode *node,
- IdeTreeNode *child);
-void ide_tree_node_insert_sorted (IdeTreeNode *node,
- IdeTreeNode *child,
- IdeTreeNodeCompareFunc compare_func,
- gpointer user_data);
-const gchar *ide_tree_node_get_icon_name (IdeTreeNode *node);
-GObject *ide_tree_node_get_item (IdeTreeNode *node);
-IdeTreeNode *ide_tree_node_get_parent (IdeTreeNode *node);
-GtkTreePath *ide_tree_node_get_path (IdeTreeNode *node);
-gboolean ide_tree_node_get_iter (IdeTreeNode *node,
- GtkTreeIter *iter);
-void ide_tree_node_prepend (IdeTreeNode *node,
- IdeTreeNode *child);
-void ide_tree_node_remove (IdeTreeNode *node,
- IdeTreeNode *child);
-void ide_tree_node_set_icon_name (IdeTreeNode *node,
- const gchar *icon_name);
-void ide_tree_node_set_item (IdeTreeNode *node,
- GObject *item);
-gboolean ide_tree_node_expand (IdeTreeNode *node,
- gboolean expand_ancestors);
-void ide_tree_node_collapse (IdeTreeNode *node);
-void ide_tree_node_select (IdeTreeNode *node);
-void ide_tree_node_get_area (IdeTreeNode *node,
- GdkRectangle *area);
-void ide_tree_node_invalidate (IdeTreeNode *node);
-gboolean ide_tree_node_get_expanded (IdeTreeNode *node);
-void ide_tree_node_show_popover (IdeTreeNode *node,
- GtkPopover *popover);
-const gchar *ide_tree_node_get_text (IdeTreeNode *node);
-void ide_tree_node_set_text (IdeTreeNode *node,
- const gchar *text);
-IdeTree *ide_tree_node_get_tree (IdeTreeNode *node);
-gboolean ide_tree_node_get_children_possible (IdeTreeNode *self);
-void ide_tree_node_set_children_possible (IdeTreeNode *self,
- gboolean children_possible);
-gboolean ide_tree_node_get_use_markup (IdeTreeNode *self);
-void ide_tree_node_set_use_markup (IdeTreeNode *self,
- gboolean use_markup);
-gboolean ide_tree_node_get_use_dim_label (IdeTreeNode *self);
-void ide_tree_node_set_use_dim_label (IdeTreeNode *self,
- gboolean use_dim_label);
+void ide_tree_node_append (IdeTreeNode *node,
+ IdeTreeNode *child);
+void ide_tree_node_insert_sorted (IdeTreeNode *node,
+ IdeTreeNode *child,
+ IdeTreeNodeCompareFunc compare_func,
+ gpointer user_data);
+const gchar *ide_tree_node_get_icon_name (IdeTreeNode *node);
+GObject *ide_tree_node_get_item (IdeTreeNode *node);
+IdeTreeNode *ide_tree_node_get_parent (IdeTreeNode *node);
+GtkTreePath *ide_tree_node_get_path (IdeTreeNode *node);
+gboolean ide_tree_node_get_iter (IdeTreeNode *node,
+ GtkTreeIter *iter);
+void ide_tree_node_prepend (IdeTreeNode *node,
+ IdeTreeNode *child);
+void ide_tree_node_remove (IdeTreeNode *node,
+ IdeTreeNode *child);
+void ide_tree_node_set_icon_name (IdeTreeNode *node,
+ const gchar *icon_name);
+void ide_tree_node_set_item (IdeTreeNode *node,
+ GObject *item);
+gboolean ide_tree_node_expand (IdeTreeNode *node,
+ gboolean expand_ancestors);
+void ide_tree_node_collapse (IdeTreeNode *node);
+void ide_tree_node_select (IdeTreeNode *node);
+void ide_tree_node_get_area (IdeTreeNode *node,
+ GdkRectangle *area);
+void ide_tree_node_invalidate (IdeTreeNode *node);
+gboolean ide_tree_node_get_expanded (IdeTreeNode *node);
+void ide_tree_node_show_popover (IdeTreeNode *node,
+ GtkPopover *popover);
+const gchar *ide_tree_node_get_text (IdeTreeNode *node);
+void ide_tree_node_set_text (IdeTreeNode *node,
+ const gchar *text);
+IdeTree *ide_tree_node_get_tree (IdeTreeNode *node);
+gboolean ide_tree_node_get_children_possible (IdeTreeNode *self);
+void ide_tree_node_set_children_possible (IdeTreeNode *self,
+ gboolean children_possible);
+gboolean ide_tree_node_get_use_markup (IdeTreeNode *self);
+void ide_tree_node_set_use_markup (IdeTreeNode *self,
+ gboolean use_markup);
+gboolean ide_tree_node_get_use_dim_label (IdeTreeNode *self);
+void ide_tree_node_set_use_dim_label (IdeTreeNode *self,
+ gboolean use_dim_label);
G_END_DECLS
diff --git a/libide/ide-tree-private.h b/libide/ide-tree-private.h
index 08ccd3c..f7d1d6f 100644
--- a/libide/ide-tree-private.h
+++ b/libide/ide-tree-private.h
@@ -54,6 +54,7 @@ void _ide_tree_node_set_parent (IdeTreeNode *node,
gboolean _ide_tree_node_get_needs_build (IdeTreeNode *node);
void _ide_tree_node_set_needs_build (IdeTreeNode *node,
gboolean needs_build);
+void _ide_tree_node_add_dummy_child (IdeTreeNode *node);
void _ide_tree_node_remove_dummy_child (IdeTreeNode *node);
void _ide_tree_builder_set_tree (IdeTreeBuilder *builder,
diff --git a/libide/ide-tree.c b/libide/ide-tree.c
index eef4552..a2b631f 100644
--- a/libide/ide-tree.c
+++ b/libide/ide-tree.c
@@ -272,11 +272,14 @@ ide_tree_popup (IdeTree *self,
g_return_if_fail (IDE_IS_TREE (self));
g_return_if_fail (IDE_IS_TREE_NODE (node));
- for (gint i = 0; i < priv->builders->len; i++)
+ if (priv->context_menu != NULL)
{
- IdeTreeBuilder *builder = g_ptr_array_index (priv->builders, i);
+ for (gint i = 0; i < priv->builders->len; i++)
+ {
+ IdeTreeBuilder *builder = g_ptr_array_index (priv->builders, i);
- _ide_tree_builder_node_popup (builder, node, G_MENU (priv->context_menu));
+ _ide_tree_builder_node_popup (builder, node, G_MENU (priv->context_menu));
+ }
}
if (priv->context_menu != NULL)
@@ -507,9 +510,9 @@ text_func (GtkCellLayout *cell_layout,
static void
ide_tree_add (IdeTree *self,
- IdeTreeNode *node,
- IdeTreeNode *child,
- gboolean prepend)
+ IdeTreeNode *node,
+ IdeTreeNode *child,
+ gboolean prepend)
{
IdeTreePrivate *priv = ide_tree_get_instance_private (self);
GtkTreePath *path;
@@ -539,6 +542,9 @@ ide_tree_add (IdeTree *self,
0, child,
-1);
+ if (ide_tree_node_get_children_possible (child))
+ _ide_tree_node_add_dummy_child (child);
+
if (node == priv->root)
_ide_tree_build_node (self, child);
@@ -547,10 +553,10 @@ ide_tree_add (IdeTree *self,
void
_ide_tree_insert_sorted (IdeTree *self,
- IdeTreeNode *node,
- IdeTreeNode *child,
- IdeTreeNodeCompareFunc compare_func,
- gpointer user_data)
+ IdeTreeNode *node,
+ IdeTreeNode *child,
+ IdeTreeNodeCompareFunc compare_func,
+ gpointer user_data)
{
IdeTreePrivate *priv = ide_tree_get_instance_private (self);
GtkTreeModel *model;
@@ -1230,14 +1236,14 @@ _ide_tree_get_path (IdeTree *self,
/**
* ide_tree_add_builder:
- * @self: (in): A #IdeTree.
- * @builder: (in) (transfer full): A #IdeTreeBuilder to add.
+ * @self: A #IdeTree.
+ * @builder: A #IdeTreeBuilder to add.
*
* Removes a builder from the tree.
*/
void
ide_tree_add_builder (IdeTree *self,
- IdeTreeBuilder *builder)
+ IdeTreeBuilder *builder)
{
GtkTreeIter iter;
IdeTreePrivate *priv = ide_tree_get_instance_private (self);
@@ -1311,8 +1317,8 @@ ide_tree_get_root (IdeTree *self)
/**
* ide_tree_set_root:
- * @self: (in): A #IdeTree.
- * @node: (in): A #IdeTreeNode.
+ * @self: A #IdeTree.
+ * @node: A #IdeTreeNode.
*
* Sets the root node of the #IdeTree widget. This is used to build
* the items within the treeview. The item itself will not be added
@@ -1320,7 +1326,7 @@ ide_tree_get_root (IdeTree *self)
*/
void
ide_tree_set_root (IdeTree *self,
- IdeTreeNode *root)
+ IdeTreeNode *root)
{
IdeTreePrivate *priv = ide_tree_get_instance_private (self);
@@ -1488,13 +1494,20 @@ _ide_tree_invalidate (IdeTree *self,
model = GTK_TREE_MODEL (priv->store);
path = ide_tree_node_get_path (node);
- gtk_tree_model_get_iter (model, &iter, path);
- if (gtk_tree_model_iter_children (model, &child, &iter))
+ if (path != NULL)
{
- while (gtk_tree_store_remove (priv->store, &child))
+ gtk_tree_model_get_iter (model, &iter, path);
+
+ if (gtk_tree_model_iter_children (model, &child, &iter))
{
+ while (gtk_tree_store_remove (priv->store, &child))
+ {
+ /* Do nothing */
+ }
}
+
+ gtk_tree_path_free (path);
}
_ide_tree_node_set_needs_build (node, TRUE);
@@ -1503,8 +1516,6 @@ _ide_tree_invalidate (IdeTree *self,
if ((parent == NULL) || ide_tree_node_get_expanded (parent))
_ide_tree_build_node (self, node);
-
- gtk_tree_path_free (path);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]