factor/basis/ui/tools/inspector/slots/slots.factor

88 lines
2.6 KiB
Factor
Raw Permalink 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.status-bar ui.gadgets.toolbar
ui.gadgets.tracks ui.gadgets.worlds ui.gestures ui.tools.common
;
IN: ui.tools.inspector.slots
2007-09-20 18:09:08 -04:00
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 with-lines
swap >>ref
swap >>update-hook
swap >>close-hook
2008-11-20 22:58:30 -05:00
add-toolbar
<source-editor> >>text
dup text>> margins <scroller> white-interior 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
: slot-editor-window ( close-hook update-hook assoc key key-string -- )
[ <value-ref> <slot-editor> ]
[
<world-attributes>
swap "Slot editor: " prepend >>title
[ { dialog-window } append ] change-window-controls
] bi*
open-status-window ;