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



commit 6974b2108bda93bf6e1cf861b0558319b38789a8
Author: Christian Hergert <chergert redhat com>
Date:   Fri Aug 12 15:41:50 2022 -0700

    libide/tweaks: add get_root() helper

 src/libide/tweaks/ide-tweaks-item.c | 21 +++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-item.h |  2 ++
 2 files changed, 23 insertions(+)
---
diff --git a/src/libide/tweaks/ide-tweaks-item.c b/src/libide/tweaks/ide-tweaks-item.c
index 92a618045..5cc40da96 100644
--- a/src/libide/tweaks/ide-tweaks-item.c
+++ b/src/libide/tweaks/ide-tweaks-item.c
@@ -802,3 +802,24 @@ ide_tweaks_item_visit_children (IdeTweaksItem        *self,
 
   return FALSE;
 }
+
+/**
+ * ide_tweaks_item_get_root:
+ * @self: a #IdeTweaksItem
+ *
+ * Gets the root #IdeTweaksItem.
+ *
+ * Returns: (transfer none): the top-most #IdeTweaksItem
+ */
+IdeTweaksItem *
+ide_tweaks_item_get_root (IdeTweaksItem *self)
+{
+  IdeTweaksItem *parent = self;
+
+  g_return_val_if_fail (IDE_IS_TWEAKS_ITEM (self), NULL);
+
+  while (ide_tweaks_item_get_parent (parent))
+    parent = ide_tweaks_item_get_parent (parent);
+
+  return parent;
+}
diff --git a/src/libide/tweaks/ide-tweaks-item.h b/src/libide/tweaks/ide-tweaks-item.h
index c54462f99..2a068e8a8 100644
--- a/src/libide/tweaks/ide-tweaks-item.h
+++ b/src/libide/tweaks/ide-tweaks-item.h
@@ -80,6 +80,8 @@ IDE_AVAILABLE_IN_ALL
 gboolean            ide_tweaks_item_is_ancestor          (IdeTweaksItem        *self,
                                                           IdeTweaksItem        *ancestor);
 IDE_AVAILABLE_IN_ALL
+IdeTweaksItem      *ide_tweaks_item_get_root             (IdeTweaksItem        *self);
+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]