Use an action for the context menu keybinding

The ::popup-menu signal is going away.
This commit is contained in:
Matthias Clasen 2020-03-15 22:25:09 -04:00
parent e8be45fabc
commit 778d884f70
7 changed files with 108 additions and 42 deletions

View File

@ -348,13 +348,12 @@ gtk_color_swatch_measure (GtkWidget *widget,
*natural = MAX (*natural, min); *natural = MAX (*natural, min);
} }
static void
swatch_popup_menu (GtkWidget *widget,
static gboolean const char *action_name,
swatch_popup_menu (GtkWidget *widget) GVariant *parameters)
{ {
do_popup (GTK_COLOR_SWATCH (widget)); do_popup (GTK_COLOR_SWATCH (widget));
return TRUE;
} }
static void static void
@ -480,7 +479,6 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
widget_class->measure = gtk_color_swatch_measure; widget_class->measure = gtk_color_swatch_measure;
widget_class->snapshot = swatch_snapshot; widget_class->snapshot = swatch_snapshot;
widget_class->popup_menu = swatch_popup_menu;
widget_class->size_allocate = swatch_size_allocate; widget_class->size_allocate = swatch_size_allocate;
widget_class->state_flags_changed = swatch_state_flags_changed; widget_class->state_flags_changed = swatch_state_flags_changed;
@ -497,6 +495,17 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
g_param_spec_boolean ("can-drop", P_("Can Drop"), P_("Whether the swatch should accept drops"), g_param_spec_boolean ("can-drop", P_("Can Drop"), P_("Whether the swatch should accept drops"),
FALSE, GTK_PARAM_READWRITE)); FALSE, GTK_PARAM_READWRITE));
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, swatch_popup_menu);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_COLOR_SWATCH_ACCESSIBLE); gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_COLOR_SWATCH_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, I_("colorswatch")); gtk_widget_class_set_css_name (widget_class, I_("colorswatch"));
} }

View File

@ -480,7 +480,9 @@ static void gtk_label_set_markup_internal (GtkLabel *label,
static void gtk_label_recalculate (GtkLabel *label); static void gtk_label_recalculate (GtkLabel *label);
static void gtk_label_root (GtkWidget *widget); static void gtk_label_root (GtkWidget *widget);
static void gtk_label_unroot (GtkWidget *widget); static void gtk_label_unroot (GtkWidget *widget);
static gboolean gtk_label_popup_menu (GtkWidget *widget); static void gtk_label_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters);
static void gtk_label_do_popup (GtkLabel *label, static void gtk_label_do_popup (GtkLabel *label,
double x, double x,
double y); double y);
@ -645,7 +647,6 @@ gtk_label_class_init (GtkLabelClass *class)
widget_class->root = gtk_label_root; widget_class->root = gtk_label_root;
widget_class->unroot = gtk_label_unroot; widget_class->unroot = gtk_label_unroot;
widget_class->mnemonic_activate = gtk_label_mnemonic_activate; widget_class->mnemonic_activate = gtk_label_mnemonic_activate;
widget_class->popup_menu = gtk_label_popup_menu;
widget_class->grab_focus = gtk_label_grab_focus; widget_class->grab_focus = gtk_label_grab_focus;
widget_class->focus = gtk_label_focus; widget_class->focus = gtk_label_focus;
widget_class->get_request_mode = gtk_label_get_request_mode; widget_class->get_request_mode = gtk_label_get_request_mode;
@ -1022,10 +1023,21 @@ gtk_label_class_init (GtkLabelClass *class)
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, label_props); g_object_class_install_properties (gobject_class, NUM_PROPERTIES, label_props);
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_label_popup_menu);
/* /*
* Key bindings * Key bindings
*/ */
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
/* Moving the insertion point */ /* Moving the insertion point */
add_move_binding (widget_class, GDK_KEY_Right, 0, add_move_binding (widget_class, GDK_KEY_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1); GTK_MOVEMENT_VISUAL_POSITIONS, 1);
@ -6059,13 +6071,14 @@ gtk_label_do_popup (GtkLabel *label,
gtk_popover_popup (GTK_POPOVER (priv->popup_menu)); gtk_popover_popup (GTK_POPOVER (priv->popup_menu));
} }
static gboolean static void
gtk_label_popup_menu (GtkWidget *widget) gtk_label_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters)
{ {
GtkLabel *label = GTK_LABEL (widget); GtkLabel *label = GTK_LABEL (widget);
gtk_label_do_popup (label, -1, -1); gtk_label_do_popup (label, -1, -1);
return TRUE;
} }
static void static void

