factor/library/ui/commands.factor

87 lines
3.0 KiB
Factor
Raw Normal View History

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
sequences words ;
2005-12-16 22:28:14 -05:00
SYMBOL: commands
TUPLE: command name pred quot context default? ;
2005-12-17 00:12:32 -05:00
V{ } clone commands set-global
2005-12-16 22:28:14 -05:00
: forget-command ( name -- )
global [
commands [ [ command-name = not ] subset-with ] change
] bind ;
2005-12-17 00:12:32 -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
: define-command ( name pred quot context -- )
2005-12-17 00:12:32 -05:00
f (define-command) ;
: 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 )
[ 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
[ 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
"Describe" [ drop t ] [ describe ] \ in-browser define-default-command
"Prettyprint" [ drop t ] [ . ] \ in-listener define-command
"Push on data stack" [ drop t ] [ ] \ in-listener define-command
"See word" [ word? ] [ see ] \ in-browser define-default-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
"Annotate with watchpoint" [ compound? ] [ watch ] \ in-listener define-command
"Annotate with breakpoint" [ compound? ] [ break ] \ in-listener define-command
"Annotate with profiling" [ compound? ] [ profile ] \ in-listener define-command
"Compile" [ word? ] [ recompile ] \ 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