From cdfcd5fc85b9e7232ce837b28165b5fb77c23863 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 6 May 2014 09:16:28 -0400 Subject: Bloatpad: port to new accel api --- examples/bloatpad.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/bloatpad.c b/examples/bloatpad.c index 840bdc6747..1eae5b6fb2 100644 --- a/examples/bloatpad.c +++ b/examples/bloatpad.c @@ -508,6 +508,7 @@ static void bloat_pad_startup (GApplication *application) { BloatPad *bloatpad = (BloatPad*) application; + GtkApplication *app = GTK_APPLICATION (application); GtkBuilder *builder; GMenu *menu; GMenuItem *item; @@ -517,6 +518,19 @@ bloat_pad_startup (GApplication *application) GFile *file; gchar *data; gsize size; + gint i; + struct { + const gchar *action_and_target; + const gchar *accelerators[2]; + } accels[] = { + { "app.new", { "n", NULL } }, + { "app.quit", { "q", NULL } }, + { "win.copy", { "c", NULL } }, + { "win.paste", { "p", NULL } }, + { "win.justify::left", { "l", NULL } }, + { "win.justify::center", { "m", NULL } }, + { "win.justify::right", { "r", NULL } } + }; G_APPLICATION_CLASS (bloat_pad_parent_class) ->startup (application); @@ -606,15 +620,10 @@ bloat_pad_startup (GApplication *application) " " " " "", -1, NULL); - gtk_application_set_app_menu (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu"))); - gtk_application_set_menubar (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "menubar"))); - gtk_application_add_accelerator (GTK_APPLICATION (application), "n", "app.new", NULL); - gtk_application_add_accelerator (GTK_APPLICATION (application), "q", "app.quit", NULL); - gtk_application_add_accelerator (GTK_APPLICATION (application), "c", "win.copy", NULL); - gtk_application_add_accelerator (GTK_APPLICATION (application), "p", "win.paste", NULL); - gtk_application_add_accelerator (GTK_APPLICATION (application), "l", "win.justify", g_variant_new_string ("left")); - gtk_application_add_accelerator (GTK_APPLICATION (application), "m", "win.justify", g_variant_new_string ("center")); - gtk_application_add_accelerator (GTK_APPLICATION (application), "r", "win.justify", g_variant_new_string ("right")); + gtk_application_set_app_menu (app, G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu"))); + gtk_application_set_menubar (app, G_MENU_MODEL (gtk_builder_get_object (builder, "menubar"))); + for (i = 0; i < G_N_ELEMENTS (accels); i++) + gtk_application_set_accels_for_action (app, accels[i].action_and_target, accels[i].accelerators); menu = G_MENU (gtk_builder_get_object (builder, "icon-menu")); @@ -743,11 +752,12 @@ main (int argc, char **argv) { BloatPad *bloat_pad; int status; + const gchar *accels[] = { "F11", NULL }; bloat_pad = bloat_pad_new (); - gtk_application_add_accelerator (GTK_APPLICATION (bloat_pad), - "F11", "win.fullscreen", NULL); + gtk_application_set_accels_for_action (GTK_APPLICATION (bloat_pad), + "win.fullscreen", accels); status = g_application_run (G_APPLICATION (bloat_pad), argc, argv); -- cgit v1.2.1