factor/basis/ui/gadgets/slots/slots.factor

84 lines
2.2 KiB
Factor
Raw Normal View History

! 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 ;
TUPLE: slot-editor < track ref close-hook update-hook text ;
2007-09-20 18:09:08 -04:00
: revert ( slot-editor -- )
[ 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
: 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
\ close H{
{ +description+ "Close the slot editor without saving changes." }
} define-command
2007-09-20 18:09:08 -04: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 )
text>> control-value parse-fresh first ;
2007-09-20 18:09:08 -04:00
: commit ( slot-editor -- )
[ [ 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 ]
[ 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 -- )
[ 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
: <slot-editor> ( close-hook update-hook ref -- gadget )
vertical slot-editor new-track
swap >>ref
swap >>update-hook
swap >>close-hook
2008-11-20 22:58:30 -05:00
add-toolbar
<source-editor> >>text
dup text>> <scroller> 1 track-add
dup revert ;
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