[gnome-builder] libide/tweaks: add IdeTweaksPage:has-subpage
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/tweaks: add IdeTweaksPage:has-subpage
- Date: Wed, 3 Aug 2022 04:20:09 +0000 (UTC)
commit 70d47d118fc2e4042231020b9308468b53e4a543
Author: Christian Hergert <chergert redhat com>
Date: Tue Aug 2 21:03:14 2022 -0700
libide/tweaks: add IdeTweaksPage:has-subpage
This boolean property denotes if a page is known to have a subpage, or
the possibility that it might create one dynamically.
src/libide/tweaks/ide-tweaks-page.c | 45 +++++++++++++++++++++++++++++-
src/libide/tweaks/ide-tweaks-page.h | 18 ++++++------
src/libide/tweaks/tests/test1/expected.xml | 6 ++--
src/libide/tweaks/tests/test2/expected.xml | 2 +-
4 files changed, 58 insertions(+), 13 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-page.c b/src/libide/tweaks/ide-tweaks-page.c
index 51bf0f698..69fa75674 100644
--- a/src/libide/tweaks/ide-tweaks-page.c
+++ b/src/libide/tweaks/ide-tweaks-page.c
@@ -23,7 +23,7 @@
#include "config.h"
-#include "ide-tweaks-factory.h"
+#include "ide-tweaks-factory-private.h"
#include "ide-tweaks-group.h"
#include "ide-tweaks-page.h"
#include "ide-tweaks-section.h"
@@ -40,6 +40,7 @@ G_DEFINE_FINAL_TYPE (IdeTweaksPage, ide_tweaks_page, IDE_TYPE_TWEAKS_ITEM)
enum {
PROP_0,
+ PROP_HAS_SUBPAGE,
PROP_ICON_NAME,
PROP_SECTION,
PROP_TITLE,
@@ -84,6 +85,10 @@ ide_tweaks_page_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_HAS_SUBPAGE:
+ g_value_set_boolean (value, ide_tweaks_page_get_has_subpage (self));
+ break;
+
case PROP_ICON_NAME:
g_value_set_string (value, ide_tweaks_page_get_icon_name (self));
break;
@@ -136,6 +141,11 @@ ide_tweaks_page_class_init (IdeTweaksPageClass *klass)
item_class->accepts = ide_tweaks_page_accepts;
+ properties [PROP_HAS_SUBPAGE] =
+ g_param_spec_boolean ("has-subpage", NULL, NULL,
+ FALSE,
+ (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
properties [PROP_ICON_NAME] =
g_param_spec_string ("icon-name", NULL, NULL, NULL,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
@@ -216,3 +226,36 @@ ide_tweaks_page_get_section (IdeTweaksPage *self)
return NULL;
}
+
+/**
+ * ide_tweaks_page_get_has_subpage:
+ * @self: a #IdeTweaksPage
+ *
+ * Checks if @page has a subpage or a factory that can generate subpages.
+ *
+ * Returns: %TRUE if @self might have a subpage
+ */
+gboolean
+ide_tweaks_page_get_has_subpage (IdeTweaksPage *self)
+{
+ static GType subpage_type;
+
+ g_return_val_if_fail (IDE_IS_TWEAKS_PAGE (self), FALSE);
+
+ if G_UNLIKELY (subpage_type == G_TYPE_INVALID)
+ subpage_type = IDE_TYPE_TWEAKS_SUBPAGE;
+
+ for (IdeTweaksItem *child = ide_tweaks_item_get_first_child (IDE_TWEAKS_ITEM (self));
+ child != NULL;
+ child = ide_tweaks_item_get_next_sibling (child))
+ {
+ if (G_TYPE_CHECK_INSTANCE_TYPE (child, subpage_type))
+ return TRUE;
+
+ if (IDE_IS_TWEAKS_FACTORY (child) &&
+ _ide_tweaks_factory_is_one_of (IDE_TWEAKS_FACTORY (child), &subpage_type, 1))
+ return TRUE;
+ }
+
+ return FALSE;
+}
diff --git a/src/libide/tweaks/ide-tweaks-page.h b/src/libide/tweaks/ide-tweaks-page.h
index 6b0affbdc..5723cbdd2 100644
--- a/src/libide/tweaks/ide-tweaks-page.h
+++ b/src/libide/tweaks/ide-tweaks-page.h
@@ -31,18 +31,20 @@ IDE_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (IdeTweaksPage, ide_tweaks_page, IDE, TWEAKS_PAGE, IdeTweaksItem)
IDE_AVAILABLE_IN_ALL
-IdeTweaksPage *ide_tweaks_page_new (void);
+IdeTweaksPage *ide_tweaks_page_new (void);
IDE_AVAILABLE_IN_ALL
-const char *ide_tweaks_page_get_icon_name (IdeTweaksPage *self);
+const char *ide_tweaks_page_get_icon_name (IdeTweaksPage *self);
IDE_AVAILABLE_IN_ALL
-void ide_tweaks_page_set_icon_name (IdeTweaksPage *self,
- const char *icon_name);
+void ide_tweaks_page_set_icon_name (IdeTweaksPage *self,
+ const char *icon_name);
IDE_AVAILABLE_IN_ALL
-IdeTweaksItem *ide_tweaks_page_get_section (IdeTweaksPage *self);
+IdeTweaksItem *ide_tweaks_page_get_section (IdeTweaksPage *self);
IDE_AVAILABLE_IN_ALL
-const char *ide_tweaks_page_get_title (IdeTweaksPage *self);
+const char *ide_tweaks_page_get_title (IdeTweaksPage *self);
IDE_AVAILABLE_IN_ALL
-void ide_tweaks_page_set_title (IdeTweaksPage *self,
- const char *title);
+void ide_tweaks_page_set_title (IdeTweaksPage *self,
+ const char *title);
+IDE_AVAILABLE_IN_ALL
+gboolean ide_tweaks_page_get_has_subpage (IdeTweaksPage *self);
G_END_DECLS
diff --git a/src/libide/tweaks/tests/test1/expected.xml b/src/libide/tweaks/tests/test1/expected.xml
index e3bf935c0..0349e25df 100644
--- a/src/libide/tweaks/tests/test1/expected.xml
+++ b/src/libide/tweaks/tests/test1/expected.xml
@@ -1,11 +1,11 @@
<IdeTweaks id="IdeTweaks" sort-key="">
<IdeTweaksSection id="visual_section" sort-key="">
- <IdeTweaksPage id="appearance_page" icon-name="" section="#visual_section" sort-key=""
title="Appearance">
+ <IdeTweaksPage id="appearance_page" has-subpage="FALSE" icon-name="" section="#visual_section"
sort-key="" title="Appearance">
<IdeTweaksGroup id="appearance_group" sort-key="" title="Appearance"/>
</IdeTweaksPage>
</IdeTweaksSection>
<IdeTweaksSection id="foundry_section" sort-key="">
- <IdeTweaksPage id="build_page" icon-name="" section="#foundry_section" sort-key="" title="Build"/>
- <IdeTweaksPage id="debugger_page" icon-name="builder-debugger-symbolic" section="#foundry_section"
sort-key="" title="Debugger"/>
+ <IdeTweaksPage id="build_page" has-subpage="FALSE" icon-name="" section="#foundry_section" sort-key=""
title="Build"/>
+ <IdeTweaksPage id="debugger_page" has-subpage="FALSE" icon-name="builder-debugger-symbolic"
section="#foundry_section" sort-key="" title="Debugger"/>
</IdeTweaksSection>
</IdeTweaks>
diff --git a/src/libide/tweaks/tests/test2/expected.xml b/src/libide/tweaks/tests/test2/expected.xml
index d80d71363..b67257c68 100644
--- a/src/libide/tweaks/tests/test2/expected.xml
+++ b/src/libide/tweaks/tests/test2/expected.xml
@@ -1,6 +1,6 @@
<IdeTweaks id="IdeTweaks" sort-key="">
<IdeTweaksSection id="programming_section" sort-key="">
- <IdeTweaksPage id="languages_page" icon-name="preferences-desktop-appearance-symbolic"
section="#programming_section" sort-key="" title="Appearance">
+ <IdeTweaksPage id="languages_page" has-subpage="TRUE"
icon-name="preferences-desktop-appearance-symbolic" section="#programming_section" sort-key=""
title="Appearance">
<IdeTweaksFactory id="language_subpage_factory" model="GListStore<GtkSourceLanguage>" sort-key="">
<IdeTweaksSubpage id="language_subpage" icon-name="" sort-key="" title="">
<IdeTweaksGroup id="language_general_group" sort-key="test-key" title="General"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]