[gnome-builder] libide/tweaks: add a number of tweaks item types



commit 1d87d8b23fda52239155e5a91170df9555916a42
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jul 30 20:44:49 2022 -0700

    libide/tweaks: add a number of tweaks item types
    
    This just gets some basic scaffolding in place. I have a few more object
    types to create though to make defining things like settings, page
    generators (load lists dynamically) and what not. Then on to merging.

 src/libide/tweaks/example.ui           |  43 ++++++++++
 src/libide/tweaks/ide-tweaks-custom.c  |  98 ++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-custom.h  |  35 ++++++++
 src/libide/tweaks/ide-tweaks-group.c   | 148 +++++++++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-group.h   |  44 ++++++++++
 src/libide/tweaks/ide-tweaks-init.c    |   4 +
 src/libide/tweaks/ide-tweaks-page.c    |  12 +++
 src/libide/tweaks/ide-tweaks-subpage.c | 134 +++++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-subpage.h |  40 +++++++++
 src/libide/tweaks/ide-tweaks.c         | 136 ++++++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks.h         |  40 +++++++++
 src/libide/tweaks/libide-tweaks.h      |   4 +
 src/libide/tweaks/meson.build          |   8 ++
 13 files changed, 746 insertions(+)
---
diff --git a/src/libide/tweaks/example.ui b/src/libide/tweaks/example.ui
new file mode 100644
index 000000000..1ced660ee
--- /dev/null
+++ b/src/libide/tweaks/example.ui
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="IdeTweaks">
+    <child>
+      <object class="IdeTweaksPage" id="appearance">
+        <property name="section">visual</property>
+        <property name="title" translatable="yes">Appearance</property>
+        <child>
+          <object class="IdeTweaksGroup" id="appearance_group">
+            <property name="title" translatable="yes">Appearance</property>
+            <child>
+              <object class="IdeTweaksCustom" id="appearance_selector">
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="IdeTweaksGroup" id="style">
+            <property name="title" translatable="yes">Style</property>
+            <child>
+              <object class="IdeTweaksCustom" id="style_preview">
+              </object>
+            </child>
+            <child>
+              <object class="IdeTweaksCustom" id="style_scheme_selector">
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="IdeTweaksPage" id="languages">
+        <property name="section">programming</property>
+        <property name="title" translatable="yes">Languages</property>
+        <property name="subpage-generator">
+          <object class="IdeTweaksSubpageGenerator">
+          </object>
+        </property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/libide/tweaks/ide-tweaks-custom.c b/src/libide/tweaks/ide-tweaks-custom.c
new file mode 100644
index 000000000..ee09e4b29
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-custom.c
@@ -0,0 +1,98 @@
+/* ide-tweaks-custom.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-tweaks-custom"
+
+#include "config.h"
+
+#include "ide-tweaks-custom.h"
+
+struct _IdeTweaksCustom
+{
+  IdeTweaksItem parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (IdeTweaksCustom, ide_tweaks_custom, IDE_TYPE_TWEAKS_ITEM)
+
+enum {
+  PROP_0,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+IdeTweaksCustom *
+ide_tweaks_custom_new (void)
+{
+  return g_object_new (IDE_TYPE_TWEAKS_CUSTOM, NULL);
+}
+
+static void
+ide_tweaks_custom_dispose (GObject *object)
+{
+  IdeTweaksCustom *self = (IdeTweaksCustom *)object;
+
+  G_OBJECT_CLASS (ide_tweaks_custom_parent_class)->dispose (object);
+}
+
+static void
+ide_tweaks_custom_get_property (GObject    *object,
+                                guint       prop_id,
+                                GValue     *value,
+                                GParamSpec *pspec)
+{
+  IdeTweaksCustom *self = IDE_TWEAKS_CUSTOM (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_custom_set_property (GObject      *object,
+                                guint         prop_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+  IdeTweaksCustom *self = IDE_TWEAKS_CUSTOM (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_custom_class_init (IdeTweaksCustomClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = ide_tweaks_custom_dispose;
+  object_class->get_property = ide_tweaks_custom_get_property;
+  object_class->set_property = ide_tweaks_custom_set_property;
+}
+
+static void
+ide_tweaks_custom_init (IdeTweaksCustom *self)
+{
+}
diff --git a/src/libide/tweaks/ide-tweaks-custom.h b/src/libide/tweaks/ide-tweaks-custom.h
new file mode 100644
index 000000000..e440bc000
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-custom.h
@@ -0,0 +1,35 @@
+/* ide-tweaks-custom.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include "ide-tweaks-item.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TWEAKS_CUSTOM (ide_tweaks_custom_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeTweaksCustom, ide_tweaks_custom, IDE, TWEAKS_CUSTOM, IdeTweaksItem)
+
+IDE_AVAILABLE_IN_ALL
+IdeTweaksCustom *ide_tweaks_custom_new (void);
+
+G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks-group.c b/src/libide/tweaks/ide-tweaks-group.c
new file mode 100644
index 000000000..cae65d852
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-group.c
@@ -0,0 +1,148 @@
+/* ide-tweaks-group.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-tweaks-group"
+
+#include "config.h"
+
+#include "ide-tweaks-custom.h"
+#include "ide-tweaks-group.h"
+
+struct _IdeTweaksGroup
+{
+  IdeTweaksItem parent_instance;
+  char *title;
+};
+
+enum {
+  PROP_0,
+  PROP_TITLE,
+  N_PROPS
+};
+
+G_DEFINE_FINAL_TYPE (IdeTweaksGroup, ide_tweaks_group, IDE_TYPE_TWEAKS_ITEM)
+
+static GParamSpec *properties [N_PROPS];
+
+static gboolean
+ide_tweaks_group_accepts (IdeTweaksItem *item,
+                          IdeTweaksItem *child)
+{
+  g_assert (IDE_IS_TWEAKS_GROUP (item));
+  g_assert (IDE_IS_TWEAKS_ITEM (child));
+
+  return IDE_IS_TWEAKS_CUSTOM (child);
+}
+
+static void
+ide_tweaks_group_dispose (GObject *object)
+{
+  IdeTweaksGroup *self = (IdeTweaksGroup *)object;
+
+  g_clear_pointer (&self->title, g_free);
+
+  G_OBJECT_CLASS (ide_tweaks_group_parent_class)->dispose (object);
+}
+
+static void
+ide_tweaks_group_get_property (GObject    *object,
+                               guint       prop_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  IdeTweaksGroup *self = IDE_TWEAKS_GROUP (object);
+
+  switch (prop_id)
+    {
+    case PROP_TITLE:
+      g_value_set_string (value, ide_tweaks_group_get_title (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_group_set_property (GObject      *object,
+                               guint         prop_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+  IdeTweaksGroup *self = IDE_TWEAKS_GROUP (object);
+
+  switch (prop_id)
+    {
+    case PROP_TITLE:
+      ide_tweaks_group_set_title (self, g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_group_class_init (IdeTweaksGroupClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeTweaksItemClass *item_class = IDE_TWEAKS_ITEM_CLASS (klass);
+
+  object_class->dispose = ide_tweaks_group_dispose;
+  object_class->get_property = ide_tweaks_group_get_property;
+  object_class->set_property = ide_tweaks_group_set_property;
+
+  item_class->accepts = ide_tweaks_group_accepts;
+
+  properties [PROP_TITLE] =
+    g_param_spec_string ("title", NULL, NULL, NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_tweaks_group_init (IdeTweaksGroup *self)
+{
+}
+
+IdeTweaksGroup *
+ide_tweaks_group_new (void)
+{
+  return g_object_new (IDE_TYPE_TWEAKS_GROUP, NULL);
+}
+
+const char *
+ide_tweaks_group_get_title (IdeTweaksGroup *self)
+{
+  g_return_val_if_fail (IDE_IS_TWEAKS_GROUP (self), NULL);
+
+  return self->title;
+}
+
+void
+ide_tweaks_group_set_title (IdeTweaksGroup *self,
+                            const char     *title)
+{
+  g_return_if_fail (IDE_IS_TWEAKS_GROUP (self));
+
+  if (ide_set_string (&self->title, title))
+    g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
+}
diff --git a/src/libide/tweaks/ide-tweaks-group.h b/src/libide/tweaks/ide-tweaks-group.h
new file mode 100644
index 000000000..280327428
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-group.h
@@ -0,0 +1,44 @@
+/* ide-tweaks-group.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#if !defined (IDE_TWEAKS_INSIDE) && !defined (IDE_TWEAKS_COMPILATION)
+# error "Only <libide-tweaks.h> can be included directly."
+#endif
+
+#include "ide-tweaks-item.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TWEAKS_GROUP (ide_tweaks_group_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeTweaksGroup, ide_tweaks_group, IDE, TWEAKS_GROUP, IdeTweaksItem)
+
+IDE_AVAILABLE_IN_ALL
+IdeTweaksGroup *ide_tweaks_group_new (void);
+IDE_AVAILABLE_IN_ALL
+const char *ide_tweaks_group_get_title (IdeTweaksGroup *self);
+IDE_AVAILABLE_IN_ALL
+void ide_tweaks_group_set_title (IdeTweaksGroup *self,
+                                 const char *title);
+
+G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks-init.c b/src/libide/tweaks/ide-tweaks-init.c
index 59a8125e7..4dc019c4c 100644
--- a/src/libide/tweaks/ide-tweaks-init.c
+++ b/src/libide/tweaks/ide-tweaks-init.c
@@ -29,7 +29,11 @@
 void
 _ide_tweaks_init (void)
 {
+  g_type_ensure (IDE_TYPE_TWEAKS);
+  g_type_ensure (IDE_TYPE_TWEAKS_CUSTOM);
+  g_type_ensure (IDE_TYPE_TWEAKS_GROUP);
   g_type_ensure (IDE_TYPE_TWEAKS_ITEM);
   g_type_ensure (IDE_TYPE_TWEAKS_PAGE);
+  g_type_ensure (IDE_TYPE_TWEAKS_SUBPAGE);
   g_type_ensure (IDE_TYPE_TWEAKS_VARIABLE);
 }
diff --git a/src/libide/tweaks/ide-tweaks-page.c b/src/libide/tweaks/ide-tweaks-page.c
index 07accda5b..bb2a65227 100644
--- a/src/libide/tweaks/ide-tweaks-page.c
+++ b/src/libide/tweaks/ide-tweaks-page.c
@@ -23,7 +23,9 @@
 
 #include "config.h"
 
+#include "ide-tweaks-group.h"
 #include "ide-tweaks-page.h"
+#include "ide-tweaks-subpage.h"
 
 struct _IdeTweaksPage
 {
@@ -49,6 +51,13 @@ ide_tweaks_page_new (void)
   return g_object_new (IDE_TYPE_TWEAKS_PAGE, NULL);
 }
 
+static gboolean
+ide_tweaks_page_accepts (IdeTweaksItem *item,
+                         IdeTweaksItem *child)
+{
+  return IDE_IS_TWEAKS_SUBPAGE (child) || IDE_IS_TWEAKS_GROUP (child);
+}
+
 static void
 ide_tweaks_page_finalize (GObject *object)
 {
@@ -110,11 +119,14 @@ static void
 ide_tweaks_page_class_init (IdeTweaksPageClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeTweaksItemClass *item_class = IDE_TWEAKS_ITEM_CLASS (klass);
 
   object_class->finalize = ide_tweaks_page_finalize;
   object_class->get_property = ide_tweaks_page_get_property;
   object_class->set_property = ide_tweaks_page_set_property;
 
+  item_class->accepts = ide_tweaks_page_accepts;
+
   properties [PROP_SECTION] =
     g_param_spec_string ("section", NULL, NULL, NULL,
                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
diff --git a/src/libide/tweaks/ide-tweaks-subpage.c b/src/libide/tweaks/ide-tweaks-subpage.c
new file mode 100644
index 000000000..a5b4588f8
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-subpage.c
@@ -0,0 +1,134 @@
+/* ide-tweaks-subpage.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-tweaks-subpage"
+
+#include "config.h"
+
+#include "ide-tweaks-subpage.h"
+
+struct _IdeTweaksSubpage
+{
+  IdeTweaksItem parent_instance;
+  char *title;
+};
+
+G_DEFINE_FINAL_TYPE (IdeTweaksSubpage, ide_tweaks_subpage, IDE_TYPE_TWEAKS_ITEM)
+
+enum {
+  PROP_0,
+  PROP_TITLE,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+IdeTweaksSubpage *
+ide_tweaks_subpage_new (void)
+{
+  return g_object_new (IDE_TYPE_TWEAKS_SUBPAGE, NULL);
+}
+
+static void
+ide_tweaks_subpage_dispose (GObject *object)
+{
+  IdeTweaksSubpage *self = (IdeTweaksSubpage *)object;
+
+  g_clear_pointer (&self->title, g_free);
+
+  G_OBJECT_CLASS (ide_tweaks_subpage_parent_class)->dispose (object);
+}
+
+static void
+ide_tweaks_subpage_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  IdeTweaksSubpage *self = IDE_TWEAKS_SUBPAGE (object);
+
+  switch (prop_id)
+    {
+    case PROP_TITLE:
+      g_value_set_string (value, ide_tweaks_subpage_get_title (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_subpage_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  IdeTweaksSubpage *self = IDE_TWEAKS_SUBPAGE (object);
+
+  switch (prop_id)
+    {
+    case PROP_TITLE:
+      ide_tweaks_subpage_set_title (self, g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_subpage_class_init (IdeTweaksSubpageClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = ide_tweaks_subpage_dispose;
+  object_class->get_property = ide_tweaks_subpage_get_property;
+  object_class->set_property = ide_tweaks_subpage_set_property;
+
+  properties [PROP_TITLE] =
+    g_param_spec_string ("title", NULL, NULL, NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_tweaks_subpage_init (IdeTweaksSubpage *self)
+{
+}
+
+const char *
+ide_tweaks_subpage_get_title (IdeTweaksSubpage *self)
+{
+  g_return_val_if_fail (IDE_IS_TWEAKS_SUBPAGE (self), NULL);
+
+  return self->title;
+}
+
+void
+ide_tweaks_subpage_set_title (IdeTweaksSubpage *self,
+                              const char       *title)
+{
+  g_return_if_fail (IDE_IS_TWEAKS_SUBPAGE (self));
+
+  if (ide_set_string (&self->title, title))
+    g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
+}
diff --git a/src/libide/tweaks/ide-tweaks-subpage.h b/src/libide/tweaks/ide-tweaks-subpage.h
new file mode 100644
index 000000000..e667e9797
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-subpage.h
@@ -0,0 +1,40 @@
+/* ide-tweaks-subpage.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include "ide-tweaks-item.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TWEAKS_SUBPAGE (ide_tweaks_subpage_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeTweaksSubpage, ide_tweaks_subpage, IDE, TWEAKS_SUBPAGE, IdeTweaksItem)
+
+IDE_AVAILABLE_IN_ALL
+IdeTweaksSubpage *ide_tweaks_subpage_new       (void);
+IDE_AVAILABLE_IN_ALL
+const char       *ide_tweaks_subpage_get_title (IdeTweaksSubpage *self);
+IDE_AVAILABLE_IN_ALL
+void              ide_tweaks_subpage_set_title (IdeTweaksSubpage *self,
+                                                const char       *title);
+
+G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks.c b/src/libide/tweaks/ide-tweaks.c
new file mode 100644
index 000000000..aed9e4790
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks.c
@@ -0,0 +1,136 @@
+/* ide-tweaks.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-tweaks"
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "ide-tweaks.h"
+#include "ide-tweaks-page.h"
+
+struct _IdeTweaks
+{
+  IdeTweaksItem parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (IdeTweaks, ide_tweaks, IDE_TYPE_TWEAKS_ITEM)
+
+enum {
+  PROP_0,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+static gboolean
+ide_tweaks_accepts (IdeTweaksItem *item,
+                    IdeTweaksItem *child)
+{
+  g_assert (IDE_IS_TWEAKS_ITEM (item));
+  g_assert (IDE_IS_TWEAKS_ITEM (child));
+
+  return IDE_IS_TWEAKS_PAGE (child);
+}
+
+static void
+ide_tweaks_dispose (GObject *object)
+{
+  IdeTweaks *self = (IdeTweaks *)object;
+
+  G_OBJECT_CLASS (ide_tweaks_parent_class)->dispose (object);
+}
+
+static void
+ide_tweaks_get_property (GObject    *object,
+                         guint       prop_id,
+                         GValue     *value,
+                         GParamSpec *pspec)
+{
+  IdeTweaks *self = IDE_TWEAKS (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_set_property (GObject      *object,
+                         guint         prop_id,
+                         const GValue *value,
+                         GParamSpec   *pspec)
+{
+  IdeTweaks *self = IDE_TWEAKS (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_class_init (IdeTweaksClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeTweaksItemClass *item_class = IDE_TWEAKS_ITEM_CLASS (klass);
+
+  object_class->dispose = ide_tweaks_dispose;
+  object_class->get_property = ide_tweaks_get_property;
+  object_class->set_property = ide_tweaks_set_property;
+
+  item_class->accepts = ide_tweaks_accepts;
+}
+
+static void
+ide_tweaks_init (IdeTweaks *self)
+{
+}
+
+IdeTweaks *
+ide_tweaks_new (void)
+{
+  return g_object_new (IDE_TYPE_TWEAKS, NULL);
+}
+
+gboolean
+ide_tweaks_load_from_file (IdeTweaks     *self,
+                           GFile         *file,
+                           GCancellable  *cancellable,
+                           GError       **error)
+{
+  g_autoptr(GtkBuilder) builder = NULL;
+  g_autofree char *contents = NULL;
+  gsize length;
+
+  g_return_val_if_fail (IDE_IS_TWEAKS (self), FALSE);
+  g_return_val_if_fail (G_IS_FILE (file), FALSE);
+  g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
+
+  if (!g_file_load_contents (file, cancellable, &contents, &length, NULL, error))
+    return FALSE;
+
+  builder = gtk_builder_new ();
+
+  return gtk_builder_extend_with_template (builder, G_OBJECT (self), IDE_TYPE_TWEAKS, contents, length, 
error);
+}
diff --git a/src/libide/tweaks/ide-tweaks.h b/src/libide/tweaks/ide-tweaks.h
new file mode 100644
index 000000000..baf4d2711
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks.h
@@ -0,0 +1,40 @@
+/* ide-tweaks.h
+ *
+ * Copyright $year Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+
+#include "ide-tweaks-item.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TWEAKS (ide_tweaks_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeTweaks, ide_tweaks, IDE, TWEAKS, IdeTweaksItem)
+
+IDE_AVAILABLE_IN_ALL
+IdeTweaks *ide_tweaks_new            (void);
+IDE_AVAILABLE_IN_ALL
+gboolean   ide_tweaks_load_from_file (IdeTweaks     *self,
+                                      GFile         *file,
+                                      GCancellable  *cancellable,
+                                      GError       **error);
+
+G_END_DECLS
diff --git a/src/libide/tweaks/libide-tweaks.h b/src/libide/tweaks/libide-tweaks.h
index f2a4c3611..493bc9abd 100644
--- a/src/libide/tweaks/libide-tweaks.h
+++ b/src/libide/tweaks/libide-tweaks.h
@@ -21,7 +21,11 @@
 #pragma once
 
 #define IDE_TWEAKS_INSIDE
+# include "ide-tweaks.h"
+# include "ide-tweaks-custom.h"
+# include "ide-tweaks-group.h"
 # include "ide-tweaks-item.h"
 # include "ide-tweaks-page.h"
+# include "ide-tweaks-subpage.h"
 # include "ide-tweaks-variable.h"
 #undef IDE_TWEAKS_INSIDE
diff --git a/src/libide/tweaks/meson.build b/src/libide/tweaks/meson.build
index 17952d97d..694472537 100644
--- a/src/libide/tweaks/meson.build
+++ b/src/libide/tweaks/meson.build
@@ -8,8 +8,12 @@ libide_include_directories += include_directories('.')
 
 libide_tweaks_public_headers = [
   'libide-tweaks.h',
+  'ide-tweaks.h',
+  'ide-tweaks-custom.h',
+  'ide-tweaks-group.h',
   'ide-tweaks-item.h',
   'ide-tweaks-page.h',
+  'ide-tweaks-subpage.h',
   'ide-tweaks-variable.h',
 ]
 
@@ -20,8 +24,12 @@ install_headers(libide_tweaks_public_headers, subdir: libide_tweaks_header_subdi
 #
 
 libide_tweaks_public_sources = [
+  'ide-tweaks.c',
+  'ide-tweaks-custom.c',
   'ide-tweaks-item.c',
+  'ide-tweaks-group.c',
   'ide-tweaks-page.c',
+  'ide-tweaks-subpage.c',
   'ide-tweaks-variable.c',
 ]
 


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