0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
45
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
73
|
13 |
'From Smalltalk/X, Version:2.10.4 on 28-feb-1995 at 2:12:00 am'!
|
|
14 |
|
0
|
15 |
View subclass:#InspectorView
|
73
|
16 |
instanceVariableNames:'listView workspace inspectedObject selectedLine nShown hasMore'
|
|
17 |
classVariableNames:'DefaultIcon'
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Interface-Inspector'
|
0
|
20 |
!
|
|
21 |
|
|
22 |
InspectorView comment:'
|
5
|
23 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
45
|
24 |
All Rights Reserved
|
0
|
25 |
|
80
|
26 |
$Header: /cvs/stx/stx/libtool/InspectorView.st,v 1.19 1995-03-09 10:59:29 claus Exp $
|
29
|
27 |
'!
|
|
28 |
|
|
29 |
!InspectorView class methodsFor:'documentation'!
|
|
30 |
|
|
31 |
copyright
|
|
32 |
"
|
|
33 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
45
|
34 |
All Rights Reserved
|
29
|
35 |
|
|
36 |
This software is furnished under a license and may be used
|
|
37 |
only in accordance with the terms of that license and with the
|
|
38 |
inclusion of the above copyright notice. This software may not
|
|
39 |
be provided or otherwise made available to, or used by, any
|
|
40 |
other person. No title to or ownership of the software is
|
|
41 |
hereby transferred.
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
version
|
|
46 |
"
|
80
|
47 |
$Header: /cvs/stx/stx/libtool/InspectorView.st,v 1.19 1995-03-09 10:59:29 claus Exp $
|
29
|
48 |
"
|
|
49 |
!
|
0
|
50 |
|
29
|
51 |
documentation
|
|
52 |
"
|
|
53 |
This class implements an graphical inspector.
|
|
54 |
Inspecting can be done on an object -
|
|
55 |
(where its instvarnames/values are inspected)
|
|
56 |
or a list of objects (where a namearray/valuesarray is inspected).
|
|
57 |
The later is used by the debugger to inspect method variables/args.
|
|
58 |
|
|
59 |
The system calls the inspector through the global variable 'Inspector'
|
|
60 |
which is bound to this class (but could be redefined - it actually is
|
|
61 |
set to MiniInspector in a smalltalk without graphical user interface).
|
0
|
62 |
|
29
|
63 |
Also notice, that there are two methods to inspect an object:
|
|
64 |
sending #basicInspect to any object, will open this kind of inspector on
|
|
65 |
it (showing instance variables which are physically present).
|
|
66 |
|
|
67 |
Sending it #inspect, will - depending on the object - sometimes invoke a
|
|
68 |
specialized inspector.
|
|
69 |
(see OrderedCollectionInspectorView, ImageInspectorView etc. as examples).
|
|
70 |
|
|
71 |
examples:
|
45
|
72 |
#(1 2 3 4) asOrderedCollection inspect
|
|
73 |
#(1 2 3 4) asOrderedCollection basicInspect
|
|
74 |
(Array new:10000) inspect
|
|
75 |
(Image fromFile:'bitmaps/claus.gif') inspect
|
|
76 |
(Image fromFile:'bitmaps/claus.gif') basicInspect
|
|
77 |
(Image fromFile:'bitmaps/SBrowser.xbm') inspect
|
|
78 |
(Image fromFile:'bitmaps/SBrowser.xbm') basicInspect
|
29
|
79 |
"
|
|
80 |
! !
|
0
|
81 |
|
|
82 |
!InspectorView class methodsFor:'instance creation'!
|
|
83 |
|
|
84 |
openOn:anObject
|
|
85 |
"create and launch a new inspector for anObject"
|
|
86 |
|
29
|
87 |
|topView inspectorView nm|
|
|
88 |
|
|
89 |
anObject isClass ifTrue:[
|
45
|
90 |
nm := anObject displayString
|
49
|
91 |
].
|
|
92 |
nm isNil ifTrue:[
|
45
|
93 |
nm := anObject classNameWithArticle
|
29
|
94 |
].
|
0
|
95 |
|
|
96 |
topView := StandardSystemView
|
45
|
97 |
label:('Inspector on: ' , nm)
|
73
|
98 |
icon:self defaultIcon
|
45
|
99 |
minExtent:(100 @ 100).
|
0
|
100 |
|
71
|
101 |
topView extent:(Display extent // 3).
|
0
|
102 |
|
|
103 |
inspectorView := self origin:(0.0 @ 0.0)
|
45
|
104 |
corner:(1.0 @ 1.0)
|
|
105 |
in:topView.
|
0
|
106 |
|
3
|
107 |
"kludge: must realize first, to be able to set menu again"
|
8
|
108 |
topView open.
|
0
|
109 |
inspectorView inspect:anObject.
|
69
|
110 |
^ inspectorView
|
0
|
111 |
|
29
|
112 |
"
|
|
113 |
InspectorView openOn:(5 @ 7)
|
|
114 |
InspectorView openOn:(Array new:400)
|
|
115 |
DictionaryInspectorView openOn:(IdentityDictionary new)
|
|
116 |
"
|
73
|
117 |
!
|
0
|
118 |
|
73
|
119 |
for:anObject
|
|
120 |
"create and launch a new inspector for anObject.
|
|
121 |
This protocol is a historic leftover - this method will vanish."
|
0
|
122 |
|
73
|
123 |
^ self openOn:anObject
|
0
|
124 |
!
|
|
125 |
|
73
|
126 |
inspect:anObject
|
|
127 |
"create and launch a new inspector for anObject.
|
|
128 |
This protocol is a historic leftover - this method will vanish."
|
|
129 |
|
|
130 |
^ self openOn:anObject
|
|
131 |
! !
|
|
132 |
|
|
133 |
!InspectorView class methodsFor:'defaults'!
|
|
134 |
|
|
135 |
defaultIcon
|
|
136 |
DefaultIcon isNil ifTrue:[
|
|
137 |
DefaultIcon := Form fromFile:'Inspector.xbm' resolution:100
|
|
138 |
].
|
|
139 |
^ DefaultIcon
|
|
140 |
! !
|
|
141 |
|
|
142 |
!InspectorView methodsFor:'accessing'!
|
|
143 |
|
|
144 |
inspect:anObject
|
|
145 |
"define the object to be inspected"
|
|
146 |
|
|
147 |
|aList sameObject|
|
|
148 |
|
|
149 |
sameObject := anObject == inspectedObject.
|
|
150 |
inspectedObject := anObject.
|
|
151 |
|
|
152 |
hasMore := false.
|
|
153 |
aList := self fieldList.
|
|
154 |
hasMore ifTrue:[
|
|
155 |
aList add:' ... '
|
|
156 |
].
|
|
157 |
|
|
158 |
sameObject ifTrue:[
|
|
159 |
listView setContents:aList.
|
80
|
160 |
"/ listView selection:1.
|
73
|
161 |
] ifFalse:[
|
|
162 |
listView contents:aList
|
|
163 |
].
|
|
164 |
|
|
165 |
workspace contents:nil.
|
|
166 |
self setDoItAction.
|
|
167 |
|
|
168 |
selectedLine := nil
|
29
|
169 |
!
|
|
170 |
|
73
|
171 |
listView
|
|
172 |
^ listView
|
52
|
173 |
! !
|
|
174 |
|
|
175 |
!InspectorView methodsFor:'private'!
|
0
|
176 |
|
73
|
177 |
setDoItAction
|
|
178 |
workspace doItAction:[:theCode |
|
|
179 |
(inspectedObject class compilerClass)
|
|
180 |
evaluate:theCode
|
|
181 |
in:nil
|
|
182 |
receiver:inspectedObject
|
|
183 |
notifying:workspace
|
|
184 |
logged:true
|
|
185 |
ifFail:nil
|
|
186 |
].
|
|
187 |
|
|
188 |
!
|
|
189 |
|
|
190 |
showMore
|
|
191 |
hasMore ifTrue:[
|
|
192 |
nShown := nShown * 2.
|
|
193 |
self inspect:inspectedObject
|
|
194 |
]
|
|
195 |
!
|
|
196 |
|
|
197 |
fieldList
|
56
|
198 |
"return a list of names to show in the selectionList.
|
|
199 |
Leave hasMore as true, if a '...' entry should be added."
|
0
|
200 |
|
79
|
201 |
|aList n cls s|
|
0
|
202 |
|
29
|
203 |
aList := OrderedCollection new.
|
0
|
204 |
aList add:'self'.
|
29
|
205 |
cls := inspectedObject class.
|
|
206 |
cls isClass ifTrue:[
|
45
|
207 |
cls allInstVarNames do:[:instVarName |
|
|
208 |
aList add:instVarName
|
|
209 |
]
|
29
|
210 |
] ifFalse:[
|
45
|
211 |
1 to:cls instSize do:[:index |
|
|
212 |
aList add:('instvar' , index printString)
|
|
213 |
]
|
0
|
214 |
].
|
29
|
215 |
cls isVariable ifTrue:[
|
45
|
216 |
n := inspectedObject basicSize.
|
|
217 |
(n > nShown) ifTrue:[
|
|
218 |
n := nShown.
|
56
|
219 |
hasMore := true.
|
45
|
220 |
].
|
79
|
221 |
(inspectedObject respondsTo:#keys) ifTrue:[
|
|
222 |
s := ReadStream on:(inspectedObject keys).
|
|
223 |
1 to:n do:[:index |
|
|
224 |
aList add:(s next printString)
|
|
225 |
]
|
|
226 |
] ifFalse:[
|
|
227 |
1 to:n do:[:index |
|
|
228 |
aList add:(index printString)
|
|
229 |
]
|
45
|
230 |
].
|
0
|
231 |
].
|
|
232 |
^ aList
|
73
|
233 |
! !
|
|
234 |
|
|
235 |
!InspectorView methodsFor:'user interaction'!
|
|
236 |
|
|
237 |
showSelection:lineNr
|
|
238 |
"user clicked on an instvar - show value in workspace"
|
|
239 |
|
|
240 |
|val string index|
|
|
241 |
|
|
242 |
(hasMore and:[lineNr == listView list size]) ifTrue:[
|
|
243 |
"clicked on the '...' entry"
|
|
244 |
self showMore.
|
|
245 |
listView selection:lineNr.
|
|
246 |
].
|
|
247 |
|
|
248 |
lineNr == 1 ifTrue:[
|
|
249 |
"selecting self also does a re-set, this allows updating the list"
|
|
250 |
self inspect:inspectedObject.
|
|
251 |
].
|
|
252 |
val := self valueAtLine:lineNr.
|
|
253 |
string := val displayString.
|
|
254 |
workspace replace:string.
|
|
255 |
selectedLine := lineNr.
|
|
256 |
!
|
|
257 |
|
|
258 |
destroy
|
|
259 |
inspectedObject := nil.
|
|
260 |
super destroy
|
0
|
261 |
!
|
|
262 |
|
73
|
263 |
valueAtLine:lineNr
|
|
264 |
"helper - return the value of the selected entry"
|
|
265 |
|
|
266 |
|index instSize|
|
|
267 |
|
|
268 |
lineNr == 1 ifTrue:[
|
|
269 |
^ inspectedObject
|
|
270 |
].
|
|
271 |
index := lineNr - 1. "/ skip self
|
|
272 |
instSize := inspectedObject class instSize.
|
|
273 |
|
|
274 |
(inspectedObject class isVariable not
|
|
275 |
or:[index <= instSize]) ifTrue:[
|
|
276 |
^ inspectedObject instVarAt:index
|
|
277 |
].
|
|
278 |
index := index - instSize.
|
|
279 |
^ inspectedObject basicAt:index
|
|
280 |
!
|
|
281 |
|
|
282 |
doInspect
|
|
283 |
"user selected inspect-menu entry"
|
|
284 |
|
|
285 |
self doInspect:false
|
|
286 |
!
|
|
287 |
|
|
288 |
doInspect:basic
|
|
289 |
"user selected inspect-menu entry"
|
|
290 |
|
|
291 |
|objectToInspect|
|
|
292 |
|
|
293 |
selectedLine notNil ifTrue:[
|
|
294 |
objectToInspect := self valueAtLine:selectedLine.
|
|
295 |
basic ifTrue:[
|
|
296 |
objectToInspect basicInspect
|
|
297 |
] ifFalse:[
|
|
298 |
objectToInspect inspect
|
|
299 |
]
|
56
|
300 |
]
|
3
|
301 |
!
|
|
302 |
|
73
|
303 |
doBasicInspect
|
|
304 |
"user selected inspect-menu entry"
|
0
|
305 |
|
73
|
306 |
self doInspect:true
|
0
|
307 |
!
|
|
308 |
|
|
309 |
keyPress:aKey x:x y:y
|
|
310 |
"all my input is passed on to the workspace-field"
|
|
311 |
|
|
312 |
workspace keyPress:aKey x:0 y:0
|
|
313 |
!
|
|
314 |
|
45
|
315 |
update:something with:someArgument from:changedObject
|
0
|
316 |
"handle updates from other inspectors"
|
|
317 |
|
|
318 |
|oldSelection|
|
|
319 |
|
45
|
320 |
changedObject == inspectedObject ifTrue:[
|
|
321 |
oldSelection := listView selection.
|
|
322 |
self inspect:inspectedObject.
|
|
323 |
oldSelection notNil ifTrue:[
|
|
324 |
self showSelection:oldSelection
|
|
325 |
]
|
0
|
326 |
]
|
|
327 |
!
|
|
328 |
|
|
329 |
doAccept:theText
|
|
330 |
|value index|
|
|
331 |
|
61
|
332 |
value := inspectedObject class compilerClass
|
45
|
333 |
evaluate:theText
|
|
334 |
receiver:inspectedObject
|
|
335 |
notifying:workspace.
|
73
|
336 |
|
|
337 |
selectedLine notNil ifTrue:[
|
|
338 |
selectedLine == 1 ifFalse:[
|
|
339 |
index := selectedLine - 1.
|
|
340 |
(inspectedObject class isVariable) ifFalse:[
|
|
341 |
inspectedObject instVarAt:index put:value
|
|
342 |
] ifTrue:[
|
|
343 |
index <= (inspectedObject class instSize) ifTrue:[
|
45
|
344 |
inspectedObject instVarAt:index put:value
|
73
|
345 |
] ifFalse:[
|
|
346 |
index := index - inspectedObject class instSize.
|
|
347 |
inspectedObject basicAt:index put:value
|
45
|
348 |
]
|
|
349 |
]
|
|
350 |
]
|
0
|
351 |
].
|
|
352 |
inspectedObject changed
|
|
353 |
!
|
|
354 |
|
52
|
355 |
inspectOwners
|
56
|
356 |
"open an inspector on owners of the inspectedObject.
|
|
357 |
(this is a secret function)"
|
|
358 |
|
52
|
359 |
self withCursor:(Cursor questionMark) do:[
|
|
360 |
|owners dict|
|
|
361 |
|
|
362 |
owners := (ObjectMemory whoReferences:inspectedObject) asOrderedCollection.
|
|
363 |
owners size > 500 ifTrue:[
|
|
364 |
(self confirm:'there are ' , owners size printString , ' owners.\\Do you really want to see them all ?' withCRs)
|
|
365 |
ifFalse:[^ self]
|
|
366 |
].
|
|
367 |
dict := IdentityDictionary new.
|
|
368 |
owners do:[:owner |
|
|
369 |
|set names oClass|
|
|
370 |
|
|
371 |
owner ~~ self ifTrue:[
|
|
372 |
set := Set new.
|
|
373 |
names := owner class allInstVarNames.
|
|
374 |
oClass := owner class.
|
|
375 |
1 to:oClass instSize do:[:i |
|
|
376 |
(owner instVarAt:i) == inspectedObject ifTrue:[
|
|
377 |
set add:(names at:i).
|
|
378 |
].
|
|
379 |
].
|
|
380 |
oClass isVariable ifTrue:[
|
|
381 |
oClass isPointers ifTrue:[
|
|
382 |
1 to:owner basicSize do:[:i |
|
|
383 |
(owner basicAt:i) == inspectedObject ifTrue:[
|
|
384 |
set add:i
|
|
385 |
]
|
|
386 |
]
|
|
387 |
]
|
|
388 |
].
|
|
389 |
dict at:owner put:set
|
|
390 |
].
|
|
391 |
].
|
|
392 |
dict inspect
|
|
393 |
]
|
0
|
394 |
! !
|
73
|
395 |
|
|
396 |
!InspectorView methodsFor:'initialization'!
|
|
397 |
|
|
398 |
mapped
|
|
399 |
"delayed setup of lists till map-time -
|
|
400 |
this makes startup of inspectors a bit faster"
|
|
401 |
|
|
402 |
|o|
|
|
403 |
|
|
404 |
super mapped.
|
|
405 |
"
|
|
406 |
kludge to trick inspect:, which ignores setting the
|
|
407 |
same object again ...
|
|
408 |
"
|
|
409 |
o := inspectedObject.
|
|
410 |
inspectedObject := nil.
|
|
411 |
self inspect:o
|
|
412 |
!
|
|
413 |
|
|
414 |
initialize
|
|
415 |
|v panel|
|
|
416 |
|
|
417 |
super initialize.
|
|
418 |
|
|
419 |
panel := VariableHorizontalPanel
|
|
420 |
origin:(0.0 @ 0.0)
|
|
421 |
corner:(1.0 @ 1.0)
|
|
422 |
in:self.
|
|
423 |
|
|
424 |
v := HVScrollableView
|
|
425 |
for:SelectionInListView
|
|
426 |
miniScrollerH:true
|
|
427 |
miniScrollerV:false
|
|
428 |
in:panel.
|
|
429 |
v origin:(0.0 @ 0.0) corner:(0.3 @ 1.0).
|
|
430 |
|
|
431 |
listView := v scrolledView.
|
|
432 |
listView action:[:lineNr | self showSelection:lineNr].
|
|
433 |
listView doubleClickAction:[:lineNr | self doInspect].
|
|
434 |
listView ignoreReselect:false.
|
|
435 |
listView model:self; menu:#fieldMenu.
|
|
436 |
|
|
437 |
v := HVScrollableView
|
|
438 |
for:CodeView
|
|
439 |
miniScrollerH:true
|
|
440 |
miniScrollerV:false
|
|
441 |
in:panel.
|
|
442 |
v origin:(0.3 @ 0.0) corner:(1.0 @ 1.0).
|
|
443 |
workspace := v scrolledView.
|
|
444 |
|
|
445 |
workspace acceptAction:[:theText | self doAccept:theText asString].
|
|
446 |
|
|
447 |
nShown := 100.
|
|
448 |
hasMore := false.
|
|
449 |
!
|
|
450 |
|
|
451 |
fieldMenu
|
|
452 |
|labels selectors|
|
|
453 |
|
|
454 |
hasMore ifTrue:[
|
|
455 |
labels := #(
|
|
456 |
'inspect'
|
|
457 |
'basicInspect'
|
|
458 |
'-'
|
|
459 |
'show more'
|
|
460 |
).
|
|
461 |
|
|
462 |
selectors := #(
|
|
463 |
doInspect
|
|
464 |
doBasicInspect
|
|
465 |
nil
|
|
466 |
showMore
|
|
467 |
).
|
|
468 |
] ifFalse:[
|
|
469 |
labels := #(
|
|
470 |
'inspect'
|
|
471 |
'basicInspect'
|
|
472 |
"/ '-'
|
|
473 |
"/ 'owners'
|
|
474 |
).
|
|
475 |
|
|
476 |
selectors := #(
|
|
477 |
doInspect
|
|
478 |
doBasicInspect
|
|
479 |
"/ nil
|
|
480 |
"/ inspectOwners
|
|
481 |
).
|
|
482 |
].
|
|
483 |
|
|
484 |
^ PopUpMenu
|
|
485 |
labels:(resources array:labels)
|
|
486 |
selectors:selectors
|
|
487 |
! !
|
|
488 |
|
|
489 |
!InspectorView methodsFor:'release'!
|
|
490 |
|
|
491 |
release
|
|
492 |
"release inpected object. This is normally not needed,
|
|
493 |
since the garbage collector will find this memory alone.
|
|
494 |
However, if some applications keeps inspectors (for example,
|
|
495 |
the debugger does this), this would be freed very late."
|
|
496 |
|
|
497 |
"
|
|
498 |
inspectedObject notNil ifTrue:[
|
|
499 |
inspectedObject removeDependent:self
|
|
500 |
].
|
|
501 |
"
|
|
502 |
inspectedObject := nil.
|
|
503 |
workspace doItAction:nil.
|
|
504 |
workspace contents:nil.
|
|
505 |
listView contents:nil
|
|
506 |
! !
|