GNOME Bugzilla – Bug 791175
[patch]: GtkBuilder does not accept an id for "item" elements
Last modified: 2018-05-02 19:32:15 UTC
Created attachment 364864 [details] [review] Accept id for item elements I noticed that the current Gtk Builder XML parser does not accept an id for "item" elements. Please consider the attached patch to address this. Background: it should be possible to query menu items at runtime to change their labels (text) at any time. The attached patch is against Gtk+ 3.91.2, but can certainly be applied against latest git master head as well. See also: https://mail.gnome.org/archives/gtkmm-list/2017-November/msg00001.html https://mail.gnome.org/archives/gtk-devel-list/2017-November/msg00002.html This issue should IMO be fixed before the first official Gtk+ 4 release, because otherwise it will be impossible to update i.e. the text of menu items at runtime using the Gtk+4 branch.
i'm not sure this is the best idea. GMenuModel is a standalone api that has ways to pull out items (even though they may not be the most convenient). The integration into GtkBuilder intentionally treats the GMenuModel as a basically opaque object - exposing parts of the menu via the builder object apis would break that.
In the end, I am just looking ahead as an application developer how you would i.e. update the text of menu items at runtime once Gtk4 is released. In practice it is a common requirement for example to update the text of certain menu items automatically i.e. when the user changes his selection in a list view. With Gtk3 and its old UIManager API you could easily do that by calling gtk_ui_manager_get_widget() at any time and then updating its label whenever needed. But since that entire API would not be available in Gtk4 anymore, and since (as far as I can see it) the recommended way to manage menus with upcoming Gtk4 is to use the Builder API and GMenuModel, how would you update the text of menu items this way? I cannot see a way for that without retrieving a menu item by ID. Plus, if you look at the current Builder code, you can already retrieve almost everything by "id", except the most important one: menu items. I cannot see profound reason why to draw a line exactly here, that is to prohibit querying menu items while allowing to query essentially anything else of the menu model. And please also note what I wrote at the provided discussion on the Gtkmm mailing list; the format's schema file officially allows ids for menu items: https://github.com/GNOME/gtk/blob/master/gtk/gtkbuilder.rnc (Line 58) : item = element item { attribute id { xsd:ID } ?, (attribute_ | link) * } -Christian
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/987.