[gnome-builder] libide/tweaks: add signal to handle cloned widgets



commit c8fea13caabb8bb2e3f7afb0ef092bd1e9bb8875
Author: Christian Hergert <chergert redhat com>
Date:   Mon Aug 15 17:52:24 2022 -0700

    libide/tweaks: add signal to handle cloned widgets
    
    This can be handy so that we don't route through the original object and
    instead handle via the cloned object.

 src/libide/tweaks/ide-tweaks-widget.c | 55 ++++++++++++++++++++++++++++++++++-
 src/libide/tweaks/ide-tweaks-widget.h |  4 ++-
 2 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-widget.c b/src/libide/tweaks/ide-tweaks-widget.c
index e189e1d83..a0fe675e4 100644
--- a/src/libide/tweaks/ide-tweaks-widget.c
+++ b/src/libide/tweaks/ide-tweaks-widget.c
@@ -33,6 +33,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (IdeTweaksWidget, ide_tweaks_widget, IDE_TYPE_TWEAKS_
 
 enum {
   CREATE,
+  CREATE_FOR_ITEM,
   N_SIGNALS
 };
 
@@ -54,6 +55,15 @@ ide_tweaks_widget_copy (IdeTweaksItem *item)
   return copy;
 }
 
+static GtkWidget *
+ide_tweaks_widget_real_create_for_item (IdeTweaksWidget *self,
+                                        IdeTweaksItem   *item)
+{
+  GtkWidget *ret = NULL;
+  g_signal_emit (self, signals [CREATE], 0, &ret);
+  return ret;
+}
+
 static void
 ide_tweaks_widget_dispose (GObject *object)
 {
@@ -75,6 +85,8 @@ ide_tweaks_widget_class_init (IdeTweaksWidgetClass *klass)
 
   object_class->dispose = ide_tweaks_widget_dispose;
 
+  klass->create_for_item = ide_tweaks_widget_real_create_for_item;
+
   /**
    * IdeTweaksWidget::create:
    *
@@ -93,6 +105,32 @@ ide_tweaks_widget_class_init (IdeTweaksWidgetClass *klass)
                   g_signal_accumulator_first_wins, NULL,
                   NULL,
                   GTK_TYPE_WIDGET, 0);
+
+  /**
+   * IdeTweaksWidget::create-for-item:
+   * @self: an #IdeTweaksWidget
+   * @item: the original #IdeTweaksItem which might be a clone
+   *
+   * Creates a new #GtkWidget that can be inserted into the #IdeTweaksWindow
+   * representing the item.
+   *
+   * @item is the original item (which might be a clone) to create the
+   * widget for.
+   *
+   * Only the first signal handler is used.
+   *
+   * Returns: (transfer full) (nullable): a #GtkWidget or %NULL
+   */
+  signals [CREATE_FOR_ITEM] =
+    g_signal_new ("create-for-item",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (IdeTweaksWidgetClass, create_for_item),
+                  g_signal_accumulator_first_wins, NULL,
+                  NULL,
+                  GTK_TYPE_WIDGET,
+                  1,
+                  IDE_TYPE_TWEAKS_ITEM);
 }
 
 static void
@@ -100,6 +138,21 @@ ide_tweaks_widget_init (IdeTweaksWidget *self)
 {
 }
 
+static GtkWidget *
+_ide_tweaks_widget_create_for_item (IdeTweaksWidget *self,
+                                    IdeTweaksItem   *item)
+{
+  GtkWidget *ret = NULL;
+
+  g_return_val_if_fail (IDE_IS_TWEAKS_WIDGET (self), NULL);
+
+  g_signal_emit (self, signals [CREATE_FOR_ITEM], 0, item, &ret);
+
+  g_return_val_if_fail (!ret || GTK_IS_WIDGET (ret), NULL);
+
+  return ret;
+}
+
 GtkWidget *
 _ide_tweaks_widget_create (IdeTweaksWidget *self)
 {
@@ -109,7 +162,7 @@ _ide_tweaks_widget_create (IdeTweaksWidget *self)
   g_return_val_if_fail (IDE_IS_TWEAKS_WIDGET (self), NULL);
 
   if (priv->cloned != NULL)
-    return _ide_tweaks_widget_create (priv->cloned);
+    return _ide_tweaks_widget_create_for_item (priv->cloned, IDE_TWEAKS_ITEM (self));
 
   g_signal_emit (self, signals [CREATE], 0, &ret);
 
diff --git a/src/libide/tweaks/ide-tweaks-widget.h b/src/libide/tweaks/ide-tweaks-widget.h
index 3f9e39c66..0d9fa0402 100644
--- a/src/libide/tweaks/ide-tweaks-widget.h
+++ b/src/libide/tweaks/ide-tweaks-widget.h
@@ -39,7 +39,9 @@ struct _IdeTweaksWidgetClass
 {
   IdeTweaksItemClass parent_class;
 
-  GtkWidget *(*create) (IdeTweaksWidget *self);
+  GtkWidget *(*create)          (IdeTweaksWidget *self);
+  GtkWidget *(*create_for_item) (IdeTweaksWidget *self,
+                                 IdeTweaksItem   *item);
 };
 
 G_END_DECLS


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