factor/core/ui/tools/operations.factor

330 lines
7.5 KiB
Factor
Raw Normal View History

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
2006-11-17 04:34:22 -05:00
gadgets-help gadgets-listener gadgets-search gadgets-text
gadgets-workspace hashtables help inference kernel namespaces
parser prettyprint scratchpad sequences strings styles syntax
2006-11-30 02:15:42 -05:00
test tools words generic models io modules errors ;
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 -- )
2006-11-26 20:36:44 -05:00
dup command-quot swap operation-listener?
[ curry call-listener ] [ call ] if ;
2006-09-14 16:15:39 -04:00
: modify-listener-operation ( quot operation -- operation )
clone t over set-operation-listener?
2006-11-19 21:13:37 -05:00
modify-command ;
2006-09-14 16:15:39 -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-11-17 04:34:22 -05:00
{ +primary+ t }
2006-09-14 16:15:39 -04:00
{ +name+ "Inspect" }
{ +quot+ [ inspect ] }
{ +listener+ t }
} define-operation
[ drop t ] H{
{ +name+ "Prettyprint" }
{ +quot+ [ . ] }
{ +listener+ t }
} define-operation
[ drop t ] H{
{ +name+ "Push" }
{ +quot+ [ ] }
{ +listener+ t }
} define-operation
2006-09-14 16:15:39 -04:00
! Input
[ input? ] H{
2006-11-17 04:34:22 -05:00
{ +primary+ t }
{ +secondary+ t }
2006-09-14 16:15:39 -04:00
{ +name+ "Input" }
{ +quot+ [ listener-gadget call-tool ] }
2006-11-30 02:15:42 -05:00
} define-operation
! Restart
[ restart? ] H{
{ +primary+ t }
{ +secondary+ t }
{ +name+ "Restart" }
{ +quot+ [ restart ] }
{ +listener+ t }
2006-09-14 16:15:39 -04:00
} define-operation
! Pathnames
[ pathname? ] H{
2006-11-17 04:34:22 -05:00
{ +primary+ t }
2006-11-17 18:11:35 -05:00
{ +secondary+ t }
{ +name+ "Edit" }
2006-10-06 17:42:12 -04:00
{ +quot+ [ pathname-string edit-file ] }
} define-operation
[ pathname? ] H{
{ +name+ "Run file" }
2006-11-17 04:37:28 -05:00
{ +keyboard+ T{ key-down f { A+ } "r" } }
2006-11-18 03:51:34 -05:00
{ +quot+ [ pathname-string run-file ] }
{ +listener+ t }
} define-operation
2006-09-14 16:15:39 -04:00
! Words
[ word? ] H{
2006-11-17 04:37:28 -05:00
{ +primary+ t }
2006-09-14 16:15:39 -04:00
{ +name+ "Browse" }
{ +keyboard+ T{ key-down f { A+ } "b" } }
2006-09-14 16:15:39 -04:00
{ +quot+ [ browser call-tool ] }
} define-operation
2006-11-17 04:37:28 -05:00
: word-completion-string ( word listener -- string )
>r dup word-name swap word-vocabulary dup vocab r>
listener-gadget-use memq?
[ drop ] [ [ "USE: " % % " " % % ] "" make ] if ;
: insert-word ( word -- )
get-listener [ word-completion-string ] keep
2006-11-17 04:37:28 -05:00
listener-gadget-input user-input ;
[ word? ] H{
{ +secondary+ t }
{ +name+ "Insert" }
{ +quot+ [ insert-word ] }
} define-operation
2006-09-14 16:15:39 -04:00
[ word? ] H{
{ +name+ "Edit" }
{ +keyboard+ T{ key-down f { A+ } "e" } }
2006-09-14 16:15:39 -04:00
{ +quot+ [ edit ] }
} define-operation
[ word? ] H{
{ +name+ "Documentation" }
{ +keyboard+ T{ key-down f { A+ } "h" } }
2006-09-14 16:15:39 -04:00
{ +quot+ [ help-gadget call-tool ] }
} define-operation
[ word? ] H{
{ +name+ "Edit documentation" }
{ +quot+ [ <link> edit ] }
} define-operation
2006-09-14 16:15:39 -04:00
[ word? ] H{
{ +name+ "Usage" }
{ +keyboard+ T{ key-down f { A+ } "u" } }
2006-09-14 16:15:39 -04:00
{ +quot+ [ usage. ] }
{ +listener+ t }
} define-operation
[ word? ] H{
{ +name+ "Reload" }
{ +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 ] }
} define-operation
[ word? ] H{
{ +name+ "Forget" }
{ +quot+ [ forget ] }
} define-operation
2006-11-18 03:51:34 -05:00
[ compound? ] H{
2006-11-12 22:40:25 -05:00
{ +name+ "Word stack effect" }
{ +quot+ [ word-def infer. ] }
{ +listener+ t }
} define-operation
2006-11-18 03:51:34 -05:00
[ compound? ] H{
2006-09-30 00:03:46 -04:00
{ +name+ "Word dataflow" }
{ +quot+ [ word-def show-dataflow ] }
2006-11-22 02:14:56 -05:00
{ +keyboard+ T{ key-down f { A+ } "d" } }
2006-09-30 00:03:46 -04:00
} define-operation
2006-09-14 16:15:39 -04:00
! Vocabularies
[ vocab-link? ] H{
2006-11-17 04:37:28 -05:00
{ +primary+ t }
2006-09-14 16:15:39 -04:00
{ +name+ "Browse" }
2006-11-17 04:37:28 -05:00
{ +keyboard+ T{ key-down f { A+ } "b" } }
{ +quot+ [ vocab-link-name get-workspace swap show-vocab-words ] }
2006-09-14 16:15:39 -04:00
} define-operation
2006-10-06 17:07:13 -04:00
[ vocab-link? ] H{
{ +name+ "Enter in" }
2006-11-17 04:37:28 -05:00
{ +keyboard+ T{ key-down f { A+ } "i" } }
2006-11-17 18:11:35 -05:00
{ +quot+ [ vocab-link-name set-in ] }
{ +listener+ t }
2006-10-06 17:07:13 -04:00
} define-operation
[ vocab-link? ] H{
2006-11-17 04:37:28 -05:00
{ +secondary+ t }
2006-10-06 17:07:13 -04:00
{ +name+ "Use" }
2006-11-17 18:11:35 -05:00
{ +quot+ [ vocab-link-name use+ ] }
{ +listener+ t }
2006-10-06 17:07:13 -04:00
} define-operation
[ vocab-link? ] H{
{ +name+ "Forget" }
{ +quot+ [ vocab-link-name forget-vocab ] }
} define-operation
! Modules
[ module? ] H{
2006-11-17 18:11:35 -05:00
{ +secondary+ t }
{ +name+ "Run" }
{ +quot+ [ module-name run-module ] }
{ +listener+ t }
} define-operation
2006-11-17 18:11:35 -05:00
[ module? ] H{
{ +name+ "Load" }
{ +quot+ [ module-name require ] }
{ +listener+ t }
} define-operation
[ module? ] H{
{ +name+ "Documentation" }
2006-11-17 04:37:28 -05:00
{ +keyboard+ T{ key-down f { A+ } "h" } }
{ +quot+ [ module-help [ help-gadget call-tool ] when* ] }
} define-operation
[ module? ] H{
{ +name+ "Edit" }
2006-11-17 04:37:28 -05:00
{ +keyboard+ T{ key-down f { A+ } "e" } }
{ +quot+ [ edit ] }
} define-operation
[ module? ] H{
2006-11-17 18:11:35 -05:00
{ +primary+ t }
{ +name+ "Browse" }
{ +keyboard+ T{ key-down f { A+ } "b" } }
{ +quot+ [ get-workspace swap show-module-files ] }
} define-operation
[ module? ] H{
{ +name+ "See" }
2006-11-17 18:11:35 -05:00
{ +quot+ [ browser call-tool ] }
} define-operation
[ module? ] H{
{ +name+ "Test" }
{ +quot+ [ module-name test-module ] }
{ +listener+ t }
} define-operation
! Module links
[ module-link? ] H{
{ +primary+ t }
{ +secondary+ t }
{ +name+ "Run" }
{ +quot+ [ module-name run-module ] }
{ +listener+ t }
} define-operation
[ module-link? ] H{
{ +name+ "Load" }
{ +quot+ [ module-name require ] }
{ +listener+ t }
} define-operation
2006-09-14 16:15:39 -04:00
! Link
[ link? ] H{
2006-11-17 04:37:28 -05:00
{ +primary+ t }
{ +secondary+ t }
2006-09-14 16:15:39 -04:00
{ +name+ "Follow" }
{ +quot+ [ help-gadget call-tool ] }
} define-operation
[ link? ] H{
{ +name+ "Edit" }
2006-11-17 04:37:28 -05:00
{ +keyboard+ T{ key-down f { A+ } "e" } }
2006-09-14 16:15:39 -04:00
{ +quot+ [ edit ] }
} define-operation
2006-09-19 02:53:14 -04:00
[ link? ] H{
{ +name+ "Reload" }
2006-11-17 04:37:28 -05:00
{ +keyboard+ T{ key-down f { A+ } "r" } }
2006-09-19 02:53:14 -04:00
{ +quot+ [ reload ] }
} define-operation
2006-09-14 16:15:39 -04:00
[ word-link? ] H{
{ +name+ "Definition" }
2006-11-17 04:37:28 -05:00
{ +keyboard+ T{ key-down f { A+ } "b" } }
2006-09-14 16:15:39 -04:00
{ +quot+ [ link-name browser call-tool ] }
} define-operation
! Quotations
[ quotation? ] H{
2006-11-12 22:40:25 -05:00
{ +name+ "Quotation stack effect" }
2006-11-22 02:14:56 -05:00
{ +keyboard+ T{ key-down f { C+ } "i" } }
2006-11-12 22:40:25 -05:00
{ +quot+ [ infer. ] }
2006-09-14 16:15:39 -04:00
{ +listener+ t }
} define-operation
[ quotation? ] H{
2006-09-30 00:03:46 -04:00
{ +name+ "Quotation dataflow" }
2006-11-22 02:14:56 -05:00
{ +keyboard+ T{ key-down f { C+ } "d" } }
2006-09-14 16:15:39 -04:00
{ +quot+ [ show-dataflow ] }
{ +listener+ t }
} define-operation
[ quotation? ] H{
{ +name+ "Walk" }
2006-11-22 02:14:56 -05:00
{ +keyboard+ T{ key-down f { C+ } "w" } }
2006-09-14 16:15:39 -04:00
{ +quot+ [ walk ] }
{ +listener+ t }
} define-operation
[ quotation? ] H{
{ +name+ "Time" }
2006-11-22 02:14:56 -05:00
{ +keyboard+ T{ key-down f { C+ } "t" } }
2006-09-14 16:15:39 -04:00
{ +quot+ [ time ] }
{ +listener+ t }
} define-operation
! Dataflow nodes
[ [ node? ] is? ] H{
2006-11-17 04:37:28 -05:00
{ +primary+ t }
2006-09-30 00:03:46 -04:00
{ +name+ "Show dataflow" }
2006-09-14 16:15:39 -04:00
{ +quot+ [ dataflow-gadget call-tool ] }
} define-operation
! Define commands in terms of operations
! Interactor commands
: word-action ( target -- quot )
selected-word search ;
: quot-action ( interactor -- quot )
dup editor-text swap select-all parse ;
2006-10-09 23:57:32 -04:00
interactor "words"
2006-11-22 02:14:56 -05:00
{ word compound } [ class-operations ] map concat
[ word-action ] modify-listener-operations
define-commands
2006-10-09 23:57:32 -04:00
interactor "quotations"
quotation class-operations
[ quot-action ] modify-listener-operations
define-commands
2006-10-09 23:57:32 -04:00
help-gadget "toolbar" {
{ "Back" T{ key-down f { C+ } "b" } [ help-gadget-history go-back ] }
{ "Forward" T{ key-down f { C+ } "f" } [ help-gadget-history go-forward ] }
{ "Home" T{ key-down f { C+ } "h" } [ go-home ] }
}
2006-11-19 21:13:37 -05:00
link class-operations [ help-action ] modify-commands
[ command-name "Follow" = not ] subset
append
define-commands