Commit 125c9f9a authored by Christian Hergert's avatar Christian Hergert

tree: add dzl_tree_node_insert()

This allows insertion of a node at a given offset. This is
useful in situations where the data is already sorted, like that
coming from a GListModel.
parent 94461f12
......@@ -132,6 +132,27 @@ _dzl_tree_node_set_tree (DzlTreeNode *node,
dzl_set_weak_pointer (&node->tree, tree);
}
/**
* dzl_tree_node_insert:
* @self: a #DzlTreeNode
* @child: a #DzlTreeNode
* @position: the position for the child
*
* Inserts @child as a child of @self at @position.
*
* Since: 3.28
*/
void
dzl_tree_node_insert (DzlTreeNode *self,
DzlTreeNode *child,
guint position)
{
g_return_if_fail (DZL_IS_TREE_NODE (self));
g_return_if_fail (DZL_IS_TREE_NODE (child));
_dzl_tree_insert (self->tree, self, child, position);
}
/**
* dzl_tree_node_insert_sorted:
* @node: A #DzlTreeNode.
......
......@@ -30,6 +30,10 @@ DzlTreeNode *dzl_tree_node_new (void);
DZL_AVAILABLE_IN_ALL
void dzl_tree_node_append (DzlTreeNode *node,
DzlTreeNode *child);
DZL_AVAILABLE_IN_3_28
void dzl_tree_node_insert (DzlTreeNode *self,
DzlTreeNode *child,
guint position);
DZL_AVAILABLE_IN_ALL
void dzl_tree_node_insert_sorted (DzlTreeNode *node,
DzlTreeNode *child,
......
......@@ -31,6 +31,10 @@ void _dzl_tree_build_children (DzlTree
DzlTreeNode *node);
void _dzl_tree_build_node (DzlTree *self,
DzlTreeNode *node);
void _dzl_tree_insert (DzlTree *self,
DzlTreeNode *node,
DzlTreeNode *child,
guint position);
void _dzl_tree_append (DzlTree *self,
DzlTreeNode *node,
DzlTreeNode *child);
......
......@@ -487,6 +487,46 @@ text_func (GtkCellLayout *cell_layout,
}
}
void
_dzl_tree_insert (DzlTree *self,
DzlTreeNode *parent,
DzlTreeNode *child,
guint position)
{
DzlTreePrivate *priv = dzl_tree_get_instance_private (self);
GtkTreeIter parent_iter;
GtkTreeIter iter;
g_return_if_fail (DZL_IS_TREE (self));
g_return_if_fail (DZL_IS_TREE_NODE (parent));
g_return_if_fail (DZL_IS_TREE_NODE (child));
g_object_ref_sink (child);
if (dzl_tree_node_get_iter (parent, &parent_iter))
{
_dzl_tree_node_set_tree (child, self);
_dzl_tree_node_set_parent (child, parent);
gtk_tree_store_insert_with_values (priv->store, &iter, &parent_iter, position,
0, child,
-1);
_dzl_tree_build_node (self, child);
if (dzl_tree_node_get_children_possible (child))
_dzl_tree_node_add_dummy_child (child);
if (priv->always_expand)
{
_dzl_tree_build_children (self, child);
dzl_tree_node_expand (child, TRUE);
}
}
g_object_unref (child);
}
static void
dzl_tree_add (DzlTree *self,
DzlTreeNode *node,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment