1 ! Copyright (C) 2007, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors eval kernel math.vectors parser prettyprint
4 refs sequences ui.commands ui.gadgets ui.gadgets.buttons
5 ui.gadgets.editors ui.gadgets.scrollers ui.gadgets.tracks
15 TUPLE: slot-editor < track ref close-hook update-hook text ;
17 : revert ( slot-editor -- )
18 [ ref>> get-ref unparse-use ] [ text>> ] bi set-editor-string ;
21 { +description+ "Revert any uncomitted changes." }
24 : close ( slot-editor -- )
25 dup close-hook>> call( slot-editor -- ) ;
28 { +description+ "Close the slot editor without saving changes." }
31 : close-and-update ( slot-editor -- )
32 [ update-hook>> call( -- ) ] [ close ] bi ;
34 : slot-editor-value ( slot-editor -- object )
35 text>> control-value parse-fresh first ;
37 : commit ( slot-editor -- )
38 [ [ slot-editor-value ] [ ref>> ] bi set-ref ]
43 { +description+ "Parse the object being edited, and store the result back into the edited slot." }
46 : com-eval ( slot-editor -- )
47 [ [ text>> editor-string eval( -- result ) ] [ ref>> ] bi set-ref ]
53 { +description+ "Parse code which evaluates to an object, and store the result back into the edited slot." }
56 : delete ( slot-editor -- )
57 [ ref>> delete-ref ] [ close-and-update ] bi ;
60 { +description+ "Delete the slot and close the slot editor." }
63 : <slot-editor> ( close-hook update-hook ref -- gadget )
64 vertical slot-editor new-track
69 <source-editor> >>text
70 dup text>> <scroller> 1 track-add
73 M: slot-editor pref-dim* call-next-method { 600 200 } vmin ;
75 M: slot-editor focusable-child* text>> ;
77 slot-editor "toolbar" f {
78 { T{ key-down f { C+ } "RET" } commit }
79 { T{ key-down f { S+ C+ } "RET" } com-eval }
82 { T{ key-down f f "ESC" } close }