GNOME Bugzilla – Bug 705509
notebook popup window on tabs shows underscores
Last modified: 2018-03-16 22:37:52 UTC
Created attachment 250869 [details] screenshot If I use gtk_notebook_popup_enable (GTK_NOTEBOOK (notebook)); the resulting menu shows the page titles with mnemonic underscores.
Created attachment 361411 [details] [review] Notebook: Don’t show underline or markup in popup The method that creates the menu item for the popup menu was using gtk_label_get_label(), which includes any mnemonic underscore in the label. It should use gtk_label_get_text(), which eschews the underscore. This fix will also avoid Pango markup showing up uninvited in the menu.
Something I thought of while here is that, in the case where the tab label is not a GtkLabel: * doesn't the notebook accessible try diving down to find some child of the tab label widget that _is_ a label? that may be a neat thing to consider here * and/or if the tab label widget is not a label, there are other things that we could fall back to, e.g. its tooltip text, if the label is an image for example.
Created attachment 361417 [details] [review] Notebook: Copy underline/markup from tab to popup Calling gtk_label_new() meant any _ in a tab label was just dumped into the MenuItem’s Label as a literal _ instead of being interpreted as signifying a mnemonic. The same would have been true for Pango markup. Fix that by propagating the :use-underline and :use-markup properties from the tab Label to the new Label that gets put in the GtkMenuItem. This seems like the better thing to do; there's no point ditching the ability to use mnemonics or have markup if we don't have to. However, I'll wait for someone else to confirm which of these approaches is best. (Hopefully we don't land on a slippery slope where we start feeling the need to propagate all properties between the tab and menu labels!)
Created attachment 369802 [details] test case Maybe I'll elaborate on this a bit and put it in as tests/testnotebook.c Anyway, for now, it shows the issue, and the fix I'll commit shortly.
Created attachment 369803 [details] [review] Notebook: Don’t show underline or markup in popup If @menu_label == NULL, we create a default page->menu_label. This took @tab_label.get_label() and passed that to page->menu_label.set_text(). This is wrong because we set the plain text of the menu_label from the rich text of @tab_label. So, if @tab_label used mnemonics or markup, our menu_label got the raw underline or markup tags shown in it as raw text. As we call set_text() on the menu Label, the fix is to be symmetric: use @tab_label's get_text() as source, as that strips underlines and markup. It's not worth making the default Label 'inherit' :use-underline/markup; that's a slippery slope, and users wanting such things can just create a fully fledged GtkLabel to pass as @menu_label to suppress the default.