2005-12-16 22:28:14 -05:00
|
|
|
IN: gadgets-presentations
|
|
|
|
USING: compiler gadgets gadgets-buttons gadgets-menus
|
2005-12-17 00:12:32 -05:00
|
|
|
gadgets-panes generic hashtables inference inspector io jedit
|
2005-12-16 22:28:14 -05:00
|
|
|
kernel lists namespaces parser prettyprint sequences words ;
|
|
|
|
|
|
|
|
SYMBOL: commands
|
|
|
|
|
2005-12-22 18:38:10 -05:00
|
|
|
TUPLE: command name pred quot context default? ;
|
2005-12-17 00:12:32 -05:00
|
|
|
|
2005-12-22 18:38:10 -05:00
|
|
|
V{ } clone commands set-global
|
2005-12-16 22:28:14 -05:00
|
|
|
|
|
|
|
: forget-command ( name -- )
|
2005-12-19 02:12:40 -05:00
|
|
|
global [
|
|
|
|
commands [ [ command-name = not ] subset-with ] change
|
|
|
|
] bind ;
|
2005-12-17 00:12:32 -05:00
|
|
|
|
2005-12-22 18:38:10 -05:00
|
|
|
: (define-command) ( name pred quot context default? -- )
|
2005-12-17 00:12:32 -05:00
|
|
|
<command> dup command-name forget-command commands get push ;
|
2005-12-16 22:28:14 -05:00
|
|
|
|
2005-12-22 18:38:10 -05:00
|
|
|
: define-command ( name pred quot context -- )
|
2005-12-17 00:12:32 -05:00
|
|
|
f (define-command) ;
|
|
|
|
|
2005-12-22 18:38:10 -05:00
|
|
|
: define-default-command ( name pred quot context -- )
|
2005-12-17 00:12:32 -05:00
|
|
|
t (define-command) ;
|
2005-12-16 22:28:14 -05:00
|
|
|
|
|
|
|
: applicable ( object -- seq )
|
2005-12-17 00:12:32 -05:00
|
|
|
commands get [ command-pred call ] subset-with ;
|
2005-12-16 22:28:14 -05:00
|
|
|
|
2005-12-17 00:12:32 -05:00
|
|
|
: command>quot ( presented command -- quot )
|
2005-12-22 18:38:10 -05:00
|
|
|
[ command-quot curry ] keep command-context unit curry ;
|
2005-12-16 22:28:14 -05:00
|
|
|
|
|
|
|
TUPLE: command-button object ;
|
|
|
|
|
2005-12-17 00:12:32 -05:00
|
|
|
: command-action ( command-button -- )
|
|
|
|
#! Invoke the default action.
|
|
|
|
command-button-object dup applicable
|
2005-12-19 02:12:40 -05:00
|
|
|
[ command-default? ] find-last nip command>quot call ;
|
2005-12-17 00:12:32 -05:00
|
|
|
|
|
|
|
: <command-menu-item> ( presented command -- item )
|
|
|
|
[ command>quot [ drop ] swap append ] keep
|
|
|
|
command-name swons ;
|
|
|
|
|
|
|
|
: <command-menu> ( presented -- menu )
|
2005-12-17 00:56:10 -05:00
|
|
|
dup applicable
|
2005-12-17 00:12:32 -05:00
|
|
|
[ <command-menu-item> ] map-with <menu> ;
|
|
|
|
|
|
|
|
: command-menu ( command-button -- )
|
2005-12-17 00:56:10 -05:00
|
|
|
dup button-update
|
|
|
|
command-button-object <command-menu>
|
|
|
|
show-hand-menu ;
|
2005-12-17 00:12:32 -05:00
|
|
|
|
|
|
|
: command-button-actions ( gadget -- )
|
|
|
|
dup
|
|
|
|
[ command-menu ] [ button-down 3 ] set-action
|
|
|
|
[ button-update ] [ button-up 3 ] set-action ;
|
2005-12-16 22:28:14 -05:00
|
|
|
|
|
|
|
C: command-button ( gadget object -- button )
|
2005-12-17 00:12:32 -05:00
|
|
|
[ set-command-button-object ] keep
|
2005-12-16 22:28:14 -05:00
|
|
|
[
|
2005-12-17 00:12:32 -05:00
|
|
|
>r [ command-action ] <roll-button> r>
|
|
|
|
set-gadget-delegate
|
2005-12-16 22:28:14 -05:00
|
|
|
] keep
|
2005-12-17 00:12:32 -05:00
|
|
|
dup command-button-actions ;
|
2005-12-16 22:28:14 -05:00
|
|
|
|
|
|
|
M: command-button gadget-help ( button -- string )
|
|
|
|
command-button-object dup word? [ synopsis ] [ summary ] if ;
|