factor/library/ui/dialogs.factor

53 lines
1.4 KiB
Factor
Raw Normal View History

2005-02-19 21:49:37 -05:00
IN: gadgets
USING: generic kernel namespaces threads ;
2005-02-19 21:49:37 -05:00
TUPLE: dialog continuation ;
2005-02-19 21:49:37 -05:00
2005-02-26 00:57:53 -05:00
: dialog-action ( ok dialog -- )
dup unparent dialog-continuation call ;
2005-02-19 21:49:37 -05:00
: dialog-ok ( dialog -- )
2005-02-26 00:57:53 -05:00
t swap dialog-action ;
2005-02-19 21:49:37 -05:00
: dialog-cancel ( dialog -- )
2005-02-26 00:57:53 -05:00
f swap dialog-action ;
2005-02-19 21:49:37 -05:00
: <dialog-buttons> ( -- gadget )
<default-shelf>
2005-03-22 21:20:58 -05:00
"OK" f <button>
dup [ dialog-ok ] [ action ] link-action
over add-gadget
"Cancel" f <button>
dup [ dialog-cancel ] [ action ] link-action
over add-gadget ;
2005-02-19 21:49:37 -05:00
2005-02-26 00:57:53 -05:00
: dialog-actions ( dialog -- )
2005-02-19 21:49:37 -05:00
dup [ dialog-ok ] dup set-action
2005-02-26 00:57:53 -05:00
[ dialog-cancel ] dup set-action ;
C: dialog ( content -- gadget )
2005-03-22 21:20:58 -05:00
[ <empty-gadget> swap set-delegate ] keep
2005-02-26 00:57:53 -05:00
[
>r <default-pile>
[ add-gadget ] keep
[ <dialog-buttons> swap add-gadget ] keep
r> add-gadget
] keep
[ dialog-actions ] keep ;
2005-02-19 21:49:37 -05:00
: <prompt> ( prompt -- gadget )
2005-02-27 16:00:55 -05:00
0 default-gap 0 <pile>
2005-02-19 21:49:37 -05:00
[ >r <label> r> add-gadget ] keep
[ >r "" <field> r> add-gadget ] keep ;
: <input-dialog> ( prompt continuation -- gadget )
2005-02-26 00:57:53 -05:00
>r <prompt> <dialog> r> over set-dialog-continuation ;
2005-02-19 21:49:37 -05:00
: input-dialog ( prompt -- input )
2005-02-26 00:57:53 -05:00
#! Show an input dialog and resume the current continuation
#! when the user clicks OK or Cancel. If they click Cancel,
#! push f.
2005-03-22 21:20:58 -05:00
[
2005-04-22 00:22:36 -04:00
<input-dialog> "Input" <tile> world get add-gadget stop
2005-03-22 21:20:58 -05:00
] callcc1 ;