|
1 " |
|
2 COPYRIGHT (c) 1989-93 by Claus Gittinger |
|
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 |
|
16 inspectedValues nShown' |
|
17 classVariableNames:'' |
|
18 poolDictionaries:'' |
|
19 category:'Interface-Inspector' |
|
20 ! |
|
21 |
|
22 InspectorView comment:' |
|
23 |
|
24 COPYRIGHT (c) 1989-93 by Claus Gittinger |
|
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 |
|
36 %W% %E% |
|
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 |
|
49 self openOn:anObject |
|
50 ! |
|
51 |
|
52 openOn:anObject |
|
53 "create and launch a new inspector for anObject" |
|
54 |
|
55 |topView inspectorView| |
|
56 |
|
57 topView := StandardSystemView |
|
58 label:(anObject class name) |
|
59 icon:(Form fromFile:'Inspector.xbm' resolution:100) |
|
60 minExtent:(100 @ 100). |
|
61 |
|
62 topView extent:(Display width // 3) @ (Display height // 3). |
|
63 |
|
64 inspectorView := self origin:(0.0 @ 0.0) |
|
65 corner:(1.0 @ 1.0) |
|
66 in:topView. |
|
67 |
|
68 inspectorView inspect:anObject. |
|
69 topView realize |
|
70 |
|
71 "InspectorView openOn:(5 @ 7)" |
|
72 "DictionaryInspectorView openOn:(IdentityDictionary new)" |
|
73 ! ! |
|
74 |
|
75 !InspectorView methodsFor:'initialization'! |
|
76 |
|
77 initialize |
|
78 |v panel| |
|
79 |
|
80 super initialize. |
|
81 resources := ResourcePack fromFile:'Inspector.rs'. |
|
82 |
|
83 panel := VariableHorizontalPanel origin:(0.0 @ 0.0) |
|
84 corner:(1.0 @ 1.0) |
|
85 in:self. |
|
86 |
|
87 v := ScrollableView for:SelectionInListView in:panel. |
|
88 v origin:(0.0 @ 0.0) corner:(0.3 @ 1.0). |
|
89 listView := v scrolledView. |
|
90 listView action:[:lineNr | self showSelection:lineNr]. |
|
91 |
|
92 workspace := CodeView origin:(0.3 @ 0.0) corner:(1.0 @ 1.0) in:panel. |
|
93 nShown := 100 |
|
94 ! |
|
95 |
|
96 initEvents |
|
97 ^ self enableKeyEvents |
|
98 ! |
|
99 |
|
100 create |
|
101 super create. |
|
102 self initializeListViewMiddleButtonMenu |
|
103 ! |
|
104 |
|
105 initializeListViewMiddleButtonMenu |
|
106 |labels| |
|
107 |
|
108 labels := resources array:#('inspect'). |
|
109 listView middleButtonMenu:(PopUpMenu |
|
110 labels:labels |
|
111 selectors:#doInspect |
|
112 receiver:self |
|
113 for:listView). |
|
114 workspace acceptAction:[:theText | self doAccept:theText] |
|
115 ! ! |
|
116 |
|
117 !InspectorView methodsFor:'accessing'! |
|
118 |
|
119 noChoice |
|
120 "clear name and value views" |
|
121 |
|
122 inspectedObject notNil ifTrue:[ |
|
123 inspectedObject removeDependent:self |
|
124 ]. |
|
125 inspectedObject := nil. |
|
126 inspectedValues := nil. |
|
127 workspace contents:nil. |
|
128 listView contents:nil |
|
129 ! |
|
130 |
|
131 listOfNames |
|
132 "return a list of names to show in the selectionList" |
|
133 |
|
134 |aList nShown cut| |
|
135 |
|
136 aList := Text new. |
|
137 aList add:'self'. |
|
138 (inspectedObject class allInstVarNames) do:[:instVarName | |
|
139 aList add:instVarName |
|
140 ]. |
|
141 (inspectedObject class isVariable) ifTrue:[ |
|
142 nShown := inspectedObject basicSize. |
|
143 (nShown > nShown) ifTrue:[ |
|
144 nShown := nShown. |
|
145 cut := true |
|
146 ] ifFalse:[ |
|
147 cut := false |
|
148 ]. |
|
149 1 to:nShown do:[:index | |
|
150 aList add:(index printString) |
|
151 ]. |
|
152 cut ifTrue:[ |
|
153 aList add:' ... ' |
|
154 ] |
|
155 ]. |
|
156 ^ aList |
|
157 ! |
|
158 |
|
159 inspect:anObject |
|
160 "define the object to be inspected" |
|
161 |
|
162 |aList nShown cut sameObject| |
|
163 |
|
164 sameObject := anObject == inspectedObject. |
|
165 sameObject ifFalse:[ |
|
166 inspectedObject notNil ifTrue:[ |
|
167 inspectedObject removeDependent:self |
|
168 ] |
|
169 ]. |
|
170 inspectedObject := anObject. |
|
171 |
|
172 aList := self listOfNames. |
|
173 sameObject ifTrue:[ |
|
174 listView setContents:aList |
|
175 ] ifFalse:[ |
|
176 listView contents:aList |
|
177 ]. |
|
178 |
|
179 workspace contents:nil. |
|
180 workspace doItAction:[:theCode | |
|
181 Compiler evaluate:theCode |
|
182 receiver:inspectedObject |
|
183 notifying:workspace |
|
184 ]. |
|
185 |
|
186 sameObject ifFalse:[ |
|
187 inspectedObject notNil ifTrue:[ |
|
188 inspectedObject addDependent:self |
|
189 ] |
|
190 ]. |
|
191 inspectedValues := nil |
|
192 ! |
|
193 |
|
194 inspect:anObject values:valueArray names:nameArray |
|
195 listView contents:nameArray. |
|
196 workspace contents:nil. |
|
197 inspectedObject notNil ifTrue:[ |
|
198 inspectedObject removeDependent:self |
|
199 ]. |
|
200 inspectedObject := anObject. |
|
201 inspectedObject notNil ifTrue:[ |
|
202 inspectedObject addDependent:self |
|
203 ]. |
|
204 inspectedValues := valueArray |
|
205 ! |
|
206 |
|
207 inspectValues:valueArray names:nameArray |
|
208 listView contents:nameArray. |
|
209 workspace contents:nil. |
|
210 inspectedObject notNil ifTrue:[ |
|
211 inspectedObject removeDependent:self |
|
212 ]. |
|
213 inspectedObject := nil. |
|
214 inspectedValues := valueArray |
|
215 ! ! |
|
216 |
|
217 !InspectorView methodsFor:'user interaction'! |
|
218 |
|
219 keyPress:aKey x:x y:y |
|
220 "all my input is passed on to the workspace-field" |
|
221 |
|
222 workspace keyPress:aKey x:0 y:0 |
|
223 ! |
|
224 |
|
225 update:something |
|
226 "handle updates from other inspectors" |
|
227 |
|
228 |oldSelection| |
|
229 |
|
230 something == inspectedObject ifTrue:[ |
|
231 oldSelection := listView selection. |
|
232 self inspect:inspectedObject. |
|
233 listView selection notNil ifTrue:[ |
|
234 self showSelection:(listView selection) |
|
235 ] |
|
236 ] |
|
237 ! |
|
238 |
|
239 destroy |
|
240 inspectedObject notNil ifTrue:[ |
|
241 inspectedObject removeDependent:self. |
|
242 inspectedObject := nil |
|
243 ]. |
|
244 inspectedValues := nil. |
|
245 super destroy |
|
246 ! |
|
247 |
|
248 showSelection:lineNr |
|
249 "user clicked on an instvar - show value in workspace" |
|
250 |
|
251 |val string index| |
|
252 |
|
253 workspace contents:nil. |
|
254 inspectedValues isNil ifTrue:[ |
|
255 lineNr == 1 ifTrue:[ |
|
256 val := inspectedObject |
|
257 ] ifFalse:[ |
|
258 index := lineNr - 1. |
|
259 (inspectedObject class isVariable) ifFalse:[ |
|
260 val := inspectedObject instVarAt:index |
|
261 ] ifTrue:[ |
|
262 index <= (inspectedObject class instSize) ifTrue:[ |
|
263 val := inspectedObject instVarAt:index |
|
264 ] ifFalse:[ |
|
265 index := index - inspectedObject class instSize. |
|
266 val := inspectedObject basicAt:index |
|
267 ] |
|
268 ] |
|
269 ] |
|
270 ] ifFalse:[ |
|
271 val := inspectedValues at:lineNr |
|
272 ]. |
|
273 string := val displayString. |
|
274 workspace show:string. |
|
275 selectedLine := lineNr |
|
276 ! |
|
277 |
|
278 doAccept:theText |
|
279 |value index| |
|
280 |
|
281 value := Compiler evaluate:theText |
|
282 receiver:inspectedObject |
|
283 notifying:workspace. |
|
284 inspectedValues isNil ifTrue:[ |
|
285 selectedLine notNil ifTrue:[ |
|
286 selectedLine == 1 ifFalse:[ |
|
287 index := selectedLine - 1. |
|
288 (inspectedObject class isVariable) ifFalse:[ |
|
289 inspectedObject instVarAt:index put:value |
|
290 ] ifTrue:[ |
|
291 index <= (inspectedObject class instSize) ifTrue:[ |
|
292 inspectedObject instVarAt:index put:value |
|
293 ] ifFalse:[ |
|
294 index := index - inspectedObject class instSize. |
|
295 inspectedObject basicAt:index put:value |
|
296 ] |
|
297 ] |
|
298 ] |
|
299 ] |
|
300 ] ifFalse:[ |
|
301 selectedLine notNil ifTrue:[ |
|
302 inspectedValues at:selectedLine put:value |
|
303 ] |
|
304 ]. |
|
305 inspectedObject changed |
|
306 ! |
|
307 |
|
308 doInspect |
|
309 "user selected inspect-menu entry" |
|
310 |index objectToInspect| |
|
311 |
|
312 selectedLine notNil ifTrue:[ |
|
313 inspectedValues isNil ifTrue:[ |
|
314 (selectedLine == 1) ifTrue:[ |
|
315 objectToInspect := inspectedObject |
|
316 ] ifFalse:[ |
|
317 index := selectedLine - 1. |
|
318 (inspectedObject class isVariable) ifFalse:[ |
|
319 objectToInspect := inspectedObject instVarAt:index |
|
320 ] ifTrue:[ |
|
321 index <= (inspectedObject class instSize) ifTrue:[ |
|
322 objectToInspect := inspectedObject instVarAt:index |
|
323 ] ifFalse:[ |
|
324 index := index - inspectedObject class instSize. |
|
325 objectToInspect := inspectedObject basicAt:index |
|
326 ] |
|
327 ] |
|
328 ] |
|
329 ] ifFalse:[ |
|
330 objectToInspect := inspectedValues at:selectedLine |
|
331 ]. |
|
332 objectToInspect inspect |
|
333 ] |
|
334 ! ! |