[gnome-builder] libide/tweaks: use signal instead of subclass for widgets



commit 3717cdb21e274a8c1658f9f4ea014b6797c14e3f
Author: Christian Hergert <chergert redhat com>
Date:   Fri Aug 12 12:31:27 2022 -0700

    libide/tweaks: use signal instead of subclass for widgets
    
    We don't need to have a subclass since we can connect signals now and
    instead use a signal for IdeTweaksWidget::create(). Plugins can add a
    closure handler for that and then create the widget on demand.

 src/libide/tweaks/ide-tweaks-external.c | 140 --------------------------------
 src/libide/tweaks/ide-tweaks-external.h |  40 ---------
 src/libide/tweaks/ide-tweaks-init.c     |   1 -
 src/libide/tweaks/ide-tweaks-widget.c   |  35 +++++++-
 src/libide/tweaks/libide-tweaks.h       |   1 -
 src/libide/tweaks/meson.build           |   2 -
 6 files changed, 33 insertions(+), 186 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-init.c b/src/libide/tweaks/ide-tweaks-init.c
index 2b513438b..a77a943b7 100644
--- a/src/libide/tweaks/ide-tweaks-init.c
+++ b/src/libide/tweaks/ide-tweaks-init.c
@@ -34,7 +34,6 @@ _ide_tweaks_init (void)
 
   g_type_ensure (IDE_TYPE_TWEAKS);
   g_type_ensure (IDE_TYPE_TWEAKS_ADDIN);
-  g_type_ensure (IDE_TYPE_TWEAKS_EXTERNAL);
   g_type_ensure (IDE_TYPE_TWEAKS_FACTORY);
   g_type_ensure (IDE_TYPE_TWEAKS_GROUP);
   g_type_ensure (IDE_TYPE_TWEAKS_ITEM);
diff --git a/src/libide/tweaks/ide-tweaks-widget.c b/src/libide/tweaks/ide-tweaks-widget.c
index 946647777..2907ac83f 100644
--- a/src/libide/tweaks/ide-tweaks-widget.c
+++ b/src/libide/tweaks/ide-tweaks-widget.c
@@ -24,11 +24,36 @@
 
 #include "ide-tweaks-widget-private.h"
 
-G_DEFINE_ABSTRACT_TYPE (IdeTweaksWidget, ide_tweaks_widget, IDE_TYPE_TWEAKS_ITEM)
+G_DEFINE_TYPE (IdeTweaksWidget, ide_tweaks_widget, IDE_TYPE_TWEAKS_ITEM)
+
+enum {
+  CREATE,
+  N_SIGNALS
+};
+
+static guint signals[N_SIGNALS];
 
 static void
 ide_tweaks_widget_class_init (IdeTweaksWidgetClass *klass)
 {
+  /**
+   * IdeTweaksWidget::create:
+   *
+   * Creates a new #GtkWidget that can be inserted into the #IdeTweaksWindow
+   * representing the item.
+   *
+   * Only the first signal handler is used.
+   *
+   * Returns: (transfer full) (nullable): a #GtkWidget or %NULL
+   */
+  signals [CREATE] =
+    g_signal_new ("create",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (IdeTweaksWidgetClass, create),
+                  g_signal_accumulator_first_wins, NULL,
+                  NULL,
+                  GTK_TYPE_WIDGET, 0);
 }
 
 static void
@@ -39,7 +64,13 @@ ide_tweaks_widget_init (IdeTweaksWidget *self)
 GtkWidget *
 _ide_tweaks_widget_create (IdeTweaksWidget *self)
 {
+  GtkWidget *ret = NULL;
+
   g_return_val_if_fail (IDE_IS_TWEAKS_WIDGET (self), NULL);
 
-  return IDE_TWEAKS_WIDGET_GET_CLASS (self)->create (self);
+  g_signal_emit (self, signals [CREATE], 0, &ret);
+
+  g_return_val_if_fail (!ret || GTK_IS_WIDGET (ret), NULL);
+
+  return ret;
 }
diff --git a/src/libide/tweaks/libide-tweaks.h b/src/libide/tweaks/libide-tweaks.h
index 99ec46cbe..699ffde7e 100644
--- a/src/libide/tweaks/libide-tweaks.h
+++ b/src/libide/tweaks/libide-tweaks.h
@@ -23,7 +23,6 @@
 #define IDE_TWEAKS_INSIDE
 # include "ide-tweaks.h"
 # include "ide-tweaks-addin.h"
-# include "ide-tweaks-external.h"
 # include "ide-tweaks-factory.h"
 # include "ide-tweaks-group.h"
 # include "ide-tweaks-item.h"
diff --git a/src/libide/tweaks/meson.build b/src/libide/tweaks/meson.build
index 7c6d4a98c..5630659ce 100644
--- a/src/libide/tweaks/meson.build
+++ b/src/libide/tweaks/meson.build
@@ -10,7 +10,6 @@ libide_tweaks_public_headers = [
   'libide-tweaks.h',
   'ide-tweaks.h',
   'ide-tweaks-addin.h',
-  'ide-tweaks-external.h',
   'ide-tweaks-factory.h',
   'ide-tweaks-group.h',
   'ide-tweaks-item.h',
@@ -33,7 +32,6 @@ install_headers(libide_tweaks_public_headers, subdir: libide_tweaks_header_subdi
 libide_tweaks_public_sources = [
   'ide-tweaks.c',
   'ide-tweaks-addin.c',
-  'ide-tweaks-external.c',
   'ide-tweaks-factory.c',
   'ide-tweaks-group.c',
   'ide-tweaks-item.c',


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