After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 680962 - GtkMenuButton doesn't display accelerators when used with GtkMenu
GtkMenuButton doesn't display accelerators when used with GtkMenu
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: general
3.7.x
Other Linux
: Normal normal
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
: 683133 692959 693745 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2012-08-01 10:22 UTC by Cosimo Cecchi
Modified: 2013-02-14 14:50 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Cosimo Cecchi 2012-08-01 10:22:35 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.
Comment 1 Cosimo Cecchi 2012-08-31 19:36:10 UTC
*** Bug 683133 has been marked as a duplicate of this bug. ***
Comment 2 Bastien Nocera 2012-09-10 16:40:13 UTC
(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
Comment 3 Cosimo Cecchi 2012-09-10 21:59:08 UTC
(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.
Comment 4 Bastien Nocera 2012-09-12 17:23:07 UTC
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
Comment 5 Cosimo Cecchi 2012-09-12 18:04:21 UTC
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
Comment 6 Bastien Nocera 2012-09-13 15:16:06 UTC
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.
Comment 7 Allison Karlitskaya (desrt) 2012-09-13 15:41:27 UTC
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).
Comment 8 António Fernandes 2013-02-02 14:51:46 UTC
*** Bug 692959 has been marked as a duplicate of this bug. ***
Comment 9 Juanjo Marín 2013-02-13 22:02:07 UTC
*** Bug 693745 has been marked as a duplicate of this bug. ***
Comment 10 Juanjo Marín 2013-02-13 22:07:15 UTC
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"/>
Comment 11 Cosimo Cecchi 2013-02-14 14:47:54 UTC
-> nautilus

Oh! So this is a nautilus bug after all.
Comment 12 Cosimo Cecchi 2013-02-14 14:50:03 UTC
Thanks a lot for tracking this down, Juanjo. I now pushed a patch to git master that fixes this.