GNOME Bugzilla – Bug 699289
API request: MenuItem has no function to set label markup
Last modified: 2013-05-20 22:50:23 UTC
There is no direct function to set markup on a MenuItem. An example when markup is used is for text formatting menu items (see gnote/tomboy as an example), so the label reflects the formatting. The workaround is to know that the MenuItem is also a Bin, and that its child is a Label. Then we can call gtk_label_set_markup(). I suggest to add: GtkWidget * gtk_menu_item_new_with_markup (const gchar *label); void gtk_menu_item_set_markup (GtkMenuItem *menu_item, const gchar *label); void gtk_menu_item_set_markup_with_mnemonic (GtkMenuItem *menu_item, const gchar *label); gboolean gtk_menu_item_get_use_markup (GtkMenuItem *menu_item); void gtk_menu_item_set_use_markup (GtkMenuItem *menu_item); gboolean setting); (I can provide a patch, if it makes sense)
> The workaround is > to know that the MenuItem is also a Bin, and that its child is a Label. Then we > can call gtk_label_set_markup(). Not a workaround - with the current crop of menu item widgets, it is expected.
From an application developer point of view, looking at the documentation, it is hidden. You have to discover it. You need a certain knowledge of GTK+ to figure it out. You can create a menu item with a label, mnemonic, but no markup. GtkWidget * gtk_menu_item_new (void); GtkWidget * gtk_menu_item_new_with_label (const gchar *label); GtkWidget * gtk_menu_item_new_with_mnemonic (const gchar *label); void gtk_menu_item_set_label (GtkMenuItem *menu_item, const gchar *label); You could possibly guess that the menu item hosts a label, but again there is no such GtkWidget* get_label(). You need to get a good view on the object hierarchy and packing system to figure out that you can get the label as the child of the menu item taken as a bin. Certainly a piece of cake for an advanced GTK+ developer, but not for everybody. Maybe the API could be a bit more consistent here. I think that this is at least missing in the documentation.
> You need a certain knowledge of GTK+ to figure it out. Thats generally true when using any complex library. Closing this since I don't want to carry around more open documentation bugs - feel free to reopen if you have a patch to attach.
Created attachment 243832 [details] [review] 0001-Add-doc-to-set-markup-and-accelerator-on-a-MenuItem.patch this fixes also bug 699290.
Created attachment 243833 [details] [review] 0002-typo.patch Not related to this bug report, but that's a typo I meant to report long ago. Maybe it could be fixed at the same time. Let me know if you want a separated report.
Review of attachment 243832 [details] [review]: ok
Review of attachment 243833 [details] [review]: ok
Thanks