factor/library/ui/presentations.factor

59 lines
1.6 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 -- )
3vector commands get push ;
2005-07-06 03:29:42 -04:00
: applicable ( object -- seq )
commands get [ first call ] subset-with ;
: command-quot ( presented quot -- quot )
[ swap literalize , % ] make-list
[ pane get pane-call drop ] cons ;
: command-menu ( presented -- menu )
dup applicable
[ [ third command-quot ] keep second swons ] map-with
<menu> ;
: init-commands ( gadget -- )
dup presented paint-prop dup [
[
\ drop ,
2005-08-04 00:48:07 -04:00
literalize ,
[ command-menu show-menu ] %
] make-list
2005-07-09 18:32:31 -04:00
button-gestures
] [
2drop
] ifte ;
: <styled-label> ( style text -- label )
<label> swap dup [ alist>hash ] when over set-gadget-paint ;
: <presentation> ( style text -- presentation )
gadget pick assoc dup
[ 2nip ] [ drop <styled-label> dup init-commands ] ifte ;
2005-07-13 18:08:54 -04:00
: gadget. ( gadget -- )
gadget swons unit
"This stream does not support live gadgets"
2005-07-21 23:37:08 -04:00
swap format terpri ;
2005-07-13 18:08:54 -04:00
2005-08-21 01:17:37 -04:00
[ drop t ] "Prettyprint" [ pp ] define-command
2005-07-13 18:08:54 -04:00
[ drop t ] "Inspect" [ inspect ] define-command
[ drop t ] "References" [ references inspect ] define-command
2005-07-06 03:29:42 -04:00
2005-07-13 18:08:54 -04:00
[ word? ] "See" [ see ] define-command
[ word? ] "Usage" [ usage . ] define-command
[ word? ] "jEdit" [ jedit ] define-command
2005-07-06 03:29:42 -04:00
[ [ gadget? ] is? ] "Display" [ gadget. ] define-command