GNOME Bugzilla – Bug 749405
GtkMenuSectionBox doesn't remove submenus when parent item is removed
Last modified: 2016-04-21 00:12:36 UTC
Start RB from the command line. Observe: (lt-rhythmbox:4503): Gtk-WARNING **: Duplicate child name in GtkStack: Add to Playlist The stack trace:
+ Trace 235065
Note: I believe it might be a bug in Gtk. Or the problem isn't obvious.
*** Bug 762143 has been marked as a duplicate of this bug. ***
Finally got around to looking into this, and the cause seems to be that GtkMenuSectionBox doesn't remove submenus from the GtkStack when the item that points to them is removed.
Created attachment 323504 [details] [review] remove submenus when parent item is removed This makes the warnings go away, doesn't appear to leak submenus, and also makes the feature in rhythmbox that triggers this work properly.
Why isn't the submenu removed before the removing the item that points to them ? Can you outline how the menu model looks, and what changes are made to it ?
The contents of rhythmbox's 'add to playlist' menu depend on the type of source that is currently selected. It contains playlists in the user's library when the user is looking at their library, and playlists on a device when they're looking at that device. The menu is linked to from a couple of different places, which are identified by a custom attribute: <submenu> <attribute name="label" translatable="yes">Add to Playlist</attribute> <attribute name="rb-playlist-menu-link"></attribute> </submenu> when this is loaded from a builder file (data/ui/edit-menu.ui) it initially points to an empty submenu. When the playlist menu is first built and when the user switches between their library and a device (or whatever else), the link is updated by deleting the item and recreating it with the new menu as the target of the submenu link. The submenu itself has a couple of static items and a section that tracks the set of available playlists using a custom GMenuModel implementation. This could certainly be managed by rearranging the contents of the submenu without replacing the item that links to it, but the current approach seemed like the simplest way to implement it, and it worked properly back when I wrote it in 2013. (In reply to Matthias Clasen from comment #4) > Why isn't the submenu removed before the removing the item that points to > them ? How would I do that? The only way I can see to remove a submenu from a GMenu structure is to remove the item that links to it.
I think what we probably need here is an example/testcase inside gtk that does this kind of complicated menu model manipulation. From my memory, changing links into non-links and back is not something that was considered we wrote the frontend and tracker code. The main idea for model changes was additions and removals, not transmutation...
*** Bug 764929 has been marked as a duplicate of this bug. ***
Created attachment 326412 [details] example program If it helps at all, here's a simple(r) example I put together that does roughly the same thing rhythmbox does. The 'flip' item in the menu switches between two different submenus, and the second time you do that, you get the 'Duplicate child in GtkStack' warning and the submenu doesn't actually change.
thanks a lot! I'll have a look. coming up with that kind of example has been on my list for a while