View File

@ -123,7 +123,9 @@ static void gtk_link_button_set_property (GObject *object,
const GValue *value, const GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void gtk_link_button_clicked (GtkButton *button); static void gtk_link_button_clicked (GtkButton *button);
static gboolean gtk_link_button_popup_menu (GtkWidget *widget); static void gtk_link_button_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters);
static gboolean gtk_link_button_query_tooltip_cb (GtkWidget *widget, static gboolean gtk_link_button_query_tooltip_cb (GtkWidget *widget,
gint x, gint x,
gint y, gint y,
@ -169,8 +171,6 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
gobject_class->get_property = gtk_link_button_get_property; gobject_class->get_property = gtk_link_button_get_property;
gobject_class->finalize = gtk_link_button_finalize; gobject_class->finalize = gtk_link_button_finalize;
widget_class->popup_menu = gtk_link_button_popup_menu;
button_class->clicked = gtk_link_button_clicked; button_class->clicked = gtk_link_button_clicked;
klass->activate_link = gtk_link_button_activate_link; klass->activate_link = gtk_link_button_activate_link;
@ -230,6 +230,17 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
gtk_widget_class_install_action (widget_class, "clipboard.copy", NULL, gtk_widget_class_install_action (widget_class, "clipboard.copy", NULL,
gtk_link_button_activate_clipboard_copy); gtk_link_button_activate_clipboard_copy);
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_link_button_popup_menu);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
} }
static GMenuModel * static GMenuModel *
@ -503,11 +514,12 @@ gtk_link_button_clicked (GtkButton *button)
g_signal_emit (button, link_signals[ACTIVATE_LINK], 0, &retval); g_signal_emit (button, link_signals[ACTIVATE_LINK], 0, &retval);
} }
static gboolean static void
gtk_link_button_popup_menu (GtkWidget *widget) gtk_link_button_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters)
{ {
gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), -1, -1); gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), -1, -1);
return TRUE;
} }
/** /**

View File

@ -772,7 +772,9 @@ static void gtk_notebook_dispose (GObject *object);
/*** GtkWidget Methods ***/ /*** GtkWidget Methods ***/
static void gtk_notebook_destroy (GtkWidget *widget); static void gtk_notebook_destroy (GtkWidget *widget);
static void gtk_notebook_unmap (GtkWidget *widget); static void gtk_notebook_unmap (GtkWidget *widget);
static gboolean gtk_notebook_popup_menu (GtkWidget *widget); static void gtk_notebook_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters);
static void gtk_notebook_motion (GtkEventController *controller, static void gtk_notebook_motion (GtkEventController *controller,
double x, double x,
double y, double y,
@ -1046,7 +1048,6 @@ gtk_notebook_class_init (GtkNotebookClass *class)
widget_class->destroy = gtk_notebook_destroy; widget_class->destroy = gtk_notebook_destroy;
widget_class->unmap = gtk_notebook_unmap; widget_class->unmap = gtk_notebook_unmap;
widget_class->popup_menu = gtk_notebook_popup_menu;
widget_class->grab_notify = gtk_notebook_grab_notify; widget_class->grab_notify = gtk_notebook_grab_notify;
widget_class->state_flags_changed = gtk_notebook_state_flags_changed; widget_class->state_flags_changed = gtk_notebook_state_flags_changed;
widget_class->direction_changed = gtk_notebook_direction_changed; widget_class->direction_changed = gtk_notebook_direction_changed;
@ -1310,6 +1311,8 @@ gtk_notebook_class_init (GtkNotebookClass *class)
G_TYPE_FROM_CLASS (gobject_class), G_TYPE_FROM_CLASS (gobject_class),
_gtk_marshal_OBJECT__OBJECTv); _gtk_marshal_OBJECT__OBJECTv);
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_notebook_popup_menu);
gtk_widget_class_add_binding_signal (widget_class, gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_space, 0, GDK_KEY_space, 0,
"select-page", "select-page",
@ -1336,6 +1339,15 @@ gtk_notebook_class_init (GtkNotebookClass *class)
"focus-tab", "focus-tab",
"(i)", GTK_NOTEBOOK_TAB_LAST); "(i)", GTK_NOTEBOOK_TAB_LAST);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
gtk_widget_class_add_binding_signal (widget_class, gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Page_Up, GDK_CONTROL_MASK, GDK_KEY_Page_Up, GDK_CONTROL_MASK,
"change-current-page", "change-current-page",
@ -2599,20 +2611,16 @@ gtk_notebook_gesture_pressed (GtkGestureClick *gesture,
} }
} }
static void
static gboolean gtk_notebook_popup_menu (GtkWidget *widget,
gtk_notebook_popup_menu (GtkWidget *widget) const char *action_name,
GVariant *parameters)
{ {
GtkNotebook *notebook = GTK_NOTEBOOK (widget); GtkNotebook *notebook = GTK_NOTEBOOK (widget);
GtkNotebookPrivate *priv = notebook->priv; GtkNotebookPrivate *priv = notebook->priv;
if (priv->menu) if (priv->menu)
{ gtk_popover_popup (GTK_POPOVER (priv->menu));
gtk_popover_popup (GTK_POPOVER (priv->menu));
return TRUE;
}
return FALSE;
} }
static void static void

