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 749405 - GtkMenuSectionBox doesn't remove submenus when parent item is removed
GtkMenuSectionBox doesn't remove submenus when parent item is removed
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
3.19.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 762143 764929 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-05-15 01:51 UTC by Hubert Figuiere (:hub)
Modified: 2016-04-21 00:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
remove submenus when parent item is removed (1.43 KB, patch)
2016-03-09 12:49 UTC, Jonathan Matthew
committed Details | Review
example program (4.06 KB, text/plain)
2016-04-20 13:20 UTC, Jonathan Matthew
  Details

Description Hubert Figuiere (:hub) 2015-05-15 01:51:08 UTC
Start RB from the command line. 

Observe:

(lt-rhythmbox:4503): Gtk-WARNING **: Duplicate child name in GtkStack: Add to Playlist


The stack trace:

  • #0 g_logv
    at gmessages.c line 315
  • #1 g_logv
    at gmessages.c line 1041
  • #2 g_log
    at gmessages.c line 1079
  • #3 gtk_stack_set_child_property
    at gtkstack.c line 657
  • #4 gtk_container_child_set_valist
    at gtkcontainer.c line 1029
  • #5 gtk_container_child_set_valist
    at gtkcontainer.c line 1241
  • #6 gtk_container_add_with_properties
    at gtkcontainer.c line 1330
  • #7 gtk_stack_add_named
    at gtkstack.c line 1178
  • #8 gtk_menu_section_box_insert_func
    at gtkmenusectionbox.c line 419
  • #9 gtk_menu_section_box_insert_func
    at gtkmenusectionbox.c line 288
  • #10 gtk_menu_tracker_add_items
    at gtkmenutracker.c line 401
  • #11 gtk_menu_tracker_model_changed
    at gtkmenutracker.c line 452
  • #12 ffi_call_unix64
    at ../src/x86/unix64.S line 76
  • #13 ffi_call
    at ../src/x86/ffi64.c line 525
  • #18 <emit signal ??? on instance 0x7fffec22b790 [GMenu]>
    at gsignal.c line 3361
  • #19 g_menu_model_items_changed
    at gmenumodel.c line 688
  • #20 g_menu_insert_item
    at gmenu.c line 173
  • #21 rb_menu_update_link
    at rb-util.c line 1276
  • #22 rb_menu_update_link
    at rb-util.c line 1258
  • #23 setup_add_to_playlist_menu
    at rb-shell-clipboard.c line 284
  • #24 g_object_set_valist
    at gobject.c line 1415
  • #25 g_object_set_valist
    at gobject.c line 2158
  • #26 g_object_set
    at gobject.c line 2268
  • #27 rb_shell_clipboard_set_source
    at rb-shell-clipboard.c line 451
  • #28 rb_shell_select_page
    at rb-shell.c line 2362
  • #29 rb_shell_constructed
    at rb-shell.c line 1780



Note: I believe it might be a bug in Gtk. Or the problem isn't obvious.
Comment 1 Sebastien Bacher 2016-02-17 16:28:32 UTC
*** Bug 762143 has been marked as a duplicate of this bug. ***
Comment 2 Jonathan Matthew 2016-03-09 12:43:11 UTC
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.
Comment 3 Jonathan Matthew 2016-03-09 12:49:00 UTC
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.
Comment 4 Matthias Clasen 2016-03-10 04:27:20 UTC
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 ?
Comment 5 Jonathan Matthew 2016-03-10 12:02:12 UTC
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.
Comment 6 Matthias Clasen 2016-03-13 14:09:36 UTC
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...
Comment 7 Jonathan Matthew 2016-04-12 07:22:21 UTC
*** Bug 764929 has been marked as a duplicate of this bug. ***
Comment 8 Jonathan Matthew 2016-04-20 13:20:23 UTC
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.
Comment 9 Matthias Clasen 2016-04-20 17:16:16 UTC
thanks a lot! I'll have a look. coming up with that kind of example has been on my list for a while