2019-10-18 09:05:08 -04:00
|
|
|
! Copyright (C) 2006, 2007 Slava Pestov.
|
2006-08-24 18:23:48 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2019-10-18 09:05:08 -04:00
|
|
|
USING: arrays definitions kernel sequences strings math assocs
|
|
|
|
|
words generic namespaces assocs help quotations ;
|
2006-08-25 20:52:13 -04:00
|
|
|
IN: gadgets
|
|
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
SYMBOL: +nullary+
|
|
|
|
|
SYMBOL: +listener+
|
|
|
|
|
SYMBOL: +description+
|
2006-08-24 18:23:48 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
GENERIC: in-listener? ( command -- ? )
|
2006-08-24 18:23:48 -04:00
|
|
|
|
2006-08-30 03:50:02 -04:00
|
|
|
GENERIC: invoke-command ( target command -- )
|
|
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
GENERIC: command-name ( command -- str )
|
2006-08-24 18:23:48 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
TUPLE: command-map blurb ;
|
2006-08-27 23:22:30 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
GENERIC: command-description ( command -- str/f )
|
2006-08-24 18:23:48 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
GENERIC: command-word ( command -- word )
|
2006-08-24 18:23:48 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
C: command-map ( blurb commands -- command-map )
|
|
|
|
|
swap { } like over set-delegate
|
|
|
|
|
[ set-command-map-blurb ] keep ;
|
2006-08-24 18:23:48 -04:00
|
|
|
|
2006-09-20 03:22:26 -04:00
|
|
|
: commands ( class -- hash )
|
|
|
|
|
dup "commands" word-prop [ ] [
|
|
|
|
|
H{ } clone [ "commands" set-word-prop ] keep
|
|
|
|
|
] ?if ;
|
|
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: command-map ( group class -- command-map )
|
|
|
|
|
commands at ;
|
|
|
|
|
|
|
|
|
|
: command-gestures ( class -- hash )
|
|
|
|
|
commands values [
|
|
|
|
|
[
|
|
|
|
|
[ first ] subset
|
|
|
|
|
[ [ invoke-command ] curry swap set ] assoc-each
|
|
|
|
|
] each
|
|
|
|
|
] H{ } make-assoc ;
|
|
|
|
|
|
|
|
|
|
: update-gestures ( class -- )
|
|
|
|
|
dup command-gestures "gestures" set-word-prop ;
|
|
|
|
|
|
|
|
|
|
: define-command-map ( class group blurb pairs -- )
|
|
|
|
|
<command-map>
|
|
|
|
|
swap pick commands set-at
|
|
|
|
|
update-gestures ;
|
|
|
|
|
|
|
|
|
|
: (command-name) ( string -- newstring )
|
|
|
|
|
"-" split " " join unclip ch>upper add* ;
|
|
|
|
|
|
|
|
|
|
M: word command-name ( word -- str )
|
|
|
|
|
word-name
|
|
|
|
|
"com-" ?head drop
|
|
|
|
|
dup first Letter? [ 1 tail ] unless
|
|
|
|
|
(command-name) ;
|
|
|
|
|
|
|
|
|
|
M: word command-description ( word -- str )
|
|
|
|
|
+description+ word-prop ;
|
|
|
|
|
|
|
|
|
|
: command-map-row
|
|
|
|
|
[
|
|
|
|
|
dup first gesture>string ,
|
|
|
|
|
second dup command-name ,
|
|
|
|
|
dup command-word \ $link swap 2array ,
|
|
|
|
|
command-description ,
|
|
|
|
|
] [ ] make ;
|
|
|
|
|
|
|
|
|
|
: command-map. ( command-map -- )
|
|
|
|
|
[ command-map-row ] map
|
|
|
|
|
{ "Shortcut" "Command" "Word" "Notes" }
|
|
|
|
|
[ \ $strong swap ] { } map>assoc add*
|
2019-10-18 09:05:04 -04:00
|
|
|
$table ;
|
2006-08-31 21:59:57 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: $command-map ( element -- )
|
|
|
|
|
first2
|
|
|
|
|
dup (command-name) " commands" append $heading
|
|
|
|
|
swap command-map
|
|
|
|
|
dup command-map-blurb print-element command-map. ;
|
2006-08-30 03:50:02 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: $command ( element -- )
|
|
|
|
|
reverse first3 command-map value-at gesture>string $snippet ;
|
2006-08-30 03:50:02 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: define-command ( word hash -- )
|
|
|
|
|
>r word-props r> update ;
|
2006-08-24 22:44:42 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: command-quot ( target command -- quot )
|
|
|
|
|
dup 1quotation swap +nullary+ word-prop
|
|
|
|
|
[ nip ] [ curry ] if ;
|
2006-09-01 01:20:38 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
M: word in-listener? +listener+ word-prop ;
|
2006-08-30 03:50:02 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
M: word command-word ;
|
2006-10-04 23:57:34 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
M: f invoke-command ( target command -- ) 2drop ;
|
2006-10-04 23:57:34 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: command-string ( gesture command -- string )
|
|
|
|
|
[
|
|
|
|
|
command-name %
|
|
|
|
|
gesture>string [ " (" % % ")" % ] when*
|
|
|
|
|
] "" make ;
|