GNOME Bugzilla – Bug 611724
[GSEAL] GtkMenuShell::active_menu_item sealed but not retrievable
Last modified: 2011-02-04 16:12:22 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.
Created attachment 155290 [details] [review]
Where are you planning on using this function?
The patch lacks documentation.
Created attachment 155765 [details] [review]
Add some documentation.
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.
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.
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.
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?
I'm not taking api additions at this point. Any accessors that are still missing have missed the window for this cycle.
Created attachment 159986 [details] [review]
Updated patch, followed documentation of other functions
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.
Created attachment 160709 [details] [review]
gtk_menu_shell_get_selected_item, like comment #6
"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.
2.22 has been released. Change target milestore to 2.24
Created attachment 171902 [details] [review]
git format patch for adding the new gtk_menu_shell_get_selected_item function
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:
* @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
gtk_menu_shell_get_selected_item was added a while ago.
12 days ago it seems, by yourself:
Another example of a patch only added when interesting for own GNOME project…