[gnome-builder] tree: improve gb_tree_get_path()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tree: improve gb_tree_get_path()
- Date: Sat, 20 Jun 2015 09:45:33 +0000 (UTC)
commit 787562bc15c62dedec5219d5e43d745d877db3fe
Author: Christian Hergert <christian hergert me>
Date: Mon Jun 15 01:54:30 2015 -0700
tree: improve gb_tree_get_path()
src/tree/gb-tree-node.c | 8 +++---
src/tree/gb-tree.c | 56 ++++++++++++++++++++++++++--------------------
2 files changed, 36 insertions(+), 28 deletions(-)
---
diff --git a/src/tree/gb-tree-node.c b/src/tree/gb-tree-node.c
index 90e0813..0f08aaa 100644
--- a/src/tree/gb-tree-node.c
+++ b/src/tree/gb-tree-node.c
@@ -215,7 +215,9 @@ gb_tree_node_get_path (GbTreeNode *node)
return NULL;
do
- list = g_list_prepend (list, node);
+ {
+ list = g_list_prepend (list, node);
+ }
while ((node = node->parent));
toplevel = list->data;
@@ -223,7 +225,6 @@ gb_tree_node_get_path (GbTreeNode *node)
g_assert (toplevel);
g_assert (toplevel->tree);
- list = g_list_remove_link (list, list);
path = _gb_tree_get_path (toplevel->tree, list);
g_list_free (list);
@@ -492,10 +493,9 @@ gb_tree_node_get_expanded (GbTreeNode *self)
g_return_val_if_fail (GB_IS_TREE_NODE (self), FALSE);
- if ((self->tree != NULL) && (self->parent != NULL) && (self->parent->parent != NULL))
+ if ((self->tree != NULL) && (self->parent != NULL))
{
path = gb_tree_node_get_path (self);
- g_assert (path != NULL);
ret = gtk_tree_view_row_expanded (GTK_TREE_VIEW (self->tree), path);
gtk_tree_path_free (path);
}
diff --git a/src/tree/gb-tree.c b/src/tree/gb-tree.c
index 1d8a3f6..cb25ea8 100644
--- a/src/tree/gb-tree.c
+++ b/src/tree/gb-tree.c
@@ -1171,46 +1171,54 @@ gb_tree_scroll_to_node (GbTree *self,
gtk_tree_path_free (path);
}
-/**
- * gb_tree_get_path:
- * @tree: (in): A #GbTree.
- * @list: (in) (element-type GbTreeNode): A list of #GbTreeNode.
- *
- * Retrieves the GtkTreePath for a list of GbTreeNode.
- *
- * Returns: (transfer full): A #GtkTreePath.
- */
GtkTreePath *
_gb_tree_get_path (GbTree *self,
GList *list)
{
+ GbTreePrivate *priv = gb_tree_get_instance_private (self);
GtkTreeModel *model;
GtkTreeIter iter;
- GtkTreeIter old_iter;
- GtkTreeIter *parent = NULL;
- GbTreePrivate *priv = gb_tree_get_instance_private (self);
+ GtkTreeIter *iter_ptr;
+ GList *list_iter;
- g_return_val_if_fail (GB_IS_TREE (self), NULL);
+ g_assert (GB_IS_TREE (self));
model = GTK_TREE_MODEL (priv->store);
- if (!list || !gtk_tree_model_get_iter_first (model, &iter))
+ if ((list == NULL) || (list->data != priv->root) || (list->next == NULL))
return NULL;
- if (list->data == priv->root)
- list = list->next;
+ iter_ptr = NULL;
- while (gb_tree_get_iter_for_node (self, parent, &iter, list->data))
+ for (list_iter = list->next; list_iter; list_iter = list_iter->next)
{
- old_iter = iter;
- parent = &old_iter;
- if (list->next)
- list = list->next;
- else
- return gtk_tree_model_get_path (model, &iter);
+ GtkTreeIter children;
+
+ if (gtk_tree_model_iter_children (model, &children, iter_ptr))
+ {
+ gboolean found = FALSE;
+
+ do
+ {
+ g_autoptr(GbTreeNode) item = NULL;
+
+ gtk_tree_model_get (model, &children, 0, &item, -1);
+ found = (item == (GbTreeNode *)list_iter->data);
+ }
+ while (!found && gtk_tree_model_iter_next (model, &children));
+
+ if (found)
+ {
+ iter = children;
+ iter_ptr = &iter;
+ continue;
+ }
+ }
+
+ return NULL;
}
- return NULL;
+ return gtk_tree_model_get_path (model, &iter);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]