diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-06-23 22:50:33 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-06-23 22:51:55 +0000 |
commit | 3acc0144999ab1e25bc6408fb3d72c9b05822b61 (patch) | |
tree | 5c1b3c2a3c494bc2af4aa5ded31fe6eac90fdede /gtk | |
parent | 3ebe30bf3261eae5ec22c30533c63fb7a87d7a41 (diff) | |
download | gtk+-3acc0144999ab1e25bc6408fb3d72c9b05822b61.tar.gz |
Make gtk_widget_activate_action better
As a convenience API, this should be easy to use,
so don't expect callers to manually create a
variant, do it for them.
Update all callers.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkcolorswatch.c | 22 | ||||
-rw-r--r-- | gtk/gtktextview.c | 1 | ||||
-rw-r--r-- | gtk/gtkwidget.c | 32 | ||||
-rw-r--r-- | gtk/gtkwidget.h | 3 |
4 files changed, 38 insertions, 20 deletions
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c index 6932fa2413..d17093fe9a 100644 --- a/gtk/gtkcolorswatch.c +++ b/gtk/gtkcolorswatch.c @@ -226,12 +226,11 @@ activate_color (GtkColorSwatch *swatch) { GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch); gtk_widget_activate_action (GTK_WIDGET (swatch), - "color.select", - g_variant_new ("(dddd)", - priv->color.red, - priv->color.green, - priv->color.blue, - priv->color.alpha)); + "color.select", "(dddd)", + priv->color.red, + priv->color.green, + priv->color.blue, + priv->color.alpha); } static void @@ -239,12 +238,11 @@ customize_color (GtkColorSwatch *swatch) { GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch); gtk_widget_activate_action (GTK_WIDGET (swatch), - "color.customize", - g_variant_new ("(dddd)", - priv->color.red, - priv->color.green, - priv->color.blue, - priv->color.alpha)); + "color.customize", "(dddd)", + priv->color.red, + priv->color.green, + priv->color.blue, + priv->color.alpha); } static gboolean diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 01cc8f3ba0..eeede5d3a6 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -8815,7 +8815,6 @@ append_bubble_item (GtkTextView *text_view, const char *icon_name; const char *action_name; GMenuModel *link; - char **split = NULL; gboolean is_toggle_action = FALSE; GActionGroup *group = NULL; gboolean enabled; diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 1aff2005fd..1768e3cd99 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -12428,7 +12428,9 @@ gtk_widget_get_template_child (GtkWidget *widget, * gtk_widget_activate_action: * @widget: a #GtkWidget * @name: a prefixed action name - * @parameter: parameters that required by the action + * @format_string: GVariant format string for arguments or %NULL + * for no arguments + * @...: arguments, as given by format string * * Looks up the action in the action groups associated * with @widget and its ancestors, and activates it. @@ -12437,21 +12439,39 @@ gtk_widget_get_template_child (GtkWidget *widget, * prefix that was used when adding the action group * with gtk_widget_insert_action_group(). * - * The @parameter must match the actions expected parameter + * The arguments must match the actions expected parameter * type, as returned by g_action_get_parameter_type(). */ void gtk_widget_activate_action (GtkWidget *widget, const char *name, - GVariant *parameter) + const char *format_string, + ...) { GtkActionMuxer *muxer; muxer = _gtk_widget_get_action_muxer (widget, FALSE); if (muxer) - g_action_group_activate_action (G_ACTION_GROUP (muxer), - name, - parameter); + { + GVariant *parameters = NULL; + + if (format_string != NULL) + { + va_list args; + + va_start (args, format_string); + parameters = g_variant_new_va (format_string, NULL, &args); + va_end (args); + + g_variant_ref_sink (parameters); + } + + g_action_group_activate_action (G_ACTION_GROUP (muxer), + name, + parameters); + + g_clear_pointer (¶meters, g_variant_unref); + } } /** diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index e2cec9400a..dd411945a9 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -978,7 +978,8 @@ void gtk_widget_insert_action_group (GtkWidget *widget, GDK_AVAILABLE_IN_ALL void gtk_widget_activate_action (GtkWidget *widget, const char *name, - GVariant *parameter); + const char *format_string, + ...); GDK_AVAILABLE_IN_ALL void gtk_widget_activate_default (GtkWidget *widget); |