34
|
1 |
"{ NameSpace: NewInspector }"
|
|
2 |
|
|
3 |
SelectionInListView subclass:#InspectorListView
|
39
|
4 |
instanceVariableNames:'actionHolder inspectorList includesSelf'
|
34
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Inspector'
|
|
8 |
!
|
|
9 |
|
|
10 |
!InspectorListView class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
examples
|
|
13 |
"
|
39
|
14 |
open a list view on an instance
|
|
15 |
[exBegin]
|
34
|
16 |
|top slv a|
|
|
17 |
|
|
18 |
a := OrderedCollection new.
|
|
19 |
a add:1.
|
|
20 |
|
|
21 |
top := StandardSystemView new
|
|
22 |
label:'select';
|
|
23 |
extent:200@200.
|
|
24 |
|
|
25 |
slv := ScrollableView for:self in:top.
|
|
26 |
slv origin:0.0@0.0 corner:1.0@1.0.
|
|
27 |
slv := slv scrolledView.
|
|
28 |
slv inspect:top.
|
|
29 |
slv action:[:el|Transcript showCR:(el printString)].
|
|
30 |
top open
|
39
|
31 |
[exEnd]
|
34
|
32 |
"
|
|
33 |
! !
|
|
34 |
|
39
|
35 |
!InspectorListView methodsFor:'accessing'!
|
34
|
36 |
|
|
37 |
includesSelf:aBool
|
|
38 |
includesSelf := aBool
|
|
39 |
!
|
|
40 |
|
39
|
41 |
list
|
|
42 |
^ inspectorList
|
34
|
43 |
!
|
|
44 |
|
39
|
45 |
list:aList
|
|
46 |
"set the lists contents from another list
|
34
|
47 |
"
|
39
|
48 |
|list selNr|
|
34
|
49 |
|
39
|
50 |
aList notNil ifTrue:[inspectorList := aList list]
|
|
51 |
ifFalse:[inspectorList := InspectorList new].
|
34
|
52 |
|
39
|
53 |
inspectorList includesSelf:includesSelf.
|
|
54 |
super list:(inspectorList instanceNames).
|
34
|
55 |
!
|
|
56 |
|
39
|
57 |
update
|
|
58 |
"update the current list
|
34
|
59 |
"
|
39
|
60 |
inspectorList update.
|
|
61 |
super list:(inspectorList instanceNames).
|
34
|
62 |
|
|
63 |
! !
|
|
64 |
|
39
|
65 |
!InspectorListView methodsFor:'accessing actions'!
|
34
|
66 |
|
39
|
67 |
action:aOneArgAction
|
|
68 |
"set the single click action block. If non-nil, that one is evaluated on single
|
|
69 |
click, passing the selected instance as argument
|
34
|
70 |
"
|
39
|
71 |
actionHolder := aOneArgAction
|
34
|
72 |
! !
|
|
73 |
|
|
74 |
!InspectorListView methodsFor:'drawing'!
|
|
75 |
|
|
76 |
drawVisibleLineSelected:visLineNr with:fg and:bg
|
39
|
77 |
"redraw a single line as selected.
|
|
78 |
"
|
34
|
79 |
|nr|
|
|
80 |
|
|
81 |
(nr := self visibleLineToListLine:visLineNr) notNil ifTrue:[
|
|
82 |
^ self drawVisibleLine:visLineNr with:fg and:bg.
|
|
83 |
].
|
|
84 |
^ super drawVisibleLine:visLineNr with:fg and:bg
|
|
85 |
|
|
86 |
!
|
|
87 |
|
|
88 |
redrawArrowVisibleLine:visLineNr
|
39
|
89 |
"draw a right arrow for visible line
|
|
90 |
"
|
34
|
91 |
|nr|
|
|
92 |
|
|
93 |
nr := self visibleLineToListLine:visLineNr.
|
|
94 |
|
39
|
95 |
(inspectorList instanceTypeAt:nr) == #directory ifTrue:[
|
34
|
96 |
self drawRightArrowInVisibleLine:visLineNr
|
|
97 |
]
|
|
98 |
|
|
99 |
|
|
100 |
!
|
|
101 |
|
|
102 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr
|
|
103 |
"redefined to look for directory in every line
|
|
104 |
"
|
|
105 |
super redrawFromVisibleLine:startVisLineNr to:endVisLineNr.
|
|
106 |
|
|
107 |
startVisLineNr to:endVisLineNr do:[:visLineNr|
|
|
108 |
self redrawArrowVisibleLine:visLineNr
|
|
109 |
]
|
|
110 |
!
|
|
111 |
|
|
112 |
redrawVisibleLine:visLineNr
|
|
113 |
"if the line is one for a directory, draw a right arrow
|
|
114 |
"
|
|
115 |
super redrawVisibleLine:visLineNr.
|
|
116 |
self redrawArrowVisibleLine:visLineNr.
|
|
117 |
!
|
|
118 |
|
|
119 |
visibleLineNeedsSpecialCare:visLineNr
|
39
|
120 |
"returns true if the visible line needs special care
|
|
121 |
"
|
34
|
122 |
|nr|
|
|
123 |
|
39
|
124 |
(inspectorList instanceTypeAt:nr) == #directory ifTrue:[
|
34
|
125 |
^ true
|
|
126 |
].
|
|
127 |
^ super visibleLineNeedsSpecialCare:visLineNr
|
|
128 |
|
|
129 |
!
|
|
130 |
|
|
131 |
widthForScrollBetween:firstLine and:lastLine
|
|
132 |
"return the width in pixels for a scroll between firstLine and lastLine
|
|
133 |
- return full width here since there might be directory marks
|
|
134 |
"
|
|
135 |
^ (width - margin - margin)
|
|
136 |
|
|
137 |
|
|
138 |
! !
|
|
139 |
|
|
140 |
!InspectorListView methodsFor:'event handling'!
|
|
141 |
|
|
142 |
sizeChanged:how
|
39
|
143 |
"redraw marks
|
|
144 |
"
|
34
|
145 |
super sizeChanged:how.
|
|
146 |
shown ifTrue:[self invalidate]
|
|
147 |
|
|
148 |
! !
|
|
149 |
|
|
150 |
!InspectorListView methodsFor:'initialization'!
|
|
151 |
|
|
152 |
initialize
|
|
153 |
"initialization
|
|
154 |
"
|
|
155 |
super initialize.
|
|
156 |
|
|
157 |
ignoreReselect := false.
|
|
158 |
includesSelf := false.
|
|
159 |
actionHolder := [:el|].
|
39
|
160 |
inspectorList := InspectorList new.
|
34
|
161 |
|
|
162 |
actionBlock := [:dummy|
|
|
163 |
self setSelection:selection.
|
|
164 |
actionHolder value:(self selectedInstanceVar)
|
|
165 |
].
|
|
166 |
! !
|
|
167 |
|
|
168 |
!InspectorListView methodsFor:'private'!
|
|
169 |
|
39
|
170 |
doesNotUnderstand:aMessage
|
|
171 |
"forward a message to the inspectorList
|
34
|
172 |
"
|
39
|
173 |
(inspectorList respondsTo:(aMessage selector)) ifTrue:[
|
|
174 |
^ aMessage sendTo:inspectorList
|
|
175 |
].
|
|
176 |
^ super doesNotUnderstand:aMessage
|
|
177 |
|
|
178 |
|
|
179 |
!
|
|
180 |
|
|
181 |
list:aCollection keepSelection:aBoolean
|
|
182 |
"set the list - redefined, since setting the list implies unselecting
|
|
183 |
and clearing attributes."
|
|
184 |
|
|
185 |
|oldSelection|
|
34
|
186 |
|
39
|
187 |
"somewhat of a kludge: if selection is first line,
|
|
188 |
we have to remove the highlight frame by hand here"
|
|
189 |
|
|
190 |
(shown and:[hilightLevel ~~ 0]) ifTrue:[
|
|
191 |
selection == firstLineShown ifTrue:[
|
|
192 |
self paint:bgColor.
|
|
193 |
self fillRectangleX:margin y:margin
|
|
194 |
width:(width - (margin * 2))
|
|
195 |
height:(hilightLevel abs).
|
|
196 |
].
|
|
197 |
].
|
|
198 |
listAttributes := nil.
|
|
199 |
super list:aCollection expandTabs:false.
|
|
200 |
super setSelection:(inspectorList selection).
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
34
|
205 |
! !
|
|
206 |
|
|
207 |
!InspectorListView methodsFor:'selections'!
|
|
208 |
|
39
|
209 |
setSelection:aNumberOrNil
|
|
210 |
"select line, aNumber or deselect if argument is nil
|
|
211 |
"
|
|
212 |
|oldSize|
|
|
213 |
|
|
214 |
oldSize := inspectorList size.
|
|
215 |
inspectorList setSelection:aNumberOrNil.
|
|
216 |
oldSize == inspectorList size ifTrue:[super setSelection:(inspectorList selection)]
|
|
217 |
ifFalse:[super list:(inspectorList instanceNames)].
|
|
218 |
! !
|
|
219 |
|
|
220 |
!InspectorListView methodsFor:'user interaction'!
|
|
221 |
|
|
222 |
accept:aText notifying:aView
|
|
223 |
"evaluating aText on the selected instance var; if an error occurs #Error
|
|
224 |
is returned otherwise the inspected object instance. On success the list
|
|
225 |
will be updated.
|
34
|
226 |
"
|
39
|
227 |
|res|
|
|
228 |
|
|
229 |
res := inspectorList accept:aText notifying:aView.
|
|
230 |
|
|
231 |
res ~~ #Error ifTrue:[
|
|
232 |
super list:(inspectorList instanceNames)
|
|
233 |
].
|
|
234 |
^ res
|
|
235 |
!
|
|
236 |
|
|
237 |
doIt:aCode notifying:aView
|
|
238 |
"evaluating aCode on the selected instance var; if an error occurs #Error
|
|
239 |
is returned otherwise the result returned from the evaluator. On success
|
|
240 |
the list will be updated.
|
|
241 |
"
|
|
242 |
|res|
|
|
243 |
|
|
244 |
res := inspectorList doIt:aCode notifying:aView.
|
|
245 |
|
|
246 |
res ~~ #Error ifTrue:[
|
|
247 |
super list:(inspectorList instanceNames)
|
|
248 |
].
|
|
249 |
^ res
|
34
|
250 |
|
|
251 |
!
|
|
252 |
|
39
|
253 |
inspect:anObject
|
|
254 |
"inspect a new instance; update contents
|
34
|
255 |
"
|
39
|
256 |
(inspectorList inspectedObject) == anObject ifTrue:[
|
|
257 |
^ self update
|
|
258 |
].
|
|
259 |
inspectorList := InspectorList for:anObject.
|
|
260 |
inspectorList includesSelf:includesSelf.
|
34
|
261 |
|
39
|
262 |
super list:(inspectorList instanceNames).
|
34
|
263 |
! !
|
|
264 |
|
|
265 |
!InspectorListView class methodsFor:'documentation'!
|
|
266 |
|
|
267 |
version
|
|
268 |
^ '$Header$'
|
|
269 |
! !
|