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.editors
5 ui.gadgets.scrollers ui.gadgets.status-bar ui.gadgets.toolbar
6 ui.gadgets.tracks ui.gadgets.worlds ui.gestures ui.tools.common
8 IN: ui.tools.inspector.slots
10 TUPLE: slot-editor < track ref close-hook update-hook text ;
12 : revert ( slot-editor -- )
13 [ ref>> get-ref unparse-use ] [ text>> ] bi set-editor-string ;
16 { +description+ "Revert any uncomitted changes." }
19 : close ( slot-editor -- )
20 dup close-hook>> call( slot-editor -- ) ;
23 { +description+ "Close the slot editor without saving changes." }
26 : close-and-update ( slot-editor -- )
27 [ update-hook>> call( -- ) ] [ close ] bi ;
29 : slot-editor-value ( slot-editor -- object )
30 text>> control-value parse-fresh first ;
32 : commit ( slot-editor -- )
33 [ [ slot-editor-value ] [ ref>> ] bi set-ref ]
38 { +description+ "Parse the object being edited, and store the result back into the edited slot." }
41 : com-eval ( slot-editor -- )
42 [ [ text>> editor-string eval( -- result ) ] [ ref>> ] bi set-ref ]
48 { +description+ "Parse code which evaluates to an object, and store the result back into the edited slot." }
51 : delete ( slot-editor -- )
52 [ ref>> delete-ref ] [ close-and-update ] bi ;
55 { +description+ "Delete the slot and close the slot editor." }
58 : <slot-editor> ( close-hook update-hook ref -- gadget )
59 vertical slot-editor new-track with-lines
64 <source-editor> >>text
65 dup text>> margins <scroller> white-interior 1 track-add
68 M: slot-editor pref-dim* call-next-method { 600 200 } vmin ;
70 M: slot-editor focusable-child* text>> ;
72 slot-editor "toolbar" f {
73 { T{ key-down f { C+ } "RET" } commit }
74 { T{ key-down f { S+ C+ } "RET" } com-eval }
77 { T{ key-down f f "ESC" } close }
80 : slot-editor-window ( close-hook update-hook assoc key key-string -- )
81 [ <value-ref> <slot-editor> ]
84 swap "Slot editor: " prepend >>title
85 [ { dialog-window } append ] change-window-controls