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 611724 - [GSEAL] GtkMenuShell::active_menu_item sealed but not retrievable
[GSEAL] GtkMenuShell::active_menu_item sealed but not retrievable
Product: gtk+
Classification: Platform
Component: Widget: GtkMenu
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
Depends on:
Blocks: 597610 612481
Reported: 2010-03-03 17:47 UTC by Cody Russell
Modified: 2011-02-04 16:12 UTC
See Also:
GNOME target: ---
GNOME version: ---

Proposed patch (1.39 KB, patch)
2010-03-05 09:20 UTC, Cody Russell
none Details | Review
Updated patch (1.54 KB, patch)
2010-03-10 17:25 UTC, Cody Russell
none Details | Review
Updated patch, followed documentation of other functions (2.19 KB, patch)
2010-04-30 17:50 UTC, Garrett Regier
none Details | Review
gtk_menu_shell_get_selected_item, like comment #6 (1.80 KB, patch)
2010-05-10 10:59 UTC, Christian Dywan
none Details | Review
git format patch for adding the new gtk_menu_shell_get_selected_item function (2.33 KB, patch)
2010-10-07 14:57 UTC, Didier Roche
none Details | Review

Description Cody Russell 2010-03-03 17:47:27 UTC
Title says it all.  I found a case where I want to know which menuitem is currently active (if you open a menu and key down to a certain menuitem).  This is determined by GtkMenuShell::active_menu_item, which is now seal'd but there is no accessor for it.

gtk_menu_get_active() doesn't work, this retrieves the last meuitem which was actually selected by hitting enter/return on it.

Can file a patch later.
Comment 1 Cody Russell 2010-03-05 09:20:01 UTC
Created attachment 155290 [details] [review]
Proposed patch
Comment 2 Christian Dywan 2010-03-05 17:03:47 UTC
Where are you planning on using this function?

The patch lacks documentation.
Comment 3 Cody Russell 2010-03-10 17:25:19 UTC
Created attachment 155765 [details] [review]
Updated patch

Add some documentation.
Comment 4 Cody Russell 2010-03-10 17:26:32 UTC
I forgot exactly where I'm using it now, but last week there was a place at work that I needed to know the active menuitem in a menu.
Comment 5 Christian Dywan 2010-03-19 16:03:28 UTC
I think you need to be more explicit in the documentation, as right now it doesn't explain the difference between gtk_menu_get_active and gtk_menu_shell_get_active_item.
Comment 6 Cody Russell 2010-03-20 18:34:51 UTC
How about I change it to gtk_menu_shell_get_selected_item() and document it as this:

+ * gtk_menu_shell_get_selected_item:
+ * @menu_shell: a #GtkMenuShell
+ *
+ * Retrieves a pointer to the currently selected menuitem,
+ * or %NULL if there is no menuitem currently selected.  A
+ * currently selected menuitem is one that is currently
+ * being displayed in the prelight state.
+ *
+ * Since: 2.20
+ **/

Because the documentation at the top of gtkmenushell.c says:

 * A menu is "active" when it is visible onscreen and the user
 * is selecting from it. A menubar is not active until the user
 * clicks on one of its menuitems. When a menu is active,
 * passing the mouse over a submenu will pop it up.
 * menu_shell->active_menu_item, is however, not an "active"
 * menu item (there is no such thing) but rather, the selected
 * menu item in that MenuShell, if there is one.
Comment 7 Cody Russell 2010-03-20 18:36:18 UTC
btw, mclasen is planning to do a 2.20 release really soon I think.  If this documentation is still not perfect, can we at least get this into master ASAP and discuss the documentation further after that if need be?
Comment 8 Matthias Clasen 2010-03-20 22:26:39 UTC
I'm not taking api additions at this point. Any accessors that are still missing have missed the window for this cycle.
Comment 9 Garrett Regier 2010-04-30 17:50:16 UTC
Created attachment 159986 [details] [review]
Updated patch, followed documentation of other functions
Comment 10 Christian Dywan 2010-05-10 10:54:45 UTC
I personally prefer the wording in comment #6 over the latest patch, it sounds more natural to me. Note that it lacks the Return value: line.
Comment 11 Christian Dywan 2010-05-10 10:59:29 UTC
Created attachment 160709 [details] [review]
gtk_menu_shell_get_selected_item, like comment #6
Comment 12 Matthias Clasen 2010-06-24 04:56:32 UTC
"I forgot exactly where I'm using it now, but last week there was a place at work"

Seems a bit weak as use case...

As for the patch itself, the documentation is terribly confusing now, since it constantly talks about 'currently selected' whereas the explanatory text in gtkmenushell.c explains 'selected' and 'current' as two different concepts.
Comment 13 Javier Jardón (IRC: jjardon) 2010-09-24 15:23:28 UTC
2.22 has been released. Change target milestore to 2.24
Comment 14 Didier Roche 2010-10-07 14:57:44 UTC
Created attachment 171902 [details] [review]
git format patch for adding the new gtk_menu_shell_get_selected_item function
Comment 15 Didier Roche 2010-10-07 14:59:08 UTC
Just attached a git format patch from the previous one (feel free to change the commiter).

I think I just came across the case Cody was looking for:
you can want to have a different behavior for key press depending on the menu item.

For instance, if you have a slider in the menu (as we do with indicator-sound), you want left and right to not switch to the next menu, but control the slider instead. I think similar case can happen with banshee and the rating integrated to their menu. For that, knowing on which is current menu item (as defined below) is needed.

In addition to Cody's comment, I saw that in gtkmenushell.c, as you pointed:

 * There is also is a concept of the current menu and a current
 * menu item. The current menu item is the selected menu item
 * that is furthest down in the hierarchy. (Every active menu_shell
 * does not necessarily contain a selected menu item, but if
 * it does, then menu_shell->parent_menu_shell must also contain
 * a selected menu item. The current menu is the menu that 
 * contains the current menu_item. It will always have a GTK
 * grab and receive all key presses.

So, I guess in that case, the function should still be named "gtk_menu_shell_get_selected_item", isn't it? I'm attaching a patch which changes the documentation to remove the "current" name usage:

 * gtk_menu_shell_get_selected_item:
 * @menu_shell: a #GtkMenuShell
 * Retrieves a pointer to the selected menuitem, or %NULL
 * if there is no menuitem selected. A selected menuitem is
 * one that is displayed in the prelight state for that menu.
 * Return value: a #GtkWidget or %NULL in case there is no
 * selected menuitem
 * Since: 2.24

If you have any remark/question, do not hesitate
Comment 16 Matthias Clasen 2011-01-04 23:14:46 UTC
gtk_menu_shell_get_selected_item was added a while ago.
Comment 17 Didier Roche 2011-01-05 08:46:08 UTC
12 days ago it seems, by yourself:

Another example of a patch only added when interesting for own GNOME project…