1 USING: kernel models namespaces math sequences arrays hashtables
2 gadgets gadgets-text gadgets-buttons generic ;
7 C: field ( model -- field )
8 <editor> over set-delegate
9 [ set-field-model ] keep
10 dup dup set-control-self ;
12 : field-commit ( field -- string )
14 [ field-model [ dupd set-model ] when* ] keep
17 field "Field commands" {
18 { "Clear input" T{ key-down f { C+ } "k" } [ control-model clear-doc ] }
19 { "Accept input" T{ key-down f f "RETURN" } [ field-commit drop ] }
22 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
24 TUPLE: action-field quot ;
26 C: action-field ( quot -- action-field )
27 tuck set-action-field-quot f <model> [ add-connection ] 2keep
28 <field> over set-gadget-delegate ;
30 M: action-field model-changed ( action-field -- ) dup action-field-quot call ;
32 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34 : variable-field ( var -- action-field )
35 unit [ editor-text ] swap append [ set ] append <action-field> ;
37 : number-field ( var -- action-field )
38 unit [ editor-text string>number ] swap append [ set ] append <action-field> ;
40 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
41 ! [bind] [unbind] and [bound?] should probably be in a separate
42 ! file. But right now boids and automata are the only programs which
43 ! use this, and I don't want to add a new contrib file just for
44 ! this. For now they'll live here. Maybe bind-button and
45 ! bind-action-field should go into a gadgets-utils file eventually.
46 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
48 : [bind] ( ns quot -- quot ) \ bind 3array >quotation ;
50 : [unbind] ( quot -- quot ) second ;
52 : [bound?] ( quot -- ? )
53 dup length 3 = [ dup first hashtable? swap third \ bind = and ] [ f ] if ;
55 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
57 : bind-button ( ns button -- ) tuck button-quot [bind] swap set-button-quot ;
59 : bind-action-field ( ns action-field -- )
60 tuck action-field-quot [bind] swap set-action-field-quot ;
62 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
64 PROVIDE: contrib/action-field ;