[gtk/widget-class-actions: 21/22] color chooser widget: Use the new action machinery



commit 7ee4d114dd5865e78c02c749daa682ff3136816d
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jun 15 03:56:45 2019 +0000

    color chooser widget: Use the new action machinery

 gtk/gtkcolorchooserwidget.c | 53 ++++++++++++++++++++-------------------------
 1 file changed, 24 insertions(+), 29 deletions(-)
---
diff --git a/gtk/gtkcolorchooserwidget.c b/gtk/gtkcolorchooserwidget.c
index 4172eb296b..77551490d2 100644
--- a/gtk/gtkcolorchooserwidget.c
+++ b/gtk/gtkcolorchooserwidget.c
@@ -90,8 +90,6 @@ struct _GtkColorChooserWidgetPrivate
   gboolean has_default_palette;
 
   GSettings *settings;
-
-  GActionMap *context_actions;
 };
 
 enum
@@ -493,11 +491,11 @@ add_default_palette (GtkColorChooserWidget *cc)
 }
 
 static void
-customize_color (GSimpleAction *action,
-                 GVariant      *parameter,
-                 gpointer       user_data)
+gtk_color_chooser_widget_activate_color_customize (GtkWidget *widget,
+                                            const char *name,
+                                            GVariant      *parameter)
 {
-  GtkColorChooserWidget *cc = user_data;
+  GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (widget);
   GtkColorChooserWidgetPrivate *priv = gtk_color_chooser_widget_get_instance_private (cc);
   GdkRGBA color;
 
@@ -511,11 +509,11 @@ customize_color (GSimpleAction *action,
 }
 
 static void
-select_color (GSimpleAction *action,
-              GVariant      *parameter,
-              gpointer       user_data)
+gtk_color_chooser_widget_activate_color_select (GtkWidget *widget,
+                                                const char *name,
+                                                GVariant      *parameter)
 {
-  GtkColorChooserWidget *cc = user_data;
+  GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (widget);
   GdkRGBA color;
 
   g_variant_get (parameter, "(dddd)", &color.red, &color.green, &color.blue, &color.alpha);
@@ -524,25 +522,17 @@ select_color (GSimpleAction *action,
 }
 
 static void
-gtk_color_chooser_widget_add_context_actions (GtkColorChooserWidget *cc)
-{
-  GtkColorChooserWidgetPrivate *priv = gtk_color_chooser_widget_get_instance_private (cc);
-
-  GActionEntry entries[] = {
-    { "select", select_color, "(dddd)", NULL, NULL },
-    { "customize", customize_color, "(dddd)", NULL, NULL },
-  };
-
-  GSimpleActionGroup *actions = g_simple_action_group_new ();
-
-  priv->context_actions = G_ACTION_MAP (actions);
-
-  g_action_map_add_action_entries (G_ACTION_MAP (actions), entries, G_N_ELEMENTS (entries), cc);
-
-  gtk_widget_insert_action_group (GTK_WIDGET (cc), "color", G_ACTION_GROUP (actions));
+gtk_color_chooser_widget_query_action (GtkWidget *widget,
+                                       const char *name,
+                                       gboolean *enabled,
+                                       const GVariantType **parameter_type)
+{
+  if (enabled)
+    *enabled = TRUE;
+  if (parameter_type)
+    *parameter_type = G_VARIANT_TYPE ("(dddd)");
 }
 
-
 static void
 gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
 {
@@ -634,8 +624,6 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
   priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
   gtk_size_group_add_widget (priv->size_group, priv->palette);
   gtk_size_group_add_widget (priv->size_group, box);
-
-  gtk_color_chooser_widget_add_context_actions (cc);
 }
 
 /* GObject implementation {{{1 */
@@ -736,6 +724,13 @@ gtk_color_chooser_widget_class_init (GtkColorChooserWidgetClass *class)
                             FALSE, GTK_PARAM_READWRITE));
 
   gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (class), I_("colorchooser"));
+
+  gtk_widget_class_install_action (GTK_WIDGET_CLASS (class), "color.select",
+                                   gtk_color_chooser_widget_activate_color_select,
+                                   gtk_color_chooser_widget_query_action);
+  gtk_widget_class_install_action (GTK_WIDGET_CLASS (class), "color.customize",
+                                   gtk_color_chooser_widget_activate_color_customize,
+                                   gtk_color_chooser_widget_query_action);
 }
 
 /* GtkColorChooser implementation {{{1 */


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