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 679454 - modelmenu: listen for toplevel changes on the attach widget
modelmenu: listen for toplevel changes on the attach widget
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: .General
unspecified
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2012-07-05 15:01 UTC by Cosimo Cecchi
Modified: 2012-07-06 15:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
modelmenu: listen for toplevel changes on the attach widget (3.19 KB, patch)
2012-07-05 15:01 UTC, Cosimo Cecchi
none Details | Review
menu: notify attach-widget property when menu is detached (849 bytes, patch)
2012-07-05 17:23 UTC, Cosimo Cecchi
committed Details | Review
modelmenu: listen for toplevel changes on the attach widget (4.04 KB, patch)
2012-07-05 17:24 UTC, Cosimo Cecchi
committed Details | Review

Description Cosimo Cecchi 2012-07-05 15:01:55 UTC
See attached patch
Comment 1 Cosimo Cecchi 2012-07-05 15:01:57 UTC
Created attachment 218100 [details] [review]
modelmenu: listen for toplevel changes on the attach widget

Right now, when we create a GtkModelMenu for a GMenuModel, we listen to
changes to the menu's attach-widget to detect when a toplevel
GtkApplicationWindow becomes available to fetch actions from it.

This unfortunately breaks this simple code:

  GtkWidget *application_window = gtk_application_window_new();
  GtkWidget *menu_button = gtk_menu_button_new();
  GMenuModel *menu_model = get_menu_model();

  gtk_menu_button_set_menu_model(menu_button, menu_model);
  gtk_container_add(GTK_CONTAINER(application_window), menu_button);

Since GtkMenuButton creates a GtkModelMenu and sets itself as its attach
widget before it's added to a hierarchy containing a
GtkApplicationWindow.

Fix the bug by simply listening for changes in the window hierarchy, and
creating the menu model when the attach widget is added to an
application window.
Comment 2 Matthias Clasen 2012-07-05 16:45:57 UTC
Review of attachment 218100 [details] [review]:

Don't you have to disconnect from the signal when detaching ?
Comment 3 Cosimo Cecchi 2012-07-05 17:23:49 UTC
Created attachment 218112 [details] [review]
menu: notify attach-widget property when menu is detached

When the menu is detached, the attach-widget property changes value to
NULL, so we should notify a property change, like
gtk_menu_attach_to_widget() does.
Comment 4 Cosimo Cecchi 2012-07-05 17:24:12 UTC
Created attachment 218113 [details] [review]
modelmenu: listen for toplevel changes on the attach widget

---

New patch, fixes review comments.
Comment 5 Matthias Clasen 2012-07-05 20:15:21 UTC
Review of attachment 218112 [details] [review]:

clearly right, thanks
Comment 6 Matthias Clasen 2012-07-05 20:17:22 UTC
Review of attachment 218112 [details] [review]:

clearly right, thanks
Comment 7 Matthias Clasen 2012-07-05 22:22:04 UTC
Review of attachment 218113 [details] [review]:

lgtm
Comment 8 Cosimo Cecchi 2012-07-06 15:14:44 UTC
Attachment 218112 [details] pushed as f81bd6c - menu: notify attach-widget property when menu is detached
Attachment 218113 [details] pushed as 5dbf3a5 - modelmenu: listen for toplevel changes on the attach widget