[gnome-builder] project-item: add gb_project_item_remove()



commit 565a2b4a84a93540f124cfce9c8c4d02dff2fc07
Author: Christian Hergert <christian hergert me>
Date:   Wed Apr 15 17:43:16 2015 -0700

    project-item: add gb_project_item_remove()
    
    This simplifies the process of removing children items.

 libide/ide-project-item.c |   28 ++++++++++++++++++++++++++++
 libide/ide-project-item.h |    2 ++
 2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-project-item.c b/libide/ide-project-item.c
index b3f1391..348f748 100644
--- a/libide/ide-project-item.c
+++ b/libide/ide-project-item.c
@@ -60,6 +60,34 @@ ide_project_item_append (IdeProjectItem *item,
   g_sequence_append (priv->children, g_object_ref (child));
 }
 
+void
+ide_project_item_remove (IdeProjectItem *item,
+                         IdeProjectItem *child)
+{
+  IdeProjectItemPrivate *priv = ide_project_item_get_instance_private (item);
+  GSequenceIter *iter;
+
+  g_return_if_fail (IDE_IS_PROJECT_ITEM (item));
+  g_return_if_fail (IDE_IS_PROJECT_ITEM (child));
+  g_return_if_fail (item == ide_project_item_get_parent (child));
+
+  if (priv->children == NULL)
+    return;
+
+  for (iter = g_sequence_get_begin_iter (priv->children);
+       !g_sequence_iter_is_end (iter);
+       iter = g_sequence_iter_next (iter))
+    {
+      if (g_sequence_get (iter) == child)
+        {
+          g_sequence_remove (iter);
+          g_object_set (child, "parent", NULL, NULL);
+          g_object_unref (child);
+          break;
+        }
+    }
+}
+
 /**
  * ide_project_item_get_children:
  *
diff --git a/libide/ide-project-item.h b/libide/ide-project-item.h
index d77a63f..be400b8 100644
--- a/libide/ide-project-item.h
+++ b/libide/ide-project-item.h
@@ -35,6 +35,8 @@ struct _IdeProjectItemClass
 IdeProjectItem *ide_project_item_get_parent   (IdeProjectItem *item);
 void            ide_project_item_append       (IdeProjectItem *item,
                                                IdeProjectItem *child);
+void            ide_project_item_remove       (IdeProjectItem *item,
+                                               IdeProjectItem *child);
 GSequence      *ide_project_item_get_children (IdeProjectItem *item);
 
 G_END_DECLS


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