GNOME Bugzilla – Bug 143007
popup menu: keyboard accelerator does not work while menu is visible
Last modified: 2007-09-02 17:00:51 UTC
* Build the popup menu sample from examples/book/menus/popup. * Run it. * Right-click in the window that opens. * Popup menu appears; one item has an accelerator "Ctrl+P". * Try to activate the accelerator using the keyboard. * Nothing happens. I've verified this with both gtkmm-2.2.11 and gtkmm-2.4.1
Changing version to 2.4, so that I see this.
I have updated this example to use GtkUIManager, by the way. The accelerator (Ctrl+P) does work, but not while the popup menu is visible. I guess we need to check whether it works in C.
I suspect that it would work if the menu item was also in a regular menu bar. Popup menus should just be shortcuts to existing menu items anyway, and I guess that's why they don't also show the keyboard shortcut in the popup menu. Reassigning to GTK+, who may disagree, and may require a C test case.
We are following the Gnome HIG here, actually: "Provide an access key for each item. However, to enhance their spatial efficiency and readability, do not show keyboard shortcuts in popup menus." If you disagree, please reopen against the HIG.
Given that The GIMP people have written a bunch of code to have the accelerators back in their "context menus" - and given that Dia now also uses GtkUIManager and thus has to either lack the accelerators or cut and paste a lof of code to resurrect them: Could there please be some function in Gtk to reenable the accelerators in nested "context menus"? They may be bad from the HIG's point of view, but IMO the toolkit should not enforce the HIG - just make it possible and convenient to follow. And to violate it where appropriate.
I run into probably the same problem just now. I see the assigned key in the popup menu, but pressing it has no effect :/ self->priv->accel_group=gtk_accel_group_new(); self->priv->context_menu=gtk_menu_new(); gtk_menu_set_accel_group(GTK_MENU(self->priv->context_menu), self->priv->accel_group); gtk_menu_set_accel_path(GTK_MENU(self->priv->context_menu),"<Buzztard-Main>/PatternView/PatternContext"); menu_item=gtk_image_menu_item_new_with_label(_("New pattern ...")); image=gtk_image_new_from_stock(GTK_STOCK_NEW,GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item),image); gtk_menu_item_set_accel_path (GTK_MENU_ITEM (menu_item), "<Buzztard-Main>/PatternView/PatternContext/NewPattern"); gtk_accel_map_add_entry ("<Buzztard-Main>/PatternView/PatternContext/NewPattern", GDK_Insert, GDK_CONTROL_MASK|GDK_SHIFT_MASK); gtk_menu_shell_append(GTK_MENU_SHELL(self->priv->context_menu),menu_item); gtk_widget_show(menu_item); g_signal_connect(G_OBJECT(menu_item),"activate",G_CALLBACK(on_context_menu_pattern_new_activate),(gpointer)self); gtk_window_add_accel_group(GTK_WINDOW(main_window),self->priv->accel_group);
My issue is now fixed as of Bug #469374. Not sure if that fixes the issue of the reporter for this bug.