1 ! Copyright (C) 2007, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors namespaces kernel parser prettyprint
4 sequences arrays io math definitions math.vectors assocs refs
5 ui.gadgets ui.gestures ui.commands ui.gadgets.scrollers
6 ui.gadgets.buttons ui.gadgets.borders ui.gadgets.tracks
7 ui.gadgets.editors eval continuations ;
10 TUPLE: update-object ;
16 TUPLE: slot-editor < track ref close-hook update-hook text ;
18 : revert ( slot-editor -- )
19 [ ref>> get-ref unparse-use ] [ text>> ] bi set-editor-string ;
22 { +description+ "Revert any uncomitted changes." }
25 : close ( slot-editor -- )
26 dup close-hook>> call ;
29 { +description+ "Close the slot editor without saving changes." }
32 : close-and-update ( slot-editor -- )
33 [ update-hook>> call ] [ close ] bi ;
35 : slot-editor-value ( slot-editor -- object )
36 text>> control-value parse-fresh first ;
38 : commit ( slot-editor -- )
39 [ [ slot-editor-value ] [ ref>> ] bi set-ref ]
44 { +description+ "Parse the object being edited, and store the result back into the edited slot." }
47 : eval-1 ( string -- object )
48 1array [ eval ] with-datastack first ;
50 : com-eval ( slot-editor -- )
51 [ [ text>> editor-string eval-1 ] [ ref>> ] bi set-ref ]
57 { +description+ "Parse code which evaluates to an object, and store the result back into the edited slot." }
60 : delete ( slot-editor -- )
61 [ ref>> delete-ref ] [ close-and-update ] bi ;
64 { +description+ "Delete the slot and close the slot editor." }
67 : <slot-editor> ( close-hook update-hook ref -- gadget )
68 vertical slot-editor new-track
73 <source-editor> >>text
74 dup text>> <scroller> 1 track-add
77 M: slot-editor pref-dim* call-next-method { 600 200 } vmin ;
79 M: slot-editor focusable-child* text>> ;
81 slot-editor "toolbar" f {
82 { T{ key-down f { C+ } "RET" } commit }
83 { T{ key-down f { S+ C+ } "RET" } com-eval }
86 { T{ key-down f f "ESC" } close }