1 ! Copyright (C) 2006, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: classes continuations help help.topics kernel models
4 sequences assocs arrays namespaces accessors math.vectors fry ui
5 ui.backend ui.tools.debugger ui.gadgets ui.gadgets.books
6 ui.gadgets.buttons ui.gadgets.labelled ui.gadgets.panes
7 ui.gadgets.scrollers ui.gadgets.tracks ui.gadgets.worlds
8 ui.gadgets.presentations ui.gadgets.status-bar ui.commands
10 IN: ui.tools.workspace
12 TUPLE: workspace < track book listener popup ;
14 : find-workspace ( gadget -- workspace ) [ workspace? ] find-parent ;
16 SYMBOL: workspace-window-hook
18 : workspace-window* ( -- workspace ) workspace-window-hook get call ;
20 : workspace-window ( -- ) workspace-window* drop ;
22 GENERIC: call-tool* ( arg tool -- )
24 GENERIC: tool-scroller ( tool -- scroller )
26 M: gadget tool-scroller drop f ;
28 : find-tool ( class workspace -- index tool )
29 book>> children>> [ class eq? ] with find ;
31 : show-tool ( class workspace -- tool )
32 [ find-tool swap ] keep book>> model>>
35 : get-workspace* ( quot -- workspace )
36 '[ dup workspace? _ [ drop f ] if ] find-window
37 [ dup raise-window gadget-child ]
38 [ workspace-window* ] if* ; inline
40 : get-workspace ( -- workspace ) [ drop t ] get-workspace* ;
42 : call-tool ( arg class -- )
43 get-workspace show-tool call-tool* ;
45 : get-tool ( class -- gadget )
46 get-workspace find-tool nip ;
48 : <help-pane> ( topic -- pane )
49 <pane> [ [ help ] with-pane ] keep ;
51 : help-window ( topic -- )
53 <help-pane> <limited-scroller>
55 ] [ article-title ] bi
58 : hide-popup ( workspace -- )
59 dup popup>> track-remove
63 : show-popup ( gadget workspace -- )
69 : show-titled-popup ( workspace gadget title -- )
70 [ find-workspace hide-popup ] <closable-gadget>
73 : debugger-popup ( error workspace -- )
74 swap dup compute-restarts
75 [ find-workspace hide-popup ] <debugger>
76 "Error" show-titled-popup ;
80 { 600 700 } workspace-dim set-global
82 M: workspace pref-dim* call-next-method workspace-dim get vmax ;
84 M: workspace focusable-child*
85 dup popup>> [ ] [ listener>> ] ?if ;
87 : workspace-page ( workspace -- gadget )
90 M: workspace tool-scroller ( workspace -- scroller )
91 workspace-page tool-scroller ;
93 : com-scroll-up ( workspace -- )
94 tool-scroller [ scroll-up-page ] when* ;
96 : com-scroll-down ( workspace -- )
97 tool-scroller [ scroll-down-page ] when* ;
100 "The current tool's scroll pane can be scrolled from the keyboard."
102 { T{ key-down f { C+ } "PAGE_UP" } com-scroll-up }
103 { T{ key-down f { C+ } "PAGE_DOWN" } com-scroll-down }