View File

@ -389,7 +389,9 @@ static void gtk_text_set_alignment (GtkText *self,
/* Default signal handlers /* Default signal handlers
*/ */
static GMenuModel *gtk_text_get_menu_model (GtkText *self); static GMenuModel *gtk_text_get_menu_model (GtkText *self);
static gboolean gtk_text_popup_menu (GtkWidget *widget); static void gtk_text_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters);
static void gtk_text_move_cursor (GtkText *self, static void gtk_text_move_cursor (GtkText *self,
GtkMovementStep step, GtkMovementStep step,
int count, int count,
@ -727,7 +729,6 @@ gtk_text_class_init (GtkTextClass *class)
widget_class->state_flags_changed = gtk_text_state_flags_changed; widget_class->state_flags_changed = gtk_text_state_flags_changed;
widget_class->root = gtk_text_root; widget_class->root = gtk_text_root;
widget_class->mnemonic_activate = gtk_text_mnemonic_activate; widget_class->mnemonic_activate = gtk_text_mnemonic_activate;
widget_class->popup_menu = gtk_text_popup_menu;
class->move_cursor = gtk_text_move_cursor; class->move_cursor = gtk_text_move_cursor;
class->insert_at_cursor = gtk_text_insert_at_cursor; class->insert_at_cursor = gtk_text_insert_at_cursor;
@ -1195,11 +1196,21 @@ gtk_text_class_init (GtkTextClass *class)
gtk_widget_class_install_action (widget_class, "text.undo", NULL, gtk_text_real_undo); gtk_widget_class_install_action (widget_class, "text.undo", NULL, gtk_text_real_undo);
gtk_widget_class_install_action (widget_class, "text.redo", NULL, gtk_text_real_redo); gtk_widget_class_install_action (widget_class, "text.redo", NULL, gtk_text_real_redo);
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_text_popup_menu);
/* /*
* Key bindings * Key bindings
*/ */
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
/* Moving the insertion point */ /* Moving the insertion point */
add_move_binding (widget_class, GDK_KEY_Right, 0, add_move_binding (widget_class, GDK_KEY_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1); GTK_MOVEMENT_VISUAL_POSITIONS, 1);
@ -5871,11 +5882,12 @@ gtk_text_mnemonic_activate (GtkWidget *widget,
return GDK_EVENT_STOP; return GDK_EVENT_STOP;
} }
static gboolean static void
gtk_text_popup_menu (GtkWidget *widget) gtk_text_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters)
{ {
gtk_text_do_popup (GTK_TEXT (widget), -1, -1); gtk_text_do_popup (GTK_TEXT (widget), -1, -1);
return TRUE;
} }
static void static void

View File

