1 ! Copyright (C) 2006, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs colors colors.constants combinators
4 concurrency.messaging formatting fry inspector kernel make
5 models models.arrow namespaces sequences threads tools.walker ui
6 ui.commands ui.gadgets ui.gadgets.buttons ui.gadgets.labels
7 ui.gadgets.status-bar ui.gadgets.theme ui.gadgets.toolbar
8 ui.gadgets.tracks ui.gestures ui.pens.solid ui.tools.browser
9 ui.tools.common ui.tools.listener ui.tools.traceback ;
12 TUPLE: walker-gadget < tool
13 status continuation thread
17 : walker-command ( walker msg -- )
19 dup thread>> thread-registered?
20 [ thread>> send-synchronous drop ]
24 : com-step ( walker -- ) step walker-command ;
26 : com-into ( walker -- ) step-into walker-command ;
28 : com-out ( walker -- ) step-out walker-command ;
30 : com-back ( walker -- ) step-back walker-command ;
32 : com-continue ( walker -- ) step-all walker-command ;
34 : com-abandon ( walker -- ) abandon walker-command ;
36 M: walker-gadget ungraft*
37 [ t >>closing? drop ] [ com-continue ] [ call-next-method ] tri ;
39 M: walker-gadget focusable-child*
42 : thread-status-text ( status -- string )
44 { +stopped+ "Stopped" }
45 { +suspended+ "Suspended" }
46 { +running+ "Running" }
47 } at "(" ")" surround ;
49 : thread-status-foreground ( status -- color )
51 { +stopped+ [ thread-status-stopped-foreground ] }
52 { +suspended+ [ thread-status-suspended-foreground ] }
53 { +running+ [ thread-status-running-foreground ] }
57 : thread-status-background ( status -- color )
59 { +stopped+ [ thread-status-stopped-background ] }
60 { +suspended+ [ thread-status-suspended-background ] }
61 { +running+ [ thread-status-running-background ] }
62 { f [ content-background ] }
65 TUPLE: thread-status < label ;
67 M: thread-status model-changed
69 [ [ thread-status-text ] [ string<< ] bi* ]
70 [ [ thread-status-foreground ] [ font>> foreground<< ] bi* ]
71 [ [ thread-status-background <solid> ] [ parent>> parent>> interior<< ] bi* ]
74 : <thread-status> ( model -- gadget )
75 "" thread-status new-label
78 : add-thread-status ( track -- track )
79 horizontal <track> { 5 5 } >>gap
81 [ t >>bold? text-color >>foreground ] change-font
83 self name>> <label> [ text-color >>foreground ] change-font f track-add
84 over status>> <thread-status>
85 dup font>> t >>bold? drop
89 : add-traceback ( track -- track )
90 dup traceback>> 1 track-add ;
92 : <walker-gadget> ( status continuation thread -- gadget )
93 vertical walker-gadget new-track with-lines
97 dup continuation>> <traceback-gadget> >>traceback
102 : walker-help ( -- ) "ui-walker" com-browse ;
104 \ walker-help H{ { +nullary+ t } } define-command
106 walker-gadget "toolbar" f {
107 { T{ key-down f f "s" } com-step }
108 { T{ key-down f f "i" } com-into }
109 { T{ key-down f f "o" } com-out }
110 { T{ key-down f f "b" } com-back }
111 { T{ key-down f f "c" } com-continue }
112 { T{ key-down f f "a" } com-abandon }
113 { T{ key-down f f "d" } close-window }
114 { T{ key-down f f "F1" } walker-help }
117 walker-gadget "multitouch" f {
118 { left-action com-back }
119 { right-action com-step }
120 { up-action com-out }
121 { down-action com-into }
122 { zoom-out-action close-window }
123 { zoom-in-action com-abandon }
126 : walker-for-thread? ( thread gadget -- ? )
128 { [ dup walker-gadget? not ] [ 2drop f ] }
129 { [ dup closing?>> ] [ 2drop f ] }
133 : find-walker-window ( thread -- world/f )
134 '[ _ swap walker-for-thread? ] find-window ;
136 : walker-window ( status continuation thread -- )
137 [ <walker-gadget> ] [ name>> ] bi open-status-window ;
140 dup find-walker-window dup
141 [ raise-window 3drop ] [ drop '[ _ _ _ walker-window ] with-ui ] if
142 ] show-walker-hook set-global