diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-03-18 22:36:31 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-03-22 11:14:07 -0400 |
commit | a29e6dc7ab3e9c184a85d02421ea403668966b61 (patch) | |
tree | 6fcf14020b6ca78c103d033fb7dfe96e214516fc | |
parent | 9b1fea9619f20e91feb017226c418ca3f7a879e3 (diff) | |
download | gtk+-a29e6dc7ab3e9c184a85d02421ea403668966b61.tar.gz |
colorchooser: Stop using ::popup-menu
This signal is going away. Use an action instead.
-rw-r--r-- | gtk/gtkcoloreditor.c | 25 | ||||
-rw-r--r-- | gtk/gtkcolorplane.c | 37 | ||||
-rw-r--r-- | gtk/gtkcolorscale.c | 39 | ||||
-rw-r--r-- | gtk/ui/gtkcoloreditor.ui | 6 |
4 files changed, 82 insertions, 25 deletions
diff --git a/gtk/gtkcoloreditor.c b/gtk/gtkcoloreditor.c index 6f3ac11b6d..58baf5dd8b 100644 --- a/gtk/gtkcoloreditor.c +++ b/gtk/gtkcoloreditor.c @@ -189,35 +189,44 @@ dismiss_current_popup (GtkColorEditor *editor) } static void -popup_edit (GtkWidget *widget, - GtkColorEditor *editor) +popup_edit (GtkWidget *widget, + const char *action_name, + GVariant *parameters) { + GtkColorEditor *editor = GTK_COLOR_EDITOR (widget); GtkWidget *popup = NULL; GtkRoot *root; GtkWidget *focus; gint position; gint s, e; + char *param; + + param = g_variant_get_string (parameters, NULL); - if (widget == editor->priv->sv_plane) + if (strcmp (param, "sv") == 0) { popup = editor->priv->sv_popup; focus = editor->priv->s_entry; position = 0; } - else if (widget == editor->priv->h_slider) + else if (strcmp (param, "h") == 0) { popup = editor->priv->h_popup; focus = editor->priv->h_entry; gtk_range_get_slider_range (GTK_RANGE (editor->priv->h_slider), &s, &e); position = (s + e) / 2; } - else if (widget == editor->priv->a_slider) + else if (strcmp (param, "a") == 0) { popup = editor->priv->a_popup; focus = editor->priv->a_entry; gtk_range_get_slider_range (GTK_RANGE (editor->priv->a_slider), &s, &e); position = (s + e) / 2; } + else + { + g_warning ("unsupported popup_edit parameter %s", param); + } if (popup == editor->priv->current_popup) dismiss_current_popup (editor); @@ -544,8 +553,12 @@ gtk_color_editor_class_init (GtkColorEditorClass *class) gtk_widget_class_bind_template_callback (widget_class, entry_text_changed); gtk_widget_class_bind_template_callback (widget_class, entry_apply); gtk_widget_class_bind_template_callback (widget_class, entry_focus_changed); - gtk_widget_class_bind_template_callback (widget_class, popup_edit); gtk_widget_class_bind_template_callback (widget_class, pick_color); + + gtk_widget_class_install_action (widget_class, "color.edit", "s", popup_edit); + gtk_widget_class_install_action (widget_class, "color.edit", "s", popup_edit); + gtk_widget_class_install_action (widget_class, "color.edit", "s", popup_edit); + } static void diff --git a/gtk/gtkcolorplane.c b/gtk/gtkcolorplane.c index c73b9eec22..36a9ca6b8e 100644 --- a/gtk/gtkcolorplane.c +++ b/gtk/gtkcolorplane.c @@ -28,6 +28,10 @@ #include "gtksnapshot.h" #include "gtkprivate.h" #include "gtkeventcontrollerkey.h" +#include "gtkshortcutcontroller.h" +#include "gtkshortcuttrigger.h" +#include "gtkshortcutaction.h" +#include "gtkshortcut.h" struct _GtkColorPlanePrivate { @@ -244,11 +248,11 @@ static void hold_action (GtkGestureLongPress *gesture, gdouble x, gdouble y, - GtkColorPlane *plane) + GtkWidget *plane) { - gboolean handled; - - g_signal_emit_by_name (plane, "popup-menu", &handled); + gtk_widget_activate_action (plane, + "color.edit", + "s", gtk_widget_get_name (plane)); } static void @@ -344,7 +348,7 @@ static void plane_drag_gesture_begin (GtkGestureDrag *gesture, gdouble start_x, gdouble start_y, - GtkColorPlane *plane) + GtkWidget *plane) { guint button; @@ -352,9 +356,9 @@ plane_drag_gesture_begin (GtkGestureDrag *gesture, if (button == GDK_BUTTON_SECONDARY) { - gboolean handled; - - g_signal_emit_by_name (plane, "popup-menu", &handled); + gtk_widget_activate_action (plane, + "color.edit", + "s", gtk_widget_get_name (plane)); } if (button != GDK_BUTTON_PRIMARY) @@ -363,9 +367,9 @@ plane_drag_gesture_begin (GtkGestureDrag *gesture, return; } - set_cross_cursor (GTK_WIDGET (plane), TRUE); - update_color (plane, start_x, start_y); - gtk_widget_grab_focus (GTK_WIDGET (plane)); + set_cross_cursor (plane, TRUE); + update_color (GTK_COLOR_PLANE (plane), start_x, start_y); + gtk_widget_grab_focus (plane); gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); } @@ -397,6 +401,9 @@ gtk_color_plane_init (GtkColorPlane *plane) GtkEventController *controller; GtkGesture *gesture; AtkObject *atk_obj; + GtkShortcutTrigger *trigger; + GtkShortcutAction *action; + GtkShortcut *shortcut; plane->priv = gtk_color_plane_get_instance_private (plane); @@ -430,6 +437,14 @@ gtk_color_plane_init (GtkColorPlane *plane) g_signal_connect (controller, "key-pressed", G_CALLBACK (key_controller_key_pressed), plane); gtk_widget_add_controller (GTK_WIDGET (plane), controller); + + controller = gtk_shortcut_controller_new (); + trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK), + gtk_keyval_trigger_new (GDK_KEY_Menu, 0)); + action = gtk_action_action_new ("color.edit"); + shortcut = gtk_shortcut_new_with_arguments (trigger, action, "s", "sv"); + gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut); + gtk_widget_add_controller (GTK_WIDGET (plane), controller); } static void diff --git a/gtk/gtkcolorscale.c b/gtk/gtkcolorscale.c index d4bc48452a..56d120b111 100644 --- a/gtk/gtkcolorscale.c +++ b/gtk/gtkcolorscale.c @@ -29,6 +29,10 @@ #include "gtkprivate.h" #include "gtkintl.h" #include "gtksnapshot.h" +#include "gtkshortcutcontroller.h" +#include "gtkshortcuttrigger.h" +#include "gtkshortcutaction.h" +#include "gtkshortcut.h" #include <math.h> @@ -48,7 +52,7 @@ enum static void hold_action (GtkGestureLongPress *gesture, gdouble x, gdouble y, - GtkColorScale *scale); + GtkWidget *scale); G_DEFINE_TYPE_WITH_PRIVATE (GtkColorScale, gtk_color_scale, GTK_TYPE_SCALE) @@ -161,6 +165,29 @@ gtk_color_scale_init (GtkColorScale *scale) } static void +scale_constructed (GObject *object) +{ + GtkColorScale *scale = GTK_COLOR_SCALE (object); + GtkColorScalePrivate *priv = gtk_color_scale_get_instance_private (scale); + GtkEventController *controller; + GtkShortcutTrigger *trigger; + GtkShortcutAction *action; + GtkShortcut *shortcut; + + controller = gtk_shortcut_controller_new (); + trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK), + gtk_keyval_trigger_new (GDK_KEY_Menu, 0)); + action = gtk_action_action_new ("color.edit"); + shortcut = gtk_shortcut_new_with_arguments (trigger, + action, + "s", + priv->type == GTK_COLOR_SCALE_ALPHA + ? "a" : "h"); + gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut); + gtk_widget_add_controller (GTK_WIDGET (scale), controller); +} + +static void scale_get_property (GObject *object, guint prop_id, GValue *value, @@ -223,11 +250,11 @@ static void hold_action (GtkGestureLongPress *gesture, gdouble x, gdouble y, - GtkColorScale *scale) + GtkWidget *scale) { - gboolean handled; - - g_signal_emit_by_name (scale, "popup-menu", &handled); + gtk_widget_activate_action (scale, + "color.edit", + "s", gtk_widget_get_name (scale)); } static void @@ -245,6 +272,7 @@ gtk_color_scale_class_init (GtkColorScaleClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); + object_class->constructed = scale_constructed; object_class->finalize = scale_finalize; object_class->get_property = scale_get_property; object_class->set_property = scale_set_property; @@ -253,6 +281,7 @@ gtk_color_scale_class_init (GtkColorScaleClass *class) g_param_spec_int ("scale-type", P_("Scale type"), P_("Scale type"), 0, 1, 0, GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + } void diff --git a/gtk/ui/gtkcoloreditor.ui b/gtk/ui/gtkcoloreditor.ui index 4075102a5e..d03b287278 100644 --- a/gtk/ui/gtkcoloreditor.ui +++ b/gtk/ui/gtkcoloreditor.ui @@ -83,12 +83,12 @@ </child> <child> <object class="GtkColorScale" id="h_slider"> + <property name="name">h</property> <property name="can-focus">True</property> <property name="orientation">vertical</property> <property name="adjustment">h_adj</property> <property name="draw-value">False</property> <property name="has-origin">False</property> - <signal name="popup-menu" handler="popup_edit" swapped="no"/> <layout> <property name="left-attach">0</property> <property name="top-attach">1</property> @@ -97,6 +97,7 @@ </child> <child> <object class="GtkColorScale" id="a_slider"> + <property name="name">a</property> <property name="can-focus">True</property> <property name="adjustment">a_adj</property> <property name="draw-value">False</property> @@ -105,7 +106,6 @@ <style> <class name="marks-before"/> </style> - <signal name="popup-menu" handler="popup_edit" swapped="no"/> <layout> <property name="left-attach">1</property> <property name="top-attach">2</property> @@ -115,13 +115,13 @@ </child> <child> <object class="GtkColorPlane" id="sv_plane"> + <property name="name">sv</property> <property name="width-request">300</property> <property name="height-request">300</property> <property name="can-focus">True</property> <property name="h-adjustment">h_adj</property> <property name="s-adjustment">s_adj</property> <property name="v-adjustment">v_adj</property> - <signal name="popup-menu" handler="popup_edit" swapped="no"/> <layout> <property name="left-attach">1</property> <property name="top-attach">1</property> |