0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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 |
|
|
13 |
View subclass:#InspectorView
|
|
14 |
instanceVariableNames:'listView workspace
|
|
15 |
inspectedObject selectedLine
|
3
|
16 |
inspectedValues nShown menu1 menu2'
|
0
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Interface-Inspector'
|
|
20 |
!
|
|
21 |
|
|
22 |
InspectorView comment:'
|
|
23 |
|
5
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
25 |
All Rights Reserved
|
|
26 |
|
|
27 |
This class implements an graphical inspector.
|
|
28 |
Inspecting can be done on an object -
|
|
29 |
(where its instvarnames/values are inspected)
|
|
30 |
or a list of objects (where a namearray/valuesarray is inspected).
|
|
31 |
The later is used by the debugger to inspect method variables/args.
|
|
32 |
|
|
33 |
The system calls the inspector through the global variable "Inspector"
|
|
34 |
which is bound to this class (but could be redefined).
|
|
35 |
|
17
|
36 |
$Header: /cvs/stx/stx/libtool/InspectorView.st,v 1.6 1994-01-08 17:27:26 claus Exp $
|
0
|
37 |
written winter 89 by claus
|
|
38 |
'!
|
|
39 |
|
|
40 |
!InspectorView class methodsFor:'instance creation'!
|
|
41 |
|
|
42 |
for:anObject
|
|
43 |
"create and launch a new inspector for anObject"
|
|
44 |
|
|
45 |
^ self openOn:anObject
|
|
46 |
!
|
|
47 |
|
|
48 |
inspect:anObject
|
3
|
49 |
"create and launch a new inspector for anObject"
|
|
50 |
|
|
51 |
^ self openOn:anObject
|
0
|
52 |
!
|
|
53 |
|
|
54 |
openOn:anObject
|
|
55 |
"create and launch a new inspector for anObject"
|
|
56 |
|
|
57 |
|topView inspectorView|
|
|
58 |
|
|
59 |
topView := StandardSystemView
|
13
|
60 |
label:('Inspector on: ' , anObject classNameWithArticle)
|
3
|
61 |
icon:(Form fromFile:'Inspector.xbm' resolution:100)
|
|
62 |
minExtent:(100 @ 100).
|
0
|
63 |
|
|
64 |
topView extent:(Display width // 3) @ (Display height // 3).
|
|
65 |
|
|
66 |
inspectorView := self origin:(0.0 @ 0.0)
|
|
67 |
corner:(1.0 @ 1.0)
|
|
68 |
in:topView.
|
|
69 |
|
3
|
70 |
"kludge: must realize first, to be able to set menu again"
|
8
|
71 |
topView open.
|
0
|
72 |
inspectorView inspect:anObject.
|
|
73 |
|
|
74 |
"InspectorView openOn:(5 @ 7)"
|
|
75 |
"DictionaryInspectorView openOn:(IdentityDictionary new)"
|
|
76 |
! !
|
|
77 |
|
|
78 |
!InspectorView methodsFor:'initialization'!
|
|
79 |
|
|
80 |
initialize
|
|
81 |
|v panel|
|
|
82 |
|
|
83 |
super initialize.
|
|
84 |
|
|
85 |
panel := VariableHorizontalPanel origin:(0.0 @ 0.0)
|
|
86 |
corner:(1.0 @ 1.0)
|
|
87 |
in:self.
|
|
88 |
|
|
89 |
v := ScrollableView for:SelectionInListView in:panel.
|
|
90 |
v origin:(0.0 @ 0.0) corner:(0.3 @ 1.0).
|
|
91 |
listView := v scrolledView.
|
|
92 |
listView action:[:lineNr | self showSelection:lineNr].
|
|
93 |
|
|
94 |
workspace := CodeView origin:(0.3 @ 0.0) corner:(1.0 @ 1.0) in:panel.
|
|
95 |
nShown := 100
|
|
96 |
!
|
|
97 |
|
|
98 |
initEvents
|
|
99 |
^ self enableKeyEvents
|
|
100 |
!
|
|
101 |
|
|
102 |
create
|
|
103 |
super create.
|
|
104 |
self initializeListViewMiddleButtonMenu
|
|
105 |
!
|
|
106 |
|
|
107 |
initializeListViewMiddleButtonMenu
|
3
|
108 |
menu1 := PopUpMenu
|
|
109 |
labels:(resources array:#('inspect'))
|
|
110 |
selectors:#doInspect
|
|
111 |
receiver:self
|
|
112 |
for:listView.
|
|
113 |
menu2 := PopUpMenu
|
|
114 |
labels:(resources array:#(
|
|
115 |
'inspect'
|
|
116 |
'-'
|
|
117 |
'show more'
|
|
118 |
))
|
|
119 |
selectors:#(doInspect nil showMore)
|
|
120 |
receiver:self
|
|
121 |
for:listView.
|
|
122 |
listView setMiddleButtonMenu:menu1.
|
0
|
123 |
workspace acceptAction:[:theText | self doAccept:theText]
|
|
124 |
! !
|
|
125 |
|
|
126 |
!InspectorView methodsFor:'accessing'!
|
|
127 |
|
|
128 |
noChoice
|
|
129 |
"clear name and value views"
|
|
130 |
|
8
|
131 |
"
|
0
|
132 |
inspectedObject notNil ifTrue:[
|
|
133 |
inspectedObject removeDependent:self
|
|
134 |
].
|
8
|
135 |
"
|
0
|
136 |
inspectedObject := nil.
|
|
137 |
inspectedValues := nil.
|
|
138 |
workspace contents:nil.
|
|
139 |
listView contents:nil
|
|
140 |
!
|
|
141 |
|
|
142 |
listOfNames
|
|
143 |
"return a list of names to show in the selectionList"
|
|
144 |
|
3
|
145 |
|aList n cut|
|
0
|
146 |
|
|
147 |
aList := Text new.
|
|
148 |
aList add:'self'.
|
|
149 |
(inspectedObject class allInstVarNames) do:[:instVarName |
|
|
150 |
aList add:instVarName
|
|
151 |
].
|
|
152 |
(inspectedObject class isVariable) ifTrue:[
|
3
|
153 |
n := inspectedObject basicSize.
|
|
154 |
(n > nShown) ifTrue:[
|
|
155 |
n := nShown.
|
|
156 |
cut := true.
|
|
157 |
listView setMiddleButtonMenu:menu2.
|
0
|
158 |
] ifFalse:[
|
3
|
159 |
cut := false.
|
|
160 |
listView setMiddleButtonMenu:menu1.
|
0
|
161 |
].
|
3
|
162 |
1 to:n do:[:index |
|
0
|
163 |
aList add:(index printString)
|
|
164 |
].
|
|
165 |
cut ifTrue:[
|
|
166 |
aList add:' ... '
|
|
167 |
]
|
|
168 |
].
|
|
169 |
^ aList
|
|
170 |
!
|
|
171 |
|
3
|
172 |
showMore
|
|
173 |
nShown := nShown * 2.
|
|
174 |
self inspect:inspectedObject
|
|
175 |
!
|
|
176 |
|
0
|
177 |
inspect:anObject
|
|
178 |
"define the object to be inspected"
|
|
179 |
|
3
|
180 |
|aList sameObject|
|
0
|
181 |
|
|
182 |
sameObject := anObject == inspectedObject.
|
8
|
183 |
"
|
0
|
184 |
sameObject ifFalse:[
|
|
185 |
inspectedObject notNil ifTrue:[
|
|
186 |
inspectedObject removeDependent:self
|
|
187 |
]
|
|
188 |
].
|
8
|
189 |
"
|
0
|
190 |
inspectedObject := anObject.
|
|
191 |
|
|
192 |
aList := self listOfNames.
|
|
193 |
sameObject ifTrue:[
|
|
194 |
listView setContents:aList
|
|
195 |
] ifFalse:[
|
|
196 |
listView contents:aList
|
|
197 |
].
|
|
198 |
|
|
199 |
workspace contents:nil.
|
|
200 |
workspace doItAction:[:theCode |
|
|
201 |
Compiler evaluate:theCode
|
|
202 |
receiver:inspectedObject
|
|
203 |
notifying:workspace
|
|
204 |
].
|
|
205 |
|
8
|
206 |
"
|
0
|
207 |
sameObject ifFalse:[
|
|
208 |
inspectedObject notNil ifTrue:[
|
|
209 |
inspectedObject addDependent:self
|
|
210 |
]
|
|
211 |
].
|
8
|
212 |
"
|
0
|
213 |
inspectedValues := nil
|
|
214 |
!
|
|
215 |
|
|
216 |
inspect:anObject values:valueArray names:nameArray
|
|
217 |
listView contents:nameArray.
|
|
218 |
workspace contents:nil.
|
8
|
219 |
"
|
0
|
220 |
inspectedObject notNil ifTrue:[
|
|
221 |
inspectedObject removeDependent:self
|
|
222 |
].
|
8
|
223 |
"
|
0
|
224 |
inspectedObject := anObject.
|
8
|
225 |
"
|
0
|
226 |
inspectedObject notNil ifTrue:[
|
|
227 |
inspectedObject addDependent:self
|
|
228 |
].
|
8
|
229 |
"
|
0
|
230 |
inspectedValues := valueArray
|
|
231 |
!
|
|
232 |
|
|
233 |
inspectValues:valueArray names:nameArray
|
|
234 |
listView contents:nameArray.
|
|
235 |
workspace contents:nil.
|
8
|
236 |
"
|
0
|
237 |
inspectedObject notNil ifTrue:[
|
|
238 |
inspectedObject removeDependent:self
|
|
239 |
].
|
8
|
240 |
"
|
0
|
241 |
inspectedObject := nil.
|
|
242 |
inspectedValues := valueArray
|
|
243 |
! !
|
|
244 |
|
|
245 |
!InspectorView methodsFor:'user interaction'!
|
|
246 |
|
|
247 |
keyPress:aKey x:x y:y
|
|
248 |
"all my input is passed on to the workspace-field"
|
|
249 |
|
|
250 |
workspace keyPress:aKey x:0 y:0
|
|
251 |
!
|
|
252 |
|
|
253 |
update:something
|
|
254 |
"handle updates from other inspectors"
|
|
255 |
|
|
256 |
|oldSelection|
|
|
257 |
|
|
258 |
something == inspectedObject ifTrue:[
|
|
259 |
oldSelection := listView selection.
|
|
260 |
self inspect:inspectedObject.
|
8
|
261 |
oldSelection notNil ifTrue:[
|
|
262 |
self showSelection:oldSelection
|
0
|
263 |
]
|
|
264 |
]
|
|
265 |
!
|
|
266 |
|
|
267 |
destroy
|
|
268 |
inspectedObject notNil ifTrue:[
|
8
|
269 |
"
|
0
|
270 |
inspectedObject removeDependent:self.
|
8
|
271 |
"
|
0
|
272 |
inspectedObject := nil
|
|
273 |
].
|
3
|
274 |
menu1 notNil ifTrue:[
|
8
|
275 |
menu1 destroy. menu1 := nil.
|
3
|
276 |
].
|
|
277 |
menu2 notNil ifTrue:[
|
8
|
278 |
menu2 destroy. menu2 := nil.
|
3
|
279 |
].
|
0
|
280 |
inspectedValues := nil.
|
|
281 |
super destroy
|
|
282 |
!
|
|
283 |
|
|
284 |
showSelection:lineNr
|
|
285 |
"user clicked on an instvar - show value in workspace"
|
|
286 |
|
|
287 |
|val string index|
|
|
288 |
|
|
289 |
workspace contents:nil.
|
|
290 |
inspectedValues isNil ifTrue:[
|
|
291 |
lineNr == 1 ifTrue:[
|
|
292 |
val := inspectedObject
|
|
293 |
] ifFalse:[
|
|
294 |
index := lineNr - 1.
|
|
295 |
(inspectedObject class isVariable) ifFalse:[
|
|
296 |
val := inspectedObject instVarAt:index
|
|
297 |
] ifTrue:[
|
|
298 |
index <= (inspectedObject class instSize) ifTrue:[
|
|
299 |
val := inspectedObject instVarAt:index
|
|
300 |
] ifFalse:[
|
|
301 |
index := index - inspectedObject class instSize.
|
|
302 |
val := inspectedObject basicAt:index
|
|
303 |
]
|
|
304 |
]
|
|
305 |
]
|
|
306 |
] ifFalse:[
|
|
307 |
val := inspectedValues at:lineNr
|
|
308 |
].
|
|
309 |
string := val displayString.
|
8
|
310 |
workspace cursorToTop.
|
17
|
311 |
"
|
0
|
312 |
workspace show:string.
|
17
|
313 |
"
|
|
314 |
workspace paste:string.
|
|
315 |
|
0
|
316 |
selectedLine := lineNr
|
|
317 |
!
|
|
318 |
|
|
319 |
doAccept:theText
|
|
320 |
|value index|
|
|
321 |
|
|
322 |
value := Compiler evaluate:theText
|
|
323 |
receiver:inspectedObject
|
|
324 |
notifying:workspace.
|
|
325 |
inspectedValues isNil ifTrue:[
|
|
326 |
selectedLine notNil ifTrue:[
|
|
327 |
selectedLine == 1 ifFalse:[
|
|
328 |
index := selectedLine - 1.
|
|
329 |
(inspectedObject class isVariable) ifFalse:[
|
|
330 |
inspectedObject instVarAt:index put:value
|
|
331 |
] ifTrue:[
|
|
332 |
index <= (inspectedObject class instSize) ifTrue:[
|
|
333 |
inspectedObject instVarAt:index put:value
|
|
334 |
] ifFalse:[
|
|
335 |
index := index - inspectedObject class instSize.
|
|
336 |
inspectedObject basicAt:index put:value
|
|
337 |
]
|
|
338 |
]
|
|
339 |
]
|
|
340 |
]
|
|
341 |
] ifFalse:[
|
|
342 |
selectedLine notNil ifTrue:[
|
|
343 |
inspectedValues at:selectedLine put:value
|
|
344 |
]
|
|
345 |
].
|
|
346 |
inspectedObject changed
|
|
347 |
!
|
|
348 |
|
|
349 |
doInspect
|
|
350 |
"user selected inspect-menu entry"
|
|
351 |
|index objectToInspect|
|
|
352 |
|
|
353 |
selectedLine notNil ifTrue:[
|
|
354 |
inspectedValues isNil ifTrue:[
|
|
355 |
(selectedLine == 1) ifTrue:[
|
|
356 |
objectToInspect := inspectedObject
|
|
357 |
] ifFalse:[
|
|
358 |
index := selectedLine - 1.
|
|
359 |
(inspectedObject class isVariable) ifFalse:[
|
|
360 |
objectToInspect := inspectedObject instVarAt:index
|
|
361 |
] ifTrue:[
|
|
362 |
index <= (inspectedObject class instSize) ifTrue:[
|
|
363 |
objectToInspect := inspectedObject instVarAt:index
|
|
364 |
] ifFalse:[
|
|
365 |
index := index - inspectedObject class instSize.
|
|
366 |
objectToInspect := inspectedObject basicAt:index
|
|
367 |
]
|
|
368 |
]
|
|
369 |
]
|
|
370 |
] ifFalse:[
|
|
371 |
objectToInspect := inspectedValues at:selectedLine
|
|
372 |
].
|
|
373 |
objectToInspect inspect
|
|
374 |
]
|
|
375 |
! !
|