racket/gui: fix get-plain-label
and docs about labels
This commit is contained in:
parent
c70a0313e7
commit
5d7f1363e5
|
@ -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).
|
||||
|
||||
|
|
|
@ -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].
|
||||
|
||||
}}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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"))
|
||||
|
||||
|
|
|
@ -170,12 +170,16 @@
|
|||
(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)])
|
||||
|
|
Loading…
Reference in New Issue
Block a user