add yet another dialog-mixin argument to a standard dialog, this time

get-text-from-user

also, some minor rackety to that function/file

original commit: 57c59d2ed7e1e8a29d492d533a8b3f5673022824
This commit is contained in:
Robby Findler 2011-09-05 20:03:00 -05:00
parent 1f69a824fa
commit 2c7390edb8
2 changed files with 36 additions and 41 deletions

View File

@ -1,19 +1,14 @@
(module moredialogs mzscheme #lang racket/base
(require mzlib/class (require racket/class
mzlib/etc (prefix-in wx: "kernel.rkt")
mzlib/list (prefix-in wx: racket/snip)
(prefix wx: "kernel.rkt")
(prefix wx: racket/snip)
"lock.rkt" "lock.rkt"
"const.rkt" "const.rkt"
"check.rkt" "check.rkt"
"wx.rkt" "wx.rkt"
"helper.rkt" "helper.rkt"
"editor.rkt"
"mrtop.rkt" "mrtop.rkt"
"mrcanvas.rkt" "mrcanvas.rkt"
"mrpopup.rkt"
"mrmenu.rkt"
"mritem.rkt" "mritem.rkt"
"mrpanel.rkt" "mrpanel.rkt"
"mrtextfield.rkt") "mrtextfield.rkt")
@ -190,34 +185,33 @@
(define (can-get-page-setup-from-user?) (define (can-get-page-setup-from-user?)
(wx:can-show-print-setup?)) (wx:can-show-print-setup?))
(define get-text-from-user (define (get-text-from-user title message
(case-lambda [parent #f]
[(title message) (get-text-from-user title message #f "" null)] [init-val ""]
[(title message parent) (get-text-from-user title message parent "" null)] [style null]
[(title message parent init-val) (get-text-from-user title message parent init-val null)] #:dialog-mixin [dialog-mixin values])
[(title message parent init-val style) (check-label-string 'get-text-from-user title)
(check-label-string 'get-text-from-user title) (check-label-string/false 'get-text-from-user message)
(check-label-string/false 'get-text-from-user message) (check-top-level-parent/false 'get-text-from-user parent)
(check-top-level-parent/false 'get-text-from-user parent) (check-string 'get-text-from-user init-val)
(check-string 'get-text-from-user init-val) (check-style 'get-text-from-user #f '(password) style)
(check-style 'get-text-from-user #f '(password) style) (define f (make-object (dialog-mixin dialog%) title parent box-width))
(let* ([f (make-object dialog% title parent box-width)] (define ok? #f)
[ok? #f] (define ((done ?) b e) (set! ok? ?) (send f show #f))
[done (lambda (?) (lambda (b e) (set! ok? ?) (send f show #f)))]) (define t (make-object text-field% message f (lambda (t e) (when (eq? (send e get-event-type) 'text-field-enter)
(let ([t (make-object text-field% message f (lambda (t e) (when (eq? (send e get-event-type) 'text-field-enter) ((done #t) #f #f)))
((done #t) #f #f))) init-val (list* 'single 'vertical-label style)))
init-val (list* 'single 'vertical-label style))] (define p (make-object horizontal-pane% f))
[p (make-object horizontal-pane% f)]) (send p set-alignment 'right 'center)
(send p set-alignment 'right 'center) (send f stretchable-height #f)
(send f stretchable-height #f) (ok-cancel
(ok-cancel (lambda () (make-object button% "OK" p (done #t) '(border)))
(lambda () (make-object button% "OK" p (done #t) '(border))) (lambda () (make-object button% "Cancel" p (done #f))))
(lambda () (make-object button% "Cancel" p (done #f)))) (send (send t get-editor) select-all)
(send (send t get-editor) select-all) (send t focus)
(send t focus) (send f center)
(send f center) (send f show #t)
(send f show #t) (and ok? (send t get-value)))
(and ok? (send t get-value))))]))
(define get-choices-from-user (define get-choices-from-user
(case-lambda (case-lambda
@ -347,4 +341,4 @@
(send f center) (send f center)
(send f show #t) (send f show #t)
(and ok? (and ok?
(get-current-color))))]))) (get-current-color))))]))

View File

@ -390,7 +390,8 @@ Like @racket[message-box/custom], except that
[message (or/c string? #f)] [message (or/c string? #f)]
[parent (or/c (is-a?/c frame%) (is-a?/c dialog%) #f) #f] [parent (or/c (is-a?/c frame%) (is-a?/c dialog%) #f) #f]
[init-val string? ""] [init-val string? ""]
[style (listof 'password) null]) [style (listof 'password) null]
[#:dialog-mixin dialog-mixin (make-mixin-contract dialog%) values])
(or/c string? #f)]{ (or/c string? #f)]{
Gets a text string from the user via a modal dialog, using Gets a text string from the user via a modal dialog, using
@ -406,8 +407,8 @@ If @racket[style] includes @racket['password], the dialog's text field
draws each character of its content using a generic symbol, instead draws each character of its content using a generic symbol, instead
of the actual character. of the actual character.
The @racket[dialog-mixin] argument is applied to the class that implements the dialog
before the dialog is created.
} }
@defproc[(get-choices-from-user [title string?] @defproc[(get-choices-from-user [title string?]