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 705509 - notebook popup window on tabs shows underscores
notebook popup window on tabs shows underscores
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkNotebook
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2013-08-05 12:57 UTC by William Jon McCann
Modified: 2018-03-16 22:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
screenshot (12.61 KB, image/png)
2013-08-05 12:57 UTC, William Jon McCann
  Details
Notebook: Don’t show underline or markup in popup (1.35 KB, patch)
2017-10-12 11:22 UTC, Daniel Boles
none Details | Review
Notebook: Copy underline/markup from tab to popup (1.95 KB, patch)
2017-10-12 12:26 UTC, Daniel Boles
none Details | Review
test case (2.29 KB, text/plain)
2018-03-16 22:11 UTC, Daniel Boles
  Details
Notebook: Don’t show underline or markup in popup (2.24 KB, patch)
2018-03-16 22:31 UTC, Daniel Boles
committed Details | Review

Description William Jon McCann 2013-08-05 12:57:57 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.
Comment 1 Daniel Boles 2017-10-12 11:22:25 UTC
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.
Comment 2 Daniel Boles 2017-10-12 11:29:10 UTC
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.
Comment 3 Daniel Boles 2017-10-12 12:26:35 UTC
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!)
Comment 4 Daniel Boles 2018-03-16 22:11:53 UTC
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.
Comment 5 Daniel Boles 2018-03-16 22:31:41 UTC
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.