[gnome-builder] libide/tweaks: add ide_tweaks_item_is_ancestor()



commit cbc31534ac81f725b4952bb141ee8a06b32e3dbb
Author: Christian Hergert <chergert redhat com>
Date:   Tue Aug 2 22:30:18 2022 -0700

    libide/tweaks: add ide_tweaks_item_is_ancestor()
    
    Easy check to see if an item is in the hierarchy up to the root.

 src/libide/tweaks/ide-tweaks-item.c | 18 ++++++++++++++++++
 src/libide/tweaks/ide-tweaks-item.h |  3 +++
 2 files changed, 21 insertions(+)
---
diff --git a/src/libide/tweaks/ide-tweaks-item.c b/src/libide/tweaks/ide-tweaks-item.c
index 0e4e340b8..c021fede1 100644
--- a/src/libide/tweaks/ide-tweaks-item.c
+++ b/src/libide/tweaks/ide-tweaks-item.c
@@ -614,3 +614,21 @@ _ide_tweaks_item_deep_copy (IdeTweaksItem *self)
 
   return g_object_new (G_OBJECT_TYPE (self), NULL);
 }
+
+gboolean
+ide_tweaks_item_is_ancestor (IdeTweaksItem *self,
+                             IdeTweaksItem *ancestor)
+{
+  g_return_val_if_fail (IDE_IS_TWEAKS_ITEM (self), FALSE);
+  g_return_val_if_fail (IDE_IS_TWEAKS_ITEM (ancestor), FALSE);
+
+  for (IdeTweaksItem *item = ide_tweaks_item_get_parent (self);
+       item != NULL;
+       item = ide_tweaks_item_get_parent (item))
+    {
+      if (item == ancestor)
+        return TRUE;
+    }
+
+  return FALSE;
+}
diff --git a/src/libide/tweaks/ide-tweaks-item.h b/src/libide/tweaks/ide-tweaks-item.h
index 83a4de6a9..2dbb763fe 100644
--- a/src/libide/tweaks/ide-tweaks-item.h
+++ b/src/libide/tweaks/ide-tweaks-item.h
@@ -54,6 +54,9 @@ IDE_AVAILABLE_IN_ALL
 void                ide_tweaks_item_set_sort_key         (IdeTweaksItem      *self,
                                                           const char         *sort_key);
 IDE_AVAILABLE_IN_ALL
+gboolean            ide_tweaks_item_is_ancestor          (IdeTweaksItem      *self,
+                                                          IdeTweaksItem      *ancestor);
+IDE_AVAILABLE_IN_ALL
 IdeTweaksItem      *ide_tweaks_item_get_parent           (IdeTweaksItem      *self);
 IDE_AVAILABLE_IN_ALL
 IdeTweaksItem      *ide_tweaks_item_get_last_child       (IdeTweaksItem      *self);


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