accelerators for popup menu



Hi,

I'm trying to add accelerators to a popup menu (aka context menu, aka
right-click menu) using a gtk_accel_group. I add an accelerator to the
menuitem and attach the accel group to the menu widget: e.g:

{
...
accel = gtk_accel_group_new();
menu = gtk_menu_new(); 
item = gtk_menu_item_new_with_label("Item1");
gtk_widget_show(item);
gtk_menu_append(GTK_MENU(menu), item);
gtk_signal_connect(GTK_OBJECT(item), "activate", 
                   GTK_SIGNAL_FUNC(callback), NULL);
gtk_accel_group_add(accel, 's', 0, GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE,  
                     GTK_OBJECT(item), "activate");
gtk_accel_group_attach(accel, GTK_OBJECT(menu));
...
}

The accelerator work: I open the context menu and when I type 's', the
callback function is called but then the menu remains open and I like it
to close after activation. I don't know of any application that uses
keyboard shortcuts in context menus, so I have no idea how to do it.

Any idea ? Thanks.

-- 
Melvin Hadasht



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]