2006-08-24 18:23:48 -04:00
|
|
|
! Copyright (C) 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2006-08-24 23:19:22 -04:00
|
|
|
USING: arrays definitions kernel gadgets sequences strings math
|
|
|
|
words generic namespaces hashtables help ;
|
2006-08-25 20:52:13 -04:00
|
|
|
IN: gadgets
|
|
|
|
|
|
|
|
TUPLE: command group name gesture quot ;
|
2006-08-24 18:23:48 -04:00
|
|
|
|
2006-08-25 20:52:13 -04:00
|
|
|
M: command equal? eq? ;
|
2006-08-24 18:23:48 -04:00
|
|
|
|
|
|
|
GENERIC: gesture>string ( gesture -- string )
|
|
|
|
|
|
|
|
M: key-down gesture>string
|
|
|
|
dup key-down-mods [ word-name ] map concat >string
|
|
|
|
swap key-down-sym append ;
|
|
|
|
|
|
|
|
M: button-up gesture>string
|
|
|
|
"Mouse Up" swap button-up-#
|
|
|
|
[ " " swap number>string append3 ] when* ;
|
|
|
|
|
|
|
|
M: button-down gesture>string
|
|
|
|
"Mouse Down" swap button-down-#
|
|
|
|
[ " " swap number>string append3 ] when* ;
|
|
|
|
|
|
|
|
M: object gesture>string drop f ;
|
|
|
|
|
|
|
|
: define-commands ( class specs -- )
|
2006-08-25 20:52:13 -04:00
|
|
|
#! Specs is an array of { group name gesture quot }
|
|
|
|
[ first4 <command> ] map
|
2006-08-24 20:31:02 -04:00
|
|
|
2dup "commands" set-word-prop
|
2006-08-24 18:23:48 -04:00
|
|
|
[ command-gesture ] subset
|
|
|
|
[ dup command-gesture swap command-quot ] map>hash
|
|
|
|
"gestures" set-word-prop ;
|
|
|
|
|
|
|
|
: commands ( gadget -- seq )
|
2006-08-24 22:44:42 -04:00
|
|
|
delegates [ class "commands" word-prop ] map concat ;
|
2006-08-24 19:15:50 -04:00
|
|
|
|
2006-08-25 20:52:13 -04:00
|
|
|
: all-commands ( gadget -- seq )
|
|
|
|
parents [ commands ] map concat prune
|
|
|
|
[ [ command-name ] 2apply <=> ] sort ;
|
|
|
|
|
2006-08-24 18:23:48 -04:00
|
|
|
world {
|
|
|
|
{ f "Cut" T{ key-down f { C+ } "x" } [ T{ cut-action } send-action ] }
|
|
|
|
{ f "Copy" T{ key-down f { C+ } "c" } [ T{ copy-action } send-action ] }
|
|
|
|
{ f "Paste" T{ key-down f { C+ } "v" } [ T{ paste-action } send-action ] }
|
|
|
|
{ f "Select all" T{ key-down f { C+ } "a" } [ T{ select-all-action } send-action ] }
|
|
|
|
} define-commands
|
2006-08-24 22:44:42 -04:00
|
|
|
|
|
|
|
SYMBOL: operations
|
|
|
|
|
|
|
|
: define-operation ( pred button# name quot -- )
|
2006-08-25 20:52:13 -04:00
|
|
|
>r >r f r> f r> <command> 3array operations get push-new ;
|
2006-08-24 22:44:42 -04:00
|
|
|
|
|
|
|
: object-operation ( obj button# -- command )
|
|
|
|
swap operations get
|
2006-08-25 20:52:13 -04:00
|
|
|
[ >r class r> first class< ] subset-with
|
2006-08-24 22:44:42 -04:00
|
|
|
[ second = ] subset-with
|
|
|
|
dup empty? [ drop f ] [ peek third ] if ;
|
|
|
|
|
2006-08-25 20:52:13 -04:00
|
|
|
: object-operations ( object -- seq )
|
|
|
|
3 [ 1+ object-operation ] map-with ;
|
|
|
|
|
|
|
|
global [
|
|
|
|
operations get [
|
|
|
|
V{ } clone operations set
|
|
|
|
|
|
|
|
\ word 2 "Edit" [ edit ] define-operation
|
|
|
|
link 2 "Edit" [ edit ] define-operation
|
|
|
|
] unless
|
|
|
|
] bind
|