factor/library/ui/commands.factor

84 lines
2.7 KiB
Factor
Raw Normal View History

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-17 00:12:32 -05:00
TUPLE: command name pred quot default? ;
2005-12-16 22:28:14 -05:00
V{ } clone commands global set-hash
: forget-command ( name -- )
2005-12-17 00:12:32 -05:00
commands [ [ command-name = not ] subset-with ] change ;
: (define-command) ( name pred quot default? -- )
<command> dup command-name forget-command commands get push ;
2005-12-16 22:28:14 -05:00
2005-12-17 00:12:32 -05:00
: define-command ( name pred quot -- )
f (define-command) ;
: define-default-command ( name pred quot -- )
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 [ pane get pane-call ] 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 nip command>quot call ;
: <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-17 00:12:32 -05:00
"Use as input" [ input? ] [ input-string pane get replace-input ] define-default-command
"Describe" [ drop t ] [ describe ] define-default-command
"Prettyprint" [ drop t ] [ . ] define-command
"Push on data stack" [ drop t ] [ ] define-command
"See word" [ word? ] [ see ] define-default-command
"Word call hierarchy" [ word? ] [ uses. ] define-command
"Word caller hierarchy" [ word? ] [ usage. ] define-command
"Open in jEdit" [ word? ] [ jedit ] define-command
"Reload original source" [ word? ] [ reload ] define-command
"Annotate with watchpoint" [ compound? ] [ watch ] define-command
"Annotate with breakpoint" [ compound? ] [ break ] define-command
"Annotate with profiling" [ compound? ] [ profile ] define-command
"Compile" [ word? ] [ recompile ] define-command
"Infer stack effect" [ word? ] [ unit infer . ] define-command
"Display gadget" [ [ gadget? ] is? ] [ gadget. ] define-command