From 48b9b4520b9bee794c712d3846142f6b86aa9284 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 20 Jul 2014 00:15:03 -0400 Subject: [PATCH] widget-factory: Add accelerators for some actions With this, Ctrl-Q will close the window, and Ctrl-D will toggle the dark theme. The accelerators are currently not shown in the (manually constructed) menus. --- demos/widget-factory/widget-factory.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c index 97f65b6344..e666f0864a 100644 --- a/demos/widget-factory/widget-factory.c +++ b/demos/widget-factory/widget-factory.c @@ -561,6 +561,15 @@ activate (GApplication *app) { "search", activate_search, NULL, NULL, NULL }, { "delete", activate_delete, NULL, NULL, NULL } }; + struct { + const gchar *action_and_target; + const gchar *accelerators[2]; + } accels[] = { + { "win.dark", { "d", NULL } }, + { "win.search", { "s", NULL } }, + { "win.delete", { "Delete", NULL } } + }; + gint i; builder = gtk_builder_new_from_resource ("/org/gtk/WidgetFactory/widget-factory.ui"); gtk_builder_add_callback_symbol (builder, "on_entry_icon_release", (GCallback)on_entry_icon_release); @@ -572,6 +581,9 @@ activate (GApplication *app) win_entries, G_N_ELEMENTS (win_entries), window); + 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); + widget = (GtkWidget *)gtk_builder_get_object (builder, "statusbar"); gtk_statusbar_push (GTK_STATUSBAR (widget), 0, "All systems are operating normally."); g_action_map_add_action (G_ACTION_MAP (window), @@ -665,6 +677,14 @@ main (int argc, char *argv[]) { "dessert", NULL, "s", "'bars'", NULL }, { "pay", NULL, "s", NULL, NULL } }; + struct { + const gchar *action_and_target; + const gchar *accelerators[2]; + } accels[] = { + { "app.about", { "F1", NULL } }, + { "app.quit", { "q", NULL } }, + }; + gint i; gint status; app = gtk_application_new ("org.gtk.WidgetFactory", G_APPLICATION_NON_UNIQUE); @@ -672,6 +692,8 @@ main (int argc, char *argv[]) g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), app); + 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); g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);