diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c index 3653b763bf..52c9988b66 100644 --- a/demos/widget-factory/widget-factory.c +++ b/demos/widget-factory/widget-factory.c @@ -1816,21 +1816,27 @@ activate (GApplication *app) { "app.about", { "F1", NULL } }, { "app.quit", { "q", NULL } }, { "app.open-in", { "n", NULL } }, - { "app.cut", { "x", NULL } }, - { "app.copy", { "c", NULL } }, - { "app.paste", { "v", NULL } }, { "win.dark", { "d", NULL } }, { "win.search", { "s", NULL } }, - { "win.delete", { "Delete", NULL } }, { "win.background", { "b", NULL } }, { "win.open", { "o", NULL } }, { "win.record", { "r", NULL } }, { "win.lock", { "l", NULL } }, }; + struct { + const gchar *action_and_target; + const gchar *accelerators[2]; + } late_accels[] = { + { "app.cut", { "x", NULL } }, + { "app.copy", { "c", NULL } }, + { "app.paste", { "v", NULL } }, + { "win.delete", { "Delete", NULL } }, + }; gint i; GPermission *permission; GAction *action; GError *error = NULL; + GtkEventController *controller; g_type_ensure (my_text_view_get_type ()); @@ -1870,6 +1876,24 @@ activate (GApplication *app) win_entries, G_N_ELEMENTS (win_entries), window); + controller = gtk_shortcut_controller_new (); + gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE); + + for (i = 0; i < G_N_ELEMENTS (late_accels); i++) + { + guint key; + GdkModifierType mods; + GtkShortcutTrigger *trigger; + GtkShortcutAction *ac; + + gtk_accelerator_parse (late_accels[i].accelerators[0], &key, &mods); + trigger = gtk_keyval_trigger_new (key, mods); + ac = gtk_named_action_new (late_accels[i].action_and_target); + gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), + gtk_shortcut_new (trigger, ac)); + } + gtk_widget_add_controller (GTK_WIDGET (window), controller); + for (i = 0; i < G_N_ELEMENTS (accels); i++) gtk_application_set_accels_for_action (GTK_APPLICATION (app), accels[i].action_and_target, accels[i].accelerators);