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.
This commit is contained in:
parent
caa47b2ef4
commit
48b9b4520b
@ -561,6 +561,15 @@ activate (GApplication *app)
|
|||||||
{ "search", activate_search, NULL, NULL, NULL },
|
{ "search", activate_search, NULL, NULL, NULL },
|
||||||
{ "delete", activate_delete, NULL, NULL, NULL }
|
{ "delete", activate_delete, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
struct {
|
||||||
|
const gchar *action_and_target;
|
||||||
|
const gchar *accelerators[2];
|
||||||
|
} accels[] = {
|
||||||
|
{ "win.dark", { "<Primary>d", NULL } },
|
||||||
|
{ "win.search", { "<Primary>s", NULL } },
|
||||||
|
{ "win.delete", { "Delete", NULL } }
|
||||||
|
};
|
||||||
|
gint i;
|
||||||
|
|
||||||
builder = gtk_builder_new_from_resource ("/org/gtk/WidgetFactory/widget-factory.ui");
|
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);
|
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),
|
win_entries, G_N_ELEMENTS (win_entries),
|
||||||
window);
|
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");
|
widget = (GtkWidget *)gtk_builder_get_object (builder, "statusbar");
|
||||||
gtk_statusbar_push (GTK_STATUSBAR (widget), 0, "All systems are operating normally.");
|
gtk_statusbar_push (GTK_STATUSBAR (widget), 0, "All systems are operating normally.");
|
||||||
g_action_map_add_action (G_ACTION_MAP (window),
|
g_action_map_add_action (G_ACTION_MAP (window),
|
||||||
@ -665,6 +677,14 @@ main (int argc, char *argv[])
|
|||||||
{ "dessert", NULL, "s", "'bars'", NULL },
|
{ "dessert", NULL, "s", "'bars'", NULL },
|
||||||
{ "pay", NULL, "s", NULL, NULL }
|
{ "pay", NULL, "s", NULL, NULL }
|
||||||
};
|
};
|
||||||
|
struct {
|
||||||
|
const gchar *action_and_target;
|
||||||
|
const gchar *accelerators[2];
|
||||||
|
} accels[] = {
|
||||||
|
{ "app.about", { "F1", NULL } },
|
||||||
|
{ "app.quit", { "<Primary>q", NULL } },
|
||||||
|
};
|
||||||
|
gint i;
|
||||||
gint status;
|
gint status;
|
||||||
|
|
||||||
app = gtk_application_new ("org.gtk.WidgetFactory", G_APPLICATION_NON_UNIQUE);
|
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),
|
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||||
app_entries, G_N_ELEMENTS (app_entries),
|
app_entries, G_N_ELEMENTS (app_entries),
|
||||||
app);
|
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);
|
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user