[gtk/no-varargs-activate] Add a non-varargs variant of activate_action



commit 2405e2711e047b477293bf4a0cba78d5c4785cf1
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jun 24 11:44:26 2019 -0400

    Add a non-varargs variant of activate_action
    
    I recently turned gtk_widget_activate_action()
    into a varargs function. That is more convenient
    from C, but we need a non-varargs variant for
    bindings. So add the old API back, under the
    name gtk_widget_activate_action_variant(),
    with a rename-to annotation.

 docs/reference/gtk/gtk4-sections.txt |  1 +
 gtk/gtkwidget.c                      | 67 ++++++++++++++++++++++--------------
 gtk/gtkwidget.h                      |  4 +++
 3 files changed, 47 insertions(+), 25 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 6d93fc0ebf..a9076529c2 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4628,6 +4628,7 @@ gtk_widget_observe_controllers
 <SUBSECTION Actions>
 gtk_widget_insert_action_group
 gtk_widget_activate_action
+gtk_widget_activate_action_variant
 gtk_widget_activate_default
 GtkWidgetActionActivateFunc
 gtk_widget_class_install_action
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 1768e3cd99..0c653a90f8 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -12424,10 +12424,39 @@ gtk_widget_get_template_child (GtkWidget   *widget,
   return ret;
 }
 
+/**
+ * gtk_widget_activate_action_variant: (rename-to gtk_widget_activate_action)
+ * @widget: a #GtkWidget
+ * @name: the name of the action to activate
+ * @args: (allow-none): parameters to use, or %NULL
+ *
+ * Looks up the action in the action groups associated
+ * with @widget and its ancestors, and activates it.
+ *
+ * If the action is in an action group added with
+ * gtk_widget_insert_action_group(), the @name is
+ * expected to be prefixed with the prefix that was
+ * used when the group was inserted.
+ *
+ * The arguments must match the actions expected parameter
+ * type, as returned by g_action_get_parameter_type().
+ */
+void
+gtk_widget_activate_action_variant (GtkWidget  *widget,
+                                    const char *name,
+                                    GVariant   *args)
+{
+  GtkActionMuxer *muxer;
+
+  muxer = _gtk_widget_get_action_muxer (widget, FALSE);
+  if (muxer)
+    g_action_group_activate_action (G_ACTION_GROUP (muxer), name, args);
+}
+
 /**
  * gtk_widget_activate_action:
  * @widget: a #GtkWidget
- * @name: a prefixed action name
+ * @name: the name of the action to activate
  * @format_string: GVariant format string for arguments or %NULL
  *    for no arguments
  * @...: arguments, as given by format string
@@ -12435,12 +12464,8 @@ gtk_widget_get_template_child (GtkWidget   *widget,
  * Looks up the action in the action groups associated
  * with @widget and its ancestors, and activates it.
  *
- * The action name is expected to be prefixed with the
- * prefix that was used when adding the action group
- * with gtk_widget_insert_action_group().
- *
- * The arguments must match the actions expected parameter
- * type, as returned by g_action_get_parameter_type().
+ * This is a wrapper around gtk_widget_activate_action_variant()
+ * that constructs the @args variant according to @format_string.
  */
 void
 gtk_widget_activate_action (GtkWidget  *widget,
@@ -12448,30 +12473,22 @@ gtk_widget_activate_action (GtkWidget  *widget,
                             const char *format_string,
                             ...)
 {
-  GtkActionMuxer *muxer;
+  GVariant *parameters = NULL;
 
-  muxer = _gtk_widget_get_action_muxer (widget, FALSE);
-  if (muxer)
+  if (format_string != NULL)
     {
-      GVariant *parameters = NULL;
-
-      if (format_string != NULL)
-        {
-          va_list args;
+      va_list args;
 
-          va_start (args, format_string);
-          parameters = g_variant_new_va (format_string, NULL, &args);
-          va_end (args);
+      va_start (args, format_string);
+      parameters = g_variant_new_va (format_string, NULL, &args);
+      va_end (args);
 
-          g_variant_ref_sink (parameters);
-        }
+      g_variant_ref_sink (parameters);
+    }
 
-      g_action_group_activate_action (G_ACTION_GROUP (muxer),
-                                      name,
-                                      parameters);
+  gtk_widget_activate_action_variant (widget, name, parameters);
 
-      g_clear_pointer (&parameters, g_variant_unref);
-    }
+  g_clear_pointer (&parameters, g_variant_unref);
 }
 
 /**
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index dd411945a9..a842d89031 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -980,6 +980,10 @@ void                    gtk_widget_activate_action      (GtkWidget  *widget,
                                                          const char *name,
                                                          const char *format_string,
                                                          ...);
+GDK_AVAILABLE_IN_ALL
+void                    gtk_widget_activate_action_variant (GtkWidget  *widget,
+                                                            const char *name,
+                                                            GVariant   *args);
 
 GDK_AVAILABLE_IN_ALL
 void                   gtk_widget_activate_default      (GtkWidget *widget);


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