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
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).

View File

@ -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].
}}

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.
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

View File

@ -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.

View File

@ -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"))

View File

@ -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)