2006-08-26 03:46:37 -04:00
|
|
|
! Copyright (C) 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2006-08-26 14:30:58 -04:00
|
|
|
USING: arrays gadgets gadgets-listener gadgets-buttons
|
|
|
|
gadgets-walker gadgets-help gadgets-walker sequences
|
2006-08-26 17:13:24 -04:00
|
|
|
gadgets-browser gadgets-books gadgets-frames gadgets-controls
|
2006-08-27 19:02:16 -04:00
|
|
|
gadgets-grids gadgets-presentations kernel models namespaces
|
|
|
|
styles words help parser inspector memory generic threads
|
2006-08-28 18:14:54 -04:00
|
|
|
gadgets-text definitions inference test prettyprint math ;
|
2006-08-27 23:22:30 -04:00
|
|
|
IN: gadgets-workspace
|
2006-08-26 17:13:24 -04:00
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
GENERIC: call-tool* ( arg tool -- )
|
|
|
|
|
|
|
|
TUPLE: tool gadget ;
|
2006-08-26 17:13:24 -04:00
|
|
|
|
|
|
|
C: tool ( gadget -- tool )
|
|
|
|
{
|
|
|
|
{ [ dup <toolbar> ] f f @top }
|
2006-08-27 19:02:16 -04:00
|
|
|
{ [ ] set-tool-gadget f @center }
|
2006-08-26 17:13:24 -04:00
|
|
|
} make-frame* ;
|
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
M: tool gadget-title tool-gadget gadget-title ;
|
|
|
|
|
|
|
|
M: tool focusable-child* tool-gadget ;
|
2006-08-26 17:13:24 -04:00
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
M: tool call-tool* tool-gadget call-tool* ;
|
2006-08-26 03:46:37 -04:00
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
TUPLE: workspace ;
|
2006-08-26 03:46:37 -04:00
|
|
|
|
|
|
|
: workspace-tabs
|
|
|
|
{
|
2006-08-26 14:30:58 -04:00
|
|
|
{ "Listener" listener-gadget [ <listener-gadget> ] }
|
|
|
|
{ "Walker" walker-gadget [ <walker-gadget> ] }
|
|
|
|
{ "Dictionary" browser [ <browser> ] }
|
|
|
|
{ "Documentation" help-gadget [ <help-gadget> ] }
|
2006-08-26 03:46:37 -04:00
|
|
|
} ;
|
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
C: workspace ( -- workspace )
|
|
|
|
workspace-tabs
|
|
|
|
[ third [ <tool> ] append ] map <book>
|
|
|
|
over set-gadget-delegate
|
|
|
|
dup dup set-control-self ;
|
|
|
|
|
2006-08-29 18:27:51 -04:00
|
|
|
M: workspace pref-dim* delegate pref-dim* { 500 650 } vmax ;
|
2006-08-26 03:46:37 -04:00
|
|
|
|
2006-08-26 17:13:24 -04:00
|
|
|
: <workspace-tabs> ( book -- tabs )
|
|
|
|
control-model
|
2006-08-26 03:46:37 -04:00
|
|
|
workspace-tabs dup length [ swap first 2array ] 2map
|
|
|
|
<radio-box> ;
|
|
|
|
|
2006-08-26 17:13:24 -04:00
|
|
|
: init-status ( world -- )
|
|
|
|
dup world-status <presentation-help> swap @bottom grid-add ;
|
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
: init-tabs ( world -- )
|
|
|
|
[ world-gadget <workspace-tabs> ] keep @top grid-add ;
|
2006-08-26 17:13:24 -04:00
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
: workspace-window ( -- workspace )
|
2006-08-26 17:13:24 -04:00
|
|
|
<workspace> dup <world>
|
|
|
|
[ init-status ] keep
|
|
|
|
[ init-tabs ] keep
|
|
|
|
open-window ;
|
2006-08-27 19:02:16 -04:00
|
|
|
|
|
|
|
: show-tool ( class workspace -- tool )
|
|
|
|
>r workspace-tabs [ second eq? ] find-with drop r>
|
|
|
|
[ get-page ] 2keep control-model set-model ;
|
|
|
|
|
2006-08-28 02:57:50 -04:00
|
|
|
: select-tool ( workspace class -- ) swap show-tool drop ;
|
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
: find-workspace ( -- workspace )
|
|
|
|
[ workspace? ] find-window
|
|
|
|
[ world-gadget ] [ workspace-window find-workspace ] if* ;
|
|
|
|
|
|
|
|
: call-tool ( arg class -- )
|
|
|
|
find-workspace show-tool call-tool* ;
|
|
|
|
|
2006-08-27 23:22:30 -04:00
|
|
|
: commands-window ( workspace -- )
|
|
|
|
dup find-world world-focus [ ] [ gadget-child ] ?if
|
|
|
|
[ commands. ] "Commands" pane-window ;
|
|
|
|
|
|
|
|
workspace {
|
|
|
|
{ f "Keyboard help" T{ key-down f f "F1" } [ commands-window ] }
|
2006-08-28 02:57:50 -04:00
|
|
|
{ f "Listener" T{ key-down f f "F2" } [ listener-gadget select-tool ] }
|
|
|
|
{ f "Walker" T{ key-down f f "F3" } [ walker-gadget select-tool ] }
|
|
|
|
{ f "Dictionary" T{ key-down f f "F4" } [ browser select-tool ] }
|
|
|
|
{ f "Documentation" T{ key-down f f "F5" } [ help-gadget select-tool ] }
|
2006-08-28 15:54:40 -04:00
|
|
|
{ f "New workspace" T{ key-down f { C+ } "n" } [ workspace-window drop ] }
|
2006-08-27 23:22:30 -04:00
|
|
|
} define-commands
|
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
V{ } clone operations set-global
|
|
|
|
|
2006-08-28 15:54:40 -04:00
|
|
|
: define-operation ( pred button# name tool quot -- )
|
|
|
|
[ % , \ call-tool , ] [ ] make <operation> 3array
|
|
|
|
operations get push-new ;
|
|
|
|
|
2006-08-28 16:05:52 -04:00
|
|
|
\ word 2 "Edit" listener-gadget [ [ edit ] curry ] define-operation
|
|
|
|
link 2 "Edit" listener-gadget [ [ edit ] curry ] define-operation
|
2006-08-27 19:02:16 -04:00
|
|
|
|
2006-08-28 18:14:54 -04:00
|
|
|
! Walker tool
|
|
|
|
M: walker-gadget call-tool* ( arg tool -- )
|
|
|
|
>r first2 r> (walk) ;
|
|
|
|
|
|
|
|
: walk ( quot -- )
|
|
|
|
continuation dup continuation-data pop* 2array
|
|
|
|
walker-gadget call-tool stop ;
|
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
! Listener tool
|
|
|
|
M: listener-gadget call-tool* ( quot/string listener -- )
|
|
|
|
listener-gadget-input over quotation?
|
|
|
|
[ interactor-call ] [ set-editor-text ] if ;
|
|
|
|
|
|
|
|
: listener-run-files ( seq -- )
|
|
|
|
dup empty? [
|
|
|
|
drop
|
|
|
|
] [
|
|
|
|
[ [ run-file ] each ] curry listener-gadget call-tool
|
|
|
|
] if ;
|
|
|
|
|
2006-08-28 16:44:19 -04:00
|
|
|
: quot-action ( listener quot -- )
|
|
|
|
swap listener-gadget-input
|
|
|
|
[ dup field-commit , \ parse , swap % ] [ ] make
|
|
|
|
swap interactor-call ;
|
|
|
|
|
|
|
|
listener-gadget [
|
|
|
|
{
|
|
|
|
{ f "Stack effect" T{ key-down f { C+ A+ } "i" } [ infer . ] }
|
|
|
|
{ f "Single step" T{ key-down f { C+ A+ } "w" } [ walk ] }
|
|
|
|
{ f "Time execution" T{ key-down f { C+ A+ } "t" } [ time ] }
|
|
|
|
} [ first4 [ quot-action ] curry 4array ] map %
|
|
|
|
|
|
|
|
{
|
|
|
|
{ f "Clear output" T{ key-down f f "CLEAR" } [ clear-listener ] }
|
|
|
|
{ f "Clear stack" T{ key-down f { C+ } "CLEAR" } [ clear ] }
|
|
|
|
{ f "Globals" f [ global inspect ] }
|
|
|
|
{ f "Memory" f [ heap-stats. room. ] }
|
|
|
|
} [
|
|
|
|
first4 [ listener-gadget call-tool ] curry 4array
|
|
|
|
] map %
|
|
|
|
] [ ] make define-commands
|
2006-08-27 19:02:16 -04:00
|
|
|
|
2006-08-28 16:05:52 -04:00
|
|
|
object 1 "Inspect" listener-gadget [ [ inspect ] curry ] define-operation
|
|
|
|
object 3 "Inspect" listener-gadget [ [ inspect ] curry ] define-operation
|
|
|
|
input 1 "Input" listener-gadget [ input-string ] define-operation
|
2006-08-27 19:02:16 -04:00
|
|
|
|
|
|
|
! Browser tool
|
|
|
|
M: browser call-tool*
|
|
|
|
over vocab-link? [
|
|
|
|
>r vocab-link-name r> show-vocab
|
|
|
|
] [
|
|
|
|
show-word
|
|
|
|
] if ;
|
|
|
|
|
2006-08-28 16:05:52 -04:00
|
|
|
\ word 1 "Browse" browser [ ] define-operation
|
|
|
|
vocab-link 1 "Browse" browser [ ] define-operation
|
2006-08-27 19:02:16 -04:00
|
|
|
|
|
|
|
! Help tool
|
|
|
|
M: help-gadget call-tool* show-help ;
|
|
|
|
|
2006-08-28 16:05:52 -04:00
|
|
|
link 1 "Follow link" help-gadget [ ] define-operation
|