2006-09-14 16:15:39 -04:00
|
|
|
! Copyright (C) 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
IN: gadgets-workspace
|
|
|
|
USING: definitions gadgets gadgets-browser gadgets-dataflow
|
|
|
|
gadgets-help gadgets-listener gadgets-text gadgets-workspace
|
|
|
|
hashtables help inference kernel namespaces parser prettyprint
|
|
|
|
scratchpad sequences strings styles syntax test tools words
|
2006-09-19 02:30:21 -04:00
|
|
|
generic models ;
|
2006-09-14 16:15:39 -04:00
|
|
|
|
|
|
|
V{ } clone operations set-global
|
|
|
|
|
|
|
|
: define-operation ( class props -- )
|
|
|
|
<operation> operations get push-new ;
|
|
|
|
|
|
|
|
M: operation invoke-command ( target operation -- )
|
|
|
|
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 ;
|
|
|
|
|
2006-09-20 03:22:26 -04:00
|
|
|
: modify-operations ( operations quot -- operations )
|
|
|
|
swap [ modify-operation ] map-with ;
|
2006-09-14 16:15:39 -04:00
|
|
|
|
|
|
|
: modify-listener-operation ( quot operation -- operation )
|
|
|
|
clone t over set-operation-listener?
|
|
|
|
modify-operation ;
|
|
|
|
|
2006-09-20 03:22:26 -04:00
|
|
|
: modify-listener-operations ( operations quot -- operations )
|
|
|
|
swap [ modify-listener-operation ] map-with ;
|
2006-09-14 16:15:39 -04:00
|
|
|
|
|
|
|
! Objects
|
|
|
|
[ drop t ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f f 1 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Inspect" }
|
|
|
|
{ +quot+ [ inspect ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
2006-09-20 03:22:26 -04:00
|
|
|
[ drop t ] H{
|
|
|
|
{ +mouse+ T{ button-up f { S+ } 1 } }
|
|
|
|
{ +name+ "Push" }
|
|
|
|
{ +quot+ [ ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
2006-09-20 22:31:17 -04:00
|
|
|
! Commands
|
|
|
|
[ [ command? ] is? ] H{
|
|
|
|
{ +mouse+ T{ button-up f { S+ } 3 } }
|
|
|
|
{ +name+ "Inspect" }
|
|
|
|
{ +quot+ [ inspect ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
2006-09-14 16:15:39 -04:00
|
|
|
! Input
|
|
|
|
[ input? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f f 1 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Input" }
|
|
|
|
{ +quot+ [ listener-gadget call-tool ] }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Words
|
|
|
|
[ word? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f f 1 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Browse" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f { A+ } "b" } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +quot+ [ browser call-tool ] }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
[ word? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f f 2 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Edit" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f { A+ } "e" } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +quot+ [ edit ] }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
[ word? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f f 3 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Documentation" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f { A+ } "h" } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +quot+ [ help-gadget call-tool ] }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
[ word? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f { S+ } 3 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Usage" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f { A+ } "u" } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +quot+ [ usage. ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
[ word? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f { S+ } 2 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Reload" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f { A+ } "r" } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +quot+ [ reload ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
[ word? ] H{
|
|
|
|
{ +name+ "Watch" }
|
|
|
|
{ +quot+ [ watch ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Vocabularies
|
|
|
|
[ vocab-link? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f f 1 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Browse" }
|
|
|
|
{ +quot+ [ browser call-tool ] }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Link
|
|
|
|
[ link? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f f 1 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Follow" }
|
|
|
|
{ +quot+ [ help-gadget call-tool ] }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
[ link? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f f 2 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Edit" }
|
|
|
|
{ +quot+ [ edit ] }
|
|
|
|
} define-operation
|
|
|
|
|
2006-09-19 02:53:14 -04:00
|
|
|
[ link? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f { S+ } 2 } }
|
2006-09-19 02:53:14 -04:00
|
|
|
{ +name+ "Reload" }
|
|
|
|
{ +quot+ [ reload ] }
|
|
|
|
} define-operation
|
|
|
|
|
2006-09-14 16:15:39 -04:00
|
|
|
[ word-link? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f f 3 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Definition" }
|
|
|
|
{ +quot+ [ link-name browser call-tool ] }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Strings
|
|
|
|
[ string? ] H{
|
|
|
|
{ +name+ "Apropos (all)" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f { A+ } "a" } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +quot+ [ apropos ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
: usable-words ( -- seq )
|
|
|
|
[
|
|
|
|
use get [ hash-values [ dup set ] each ] each
|
|
|
|
] make-hash hash-values natural-sort ;
|
|
|
|
|
|
|
|
[ string? ] H{
|
|
|
|
{ +name+ "Apropos (used)" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f f "TAB" } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +quot+ [ usable-words (apropos) ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Quotations
|
|
|
|
[ quotation? ] H{
|
|
|
|
{ +name+ "Infer" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f { C+ A+ } "i" } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +quot+ [ infer . ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
[ quotation? ] H{
|
|
|
|
{ +name+ "Dataflow" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f { C+ A+ } "d" } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +quot+ [ show-dataflow ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
[ quotation? ] H{
|
|
|
|
{ +name+ "Walk" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f { C+ A+ } "w" } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +quot+ [ walk ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
[ quotation? ] H{
|
|
|
|
{ +name+ "Time" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f { C+ A+ } "t" } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +quot+ [ time ] }
|
|
|
|
{ +listener+ t }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Dataflow nodes
|
|
|
|
[ word? ] H{
|
2006-09-19 02:53:14 -04:00
|
|
|
{ +name+ "Dataflow" }
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +keyboard+ T{ key-down f { A+ } "d" } }
|
2006-09-15 21:29:58 -04:00
|
|
|
{ +quot+ [ word-def show-dataflow ] }
|
2006-09-14 16:15:39 -04:00
|
|
|
} define-operation
|
|
|
|
|
|
|
|
[ [ node? ] is? ] H{
|
2006-09-20 03:22:26 -04:00
|
|
|
{ +mouse+ T{ button-up f f 1 } }
|
2006-09-14 16:15:39 -04:00
|
|
|
{ +name+ "Quotation dataflow" }
|
|
|
|
{ +quot+ [ dataflow-gadget call-tool ] }
|
|
|
|
} define-operation
|
|
|
|
|
|
|
|
! Define commands in terms of operations
|
|
|
|
|
|
|
|
! Tile commands
|
2006-09-20 03:22:26 -04:00
|
|
|
tile "Word commands"
|
|
|
|
\ word class-operations [ tile-definition ] modify-operations
|
2006-09-14 16:15:39 -04:00
|
|
|
[ command-name "Browse" = not ] subset
|
2006-09-20 03:22:26 -04:00
|
|
|
define-commands
|
2006-09-14 16:15:39 -04:00
|
|
|
|
|
|
|
! Interactor commands
|
2006-09-19 02:30:21 -04:00
|
|
|
|
|
|
|
! Listener commands
|
2006-09-14 16:15:39 -04:00
|
|
|
: selected-word ( editor -- string )
|
|
|
|
dup gadget-selection?
|
|
|
|
[ dup T{ word-elt } select-elt ] unless
|
|
|
|
gadget-selection ;
|
|
|
|
|
|
|
|
: word-action ( target -- quot )
|
2006-09-20 03:22:26 -04:00
|
|
|
selected-word search ;
|
|
|
|
|
|
|
|
: quot-action ( interactor -- quot )
|
|
|
|
field-commit parse ;
|
|
|
|
|
|
|
|
interactor "Word commands"
|
|
|
|
\ word class-operations
|
|
|
|
[ word-action ] modify-listener-operations
|
|
|
|
define-commands
|
|
|
|
|
|
|
|
interactor "Word search commands"
|
|
|
|
string class-operations
|
|
|
|
[ selected-word ] modify-listener-operations
|
|
|
|
define-commands
|
|
|
|
|
|
|
|
interactor "Quotation commands"
|
|
|
|
quotation class-operations
|
|
|
|
[ quot-action ] modify-listener-operations
|
|
|
|
define-commands
|
|
|
|
|
|
|
|
help-gadget "Link commands"
|
|
|
|
link class-operations [ help-action ] modify-operations
|
|
|
|
[ command-name "Follow" = not ] subset
|
|
|
|
define-commands
|