2009-01-08 18:02:54 -05:00
|
|
|
! Copyright (C) 2007, 2009 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2015-01-29 14:41:18 -05:00
|
|
|
USING: accessors eval kernel math.vectors parser prettyprint
|
2015-07-29 11:31:19 -04:00
|
|
|
refs sequences ui.commands ui.gadgets ui.gadgets.editors
|
|
|
|
ui.gadgets.scrollers ui.gadgets.toolbar ui.gadgets.tracks
|
2015-01-29 14:41:18 -05:00
|
|
|
ui.gestures ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: ui.gadgets.slots
|
|
|
|
|
|
|
|
TUPLE: update-object ;
|
|
|
|
|
|
|
|
TUPLE: update-slot ;
|
|
|
|
|
|
|
|
TUPLE: edit-slot ;
|
|
|
|
|
2009-01-08 18:02:54 -05:00
|
|
|
TUPLE: slot-editor < track ref close-hook update-hook text ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: revert ( slot-editor -- )
|
2009-01-08 18:02:54 -05:00
|
|
|
[ ref>> get-ref unparse-use ] [ text>> ] bi set-editor-string ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
\ revert H{
|
|
|
|
{ +description+ "Revert any uncomitted changes." }
|
|
|
|
} define-command
|
|
|
|
|
2009-01-08 18:02:54 -05:00
|
|
|
: close ( slot-editor -- )
|
2009-04-12 17:08:54 -04:00
|
|
|
dup close-hook>> call( slot-editor -- ) ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-01-08 18:02:54 -05:00
|
|
|
\ close H{
|
|
|
|
{ +description+ "Close the slot editor without saving changes." }
|
|
|
|
} define-command
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-01-08 18:02:54 -05:00
|
|
|
: close-and-update ( slot-editor -- )
|
2009-04-12 17:08:54 -04:00
|
|
|
[ update-hook>> call( -- ) ] [ close ] bi ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: slot-editor-value ( slot-editor -- object )
|
2009-01-08 18:02:54 -05:00
|
|
|
text>> control-value parse-fresh first ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: commit ( slot-editor -- )
|
2009-01-08 18:02:54 -05:00
|
|
|
[ [ slot-editor-value ] [ ref>> ] bi set-ref ]
|
|
|
|
[ close-and-update ]
|
|
|
|
bi ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
\ commit H{
|
|
|
|
{ +description+ "Parse the object being edited, and store the result back into the edited slot." }
|
|
|
|
} define-command
|
|
|
|
|
|
|
|
: com-eval ( slot-editor -- )
|
2009-04-15 20:03:44 -04:00
|
|
|
[ [ text>> editor-string eval( -- result ) ] [ ref>> ] bi set-ref ]
|
2009-01-08 18:02:54 -05:00
|
|
|
[ close-and-update ]
|
|
|
|
bi ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
\ com-eval H{
|
|
|
|
{ +listener+ t }
|
|
|
|
{ +description+ "Parse code which evaluates to an object, and store the result back into the edited slot." }
|
|
|
|
} define-command
|
|
|
|
|
|
|
|
: delete ( slot-editor -- )
|
2009-01-08 18:02:54 -05:00
|
|
|
[ ref>> delete-ref ] [ close-and-update ] bi ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
\ delete H{
|
|
|
|
{ +description+ "Delete the slot and close the slot editor." }
|
|
|
|
} define-command
|
|
|
|
|
2009-01-08 18:02:54 -05:00
|
|
|
: <slot-editor> ( close-hook update-hook ref -- gadget )
|
2009-02-02 01:02:55 -05:00
|
|
|
vertical slot-editor new-track
|
2008-09-27 15:36:04 -04:00
|
|
|
swap >>ref
|
2009-01-08 18:02:54 -05:00
|
|
|
swap >>update-hook
|
|
|
|
swap >>close-hook
|
2008-11-20 22:58:30 -05:00
|
|
|
add-toolbar
|
2008-09-27 15:36:04 -04:00
|
|
|
<source-editor> >>text
|
|
|
|
dup text>> <scroller> 1 track-add
|
|
|
|
dup revert ;
|
2015-06-29 19:43:15 -04:00
|
|
|
|
2008-07-11 01:01:22 -04:00
|
|
|
M: slot-editor pref-dim* call-next-method { 600 200 } vmin ;
|
|
|
|
|
|
|
|
M: slot-editor focusable-child* text>> ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
slot-editor "toolbar" f {
|
|
|
|
{ T{ key-down f { C+ } "RET" } commit }
|
|
|
|
{ T{ key-down f { S+ C+ } "RET" } com-eval }
|
|
|
|
{ f revert }
|
|
|
|
{ f delete }
|
|
|
|
{ T{ key-down f f "ESC" } close }
|
|
|
|
} define-command-map
|