2008-07-11 01:01:22 -04:00
|
|
|
! Copyright (C) 2006, 2008 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-06-28 03:36:20 -04:00
|
|
|
USING: accessors arrays definitions kernel sequences strings
|
2009-05-14 17:54:16 -04:00
|
|
|
math assocs words generic namespaces make quotations
|
2009-03-16 21:11:36 -04:00
|
|
|
splitting ui.gestures unicode.case unicode.categories tr fry ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: ui.commands
|
|
|
|
|
|
|
|
SYMBOL: +nullary+
|
|
|
|
SYMBOL: +listener+
|
|
|
|
SYMBOL: +description+
|
|
|
|
|
2008-03-26 19:23:19 -04:00
|
|
|
PREDICATE: listener-command < word +listener+ word-prop ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
GENERIC: invoke-command ( target command -- )
|
|
|
|
|
|
|
|
GENERIC: command-name ( command -- str )
|
|
|
|
|
2008-07-11 01:01:22 -04:00
|
|
|
TUPLE: command-map blurb commands ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
GENERIC: command-description ( command -- str/f )
|
|
|
|
|
|
|
|
GENERIC: command-word ( command -- word )
|
|
|
|
|
|
|
|
: <command-map> ( blurb commands -- command-map )
|
2008-07-11 01:01:22 -04:00
|
|
|
{ } like \ command-map boa ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: commands ( class -- hash )
|
|
|
|
dup "commands" word-prop [ ] [
|
|
|
|
H{ } clone [ "commands" set-word-prop ] keep
|
|
|
|
] ?if ;
|
|
|
|
|
|
|
|
: command-map ( group class -- command-map )
|
|
|
|
commands at ;
|
|
|
|
|
|
|
|
: command-gestures ( class -- hash )
|
|
|
|
commands values [
|
|
|
|
[
|
2008-07-11 01:01:22 -04:00
|
|
|
commands>>
|
|
|
|
[ drop ] assoc-filter
|
2008-11-28 01:02:02 -05:00
|
|
|
[ '[ _ invoke-command ] swap set ] assoc-each
|
2007-09-20 18:09:08 -04:00
|
|
|
] 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 ;
|
|
|
|
|
2008-07-09 20:43:46 -04:00
|
|
|
TR: convert-command-name "-" " " ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: (command-name) ( string -- newstring )
|
2008-07-09 20:43:46 -04:00
|
|
|
convert-command-name >title ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: word command-name ( word -- str )
|
2008-06-28 03:36:20 -04:00
|
|
|
name>>
|
2009-01-31 00:52:02 -05:00
|
|
|
"com-" ?head drop "." ?tail drop
|
2008-04-26 03:01:43 -04:00
|
|
|
dup first Letter? [ rest ] unless
|
2007-09-20 18:09:08 -04:00
|
|
|
(command-name) ;
|
|
|
|
|
|
|
|
M: word command-description ( word -- str )
|
|
|
|
+description+ word-prop ;
|
|
|
|
|
|
|
|
: default-flags ( -- assoc )
|
|
|
|
H{ { +nullary+ f } { +listener+ f } { +description+ f } } ;
|
|
|
|
|
|
|
|
: define-command ( word hash -- )
|
2010-02-03 08:55:00 -05:00
|
|
|
default-flags swap assoc-union
|
|
|
|
'[ _ assoc-union ] change-props drop ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: command-quot ( target command -- quot )
|
2009-02-21 17:42:57 -05:00
|
|
|
[ 1quotation ] [ +nullary+ word-prop ] bi
|
2007-09-20 18:09:08 -04:00
|
|
|
[ nip ] [ curry ] if ;
|
|
|
|
|
|
|
|
M: word invoke-command ( target command -- )
|
2009-02-09 01:49:48 -05:00
|
|
|
command-quot call( -- ) ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: word command-word ;
|
|
|
|
|
2009-09-23 23:50:36 -04:00
|
|
|
M: f invoke-command ( target command -- ) 2drop ;
|