[gnome-builder] tree: move model access functions to gb-tree.c



commit 7833ee6c891f5c3ca10994ce05afb23c836a984d
Author: Christian Hergert <christian hergert me>
Date:   Fri Jun 19 01:59:02 2015 -0700

    tree: move model access functions to gb-tree.c
    
    We need this so that we can apply filters going forward.

 src/tree/gb-tree-node.c    |   41 +++--------------------------------------
 src/tree/gb-tree-private.h |    5 +++++
 src/tree/gb-tree.c         |   40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 38 deletions(-)
---
diff --git a/src/tree/gb-tree-node.c b/src/tree/gb-tree-node.c
index 1764f94..89ee636 100644
--- a/src/tree/gb-tree-node.c
+++ b/src/tree/gb-tree-node.c
@@ -173,27 +173,10 @@ void
 gb_tree_node_remove (GbTreeNode *node,
                      GbTreeNode *child)
 {
-  GtkTreeModel *model = NULL;
-  GtkTreePath *path;
-  GtkTreeIter iter;
-  GbTree *tree = NULL;
-
   g_return_if_fail (GB_IS_TREE_NODE (node));
+  g_return_if_fail (GB_IS_TREE_NODE (child));
 
-  tree = gb_tree_node_get_tree (node);
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
-  path = gb_tree_node_get_path (node);
-
-  g_object_ref (tree);
-  g_object_ref (model);
-
-  if (gtk_tree_model_get_iter (model, &iter, path))
-    gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
-
-  g_clear_object (&model);
-  g_clear_object (&tree);
-
-  gtk_tree_path_free (path);
+  _gb_tree_remove (node->tree, child);
 }
 
 /**
@@ -238,31 +221,13 @@ gboolean
 gb_tree_node_get_iter (GbTreeNode  *self,
                        GtkTreeIter *iter)
 {
-  GtkTreeModel *model;
-  GtkTreePath *path;
   gboolean ret = FALSE;
 
   g_return_val_if_fail (GB_IS_TREE_NODE (self), FALSE);
   g_return_val_if_fail (iter != NULL, FALSE);
 
   if (self->tree != NULL)
-    {
-      model = gtk_tree_view_get_model (GTK_TREE_VIEW (self->tree));
-      path = gb_tree_node_get_path (self);
-      ret = gtk_tree_model_get_iter (model, iter, path);
-      gtk_tree_path_free (path);
-    }
-
-#if 0
-  if (ret)
-    {
-      GbTreeNode *other = NULL;
-
-      gtk_tree_model_get (model, iter, 0, &other, -1);
-      g_assert (other == self);
-      g_clear_object (&other);
-    }
-#endif
+    ret = _gb_tree_get_iter (self->tree, self, iter);
 
   return ret;
 }
diff --git a/src/tree/gb-tree-private.h b/src/tree/gb-tree-private.h
index 5aee1e9..8da051c 100644
--- a/src/tree/gb-tree-private.h
+++ b/src/tree/gb-tree-private.h
@@ -38,6 +38,11 @@ void         _gb_tree_insert_sorted           (GbTree        *self,
                                                GbTreeNode    *child,
                                                GbTreeNodeCompareFunc compare_func,
                                                gpointer       user_data);
+void         _gb_tree_remove                  (GbTree        *self,
+                                               GbTreeNode    *node);
+gboolean     _gb_tree_get_iter                (GbTree        *self,
+                                               GbTreeNode    *node,
+                                               GtkTreeIter   *iter);
 
 void         _gb_tree_node_set_tree           (GbTreeNode    *node,
                                                GbTree        *tree);
diff --git a/src/tree/gb-tree.c b/src/tree/gb-tree.c
index 54ad72a..bbc706a 100644
--- a/src/tree/gb-tree.c
+++ b/src/tree/gb-tree.c
@@ -1513,3 +1513,43 @@ failure:
 
   return NULL;
 }
+
+void
+_gb_tree_remove (GbTree     *self,
+                 GbTreeNode *node)
+{
+  GbTreePrivate *priv = gb_tree_get_instance_private (self);
+  GtkTreePath *path;
+  GtkTreeIter iter;
+
+  g_return_if_fail (GB_IS_TREE (self));
+  g_return_if_fail (GB_IS_TREE_NODE (node));
+
+  path = gb_tree_node_get_path (node);
+
+  if (gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->store), &iter, path))
+    gtk_tree_store_remove (priv->store, &iter);
+
+  gtk_tree_path_free (path);
+}
+
+gboolean
+_gb_tree_get_iter (GbTree      *self,
+                   GbTreeNode  *node,
+                   GtkTreeIter *iter)
+{
+  GbTreePrivate *priv = gb_tree_get_instance_private (self);
+  GtkTreePath *path;
+  gboolean ret;
+
+  g_return_val_if_fail (GB_IS_TREE (self), FALSE);
+  g_return_val_if_fail (GB_IS_TREE_NODE (node), FALSE);
+  g_return_val_if_fail (iter, FALSE);
+
+  path = gb_tree_node_get_path (node);
+  ret = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->store), iter, path);
+  gtk_tree_path_free (path);
+
+  return ret;
+}
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]