tests: Add accelerator example to testmenubutton

https://bugzilla.gnome.org/show_bug.cgi?id=680962
This commit is contained in:
Bastien Nocera 2012-09-12 18:12:41 +01:00
parent 97912acbee
commit 634ebb593c

View File

@ -8,6 +8,7 @@ int main (int argc, char **argv)
GtkWidget *grid; GtkWidget *grid;
GtkWidget *entry; GtkWidget *entry;
GtkWidget *menu_widget; GtkWidget *menu_widget;
GtkAccelGroup *accel_group;
guint i; guint i;
GMenu *menu; GMenu *menu;
@ -19,6 +20,9 @@ int main (int argc, char **argv)
grid = gtk_grid_new (); grid = gtk_grid_new ();
gtk_container_add (GTK_CONTAINER (window), grid); gtk_container_add (GTK_CONTAINER (window), grid);
accel_group = gtk_accel_group_new ();
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
/* Button next to entry */ /* Button next to entry */
entry = gtk_entry_new (); entry = gtk_entry_new ();
gtk_grid_attach (GTK_GRID (grid), gtk_grid_attach (GTK_GRID (grid),
@ -35,11 +39,17 @@ int main (int argc, char **argv)
menu_widget = gtk_menu_new (); menu_widget = gtk_menu_new ();
for (i = 5; i > 0; i--) { for (i = 5; i > 0; i--) {
GtkWidget *item; GtkWidget *item;
if (i == 3) {
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, accel_group);
} else {
char *label; char *label;
label = g_strdup_printf ("Item _%d", i); label = g_strdup_printf ("Item _%d", i);
item = gtk_menu_item_new_with_mnemonic (label); item = gtk_menu_item_new_with_mnemonic (label);
g_free (label); g_free (label);
}
gtk_menu_item_set_use_underline (GTK_MENU_ITEM (item), TRUE);
gtk_menu_attach (GTK_MENU (menu_widget), gtk_menu_attach (GTK_MENU (menu_widget),
item, item,
0, 1, 0, 1,