factor/library/ui/presentations.factor

52 lines
1.4 KiB
Factor
Raw Normal View History

! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
2005-07-06 03:29:42 -04:00
USING: generic hashtables inspector io jedit kernel lists memory
namespaces parser prettyprint sequences styles vectors words ;
SYMBOL: commands
global [ 100 <vector> commands set ] bind
: define-command ( class name quot -- )
3list commands get push ;
: applicable ( object -- )
commands get >list
[ car "predicate" word-prop call ] subset-with ;
2005-07-07 20:17:34 -04:00
DEFER: pane-call
2005-06-29 19:40:44 -04:00
2005-07-06 03:29:42 -04:00
: command-menu ( pane -- menu )
presented get dup applicable [
3dup third [
2005-07-09 18:32:31 -04:00
[ swap literal, % ] make-list , ,
[ pane-call drop ] %
2005-07-06 03:29:42 -04:00
] make-list >r second r> cons
] map 2nip ;
2005-07-06 03:29:42 -04:00
: init-commands ( gadget pane -- )
2005-07-09 18:32:31 -04:00
over presented paint-prop [
[ drop ] swap
unit
[ command-menu <menu> show-menu ] append3
button-gestures
] [
2drop
] ifte ;
: <styled-label> ( style text -- label )
<label> swap alist>hash over set-gadget-paint ;
: <presentation> ( style text pane -- presentation )
2005-07-06 03:29:42 -04:00
>r <styled-label> dup r> init-commands ;
object "Prettyprint" [ prettyprint ] define-command
object "Inspect" [ inspect ] define-command
object "References" [ references inspect ] define-command
\ word "See" [ see ] define-command
\ word "Execute" [ execute ] define-command
\ word "Usage" [ usage . ] define-command
\ word "jEdit" [ jedit ] define-command