2005-12-16 22:28:14 -05:00
|
|
|
IN: gadgets-presentations
|
2005-12-22 22:54:54 -05:00
|
|
|
USING: compiler gadgets gadgets-buttons gadgets-listener
|
|
|
|
gadgets-menus gadgets-panes generic hashtables inference
|
|
|
|
inspector io jedit kernel lists namespaces parser prettyprint
|
2006-01-06 02:04:42 -05:00
|
|
|
sequences words styles ;
|
2005-12-16 22:28:14 -05:00
|
|
|
|
|
|
|
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 ;
|
2005-12-22 22:54:54 -05:00
|
|
|
|
2005-12-25 22:18:25 -05:00
|
|
|
"Describe object" [ drop t ] [ describe ] \ in-browser define-default-command
|
2005-12-31 04:20:07 -05:00
|
|
|
"Describe commands" [ drop t ] [ applicable describe ] \ in-browser define-command
|
2005-12-22 22:54:54 -05:00
|
|
|
"Prettyprint" [ drop t ] [ . ] \ in-listener define-command
|
|
|
|
"Push on data stack" [ drop t ] [ ] \ in-listener define-command
|
|
|
|
|
|
|
|
"Word call hierarchy" [ word? ] [ uses. ] \ in-browser define-command
|
|
|
|
"Word caller hierarchy" [ word? ] [ usage. ] \ in-browser define-command
|
|
|
|
"Open in jEdit" [ word? ] [ jedit ] \ call define-command
|
|
|
|
"Reload original source" [ word? ] [ reload ] \ in-listener define-command
|
|
|
|
"Infer stack effect" [ word? ] [ unit infer . ] \ in-listener define-command
|
|
|
|
|
|
|
|
"Display gadget" [ [ gadget? ] is? ] [ gadget. ] \ in-listener define-command
|
|
|
|
|
|
|
|
"Use as input" [ input? ] [ input-string pane get replace-input ] \ call define-default-command
|