author | Claus Gittinger <cg@exept.de> |
Fri, 21 Aug 1998 20:54:35 +0200 | |
changeset 962 | 54f981030675 |
parent 810 | 032e13b1bfda |
child 1022 | afd2ac9d1b55 |
permissions | -rw-r--r-- |
809
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
1 |
" |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
3 |
All Rights Reserved |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
4 |
|
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
5 |
This software is furnished under a license and may be used |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
6 |
only in accordance with the terms of that license and with the |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
7 |
inclusion of the above copyright notice. This software may not |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
8 |
be provided or otherwise made available to, or used by, any |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
9 |
other person. No title to or ownership of the software is |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
10 |
hereby transferred. |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
11 |
" |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
12 |
|
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
13 |
|
33 | 14 |
"{ NameSpace: NewInspector }" |
15 |
||
16 |
Object subclass:#InspectorList |
|
17 |
instanceVariableNames:'inspectedObject instanceNames instanceTypes selection' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
810 | 20 |
category:'Interface-Inspector' |
33 | 21 |
! |
22 |
||
809
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
23 |
!InspectorList class methodsFor:'documentation'! |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
24 |
|
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
25 |
copyright |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
26 |
" |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
27 |
COPYRIGHT (c) 1997 by eXept Software AG |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
28 |
All Rights Reserved |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
29 |
|
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
30 |
This software is furnished under a license and may be used |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
31 |
only in accordance with the terms of that license and with the |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
32 |
inclusion of the above copyright notice. This software may not |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
33 |
be provided or otherwise made available to, or used by, any |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
34 |
other person. No title to or ownership of the software is |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
35 |
hereby transferred. |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
36 |
" |
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
37 |
|
6f127dd5e578
added copyright & documentation
Claus Gittinger <cg@exept.de>
parents:
327
diff
changeset
|
38 |
! ! |
33 | 39 |
|
40 |
!InspectorList class methodsFor:'instance creation'! |
|
41 |
||
42 |
for:anObject |
|
43 |
"create a new list for an instance |
|
44 |
" |
|
38 | 45 |
^ self new inspect:anObject |
46 |
||
47 |
||
48 |
! |
|
49 |
||
50 |
new |
|
51 |
"create a new instance and set the inspected object to nil |
|
52 |
" |
|
53 |
^ self basicNew initialize. |
|
54 |
||
55 |
! ! |
|
56 |
||
57 |
!InspectorList class methodsFor:'helpers'! |
|
58 |
||
59 |
asString:aCollection |
|
60 |
"converts any collection to a string seperated by spaces. If |
|
61 |
the collection is empty or nil, nil is returned otherwise a |
|
62 |
string. |
|
63 |
" |
|
64 |
|string| |
|
65 |
||
66 |
aCollection isCollection ifTrue:[ |
|
67 |
aCollection isString ifTrue:[ |
|
68 |
string := aCollection |
|
69 |
] ifFalse:[ |
|
70 |
string := aCollection asStringWith:Character space |
|
71 |
from:1 to:(aCollection size) |
|
72 |
compressTabs:true |
|
73 |
final:nil |
|
74 |
]. |
|
75 |
string := string withoutSeparators. |
|
76 |
||
77 |
string notEmpty ifTrue:[ |
|
78 |
^ string |
|
79 |
] |
|
80 |
]. |
|
81 |
^ nil |
|
33 | 82 |
|
83 |
||
84 |
! ! |
|
85 |
||
86 |
!InspectorList class methodsFor:'testing'! |
|
87 |
||
88 |
isDirectory:anInstance |
|
38 | 89 |
"returns true if the instance is a directory |
33 | 90 |
" |
91 |
|cls| |
|
92 |
||
93 |
anInstance notNil ifTrue:[ |
|
94 |
cls := anInstance class. |
|
95 |
||
96 |
cls == Character ifTrue:[ ^ false ]. |
|
97 |
cls == Symbol ifTrue:[ ^ false ]. |
|
98 |
cls == String ifTrue:[ ^ false ]. |
|
99 |
||
100 |
cls allInstVarNames notEmpty ifTrue:[ |
|
101 |
^ true |
|
102 |
]. |
|
103 |
||
104 |
anInstance isVariable ifTrue:[ |
|
105 |
^ true |
|
106 |
]. |
|
107 |
]. |
|
108 |
^ false |
|
109 |
||
110 |
||
38 | 111 |
! |
112 |
||
113 |
isTraceable:anInstance |
|
114 |
"returns true if the instance could be traced or traped |
|
115 |
" |
|
116 |
|cls| |
|
117 |
||
118 |
anInstance notNil ifTrue:[ |
|
119 |
cls := anInstance class. |
|
120 |
||
121 |
^ ( cls ~~ True |
|
122 |
and:[cls ~~ False |
|
123 |
and:[cls ~~ SmallInteger]] |
|
124 |
) |
|
125 |
]. |
|
126 |
^ false. |
|
127 |
||
33 | 128 |
! ! |
129 |
||
130 |
!InspectorList methodsFor:'accessing'! |
|
131 |
||
132 |
includesSelf:aBoolean |
|
133 |
"includes 'self' dependant on the boolean |
|
134 |
" |
|
135 |
(self includesSelf) ~~ aBoolean ifTrue:[ |
|
136 |
aBoolean ifTrue:[ |
|
137 |
instanceNames addFirst:'self'. |
|
138 |
instanceTypes addFirst:#self. |
|
139 |
||
38 | 140 |
selection notNil ifTrue:[selection := selection + 1] |
141 |
ifFalse:[selection := 1] |
|
142 |
||
33 | 143 |
] ifFalse:[ |
144 |
instanceNames removeFirst. |
|
145 |
instanceTypes removeFirst. |
|
146 |
||
147 |
selection isNil ifFalse:[ |
|
148 |
(selection := selection - 1) == 0 ifTrue:[ |
|
149 |
selection := nil |
|
150 |
] |
|
151 |
] |
|
152 |
] |
|
153 |
] |
|
154 |
||
155 |
||
156 |
! |
|
157 |
||
38 | 158 |
list |
159 |
"returns self |
|
160 |
" |
|
161 |
^ self |
|
162 |
! |
|
163 |
||
33 | 164 |
size |
38 | 165 |
"returns size of list |
33 | 166 |
" |
167 |
^ instanceNames size |
|
168 |
||
38 | 169 |
! |
170 |
||
171 |
update |
|
172 |
"update list contents |
|
173 |
" |
|
174 |
|start stop size| |
|
175 |
||
176 |
inspectedObject isVariable ifTrue:[ |
|
177 |
start := instanceNames findFirst:[:el|(el at:1) isDigit]. |
|
178 |
stop := instanceTypes size. |
|
179 |
||
180 |
start == 0 ifTrue:[ |
|
181 |
size := stop + 10. "must be > 1: force a resize the first time" |
|
182 |
] ifFalse:[ |
|
183 |
instanceTypes last ~~ #grow ifTrue:[size := stop] |
|
184 |
ifFalse:[size := stop-1]. |
|
185 |
||
186 |
instanceTypes removeFromIndex:start toIndex:stop. |
|
187 |
instanceNames removeFromIndex:start toIndex:stop. |
|
188 |
]. |
|
189 |
self resizeTo:size. |
|
190 |
] |
|
33 | 191 |
! ! |
192 |
||
193 |
!InspectorList methodsFor:'accessing contents'! |
|
194 |
||
195 |
inspectedObject |
|
196 |
"returns current inspected object |
|
197 |
" |
|
198 |
^ inspectedObject |
|
199 |
||
200 |
||
201 |
! |
|
202 |
||
203 |
instanceNames |
|
204 |
"returns list of instance names |
|
205 |
" |
|
206 |
^ instanceNames |
|
207 |
||
208 |
||
209 |
! |
|
210 |
||
211 |
instanceTypeAt:anIndex |
|
38 | 212 |
"returns type assigned to the list entry (#directory #normal #self #grow) |
213 |
In case of an invalid index nil is returned. |
|
33 | 214 |
" |
38 | 215 |
(anIndex isNil or:[anIndex > instanceTypes size]) ifFalse:[^ instanceTypes at:anIndex] |
216 |
ifTrue:[^ nil]. |
|
33 | 217 |
|
218 |
||
219 |
! |
|
220 |
||
221 |
instanceTypes |
|
38 | 222 |
"returns list of types (#directory #normal #self #grow) |
33 | 223 |
" |
224 |
^ instanceTypes |
|
225 |
||
226 |
||
227 |
! |
|
228 |
||
229 |
instanceVarAt:anIndex |
|
38 | 230 |
"returns the instnace variable assigned to the index or |
231 |
nil in case of an invalid index. |
|
33 | 232 |
" |
327
0040d47658c6
check - warnings eliminated. Fix in InspectorList.st
Claus Gittinger <cg@exept.de>
parents:
38
diff
changeset
|
233 |
|nm| |
33 | 234 |
|
38 | 235 |
(anIndex isNil or:[anIndex > instanceTypes size]) ifFalse:[ |
33 | 236 |
nm := instanceNames at:anIndex. |
237 |
||
238 |
(nm at:1) isDigit ifFalse:[ |
|
239 |
self includesSelf ifFalse:[ |
|
240 |
^ inspectedObject instVarAt:anIndex |
|
241 |
]. |
|
242 |
anIndex == 1 ifFalse:[^ inspectedObject instVarAt:(anIndex-1)] |
|
243 |
ifTrue:[^ inspectedObject] |
|
244 |
]. |
|
245 |
^ inspectedObject basicAt:(Number readFrom:nm onError:0) |
|
246 |
]. |
|
247 |
^ nil |
|
248 |
||
249 |
||
250 |
! ! |
|
251 |
||
252 |
!InspectorList methodsFor:'initialization'! |
|
253 |
||
38 | 254 |
initialize |
255 |
"initialize instance attributes |
|
33 | 256 |
" |
38 | 257 |
super initialize. |
33 | 258 |
|
38 | 259 |
instanceNames := OrderedCollection new. |
260 |
instanceTypes := OrderedCollection new. |
|
261 |
||
33 | 262 |
! ! |
263 |
||
264 |
!InspectorList methodsFor:'private'! |
|
265 |
||
38 | 266 |
resizeTo:aNumber |
267 |
"resize list to minimum aNumber |
|
33 | 268 |
" |
38 | 269 |
|lstVarId basicSize newLastId obj instSize| |
33 | 270 |
|
271 |
(inspectedObject isVariable and:[self class isDirectory:inspectedObject]) ifFalse:[ |
|
272 |
^ self |
|
273 |
]. |
|
274 |
||
38 | 275 |
instanceTypes size == 0 ifTrue:[ |
276 |
lstVarId := 0 |
|
277 |
] ifFalse:[ |
|
278 |
instSize := inspectedObject class instSize. |
|
33 | 279 |
|
38 | 280 |
instanceTypes first == #self ifTrue:[ |
281 |
instSize := instSize + 1 |
|
282 |
]. |
|
33 | 283 |
instanceTypes last == #grow ifTrue:[ |
284 |
instanceNames removeLast. " .. " |
|
285 |
instanceTypes removeLast. " #grow " |
|
38 | 286 |
]. |
287 |
lstVarId := instanceTypes size - instSize. |
|
288 |
]. |
|
289 |
||
290 |
(basicSize := inspectedObject basicSize) == lstVarId ifTrue:[ |
|
291 |
^ self |
|
292 |
]. |
|
293 |
newLastId := (1 bitShift:((aNumber-1) highBit)) max:128. |
|
294 |
||
295 |
(newLastId + 64) > basicSize ifTrue:[ |
|
296 |
newLastId := basicSize |
|
33 | 297 |
]. |
298 |
||
299 |
[lstVarId ~~ newLastId] whileTrue:[ |
|
300 |
lstVarId := lstVarId + 1. |
|
301 |
obj := inspectedObject basicAt:lstVarId. |
|
302 |
||
303 |
(self class isDirectory:obj) ifTrue:[instanceTypes add:#directory] |
|
304 |
ifFalse:[instanceTypes add:#normal]. |
|
305 |
||
306 |
instanceNames add:(lstVarId printString, ' ', obj class name printString). |
|
307 |
]. |
|
308 |
||
309 |
lstVarId ~~ basicSize ifTrue:[ |
|
310 |
instanceNames add:'..'. |
|
311 |
instanceTypes add:#grow |
|
312 |
]. |
|
313 |
! ! |
|
314 |
||
315 |
!InspectorList methodsFor:'selections'! |
|
316 |
||
317 |
selectedInstanceType |
|
38 | 318 |
"returns type assigned to the selected list entry (#directory #normal #self #grow). |
319 |
In case of no selection nil is returned. |
|
33 | 320 |
" |
321 |
^ self instanceTypeAt:selection |
|
322 |
||
323 |
||
324 |
! |
|
325 |
||
326 |
selectedInstanceVar |
|
327 |
"returns current inspected instance variable or nil |
|
328 |
" |
|
329 |
^ self instanceVarAt:selection |
|
330 |
||
331 |
||
332 |
! |
|
333 |
||
334 |
selection |
|
335 |
"returns current selection number or nil |
|
336 |
" |
|
337 |
^ selection |
|
338 |
||
339 |
||
340 |
! |
|
341 |
||
38 | 342 |
setSelection:aNrOrNil |
343 |
"change current selection to a number or nil; may resize the lists |
|
344 |
" |
|
345 |
selection := aNrOrNil. |
|
346 |
||
347 |
(selection isNil or:[instanceTypes size > selection]) ifFalse:[ |
|
348 |
self resizeTo:selection. |
|
349 |
||
350 |
selection > instanceTypes size ifTrue:[ |
|
351 |
selection := nil |
|
352 |
] |
|
353 |
] |
|
354 |
! ! |
|
355 |
||
356 |
!InspectorList methodsFor:'testing'! |
|
357 |
||
358 |
includesSelf |
|
359 |
"returns true if 'self' is included in the list |
|
360 |
" |
|
361 |
^ (instanceTypes notEmpty and:[instanceTypes first == #self]) |
|
362 |
||
363 |
||
364 |
! |
|
365 |
||
366 |
isEmpty |
|
367 |
"returns true if the list is empty |
|
33 | 368 |
" |
38 | 369 |
^ instanceNames isEmpty |
370 |
||
371 |
! |
|
372 |
||
373 |
notEmpty |
|
374 |
"returns true if the list is not empty |
|
375 |
" |
|
376 |
^ instanceNames notEmpty |
|
377 |
||
378 |
! ! |
|
379 |
||
380 |
!InspectorList methodsFor:'user interaction'! |
|
381 |
||
382 |
accept:aText notifying:aView |
|
383 |
"evaluating aText on the selected instance var; if an error occurs #Error |
|
384 |
is returned otherwise the inspected object instance. On success the list |
|
385 |
will be updated. |
|
386 |
" |
|
387 |
|text slNr value| |
|
388 |
||
389 |
selection notNil ifTrue:[ |
|
390 |
text := self class asString:aText. |
|
391 |
||
392 |
text notNil ifTrue:[ |
|
393 |
self includesSelf ifFalse:[slNr := selection] |
|
394 |
ifTrue:[slNr := selection-1]. |
|
395 |
||
396 |
value := inspectedObject class evaluatorClass |
|
397 |
evaluate:text |
|
398 |
receiver:inspectedObject |
|
399 |
notifying:aView. |
|
33 | 400 |
|
38 | 401 |
slNr ~~ 0 ifTrue:[ |
402 |
(inspectedObject class isVariable) ifFalse:[ |
|
403 |
inspectedObject instVarAt:slNr put:value |
|
404 |
] ifTrue:[ |
|
405 |
slNr <= (inspectedObject class instSize) ifTrue:[ |
|
406 |
inspectedObject instVarAt:slNr put:value |
|
407 |
] ifFalse:[ |
|
408 |
slNr := slNr - inspectedObject class instSize. |
|
409 |
inspectedObject basicAt:slNr put:value |
|
410 |
] |
|
411 |
] |
|
412 |
]. |
|
413 |
inspectedObject changed. |
|
414 |
self update. |
|
415 |
^ inspectedObject |
|
416 |
] |
|
417 |
]. |
|
418 |
^ #Error |
|
419 |
! |
|
420 |
||
421 |
doIt:aCode notifying:aView |
|
422 |
"evaluating aCode on the selected instance var; if an error occurs #Error |
|
423 |
is returned otherwise the result returned from the evaluator. On success |
|
424 |
the list will be updated. |
|
425 |
" |
|
426 |
|successFg result evaluator selInstVar code| |
|
427 |
||
428 |
selInstVar := self selectedInstanceVar. |
|
429 |
||
430 |
selInstVar notNil ifTrue:[ |
|
431 |
code := self class asString:aCode. |
|
432 |
||
433 |
code notNil ifTrue:[ |
|
434 |
evaluator := selInstVar class evaluatorClass. |
|
435 |
successFg := true. |
|
33 | 436 |
|
38 | 437 |
evaluator notNil ifTrue:[ |
438 |
result := evaluator evaluate:code |
|
439 |
in:nil |
|
440 |
receiver:selInstVar |
|
441 |
notifying:aView |
|
442 |
logged:true |
|
443 |
ifFail:[successFg := false]. |
|
444 |
||
445 |
successFg ifTrue:[ |
|
446 |
self update. |
|
447 |
^ result |
|
448 |
] |
|
33 | 449 |
] |
38 | 450 |
] |
451 |
]. |
|
452 |
^ #Error. |
|
453 |
||
454 |
||
455 |
! |
|
456 |
||
457 |
inspect:anObject |
|
458 |
"inspect a new instance; update contents |
|
459 |
" |
|
460 |
|varNamesSize| |
|
461 |
||
462 |
selection := nil. |
|
463 |
||
464 |
anObject == inspectedObject ifFalse:[ |
|
465 |
inspectedObject := anObject. |
|
33 | 466 |
|
38 | 467 |
(self class isDirectory:inspectedObject) ifFalse:[ |
468 |
instanceNames := OrderedCollection new. |
|
469 |
instanceTypes := OrderedCollection new. |
|
470 |
] ifTrue:[ |
|
471 |
instanceNames := inspectedObject class allInstVarNames. |
|
472 |
varNamesSize := instanceNames size. |
|
473 |
instanceTypes := OrderedCollection new:varNamesSize. |
|
474 |
||
475 |
1 to:varNamesSize do:[:i| |
|
476 |
(self class isDirectory:(inspectedObject instVarAt:i)) ifTrue:[ |
|
477 |
instanceTypes add:#directory |
|
478 |
] ifFalse:[ |
|
479 |
instanceTypes add:#normal |
|
480 |
] |
|
481 |
]. |
|
482 |
] |
|
483 |
]. |
|
484 |
self update |
|
33 | 485 |
! ! |
486 |
||
487 |
!InspectorList class methodsFor:'documentation'! |
|
488 |
||
489 |
version |
|
490 |
^ '$Header$' |
|
491 |
! ! |