GNOME Bugzilla – Bug 680962
GtkMenuButton doesn't display accelerators when used with GtkMenu
Last modified: 2013-02-14 14:50:03 UTC
Creating a GtkMenu and packing it into a GtkMenuButton fails to display accelerators in the resulting popup. It appears to work fine instead if a GMenuModel is used.
*** Bug 683133 has been marked as a duplicate of this bug. ***
(In reply to comment #0) > Creating a GtkMenu and packing it into a GtkMenuButton fails to display > accelerators in the resulting popup. It appears to work fine instead if a > GMenuModel is used. Not quite. It's broken in both cases, try to put your mouse over the menu itself rather than leaving it on the button. The code to change would be in gtk/gtkmenushell.c _gtk_menu_shell_update_mnemonics(). We could force "mnemonics_visible" if the target was a GtkMenuButton. I added a test to tests/testmenubutton: commit 4519fb53fcb97360e3be01f5b72eb2d1dc895955 Author: Bastien Nocera <hadess@hadess.net> Date: Mon Sep 10 17:38:35 2012 +0100 tests: Add test for mnemonics in GtkMenuButton To check https://bugzilla.gnome.org/show_bug.cgi?id=680962
(In reply to comment #2) > Not quite. It's broken in both cases, try to put your mouse over the menu > itself rather than leaving it on the button. > > The code to change would be in gtk/gtkmenushell.c > _gtk_menu_shell_update_mnemonics(). > We could force "mnemonics_visible" if the target was a GtkMenuButton. Note that this bug is about accelerator labels being displayed, not mnemonics.
You need to set the accel group yourself in this case, as you would have before. I'm really not sure that we should be doing this automatically, as it only worked in the past if you used GtkActions for example, never if you constructed the menu by hand. commit 634ebb593c1a61638d2ad4187ce82dd6c746a57a Author: Bastien Nocera <hadess@hadess.net> Date: Wed Sep 12 18:12:41 2012 +0100 tests: Add accelerator example to testmenubutton https://bugzilla.gnome.org/show_bug.cgi?id=680962
I am using GtkActions with GtkUIManager, and calling gtk_window_add_accel_group() with the GtkUIManager's accel group, see [1]. [1] http://git.gnome.org/browse/nautilus/tree/src/nautilus-window-menus.c#n753
The way that gtkmenubar does it is pretty gross: http://git.gnome.org/browse/gtk+/tree/gtk/gtkmenubar.c#n790 Ryan, you're apparently working in that problem space, opinions welcome.
Bug 683738 is more or less aimed at simplifying how this works for sake of GMenuModel-created GtkMenu. Basically: treat the accel as strictly presentational and force the user to specify what they want to appear in that spot as part of the GMenuModel. That's what I want to do for this cycle to get things out the door. It's kinda inconvenient because it forces the accels to be listed in the menumodel (which currently forces duplication because we have no way to construct menuitems from action descriptions using GActionGroup) and it gets the job done. In the longterm it's starting to become clear that we are going to need some sort of an accel context that works in a similar way to how our new action context works and possibly sharing the same mechanism (ie: widgets can 'look up' the widget tree and across attach-to boundaries to find their accels). GtkMenuButton is causing a lot of the old hacks to fall apart in some pretty unfortunate ways. In addition, the recent discussion on gtk-devel-list is providing some indication that at least some people still love the party that is dynamic accelerator changes (which means that simply constructing widgets/menuitems with the accel set from an original action description with no ability to update it won't fly).
*** Bug 692959 has been marked as a duplicate of this bug. ***
*** Bug 693745 has been marked as a duplicate of this bug. ***
Hi, I've realized that if I add accelerators="true" in /src/nautilus-shell-ui.xml in the ViewMenu and ActionMenu the accelerators are shown. diff --git a/src/nautilus-shell-ui.xml b/src/nautilus-shell-ui.xml index 2fb2961..4cb7348 100644 --- a/src/nautilus-shell-ui.xml +++ b/src/nautilus-shell-ui.xml @@ -15,7 +15,7 @@ <accelerator action="ZoomOutAccel"/> <accelerator action="PromptLocationAccel"/> <accelerator action="ReloadAccel"/> -<popup name="ViewMenu"> +<popup name="ViewMenu" accelerators="true"> <placeholder name="Zoom Items Placeholder"> <menuitem name="Zoom In" action="Zoom In"/> <menuitem name="Zoom Out" action="Zoom Out"/> @@ -33,7 +33,7 @@ <separator/> <placeholder name="View Details"/> </popup> -<popup name="ActionMenu"> +<popup name="ActionMenu" accelerators="true"> <placeholder name="New Items Placeholder"> <menuitem name="New Tab" action="New Tab"/> <menuitem name="New Window" action="New Window"/>
-> nautilus Oh! So this is a nautilus bug after all.
Thanks a lot for tracking this down, Juanjo. I now pushed a patch to git master that fixes this.