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-30 03:50:02 -04:00
|
|
|
gadgets-text definitions inference test prettyprint math strings
|
|
|
|
hashtables ;
|
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 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-31 21:58:15 -04:00
|
|
|
{ "Listener" <listener-gadget> }
|
|
|
|
{ "Definitions" <browser> }
|
|
|
|
{ "Documentation" <help-gadget> }
|
|
|
|
{ "Walker" <walker-gadget> }
|
2006-08-26 03:46:37 -04:00
|
|
|
} ;
|
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
C: workspace ( -- workspace )
|
2006-08-31 21:58:15 -04:00
|
|
|
workspace-tabs [ second execute <tool> ] map <book>
|
|
|
|
over set-gadget-delegate dup dup set-control-self ;
|
2006-08-27 19:02:16 -04:00
|
|
|
|
2006-08-31 21:58:15 -04:00
|
|
|
M: workspace pref-dim* delegate pref-dim* { 550 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 )
|
2006-08-31 22:36:31 -04:00
|
|
|
[ book-pages [ tool-gadget class eq? ] find-with swap ] keep
|
2006-08-31 21:58:15 -04:00
|
|
|
control-model set-model* ;
|
2006-08-28 02:57:50 -04:00
|
|
|
|
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 ;
|
|
|
|
|
2006-08-31 21:58:15 -04:00
|
|
|
: select-tool ( workspace class -- ) swap show-tool drop ;
|
|
|
|
|
|
|
|
: tool-window ( class -- ) workspace-window show-tool drop ;
|
|
|
|
|
2006-08-27 23:22:30 -04:00
|
|
|
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 ] }
|
2006-08-31 21:58:15 -04:00
|
|
|
{ f "Definitions" T{ key-down f f "F3" } [ browser select-tool ] }
|
|
|
|
{ f "Documentation" T{ key-down f f "F4" } [ help-gadget select-tool ] }
|
|
|
|
{ f "Walker" T{ key-down f f "F5" } [ walker-gadget select-tool ] }
|
|
|
|
|
|
|
|
{ f "New listener" T{ key-down f { S+ } "F2" } [ listener-gadget tool-window drop ] }
|
|
|
|
{ f "New definitions" T{ key-down f { S+ } "F3" } [ browser tool-window drop ] }
|
|
|
|
{ f "New documentation" T{ key-down f { S+ } "F4" } [ help-gadget tool-window drop ] }
|
2006-08-27 23:22:30 -04:00
|
|
|
} define-commands
|
|
|
|
|
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
|
2006-08-30 03:50:02 -04:00
|
|
|
G: call-listener ( quot/string listener -- )
|
|
|
|
1 standard-combination ;
|
|
|
|
|
|
|
|
M: quotation call-listener
|
|
|
|
listener-gadget-input interactor-call ;
|
|
|
|
|
|
|
|
M: string call-listener
|
|
|
|
listener-gadget-input set-editor-text ;
|
|
|
|
|
|
|
|
M: input call-listener
|
|
|
|
>r input-string r> call-listener ;
|
|
|
|
|
2006-08-27 19:02:16 -04:00
|
|
|
M: listener-gadget call-tool* ( quot/string listener -- )
|
2006-08-30 03:50:02 -04:00
|
|
|
call-listener ;
|
2006-08-27 19:02:16 -04:00
|
|
|
|
|
|
|
: listener-run-files ( seq -- )
|
|
|
|
dup empty? [
|
|
|
|
drop
|
|
|
|
] [
|
|
|
|
[ [ run-file ] each ] curry listener-gadget call-tool
|
|
|
|
] if ;
|
|
|
|
|
|
|
|
! Browser tool
|
|
|
|
M: browser call-tool*
|
|
|
|
over vocab-link? [
|
|
|
|
>r vocab-link-name r> show-vocab
|
|
|
|
] [
|
|
|
|
show-word
|
|
|
|
] if ;
|
|
|
|
|
|
|
|
! Help tool
|
|
|
|
M: help-gadget call-tool* show-help ;
|
|
|
|
|
2006-08-30 03:50:02 -04:00
|
|
|
! Operations
|
|
|
|
V{ } clone operations set-global
|
|
|
|
|
|
|
|
: define-operation ( class props -- )
|
|
|
|
<operation> operations get push-new ;
|
|
|
|
|
2006-08-31 21:59:57 -04:00
|
|
|
M: operation invoke-command ( target operation -- )
|
2006-09-01 01:10:30 -04:00
|
|
|
dup command-quot swap operation-listener?
|
|
|
|
[ curry listener-gadget call-tool ] [ call ] if ;
|
|
|
|
|
|
|
|
: modify-operation ( quot operation -- operation )
|
|
|
|
clone
|
|
|
|
[ command-quot append ] keep
|
|
|
|
[ set-command-quot ] keep ;
|
|
|
|
|
|
|
|
: modify-operations ( quot operations -- operations )
|
|
|
|
[ modify-operation ] map-with ;
|
|
|
|
|
|
|
|
: modify-listener-operation ( quot operation -- operation )
|
|
|
|
clone t over set-operation-listener?
|
|
|
|
modify-operation ;
|
|
|
|
|
|
|
|
: modify-listener-operations ( quot operations -- operations )
|
|
|
|
[ modify-listener-operation ] map-with ;
|
2006-08-31 21:59:57 -04:00
|
|
|
|
2006-08-30 03:50:02 -04:00
|
|
|
! Objects
|
2006-09-01 01:20:38 -04:00
|
|
|
[ drop t ] H{
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +button+ 1 }
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +name+ "Inspect" }
|
|
|
|
{ +quot+ [ inspect ] }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +listener+ t }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Input
|
2006-09-01 01:20:38 -04:00
|
|
|
[ input? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +button+ 1 }
|
|
|
|
{ +name+ "Input" }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +quot+ [ listener-gadget call-tool ] }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Words
|
2006-09-01 01:20:38 -04:00
|
|
|
[ word? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +button+ 1 }
|
|
|
|
{ +name+ "Browse" }
|
|
|
|
{ +gesture+ T{ key-down f { A+ } "b" } }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +quot+ [ browser call-tool ] }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
2006-09-01 01:20:38 -04:00
|
|
|
[ word? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +button+ 2 }
|
|
|
|
{ +name+ "Edit" }
|
|
|
|
{ +gesture+ T{ key-down f { A+ } "e" } }
|
|
|
|
{ +quot+ [ edit ] }
|
|
|
|
} define-operation
|
|
|
|
|
2006-09-01 01:20:38 -04:00
|
|
|
[ word? ] H{
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +button+ 3 }
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +name+ "Documentation" }
|
|
|
|
{ +gesture+ T{ key-down f { A+ } "h" } }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +quot+ [ help-gadget call-tool ] }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
2006-09-01 01:20:38 -04:00
|
|
|
[ word? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +name+ "Usage" }
|
|
|
|
{ +gesture+ T{ key-down f { A+ } "u" } }
|
|
|
|
{ +quot+ [ usage. ] }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +listener+ t }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
2006-09-01 01:20:38 -04:00
|
|
|
[ word? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +name+ "Reload" }
|
|
|
|
{ +gesture+ T{ key-down f { A+ } "r" } }
|
|
|
|
{ +quot+ [ reload ] }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +listener+ t }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
2006-09-01 01:20:38 -04:00
|
|
|
[ word? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +name+ "Watch" }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +quot+ [ watch ] }
|
|
|
|
{ +listener+ t }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Vocabularies
|
2006-09-01 01:20:38 -04:00
|
|
|
[ vocab-link? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +button+ 1 }
|
|
|
|
{ +name+ "Browse" }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +quot+ [ browser call-tool ] }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Link
|
2006-09-01 01:20:38 -04:00
|
|
|
[ link? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +button+ 1 }
|
|
|
|
{ +name+ "Follow" }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +quot+ [ help-gadget call-tool ] }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
2006-09-01 01:20:38 -04:00
|
|
|
[ link? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +button+ 2 }
|
|
|
|
{ +name+ "Edit" }
|
|
|
|
{ +quot+ [ edit ] }
|
|
|
|
} define-operation
|
|
|
|
|
2006-09-01 01:20:38 -04:00
|
|
|
[ word-link? ] H{
|
2006-09-01 01:27:51 -04:00
|
|
|
{ +button+ 3 }
|
2006-09-01 01:20:38 -04:00
|
|
|
{ +name+ "Definition" }
|
|
|
|
{ +quot+ [ link-name browser call-tool ] }
|
|
|
|
} define-operation
|
|
|
|
|
2006-08-30 03:50:02 -04:00
|
|
|
! Strings
|
2006-09-01 01:20:38 -04:00
|
|
|
[ string? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +name+ "Apropos (all)" }
|
|
|
|
{ +gesture+ T{ key-down f { A+ } "a" } }
|
|
|
|
{ +quot+ [ apropos ] }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +listener+ t }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
|
|
|
: usable-words ( -- seq )
|
|
|
|
[
|
|
|
|
use get [ hash-values [ dup set ] each ] each
|
|
|
|
] make-hash hash-values natural-sort ;
|
|
|
|
|
2006-09-01 01:20:38 -04:00
|
|
|
[ string? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +name+ "Apropos (used)" }
|
|
|
|
{ +gesture+ T{ key-down f f "TAB" } }
|
|
|
|
{ +quot+ [ usable-words (apropos) ] }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +listener+ t }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Quotations
|
2006-09-01 01:20:38 -04:00
|
|
|
[ quotation? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +name+ "Infer" }
|
|
|
|
{ +gesture+ T{ key-down f { C+ A+ } "i" } }
|
2006-08-31 21:59:57 -04:00
|
|
|
{ +quot+ [ infer . ] }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +listener+ t }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
2006-09-01 01:20:38 -04:00
|
|
|
[ quotation? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +name+ "Walk" }
|
|
|
|
{ +gesture+ T{ key-down f { C+ A+ } "w" } }
|
|
|
|
{ +quot+ [ walk ] }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +listener+ t }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
2006-09-01 01:20:38 -04:00
|
|
|
[ quotation? ] H{
|
2006-08-30 03:50:02 -04:00
|
|
|
{ +name+ "Time" }
|
|
|
|
{ +gesture+ T{ key-down f { C+ A+ } "t" } }
|
|
|
|
{ +quot+ [ time ] }
|
2006-09-01 01:10:30 -04:00
|
|
|
{ +listener+ t }
|
2006-08-30 03:50:02 -04:00
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Define commands in terms of operations
|
|
|
|
|
|
|
|
! Tile commands
|
|
|
|
tile
|
2006-09-01 01:10:30 -04:00
|
|
|
[ tile-definition ] \ word class-operations modify-operations
|
|
|
|
[ command-name "Browse" = not ] subset
|
2006-08-30 03:50:02 -04:00
|
|
|
T{ command f f "Close" f [ close-tile ] } add*
|
|
|
|
define-commands*
|
|
|
|
|
|
|
|
! Interactor commands
|
|
|
|
: selected-word ( editor -- string )
|
|
|
|
dup gadget-selection?
|
2006-08-31 21:58:15 -04:00
|
|
|
[ dup T{ word-elt } select-elt ] unless
|
|
|
|
gadget-selection ;
|
2006-08-30 03:50:02 -04:00
|
|
|
|
2006-09-01 01:10:30 -04:00
|
|
|
: word-action ( target -- quot )
|
|
|
|
selected-word search ;
|
2006-08-30 03:50:02 -04:00
|
|
|
|
2006-08-31 21:58:15 -04:00
|
|
|
: quot-action ( quot -- quot )
|
2006-09-01 01:10:30 -04:00
|
|
|
field-commit parse ;
|
2006-08-30 03:50:02 -04:00
|
|
|
|
|
|
|
interactor [
|
|
|
|
{
|
|
|
|
{ f "Evaluate" T{ key-down f f "RETURN" } [ interactor-commit ] }
|
|
|
|
{ f "Send EOF" T{ key-down f { C+ } "d" } [ f swap interactor-eval ] }
|
|
|
|
} <commands> %
|
|
|
|
|
2006-09-01 01:10:30 -04:00
|
|
|
[ word-action ] \ word class-operations modify-listener-operations %
|
|
|
|
[ selected-word ] string class-operations modify-listener-operations %
|
|
|
|
[ quot-action ] quotation class-operations modify-listener-operations %
|
2006-08-30 03:50:02 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
{ f "History" T{ key-down f { C+ } "h" } [ [ interactor-history. ] swap interactor-call ] }
|
|
|
|
{ f "Clear output" T{ key-down f f "CLEAR" } [ [ clear-output ] swap interactor-call ] }
|
2006-08-31 21:58:15 -04:00
|
|
|
{ f "Clear stack" T{ key-down f { C+ } "CLEAR" } [ [ clear ] swap interactor-call ] }
|
2006-08-30 03:50:02 -04:00
|
|
|
} <commands> %
|
|
|
|
] { } make define-commands*
|