From 5d7f1363e53b7dd8b6f8ba73ea402da807756e7d Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 5 Sep 2013 10:56:35 -0600 Subject: [PATCH] racket/gui: fix `get-plain-label` and docs about labels --- .../scribblings/gui/button-class.scrbl | 5 +++-- .../gui/labelled-menu-item-intf.scrbl | 21 ++++++++++--------- .../gui-doc/scribblings/gui/menu-class.scrbl | 13 +++--------- .../gui-doc/scribblings/gui/window-intf.scrbl | 20 +++++++++++++++++- .../gui-lib/mred/private/wx/common/procs.rkt | 4 ++-- .../gui-test/tests/gracket/windowing.rktl | 10 ++++++--- 6 files changed, 45 insertions(+), 28 deletions(-) diff --git a/pkgs/gui-pkgs/gui-doc/scribblings/gui/button-class.scrbl b/pkgs/gui-pkgs/gui-doc/scribblings/gui/button-class.scrbl index 6b691eed81..492f359238 100644 --- a/pkgs/gui-pkgs/gui-doc/scribblings/gui/button-class.scrbl +++ b/pkgs/gui-pkgs/gui-doc/scribblings/gui/button-class.scrbl @@ -48,8 +48,9 @@ in @racket[label] is converted to @litchar{&} (with no mnemonic underlining). On Mac OS X, a parenthesized mnemonic character is removed (along with any surrounding space) before the label is displayed, since a parenthesized mnemonic is often used for non-Roman -languages. Finally, any text after a tab character is removed on all -platforms. Mnemonic keyboard events are handled by +languages. Finally, for historical reasons, any text after a tab character is removed on all +platforms. All of these rules are consistent with label handling in +menu items (see @method[labelled-menu-item<%> set-label]). Mnemonic keyboard events are handled by @method[top-level-window<%> on-traverse-char] (but not on Mac OS X). diff --git a/pkgs/gui-pkgs/gui-doc/scribblings/gui/labelled-menu-item-intf.scrbl b/pkgs/gui-pkgs/gui-doc/scribblings/gui/labelled-menu-item-intf.scrbl index 15a401e624..4f1330b385 100644 --- a/pkgs/gui-pkgs/gui-doc/scribblings/gui/labelled-menu-item-intf.scrbl +++ b/pkgs/gui-pkgs/gui-doc/scribblings/gui/labelled-menu-item-intf.scrbl @@ -47,10 +47,8 @@ See also @method[labelled-menu-item<%> set-label] and label-string?]{ Like @method[labelled-menu-item<%> get-label], except that -@litchar{&}s in the label are removed as described in -@method[labelled-menu-item<%> set-label]. - - +@litchar{&}s and tab characters in the label are stripped in +the same way as for @method[window<%> set-label]. } @defmethod[(is-enabled?) @@ -110,14 +108,17 @@ If the label contains @litchar{&} and the window is a control, the @litchar{&&} in the label is replaced by a literal (non-navigation) @litchar{&}. On Mac OS X, @litchar{&}s in the label are parsed in the same way as for Unix and Windows, but no mnemonic underline is - displayed. + displayed. On Mac OS X, a parenthesized mnemonic character is + removed (along with any surrounding space) before the label is + displayed, since a parenthesized mnemonic is often used for non-Roman + languages. Finally, for historical reasons, if a label contains a tab character, then the + tab and all remaining characters are hidden in the displayed menu. + All of these rules are consistent with label handling in @racket[button%] + and other windows. A @litchar{&} is always preserved in the label returned by -@method[labelled-menu-item<%> get-label], but never preserved in the -label returned by @method[labelled-menu-item<%> get-plain-label]. - -For historical reasons, if a label contains a tab character, then the - tab and all remaining characters are hidden in the displayed menu. + @method[labelled-menu-item<%> get-label], but never preserved in the + label returned by @method[labelled-menu-item<%> get-plain-label]. }} diff --git a/pkgs/gui-pkgs/gui-doc/scribblings/gui/menu-class.scrbl b/pkgs/gui-pkgs/gui-doc/scribblings/gui/menu-class.scrbl index ff9d6b1646..bdf38aabb7 100644 --- a/pkgs/gui-pkgs/gui-doc/scribblings/gui/menu-class.scrbl +++ b/pkgs/gui-pkgs/gui-doc/scribblings/gui/menu-class.scrbl @@ -16,16 +16,9 @@ A @racket[menu%] object is a submenu within a @racket[menu%] or Creates a new menu with the given label. -If @racket[label] contains a @litchar{&}, it is handled specially; - on Windows, the character following a @litchar{&} is underlined in - the displayed menu title to indicate a keyboard mnemonic. Pressing - and releasing the Alt key switches to menu-selection mode in the menu - bar where mnemonic characters are used for navigation. An Alt - combination might select a specific menu via @method[frame% - on-menu-char]. A @litchar{&&} in @racket[label] is replaced by a - literal (non-navigation) @litchar{&}ampersand. On Unix and Mac OS X, - @litchar{&}s in the label are parsed in the same way as for Windows, - but no mnemonic underline is displayed. +If @racket[label] contains a @litchar{&} or tab characters, they are + handled specially in the same way as for menu-item labels and buttons. See + @method[labelled-menu-item<%> set-label] and @racket[button%]. If @racket[help-string] is not @racket[#f], the menu has a help string. See @method[labelled-menu-item<%> get-help-string] for more diff --git a/pkgs/gui-pkgs/gui-doc/scribblings/gui/window-intf.scrbl b/pkgs/gui-pkgs/gui-doc/scribblings/gui/window-intf.scrbl index 2b7ee67f40..1b82aa1dc3 100644 --- a/pkgs/gui-pkgs/gui-doc/scribblings/gui/window-intf.scrbl +++ b/pkgs/gui-pkgs/gui-doc/scribblings/gui/window-intf.scrbl @@ -195,7 +195,25 @@ If the window does not have a label, @racket[#f] is returned. (or/c string? #f)]{ Like -@method[window<%> get-label], except that ampersands in the label are removed. If the window has +@method[window<%> get-label], except that: + +@itemlist[ + + @item{If the label includes @litchar{(&}@racket[_c]@litchar{)} for + any character @racket[_c], then the sequenece and any surrounding + whitespace is removed.} + + @item{If the label contains @litchar{&}@racket[_c] for any character @racket[_c], + the @litchar{&} is removed.} + + @item{If the label contains a tab character, then the tab character and all following + characters are removed.} + +] + +See also @racket[button%]'s handling of labels. + +If the window has no label or the window's label is not a string, @racket[#f] is returned. diff --git a/pkgs/gui-pkgs/gui-lib/mred/private/wx/common/procs.rkt b/pkgs/gui-pkgs/gui-lib/mred/private/wx/common/procs.rkt index 6434cc48ec..5631fd6106 100644 --- a/pkgs/gui-pkgs/gui-lib/mred/private/wx/common/procs.rkt +++ b/pkgs/gui-pkgs/gui-lib/mred/private/wx/common/procs.rkt @@ -7,8 +7,8 @@ (define/top (label->plain-label [string? s]) (regexp-replace* #rx"&(.)" (regexp-replace - #rx"[(]&(.)[)] *" + #rx" *[(]&.[)] *" (regexp-replace #rx"\t.*$" s "") - "\\1") + "") "\\1")) diff --git a/pkgs/gui-pkgs/gui-test/tests/gracket/windowing.rktl b/pkgs/gui-pkgs/gui-test/tests/gracket/windowing.rktl index 71df08bfb0..134f8f986b 100644 --- a/pkgs/gui-pkgs/gui-test/tests/gracket/windowing.rktl +++ b/pkgs/gui-pkgs/gui-test/tests/gracket/windowing.rktl @@ -170,14 +170,18 @@ (define (label-test b l) (let ([&-l (format "&~a" l)] [my-l (format "My ~a" l)] - [&-my-l (format "&My ~a" l)]) + [&-my-l (format "&My ~a" l)] + [my-l-& (format "My ~a (&X) " l)]) (st &-l b get-label) (st l b get-plain-label) (stv b set-label &-my-l) (st &-my-l b get-label) (st my-l b get-plain-label) + (stv b set-label my-l-&) + (st my-l-& b get-label) + (st my-l b get-plain-label) (stv b set-label &-l))) - + (let ([f (make-object frame% "Yes & No" #f 150 151 70 21)]) (let ([init-tests (lambda (hidden?) @@ -491,7 +495,7 @@ (set! side-effect 'button) 'oops) '(border))]) - (label-test b "Button") + (label-test b "Button") (stv b command (make-object control-event% 'button)) (test 'button 'button-callback side-effect)