factor/library/ui/tools/operations.factor

243 lines
6.1 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
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 ;
: 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 ;
! Objects
[ drop t ] H{
{ +button+ 1 }
{ +name+ "Inspect" }
{ +quot+ [ inspect ] }
{ +listener+ t }
} define-operation
! Input
[ input? ] H{
{ +button+ 1 }
{ +name+ "Input" }
{ +quot+ [ listener-gadget call-tool ] }
} define-operation
! Words
[ word? ] H{
{ +button+ 1 }
2006-09-19 02:30:21 -04:00
{ +group+ "Word commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Browse" }
{ +gesture+ T{ key-down f { A+ } "b" } }
{ +quot+ [ browser call-tool ] }
} define-operation
[ word? ] H{
{ +button+ 2 }
2006-09-19 02:30:21 -04:00
{ +group+ "Word commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Edit" }
{ +gesture+ T{ key-down f { A+ } "e" } }
{ +quot+ [ edit ] }
} define-operation
[ word? ] H{
{ +button+ 3 }
2006-09-19 02:30:21 -04:00
{ +group+ "Word commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Documentation" }
{ +gesture+ T{ key-down f { A+ } "h" } }
{ +quot+ [ help-gadget call-tool ] }
} define-operation
[ word? ] H{
2006-09-19 02:30:21 -04:00
{ +group+ "Word commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Usage" }
{ +gesture+ T{ key-down f { A+ } "u" } }
{ +quot+ [ usage. ] }
{ +listener+ t }
} define-operation
[ word? ] H{
2006-09-19 02:30:21 -04:00
{ +group+ "Word commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Reload" }
{ +gesture+ T{ key-down f { A+ } "r" } }
{ +quot+ [ reload ] }
{ +listener+ t }
} define-operation
[ word? ] H{
2006-09-19 02:30:21 -04:00
{ +group+ "Word commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Watch" }
{ +quot+ [ watch ] }
{ +listener+ t }
} define-operation
! Vocabularies
[ vocab-link? ] H{
{ +button+ 1 }
{ +name+ "Browse" }
{ +quot+ [ browser call-tool ] }
} define-operation
! Link
[ link? ] H{
{ +button+ 1 }
{ +name+ "Follow" }
{ +quot+ [ help-gadget call-tool ] }
} define-operation
[ link? ] H{
{ +button+ 2 }
{ +name+ "Edit" }
{ +quot+ [ edit ] }
} define-operation
[ word-link? ] H{
{ +button+ 3 }
{ +name+ "Definition" }
{ +quot+ [ link-name browser call-tool ] }
} define-operation
! Strings
[ string? ] H{
2006-09-19 02:30:21 -04:00
{ +group+ "Word commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Apropos (all)" }
{ +gesture+ T{ key-down f { A+ } "a" } }
{ +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{
2006-09-19 02:30:21 -04:00
{ +group+ "Word commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Apropos (used)" }
{ +gesture+ T{ key-down f f "TAB" } }
{ +quot+ [ usable-words (apropos) ] }
{ +listener+ t }
} define-operation
! Quotations
[ quotation? ] H{
2006-09-19 02:30:21 -04:00
{ +group+ "Quotation commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Infer" }
{ +gesture+ T{ key-down f { C+ A+ } "i" } }
{ +quot+ [ infer . ] }
{ +listener+ t }
} define-operation
[ quotation? ] H{
2006-09-19 02:30:21 -04:00
{ +group+ "Quotation commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Dataflow" }
{ +gesture+ T{ key-down f { C+ A+ } "d" } }
{ +quot+ [ show-dataflow ] }
{ +listener+ t }
} define-operation
[ quotation? ] H{
2006-09-19 02:30:21 -04:00
{ +group+ "Quotation commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Walk" }
{ +gesture+ T{ key-down f { C+ A+ } "w" } }
{ +quot+ [ walk ] }
{ +listener+ t }
} define-operation
[ quotation? ] H{
2006-09-19 02:30:21 -04:00
{ +group+ "Quotation commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Time" }
{ +gesture+ T{ key-down f { C+ A+ } "t" } }
{ +quot+ [ time ] }
{ +listener+ t }
} define-operation
! Dataflow nodes
[ word? ] H{
2006-09-19 02:30:21 -04:00
{ +group+ "Word commands" }
2006-09-14 16:15:39 -04:00
{ +name+ "Word dataflow" }
2006-09-15 21:29:58 -04:00
{ +gesture+ T{ key-down f { A+ } "d" } }
{ +quot+ [ word-def show-dataflow ] }
2006-09-14 16:15:39 -04:00
} define-operation
[ [ node? ] is? ] H{
{ +button+ 1 }
{ +name+ "Quotation dataflow" }
{ +quot+ [ dataflow-gadget call-tool ] }
} define-operation
! Define commands in terms of operations
! Tile commands
tile
[ tile-definition ] \ word class-operations modify-operations
[ command-name "Browse" = not ] subset
T{ command f f "Close" f [ close-tile ] } add*
define-commands*
! 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 ;
2006-09-19 02:30:21 -04:00
: listener-selected-word ( listener -- string )
listener-gadget-input selected-word ;
2006-09-14 16:15:39 -04:00
: word-action ( target -- quot )
2006-09-19 02:30:21 -04:00
listener-selected-word search ;
2006-09-14 16:15:39 -04:00
: quot-action ( quot -- quot )
2006-09-19 02:30:21 -04:00
listener-gadget-input field-commit parse ;
2006-09-14 16:15:39 -04:00
2006-09-19 02:30:21 -04:00
listener-gadget [
2006-09-14 16:15:39 -04:00
{
2006-09-19 02:30:21 -04:00
"Listener commands"
{ "Send EOF" T{ key-down f { C+ } "d" } [ listener-eof ] }
{ "History" T{ key-down f { C+ } "h" } [ listener-history ] }
{ "Clear output" T{ key-down f f "CLEAR" } [ clear-listener-output ] }
{ "Clear stack" T{ key-down f { C+ } "CLEAR" } [ clear-listener-stack ] }
2006-09-14 16:15:39 -04:00
} <commands> %
[ word-action ] \ word class-operations modify-listener-operations %
2006-09-19 02:30:21 -04:00
[ listener-selected-word ] string class-operations modify-listener-operations %
2006-09-14 16:15:39 -04:00
[ quot-action ] quotation class-operations modify-listener-operations %
2006-09-19 02:30:21 -04:00
] { } make define-commands*
2006-09-14 16:15:39 -04:00
2006-09-19 02:30:21 -04:00
help-gadget [
2006-09-14 16:15:39 -04:00
{
2006-09-19 02:30:21 -04:00
"Help commands"
{ "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 ] }
}
[ help-gadget-history model-value ] link class-operations modify-listener-operations
[ command-name "Follow" = not ] subset %
2006-09-14 16:15:39 -04:00
] { } make define-commands*