racket/gui: fix get-plain-label and docs about labels

This commit is contained in:
Matthew Flatt 2013-09-05 10:56:35 -06:00
parent c70a0313e7
commit 5d7f1363e5
6 changed files with 45 additions and 28 deletions

View File

@ -48,8 +48,9 @@ in @racket[label] is converted to @litchar{&} (with no mnemonic
underlining). On Mac OS X, a parenthesized mnemonic character is underlining). On Mac OS X, a parenthesized mnemonic character is
removed (along with any surrounding space) before the label is removed (along with any surrounding space) before the label is
displayed, since a parenthesized mnemonic is often used for non-Roman displayed, since a parenthesized mnemonic is often used for non-Roman
languages. Finally, any text after a tab character is removed on all languages. Finally, for historical reasons, any text after a tab character is removed on all
platforms. Mnemonic keyboard events are handled by 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 @method[top-level-window<%> on-traverse-char] (but not on Mac OS
X). X).

View File

@ -47,10 +47,8 @@ See also @method[labelled-menu-item<%> set-label] and
label-string?]{ label-string?]{
Like @method[labelled-menu-item<%> get-label], except that Like @method[labelled-menu-item<%> get-label], except that
@litchar{&}s in the label are removed as described in @litchar{&}s and tab characters in the label are stripped in
@method[labelled-menu-item<%> set-label]. the same way as for @method[window<%> set-label].
} }
@defmethod[(is-enabled?) @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{&&} in the label is replaced by a literal (non-navigation)
@litchar{&}. On Mac OS X, @litchar{&}s in the label are parsed in @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 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 A @litchar{&} is always preserved in the label returned by
@method[labelled-menu-item<%> get-label], but never preserved in the @method[labelled-menu-item<%> get-label], but never preserved in the
label returned by @method[labelled-menu-item<%> get-plain-label]. 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.
}} }}

View File

@ -16,16 +16,9 @@ A @racket[menu%] object is a submenu within a @racket[menu%] or
Creates a new menu with the given label. Creates a new menu with the given label.
If @racket[label] contains a @litchar{&}, it is handled specially; If @racket[label] contains a @litchar{&} or tab characters, they are
on Windows, the character following a @litchar{&} is underlined in handled specially in the same way as for menu-item labels and buttons. See
the displayed menu title to indicate a keyboard mnemonic. Pressing @method[labelled-menu-item<%> set-label] and @racket[button%].
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[help-string] is not @racket[#f], the menu has a help If @racket[help-string] is not @racket[#f], the menu has a help
string. See @method[labelled-menu-item<%> get-help-string] for more string. See @method[labelled-menu-item<%> get-help-string] for more

View File

@ -195,7 +195,25 @@ If the window does not have a label, @racket[#f] is returned.
(or/c string? #f)]{ (or/c string? #f)]{
Like 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 no label or the window's
label is not a string, @racket[#f] is returned. label is not a string, @racket[#f] is returned.

View File

@ -7,8 +7,8 @@
(define/top (label->plain-label [string? s]) (define/top (label->plain-label [string? s])
(regexp-replace* #rx"&(.)" (regexp-replace* #rx"&(.)"
(regexp-replace (regexp-replace
#rx"[(]&(.)[)] *" #rx" *[(]&.[)] *"
(regexp-replace #rx"\t.*$" s "") (regexp-replace #rx"\t.*$" s "")
"\\1") "")
"\\1")) "\\1"))

View File

@ -170,12 +170,16 @@
(define (label-test b l) (define (label-test b l)
(let ([&-l (format "&~a" 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" l)]
[my-l-& (format "My ~a (&X) " l)])
(st &-l b get-label) (st &-l b get-label)
(st l b get-plain-label) (st l b get-plain-label)
(stv b set-label &-my-l) (stv b set-label &-my-l)
(st &-my-l b get-label) (st &-my-l b get-label)
(st my-l b get-plain-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))) (stv b set-label &-l)))
(let ([f (make-object frame% "Yes & No" #f 150 151 70 21)]) (let ([f (make-object frame% "Yes & No" #f 150 151 70 21)])