[gnome-builder] libide/tweaks: add subpage generator type



commit 6d5905cd48a67e60cb66e49435cf00f16ca1fd17
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jul 30 21:23:03 2022 -0700

    libide/tweaks: add subpage generator type
    
    This is a more lazy form of an object that allows content to be generated
    at runtime after merging UI files. The goal here is for things like
    GtkSourceView languages to be filled referencing a templated subpage.

 src/libide/tweaks/example.ui                     |  6 +-
 src/libide/tweaks/ide-tweaks-init.c              |  1 +
 src/libide/tweaks/ide-tweaks-page.c              |  5 +-
 src/libide/tweaks/ide-tweaks-subpage-generator.c | 71 ++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-subpage-generator.h | 44 +++++++++++++++
 src/libide/tweaks/libide-tweaks.h                |  1 +
 src/libide/tweaks/meson.build                    |  4 +-
 7 files changed, 127 insertions(+), 5 deletions(-)
---
diff --git a/src/libide/tweaks/example.ui b/src/libide/tweaks/example.ui
index 1ced660ee..4b1d29288 100644
--- a/src/libide/tweaks/example.ui
+++ b/src/libide/tweaks/example.ui
@@ -33,10 +33,10 @@
       <object class="IdeTweaksPage" id="languages">
         <property name="section">programming</property>
         <property name="title" translatable="yes">Languages</property>
-        <property name="subpage-generator">
-          <object class="IdeTweaksSubpageGenerator">
+        <child>
+          <object class="IdeTweaksSubpageGenerator" id="source_languages">
           </object>
-        </property>
+        </child>
       </object>
     </child>
   </template>
diff --git a/src/libide/tweaks/ide-tweaks-init.c b/src/libide/tweaks/ide-tweaks-init.c
index 4dc019c4c..e7ab4eb41 100644
--- a/src/libide/tweaks/ide-tweaks-init.c
+++ b/src/libide/tweaks/ide-tweaks-init.c
@@ -35,5 +35,6 @@ _ide_tweaks_init (void)
   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_SUBPAGE_GENERATOR);
   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 bb2a65227..e103f5aa6 100644
--- a/src/libide/tweaks/ide-tweaks-page.c
+++ b/src/libide/tweaks/ide-tweaks-page.c
@@ -26,6 +26,7 @@
 #include "ide-tweaks-group.h"
 #include "ide-tweaks-page.h"
 #include "ide-tweaks-subpage.h"
+#include "ide-tweaks-subpage-generator.h"
 
 struct _IdeTweaksPage
 {
@@ -55,7 +56,9 @@ static gboolean
 ide_tweaks_page_accepts (IdeTweaksItem *item,
                          IdeTweaksItem *child)
 {
-  return IDE_IS_TWEAKS_SUBPAGE (child) || IDE_IS_TWEAKS_GROUP (child);
+  return IDE_IS_TWEAKS_SUBPAGE (child) ||
+         IDE_IS_TWEAKS_SUBPAGE_GENERATOR (child) ||
+         IDE_IS_TWEAKS_GROUP (child);
 }
 
 static void
diff --git a/src/libide/tweaks/ide-tweaks-subpage-generator.c 
b/src/libide/tweaks/ide-tweaks-subpage-generator.c
new file mode 100644
index 000000000..eb7fba084
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-subpage-generator.c
@@ -0,0 +1,71 @@
+/* ide-tweaks-subpage-generator.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-generator"
+
+#include "config.h"
+
+#include "ide-tweaks-subpage-generator.h"
+
+typedef struct
+{
+  guint populated : 1;
+} IdeTweaksSubpageGeneratorPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (IdeTweaksSubpageGenerator, ide_tweaks_subpage_generator, IDE_TYPE_TWEAKS_ITEM)
+
+enum {
+  POPULATE,
+  N_SIGNALS
+};
+
+static guint signals [N_SIGNALS];
+
+static void
+ide_tweaks_subpage_generator_class_init (IdeTweaksSubpageGeneratorClass *klass)
+{
+  signals [POPULATE] =
+    g_signal_new ("populate",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (IdeTweaksSubpageGeneratorClass, populate),
+                  NULL, NULL,
+                  NULL,
+                  G_TYPE_NONE, 0);
+}
+
+static void
+ide_tweaks_subpage_generator_init (IdeTweaksSubpageGenerator *self)
+{
+}
+
+void
+ide_tweaks_subpage_generator_populate (IdeTweaksSubpageGenerator *self)
+{
+  IdeTweaksSubpageGeneratorPrivate *priv = ide_tweaks_subpage_generator_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_TWEAKS_SUBPAGE_GENERATOR (self));
+
+  if (!priv->populated)
+    {
+      priv->populated = TRUE;
+      g_signal_emit (self, signals [POPULATE], 0);
+    }
+}
diff --git a/src/libide/tweaks/ide-tweaks-subpage-generator.h 
b/src/libide/tweaks/ide-tweaks-subpage-generator.h
new file mode 100644
index 000000000..dc7a59d2f
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-subpage-generator.h
@@ -0,0 +1,44 @@
+/* ide-tweaks-subpage-generator.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_GENERATOR (ide_tweaks_subpage_generator_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);
+};
+
+IDE_AVAILABLE_IN_ALL
+IdeTweaksSubpageGenerator *ide_tweaks_subpage_generator_new      (void);
+IDE_AVAILABLE_IN_ALL
+void                       ide_tweaks_subpage_generator_populate (IdeTweaksSubpageGenerator *self);
+
+G_END_DECLS
diff --git a/src/libide/tweaks/libide-tweaks.h b/src/libide/tweaks/libide-tweaks.h
index 493bc9abd..664aae70e 100644
--- a/src/libide/tweaks/libide-tweaks.h
+++ b/src/libide/tweaks/libide-tweaks.h
@@ -27,5 +27,6 @@
 # include "ide-tweaks-item.h"
 # include "ide-tweaks-page.h"
 # include "ide-tweaks-subpage.h"
+# include "ide-tweaks-subpage-generator.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 694472537..adff4ee19 100644
--- a/src/libide/tweaks/meson.build
+++ b/src/libide/tweaks/meson.build
@@ -14,6 +14,7 @@ libide_tweaks_public_headers = [
   'ide-tweaks-item.h',
   'ide-tweaks-page.h',
   'ide-tweaks-subpage.h',
+  'ide-tweaks-subpage-generator.h',
   'ide-tweaks-variable.h',
 ]
 
@@ -30,6 +31,7 @@ libide_tweaks_public_sources = [
   'ide-tweaks-group.c',
   'ide-tweaks-page.c',
   'ide-tweaks-subpage.c',
+  'ide-tweaks-subpage-generator.c',
   'ide-tweaks-variable.c',
 ]
 
@@ -71,4 +73,4 @@ gnome_builder_gir_extra_args += ['--c-include=libide-tweaks.h', '-DIDE_TWEAKS_CO
 
 test_tweaks = executable('test-tweaks', 'test-tweaks.c',
   dependencies: [libide_tweaks_dep],
-)
\ No newline at end of file
+)


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