[gnome-builder] libide/tweaks: rename SubpageGenerator to SubpageFactory
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/tweaks: rename SubpageGenerator to SubpageFactory
- Date: Sun, 31 Jul 2022 12:37:57 +0000 (UTC)
commit e0ba5cb8f443c5de6f6298209c18cc1c5636fcce
Author: Christian Hergert <chergert redhat com>
Date: Sun Jul 31 05:33:12 2022 -0700
libide/tweaks: rename SubpageGenerator to SubpageFactory
Additionally, we allow an IdeTweaksSubpage child which can be used to
expand based on the model property. An item property will be added which
can be used for bindings during expansion.
src/libide/tweaks/ide-tweaks-init.c | 2 +-
src/libide/tweaks/ide-tweaks-page.c | 4 +-
src/libide/tweaks/ide-tweaks-subpage-factory.c | 147 +++++++++++++++++++++
...ge-generator.h => ide-tweaks-subpage-factory.h} | 20 ++-
src/libide/tweaks/ide-tweaks-subpage-generator.c | 71 ----------
src/libide/tweaks/libide-tweaks.h | 2 +-
src/libide/tweaks/meson.build | 4 +-
7 files changed, 161 insertions(+), 89 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-init.c b/src/libide/tweaks/ide-tweaks-init.c
index 9d4d03474..f4d2bfe0a 100644
--- a/src/libide/tweaks/ide-tweaks-init.c
+++ b/src/libide/tweaks/ide-tweaks-init.c
@@ -36,6 +36,6 @@ _ide_tweaks_init (void)
g_type_ensure (IDE_TYPE_TWEAKS_PAGE);
g_type_ensure (IDE_TYPE_TWEAKS_SECTION);
g_type_ensure (IDE_TYPE_TWEAKS_SUBPAGE);
- g_type_ensure (IDE_TYPE_TWEAKS_SUBPAGE_GENERATOR);
+ g_type_ensure (IDE_TYPE_TWEAKS_SUBPAGE_FACTORY);
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 889d9d9fc..f0353e2da 100644
--- a/src/libide/tweaks/ide-tweaks-page.c
+++ b/src/libide/tweaks/ide-tweaks-page.c
@@ -26,7 +26,7 @@
#include "ide-tweaks-group.h"
#include "ide-tweaks-page.h"
#include "ide-tweaks-subpage.h"
-#include "ide-tweaks-subpage-generator.h"
+#include "ide-tweaks-subpage-factory.h"
struct _IdeTweaksPage
{
@@ -57,7 +57,7 @@ ide_tweaks_page_accepts (IdeTweaksItem *item,
IdeTweaksItem *child)
{
return IDE_IS_TWEAKS_SUBPAGE (child) ||
- IDE_IS_TWEAKS_SUBPAGE_GENERATOR (child) ||
+ IDE_IS_TWEAKS_SUBPAGE_FACTORY (child) ||
IDE_IS_TWEAKS_GROUP (child);
}
diff --git a/src/libide/tweaks/ide-tweaks-subpage-factory.c b/src/libide/tweaks/ide-tweaks-subpage-factory.c
new file mode 100644
index 000000000..66a864d68
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-subpage-factory.c
@@ -0,0 +1,147 @@
+/* ide-tweaks-subpage-factory.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-factory"
+
+#include "config.h"
+
+#include "ide-tweaks-subpage.h"
+#include "ide-tweaks-subpage-factory.h"
+
+struct _IdeTweaksSubpageFactory
+{
+ IdeTweaksItem parent_instance;
+ GListModel *model;
+};
+
+G_DEFINE_FINAL_TYPE (IdeTweaksSubpageFactory, ide_tweaks_subpage_factory, IDE_TYPE_TWEAKS_ITEM)
+
+enum {
+ PROP_0,
+ PROP_MODEL,
+ N_PROPS
+};
+
+static GParamSpec *properties[N_PROPS];
+
+static gboolean
+ide_tweaks_subpage_factory_accepts (IdeTweaksItem *item,
+ IdeTweaksItem *child)
+{
+ return IDE_IS_TWEAKS_SUBPAGE (child);
+}
+
+static void
+ide_tweaks_subpage_factory_dispose (GObject *object)
+{
+ IdeTweaksSubpageFactory *self = (IdeTweaksSubpageFactory *)object;
+
+ g_clear_object (&self->model);
+
+ G_OBJECT_CLASS (ide_tweaks_subpage_factory_parent_class)->dispose (object);
+}
+
+static void
+ide_tweaks_subpage_factory_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ IdeTweaksSubpageFactory *self = IDE_TWEAKS_SUBPAGE_FACTORY (object);
+
+ switch (prop_id)
+ {
+ case PROP_MODEL:
+ g_value_set_object (value, ide_tweaks_subpage_factory_get_model (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_tweaks_subpage_factory_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ IdeTweaksSubpageFactory *self = IDE_TWEAKS_SUBPAGE_FACTORY (object);
+
+ switch (prop_id)
+ {
+ case PROP_MODEL:
+ ide_tweaks_subpage_factory_set_model (self, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_tweaks_subpage_factory_class_init (IdeTweaksSubpageFactoryClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ IdeTweaksItemClass *item_class = IDE_TWEAKS_ITEM_CLASS (klass);
+
+ object_class->dispose = ide_tweaks_subpage_factory_dispose;
+ object_class->get_property = ide_tweaks_subpage_factory_get_property;
+ object_class->set_property = ide_tweaks_subpage_factory_set_property;
+
+ item_class->accepts = ide_tweaks_subpage_factory_accepts;
+
+ properties[PROP_MODEL] =
+ g_param_spec_object ("model", NULL, NULL,
+ G_TYPE_LIST_MODEL,
+ (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_factory_init (IdeTweaksSubpageFactory *self)
+{
+}
+
+/**
+ * ide_tweaks_subpage_factory_get_model:
+ * @self: a #IdeTweaksSubpageFactory
+ *
+ * Returns: (transfer none) (nullable): a #GListModel or %NULL
+ */
+GListModel *
+ide_tweaks_subpage_factory_get_model (IdeTweaksSubpageFactory *self)
+{
+ g_return_val_if_fail (IDE_IS_TWEAKS_SUBPAGE_FACTORY (self), NULL);
+
+ return self->model;
+}
+
+void
+ide_tweaks_subpage_factory_set_model (IdeTweaksSubpageFactory *self,
+ GListModel *model)
+{
+ g_return_if_fail (IDE_IS_TWEAKS_SUBPAGE_FACTORY (self));
+ g_return_if_fail (!model || G_IS_LIST_MODEL (model));
+
+ if (g_set_object (&self->model, model))
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_MODEL]);
+}
diff --git a/src/libide/tweaks/ide-tweaks-subpage-generator.h b/src/libide/tweaks/ide-tweaks-subpage-factory.h
similarity index 59%
rename from src/libide/tweaks/ide-tweaks-subpage-generator.h
rename to src/libide/tweaks/ide-tweaks-subpage-factory.h
index dc7a59d2f..ffe0509ed 100644
--- a/src/libide/tweaks/ide-tweaks-subpage-generator.h
+++ b/src/libide/tweaks/ide-tweaks-subpage-factory.h
@@ -1,4 +1,4 @@
-/* ide-tweaks-subpage-generator.h
+/* ide-tweaks-subpage-factory.h
*
* Copyright 2022 Christian Hergert <chergert redhat com>
*
@@ -24,21 +24,17 @@
G_BEGIN_DECLS
-#define IDE_TYPE_TWEAKS_SUBPAGE_GENERATOR (ide_tweaks_subpage_generator_get_type())
+#define IDE_TYPE_TWEAKS_SUBPAGE_FACTORY (ide_tweaks_subpage_factory_get_type())
IDE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (IdeTweaksSubpageGenerator, ide_tweaks_subpage_generator, IDE,
TWEAKS_SUBPAGE_GENERATOR, IdeTweaksItem)
-
-struct _IdeTweaksSubpageGeneratorClass
-{
- IdeTweaksItemClass parent_class;
-
- void (*populate) (IdeTweaksSubpageGenerator *self);
-};
+G_DECLARE_FINAL_TYPE (IdeTweaksSubpageFactory, ide_tweaks_subpage_factory, IDE, TWEAKS_SUBPAGE_FACTORY,
IdeTweaksItem)
IDE_AVAILABLE_IN_ALL
-IdeTweaksSubpageGenerator *ide_tweaks_subpage_generator_new (void);
+IdeTweaksSubpageFactory *ide_tweaks_subpage_factory_new (void);
+IDE_AVAILABLE_IN_ALL
+GListModel *ide_tweaks_subpage_factory_get_model (IdeTweaksSubpageFactory *self);
IDE_AVAILABLE_IN_ALL
-void ide_tweaks_subpage_generator_populate (IdeTweaksSubpageGenerator *self);
+void ide_tweaks_subpage_factory_set_model (IdeTweaksSubpageFactory *self,
+ GListModel *model);
G_END_DECLS
diff --git a/src/libide/tweaks/libide-tweaks.h b/src/libide/tweaks/libide-tweaks.h
index 88eef35f5..7040a5e73 100644
--- a/src/libide/tweaks/libide-tweaks.h
+++ b/src/libide/tweaks/libide-tweaks.h
@@ -28,6 +28,6 @@
# include "ide-tweaks-page.h"
# include "ide-tweaks-section.h"
# include "ide-tweaks-subpage.h"
-# include "ide-tweaks-subpage-generator.h"
+# include "ide-tweaks-subpage-factory.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 bcde99295..b23c68e1b 100644
--- a/src/libide/tweaks/meson.build
+++ b/src/libide/tweaks/meson.build
@@ -15,7 +15,7 @@ libide_tweaks_public_headers = [
'ide-tweaks-page.h',
'ide-tweaks-section.h',
'ide-tweaks-subpage.h',
- 'ide-tweaks-subpage-generator.h',
+ 'ide-tweaks-subpage-factory.h',
'ide-tweaks-variable.h',
]
@@ -33,7 +33,7 @@ libide_tweaks_public_sources = [
'ide-tweaks-page.c',
'ide-tweaks-section.c',
'ide-tweaks-subpage.c',
- 'ide-tweaks-subpage-generator.c',
+ 'ide-tweaks-subpage-factory.c',
'ide-tweaks-variable.c',
]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]