|
1 "{ NameSpace: NewInspector }" |
|
2 |
|
3 SelectionInListView subclass:#InspectorListView |
|
4 instanceVariableNames:'actionHolder listHolder includesSelf' |
|
5 classVariableNames:'' |
|
6 poolDictionaries:'' |
|
7 category:'Inspector' |
|
8 ! |
|
9 |
|
10 !InspectorListView class methodsFor:'documentation'! |
|
11 |
|
12 examples |
|
13 " |
|
14 |
|
15 |top slv a| |
|
16 |
|
17 a := OrderedCollection new. |
|
18 a add:1. |
|
19 |
|
20 top := StandardSystemView new |
|
21 label:'select'; |
|
22 extent:200@200. |
|
23 |
|
24 slv := ScrollableView for:self in:top. |
|
25 slv origin:0.0@0.0 corner:1.0@1.0. |
|
26 slv := slv scrolledView. |
|
27 slv inspect:top. |
|
28 slv action:[:el|Transcript showCR:(el printString)]. |
|
29 top open |
|
30 " |
|
31 ! ! |
|
32 |
|
33 !InspectorListView methodsFor:'accessing actions'! |
|
34 |
|
35 action:aOneArgAction |
|
36 "set the single click action block. |
|
37 If non-nil, that one is evaluated on single click, passing the |
|
38 selected instance as argument |
|
39 " |
|
40 actionHolder := aOneArgAction |
|
41 ! ! |
|
42 |
|
43 !InspectorListView methodsFor:'accessing attributes'! |
|
44 |
|
45 includesSelf |
|
46 ^ includesSelf |
|
47 ! |
|
48 |
|
49 includesSelf:aBool |
|
50 includesSelf := aBool |
|
51 ! |
|
52 |
|
53 inspectedObject |
|
54 ^ listHolder inspectedObject |
|
55 ! |
|
56 |
|
57 isEmpty |
|
58 "returns true if view is empty |
|
59 " |
|
60 ^ listHolder size == 0 |
|
61 ! |
|
62 |
|
63 listHolder |
|
64 ^ listHolder |
|
65 ! |
|
66 |
|
67 notEmpty |
|
68 "returns true if view is empty |
|
69 " |
|
70 ^ listHolder size ~~ 0 |
|
71 ! ! |
|
72 |
|
73 !InspectorListView methodsFor:'accessing contents'! |
|
74 |
|
75 updateFromList:aListHolder |
|
76 "set the lists contents from a list |
|
77 " |
|
78 listHolder := aListHolder. |
|
79 listHolder includesSelf:includesSelf. |
|
80 |
|
81 super list:(listHolder instanceNames). |
|
82 self setSelection:(listHolder selection). |
|
83 |
|
84 ! |
|
85 |
|
86 updateFromView:aInspectorListView |
|
87 "update contents from other view |
|
88 " |
|
89 self updateFromList:(aInspectorListView listHolder) |
|
90 ! |
|
91 |
|
92 updateList |
|
93 "set the lists contents dependant on the object |
|
94 " |
|
95 self updateList:(listHolder inspectedObject) selection:selection. |
|
96 ! ! |
|
97 |
|
98 !InspectorListView methodsFor:'actions'! |
|
99 |
|
100 accept:aText notifying:aView |
|
101 "on error #Error is returned otherwise the inspected object instance |
|
102 " |
|
103 |res| |
|
104 |
|
105 res := listHolder accept:aText notifying:aView. |
|
106 |
|
107 res ~~ #Error ifTrue:[ |
|
108 super list:(listHolder instanceNames). |
|
109 self setSelection:(listHolder selection) |
|
110 ]. |
|
111 ^ res |
|
112 ! |
|
113 |
|
114 doIt:aCode notifying:aView |
|
115 "on success the value returned from parser is returned otherwise #Error |
|
116 " |
|
117 |res| |
|
118 |
|
119 res := listHolder doIt:aCode notifying:aView. |
|
120 |
|
121 res ~~ #Error ifTrue:[ |
|
122 super list:(listHolder instanceNames). |
|
123 self setSelection:(listHolder selection) |
|
124 ]. |
|
125 ^ res |
|
126 |
|
127 ! |
|
128 |
|
129 inspect:anObject |
|
130 "inspect an object |
|
131 " |
|
132 ^ self inspect:anObject selection:nil |
|
133 ! |
|
134 |
|
135 inspect:anObject selection:aNumber |
|
136 "inspect an object and set the selection |
|
137 " |
|
138 aNumber notNil ifTrue:[ |
|
139 selection := aNumber |
|
140 ] ifFalse:[ |
|
141 (listHolder inspectedObject) ~~ anObject ifTrue:[ |
|
142 selection := nil |
|
143 ] |
|
144 ]. |
|
145 self updateList:anObject selection:selection |
|
146 ! ! |
|
147 |
|
148 !InspectorListView methodsFor:'drawing'! |
|
149 |
|
150 drawVisibleLineSelected:visLineNr with:fg and:bg |
|
151 "redraw a single line as selected." |
|
152 |
|
153 |nr| |
|
154 |
|
155 (nr := self visibleLineToListLine:visLineNr) notNil ifTrue:[ |
|
156 ^ self drawVisibleLine:visLineNr with:fg and:bg. |
|
157 ]. |
|
158 ^ super drawVisibleLine:visLineNr with:fg and:bg |
|
159 |
|
160 ! |
|
161 |
|
162 redrawArrowVisibleLine:visLineNr |
|
163 "draw a right arrow for visible line" |
|
164 |
|
165 |nr| |
|
166 |
|
167 nr := self visibleLineToListLine:visLineNr. |
|
168 |
|
169 (listHolder instanceTypeAt:nr) == #directory ifTrue:[ |
|
170 self drawRightArrowInVisibleLine:visLineNr |
|
171 ] |
|
172 |
|
173 |
|
174 ! |
|
175 |
|
176 redrawFromVisibleLine:startVisLineNr to:endVisLineNr |
|
177 "redefined to look for directory in every line |
|
178 " |
|
179 super redrawFromVisibleLine:startVisLineNr to:endVisLineNr. |
|
180 |
|
181 startVisLineNr to:endVisLineNr do:[:visLineNr| |
|
182 self redrawArrowVisibleLine:visLineNr |
|
183 ] |
|
184 ! |
|
185 |
|
186 redrawVisibleLine:visLineNr |
|
187 "if the line is one for a directory, draw a right arrow |
|
188 " |
|
189 super redrawVisibleLine:visLineNr. |
|
190 self redrawArrowVisibleLine:visLineNr. |
|
191 ! |
|
192 |
|
193 visibleLineNeedsSpecialCare:visLineNr |
|
194 |nr| |
|
195 |
|
196 (listHolder instanceTypeAt:nr) == #directory ifTrue:[ |
|
197 ^ true |
|
198 ]. |
|
199 ^ super visibleLineNeedsSpecialCare:visLineNr |
|
200 |
|
201 ! |
|
202 |
|
203 widthForScrollBetween:firstLine and:lastLine |
|
204 "return the width in pixels for a scroll between firstLine and lastLine |
|
205 - return full width here since there might be directory marks |
|
206 " |
|
207 ^ (width - margin - margin) |
|
208 |
|
209 |
|
210 ! ! |
|
211 |
|
212 !InspectorListView methodsFor:'event handling'! |
|
213 |
|
214 sizeChanged:how |
|
215 "redraw marks" |
|
216 |
|
217 super sizeChanged:how. |
|
218 shown ifTrue:[self invalidate] |
|
219 |
|
220 ! ! |
|
221 |
|
222 !InspectorListView methodsFor:'initialization'! |
|
223 |
|
224 initialize |
|
225 "initialization |
|
226 " |
|
227 super initialize. |
|
228 |
|
229 ignoreReselect := false. |
|
230 includesSelf := false. |
|
231 actionHolder := [:el|]. |
|
232 listHolder := InspectorList for:nil. |
|
233 |
|
234 actionBlock := [:dummy| |
|
235 self setSelection:selection. |
|
236 actionHolder value:(self selectedInstanceVar) |
|
237 ]. |
|
238 ! ! |
|
239 |
|
240 !InspectorListView methodsFor:'private'! |
|
241 |
|
242 updateList:inspObject selection:aSelection |
|
243 "set the lists contents dependant on the object |
|
244 " |
|
245 listHolder := InspectorList for:inspObject. |
|
246 listHolder includesSelf:includesSelf. |
|
247 super list:(listHolder instanceNames). |
|
248 |
|
249 aSelection notNil ifTrue:[ |
|
250 self setSelection:aSelection |
|
251 ] ifFalse:[ |
|
252 includesSelf ifTrue:[ |
|
253 self setSelection:1 |
|
254 ] |
|
255 ] |
|
256 ! ! |
|
257 |
|
258 !InspectorListView methodsFor:'selections'! |
|
259 |
|
260 selectedInstanceName |
|
261 "returns the name assigned to the selected instance or nil |
|
262 " |
|
263 ^ listHolder instanceNameAt:selection |
|
264 |
|
265 ! |
|
266 |
|
267 selectedInstanceType |
|
268 "returns the type of the selected instance or nil |
|
269 known types are: #directory #normal or:#self |
|
270 " |
|
271 ^ listHolder instanceTypeAt:selection |
|
272 ! |
|
273 |
|
274 selectedInstanceVar |
|
275 "returns the value assigned to the selected instance or nil |
|
276 " |
|
277 ^ listHolder instanceVarAt:selection |
|
278 |
|
279 ! |
|
280 |
|
281 setSelection:aNumberOrNil |
|
282 "select line, aNumber or deselect if argument is nil |
|
283 " |
|
284 |type| |
|
285 |
|
286 aNumberOrNil notNil ifTrue:[ |
|
287 type := listHolder instanceTypeAt:aNumberOrNil. |
|
288 listHolder selection:aNumberOrNil. |
|
289 |
|
290 type == #grow ifTrue:[ |
|
291 super list:(listHolder instanceNames) |
|
292 ] |
|
293 ]. |
|
294 super setSelection:aNumberOrNil |
|
295 |
|
296 ! ! |
|
297 |
|
298 !InspectorListView class methodsFor:'documentation'! |
|
299 |
|
300 version |
|
301 ^ '$Header$' |
|
302 ! ! |