[gnome-builder] tree: add gb_tree_find_item()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tree: add gb_tree_find_item()
- Date: Sat, 11 Apr 2015 21:12:52 +0000 (UTC)
commit 18da25edfed5c7db1f8d9719e1a7f5fdf0cd1fae
Author: Christian Hergert <christian hergert me>
Date: Sat Apr 11 14:12:04 2015 -0700
tree: add gb_tree_find_item()
This is handy if you want to find an item between rebuilds of the tree.
src/tree/gb-tree.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
src/tree/gb-tree.h | 2 ++
2 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/src/tree/gb-tree.c b/src/tree/gb-tree.c
index 85da6ac..c59eda1 100644
--- a/src/tree/gb-tree.c
+++ b/src/tree/gb-tree.c
@@ -1016,6 +1016,52 @@ gb_tree_scroll_to_node (GbTree *tree,
gtk_tree_path_free (path);
}
+static gboolean
+gb_tree_find_item_foreach_cb (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GbTreeNode *node = NULL;
+ struct {
+ GObject *item;
+ GbTreeNode *result;
+ } *lookup = data;
+
+ gtk_tree_model_get (model, iter, 0, &node, -1);
+
+ if (node && (lookup->item == gb_tree_node_get_item (node)))
+ {
+ lookup->result = node;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+GbTreeNode *
+gb_tree_find_item (GbTree *self,
+ GObject *item)
+{
+ GbTreePrivate *priv = gb_tree_get_instance_private (self);
+ struct {
+ GObject *item;
+ GbTreeNode *result;
+ } lookup;
+
+ g_return_val_if_fail (GB_IS_TREE (self), NULL);
+ g_return_val_if_fail (!item || G_IS_OBJECT (item), NULL);
+
+ lookup.item = item;
+ lookup.result = NULL;
+
+ gtk_tree_model_foreach (GTK_TREE_MODEL (priv->store),
+ gb_tree_find_item_foreach_cb,
+ &lookup);
+
+ return lookup.result;
+}
+
/**
* gb_tree_finalize:
* @object: (in): A #GbTree.
diff --git a/src/tree/gb-tree.h b/src/tree/gb-tree.h
index 71a76fb..bdb56b1 100644
--- a/src/tree/gb-tree.h
+++ b/src/tree/gb-tree.h
@@ -78,6 +78,8 @@ GbTree *gb_tree_node_get_tree (GbTreeNode *node);
void gb_tree_set_show_icons (GbTree *tree,
gboolean show_icons);
gboolean gb_tree_get_show_icons (GbTree *tree);
+GbTreeNode *gb_tree_find_item (GbTree *tree,
+ GObject *item);
void gb_tree_scroll_to_node (GbTree *tree,
GbTreeNode *node);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]