@ -443,7 +443,9 @@ static gboolean gtk_text_view_drag_drop (GtkDropTarget *dest,
double y, double y,
GtkTextView *text_view); GtkTextView *text_view);
static gboolean gtk_text_view_popup_menu (GtkWidget *widget); static void gtk_text_view_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters);
static void gtk_text_view_move_cursor (GtkTextView *text_view, static void gtk_text_view_move_cursor (GtkTextView *text_view,
GtkMovementStep step, GtkMovementStep step,
gint count, gint count,
@ -823,8 +825,6 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
widget_class->snapshot = gtk_text_view_snapshot; widget_class->snapshot = gtk_text_view_snapshot;
widget_class->focus = gtk_text_view_focus; widget_class->focus = gtk_text_view_focus;
widget_class->popup_menu = gtk_text_view_popup_menu;
container_class->add = gtk_text_view_add; container_class->add = gtk_text_view_add;
container_class->remove = gtk_text_view_remove; container_class->remove = gtk_text_view_remove;
container_class->forall = gtk_text_view_forall; container_class->forall = gtk_text_view_forall;
@ -1467,11 +1467,21 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
gtk_widget_class_install_action (widget_class, "text.undo", NULL, gtk_text_view_real_undo); gtk_widget_class_install_action (widget_class, "text.undo", NULL, gtk_text_view_real_undo);
gtk_widget_class_install_action (widget_class, "text.redo", NULL, gtk_text_view_real_redo); gtk_widget_class_install_action (widget_class, "text.redo", NULL, gtk_text_view_real_redo);
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_text_view_popup_menu);
/* /*
* Key bindings * Key bindings
*/ */
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
/* Moving the insertion point */ /* Moving the insertion point */
add_move_binding (widget_class, GDK_KEY_Right, 0, add_move_binding (widget_class, GDK_KEY_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1); GTK_MOVEMENT_VISUAL_POSITIONS, 1);
@ -8677,11 +8687,12 @@ gtk_text_view_do_popup (GtkTextView *text_view,
gdk_event_unref (trigger_event); gdk_event_unref (trigger_event);
} }
static gboolean static void
gtk_text_view_popup_menu (GtkWidget *widget) gtk_text_view_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters)
{ {
gtk_text_view_do_popup (GTK_TEXT_VIEW (widget), NULL); gtk_text_view_do_popup (GTK_TEXT_VIEW (widget), NULL);
return TRUE;
} }
static void static void

View File

@ -365,6 +365,7 @@ test_introspection (void)
{ GTK_TYPE_TEXT, "clipboard.paste", NULL, NULL }, { GTK_TYPE_TEXT, "clipboard.paste", NULL, NULL },
{ GTK_TYPE_TEXT, "clipboard.copy", NULL, NULL }, { GTK_TYPE_TEXT, "clipboard.copy", NULL, NULL },
{ GTK_TYPE_TEXT, "clipboard.cut", NULL, NULL }, { GTK_TYPE_TEXT, "clipboard.cut", NULL, NULL },
{ GTK_TYPE_TEXT, "menu.popup", NULL, NULL },
{ GTK_TYPE_TEXT, "text.redo", NULL, NULL }, { GTK_TYPE_TEXT, "text.redo", NULL, NULL },
{ GTK_TYPE_TEXT, "text.undo", NULL, NULL }, { GTK_TYPE_TEXT, "text.undo", NULL, NULL },
}; };
@ -378,9 +379,9 @@ test_introspection (void)
&property)) &property))
{ {
g_assert (expected[i].owner == owner); g_assert (expected[i].owner == owner);
g_assert (strcmp (expected[i].name, name) == 0); g_assert_cmpstr (expected[i].name, ==, name);
g_assert (g_strcmp0 (expected[i].params, params ? g_variant_type_peek_string (params) : NULL) == 0); g_assert_cmpstr (expected[i].params, ==, params ? g_variant_type_peek_string (params) : NULL);
g_assert (g_strcmp0 (expected[i].property, property) == 0); g_assert_cmpstr (expected[i].property, ==, property);
i++; i++;
} }
g_assert (i == G_N_ELEMENTS (expected)); g_assert (i == G_N_ELEMENTS (expected));