[gnome-builder] libide/tweaks: add ide_tweaks_item_get_ancestor()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/tweaks: add ide_tweaks_item_get_ancestor()
- Date: Wed, 3 Aug 2022 23:29:09 +0000 (UTC)
commit d80d79e49c6836e56696786161e5d9a32b5be2b3
Author: Christian Hergert <chergert redhat com>
Date: Wed Aug 3 15:32:28 2022 -0700
libide/tweaks: add ide_tweaks_item_get_ancestor()
This is a helper to find an ancestor by their GType.
src/libide/tweaks/ide-tweaks-item.c | 27 +++++++++++++++++++++++++++
src/libide/tweaks/ide-tweaks-item.h | 3 +++
2 files changed, 30 insertions(+)
---
diff --git a/src/libide/tweaks/ide-tweaks-item.c b/src/libide/tweaks/ide-tweaks-item.c
index 2026a4e63..e0c804bde 100644
--- a/src/libide/tweaks/ide-tweaks-item.c
+++ b/src/libide/tweaks/ide-tweaks-item.c
@@ -712,3 +712,30 @@ ide_tweaks_item_is_ancestor (IdeTweaksItem *self,
return FALSE;
}
+
+/**
+ * ide_tweaks_item_get_ancestor:
+ * @self: an #IdeTweaksItem
+ * @ancestor_type: the #GType of #IdeTweaksItem or subclass
+ *
+ * Finds the first ancestor of @self matching the #GType @ancestor_type.
+ *
+ * Returns: (transfer none) (nullable): an #IdeTweaksItem or %NULL
+ */
+gpointer
+ide_tweaks_item_get_ancestor (IdeTweaksItem *self,
+ GType ancestor_type)
+{
+ IdeTweaksItem *parent = self;
+
+ g_return_val_if_fail (IDE_IS_TWEAKS_ITEM (self), NULL);
+ g_return_val_if_fail (g_type_is_a (ancestor_type, IDE_TYPE_TWEAKS_ITEM), NULL);
+
+ while ((parent = ide_tweaks_item_get_parent (parent)))
+ {
+ if (G_TYPE_CHECK_INSTANCE_TYPE (parent, ancestor_type))
+ return parent;
+ }
+
+ return NULL;
+}
diff --git a/src/libide/tweaks/ide-tweaks-item.h b/src/libide/tweaks/ide-tweaks-item.h
index dea4e1d00..bc832713e 100644
--- a/src/libide/tweaks/ide-tweaks-item.h
+++ b/src/libide/tweaks/ide-tweaks-item.h
@@ -78,6 +78,9 @@ void ide_tweaks_item_insert_before (IdeTweaksItem *se
IdeTweaksItem *parent,
IdeTweaksItem *next_sibling);
IDE_AVAILABLE_IN_ALL
+gpointer ide_tweaks_item_get_ancestor (IdeTweaksItem *self,
+ GType ancestor_type);
+IDE_AVAILABLE_IN_ALL
void ide_tweaks_item_unparent (IdeTweaksItem *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]