author | ca |
Fri, 02 Jan 1998 16:57:44 +0100 | |
changeset 391 | 5c7fa5484d14 |
parent 376 | 3023fc08ee35 |
child 392 | 53a63b0e8279 |
permissions | -rw-r--r-- |
60 | 1 |
" |
156 | 2 |
COPYRIGHT (c) 1995 by Claus Gittinger / eXept Software AG |
3 |
All Rights Reserved |
|
60 | 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 |
UIObjectView subclass:#UIPainterView |
|
278 | 14 |
instanceVariableNames:'treeView listHolder superclassName className methodName |
15 |
categoryName' |
|
60 | 16 |
classVariableNames:'HandCursor' |
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-UIPainter' |
|
19 |
! |
|
20 |
||
211 | 21 |
Object subclass:#ViewProperty |
22 |
instanceVariableNames:'view spec identifier' |
|
23 |
classVariableNames:'Identifier' |
|
24 |
poolDictionaries:'' |
|
25 |
privateIn:UIPainterView |
|
26 |
! |
|
27 |
||
60 | 28 |
!UIPainterView class methodsFor:'documentation'! |
29 |
||
30 |
copyright |
|
31 |
" |
|
156 | 32 |
COPYRIGHT (c) 1995 by Claus Gittinger / eXept Software AG |
33 |
All Rights Reserved |
|
60 | 34 |
|
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
128 | 46 |
buildIn view used by the UIPainter; from this view, the layout of the |
47 |
new application derives from. |
|
48 |
||
49 |
[see also:] |
|
50 |
UIBuilder |
|
51 |
UIObjectView |
|
156 | 52 |
|
53 |
[author:] |
|
54 |
Claus Gittinger |
|
55 |
Claus Atzkern |
|
60 | 56 |
" |
57 |
! ! |
|
58 |
||
59 |
!UIPainterView class methodsFor:'defaults'! |
|
60 |
||
61 |
defaultMenuMessage |
|
62 |
"This message is the default yo be sent to the menuHolder to get a menu |
|
63 |
" |
|
121 | 64 |
^ #showMiddleButtonMenu |
60 | 65 |
|
66 |
||
67 |
! ! |
|
68 |
||
69 |
!UIPainterView methodsFor:'accessing'! |
|
70 |
||
71 |
application |
|
72 |
^ nil |
|
73 |
||
74 |
"Modified: 6.9.1995 / 00:46:44 / claus" |
|
75 |
! |
|
76 |
||
78 | 77 |
applicationName |
78 |
^ self className |
|
79 |
! |
|
80 |
||
81 |
applicationName:aName |
|
82 |
self className:aName |
|
83 |
! |
|
84 |
||
60 | 85 |
className |
86 |
^ className |
|
87 |
! |
|
88 |
||
78 | 89 |
className:aName |
90 |
className := aName |
|
60 | 91 |
! |
92 |
||
93 |
className:aClassName superclassName:aSuperclassName selector:aSelector |
|
78 | 94 |
className := aClassName. |
60 | 95 |
superclassName := aSuperclassName. |
78 | 96 |
methodName := aSelector. |
60 | 97 |
|
98 |
! |
|
99 |
||
223 | 100 |
findInputViewIn:aSuperView |
101 |
"returns index of input view into superview or nil |
|
102 |
" |
|
103 |
aSuperView == self ifTrue:[ |
|
104 |
^ self subViews findFirst:[:v| v == inputView ] |
|
105 |
]. |
|
106 |
^ 0 |
|
107 |
! |
|
108 |
||
109 |
inputView |
|
110 |
^ inputView |
|
111 | 111 |
! |
112 |
||
60 | 113 |
methodName |
114 |
^ methodName |
|
115 |
! |
|
116 |
||
78 | 117 |
methodName:aName |
118 |
methodName := aName |
|
60 | 119 |
! |
120 |
||
121 |
selectNames:aStringOrCollection |
|
122 |
|prop coll s| |
|
123 |
||
124 |
(aStringOrCollection isNil or:[aStringOrCollection isEmpty]) ifTrue:[ |
|
131 | 125 |
^ self select:nil |
60 | 126 |
]. |
127 |
||
128 |
(s := aStringOrCollection) isString ifFalse:[ |
|
129 |
s size == 1 ifTrue:[ |
|
130 |
s := s first |
|
131 |
] ifFalse:[ |
|
132 |
coll := OrderedCollection new. |
|
133 |
||
134 |
s do:[:aName| |
|
135 |
(prop := self propertyOfName:aName) notNil ifTrue:[ |
|
136 |
coll add:(prop view) |
|
137 |
] |
|
138 |
]. |
|
139 |
coll size == 1 ifTrue:[ ^ self select:(coll at:1) ]. |
|
131 | 140 |
coll size == 0 ifTrue:[ ^ self select:nil ]. |
60 | 141 |
|
142 |
^ self select:coll. |
|
143 |
] |
|
144 |
]. |
|
145 |
||
146 |
prop := self propertyOfName:s. |
|
131 | 147 |
prop isNil ifTrue:[^ self select:nil] |
60 | 148 |
ifFalse:[^ self select:(prop view)] |
149 |
||
150 |
! ! |
|
151 |
||
111 | 152 |
!UIPainterView methodsFor:'change & update'! |
153 |
||
223 | 154 |
layoutChanged |
238 | 155 |
treeView layoutChanged |
111 | 156 |
! ! |
157 |
||
60 | 158 |
!UIPainterView methodsFor:'copy & cut & paste'! |
159 |
||
160 |
copySelection |
|
161 |
"copy the selection into the cut&paste-buffer |
|
162 |
" |
|
71 | 163 |
|specs coll| |
164 |
||
128 | 165 |
coll := self minSetOfSuperViews:(self selection). |
60 | 166 |
|
71 | 167 |
coll notNil ifTrue:[ |
131 | 168 |
self select:nil. |
78 | 169 |
specs := coll collect:[:aView| self fullSpecFor:aView ]. |
60 | 170 |
self setSelection:specs |
171 |
]. |
|
78 | 172 |
|
173 |
||
60 | 174 |
! |
175 |
||
176 |
deleteSelection |
|
62 | 177 |
"delete the selection; copy the selection into the cut&paste-buffer |
178 |
and open a transaction |
|
60 | 179 |
" |
134 | 180 |
|specs coll| |
71 | 181 |
|
128 | 182 |
coll := self minSetOfSuperViews:(self selection). |
60 | 183 |
|
78 | 184 |
coll notNil ifTrue:[ |
238 | 185 |
treeView cvsEventsDisabledDo:[ |
131 | 186 |
self select:nil. |
111 | 187 |
specs := coll collect:[:aView| self fullSpecFor:aView ]. |
60 | 188 |
|
134 | 189 |
self withinTransaction:#cut objects:coll do:[ |
190 |
coll reverseDo:[:aView| |
|
191 |
self createUndoRemove:aView. |
|
192 |
self remove:aView |
|
111 | 193 |
] |
194 |
]. |
|
195 |
self setSelection:specs. |
|
196 |
] |
|
60 | 197 |
] |
198 |
! |
|
199 |
||
200 |
pasteBuffer |
|
62 | 201 |
"add the objects in the paste-buffer to the object view |
60 | 202 |
" |
223 | 203 |
|sel| |
204 |
||
205 |
sel := self pasteSpecifications:(self getSelection) keepLayout:false. |
|
206 |
||
207 |
sel notNil ifTrue:[ |
|
208 |
self select:sel. |
|
209 |
]. |
|
89 | 210 |
|
211 |
! |
|
212 |
||
213 |
pasteSpecifications:aSpecificationOrList keepLayout:keepLayout |
|
223 | 214 |
"add the specs to the object view; returns list of pasted components |
89 | 215 |
" |
278 | 216 |
|
217 |
^ self |
|
218 |
pasteSpecifications:aSpecificationOrList |
|
219 |
keepLayout:keepLayout |
|
220 |
at:nil |
|
221 |
||
222 |
"Modified: 11.8.1997 / 01:00:35 / cg" |
|
223 |
! |
|
224 |
||
225 |
pasteSpecifications:aSpecificationOrList keepLayout:keepLayout at:aPointOrNil |
|
226 |
"add the specs to the object view; returns list of pasted components |
|
227 |
" |
|
312 | 228 |
|paste frame pasteOrigin pasteOffset builder newSel bounds| |
60 | 229 |
|
89 | 230 |
(self canPaste:aSpecificationOrList) ifFalse:[ |
223 | 231 |
^ nil |
89 | 232 |
]. |
223 | 233 |
|
238 | 234 |
treeView cvsSetupListDo:[ |
165 | 235 |
aSpecificationOrList isCollection ifTrue:[ |
236 |
paste := aSpecificationOrList |
|
237 |
] ifFalse:[ |
|
238 |
paste := Array with:aSpecificationOrList |
|
239 |
]. |
|
223 | 240 |
(frame := self singleSelection) isNil ifTrue:[ |
165 | 241 |
frame := self |
242 |
]. |
|
243 |
self setSelection:nil withRedraw:true. |
|
60 | 244 |
|
165 | 245 |
newSel := OrderedCollection new. |
246 |
builder := UIBuilder new. |
|
212 | 247 |
className notNil ifTrue:[ |
330 | 248 |
builder applicationClass:(self resolveName:className) |
212 | 249 |
]. |
89 | 250 |
|
165 | 251 |
keepLayout ifFalse:[ |
252 |
pasteOffset := 0@0. |
|
312 | 253 |
|
278 | 254 |
aPointOrNil isNil ifTrue:[ |
255 |
pasteOrigin := self sensor mousePoint. |
|
312 | 256 |
pasteOrigin := device translatePoint:pasteOrigin |
257 |
from:device rootView id |
|
258 |
to:frame id. |
|
278 | 259 |
] ifFalse:[ |
312 | 260 |
pasteOrigin := device translatePoint:aPointOrNil |
261 |
from:self id |
|
262 |
to:frame id. |
|
263 |
] |
|
264 |
]. |
|
265 |
keepLayout ifFalse:[ |
|
266 |
bounds := Rectangle origin:0@0 extent:(frame bounds extent) |
|
165 | 267 |
]. |
60 | 268 |
|
223 | 269 |
paste do:[:aSpec| |
270 |
|view| |
|
60 | 271 |
|
223 | 272 |
view := self addSpec:aSpec builder:builder in:frame. |
60 | 273 |
|
223 | 274 |
keepLayout ifFalse:[ |
312 | 275 |
(bounds containsPoint:pasteOrigin) ifFalse:[ |
315 | 276 |
self moveObject:view to:pasteOffset. |
223 | 277 |
] ifTrue:[ |
278 |
self moveObject:view to:pasteOrigin + pasteOffset. |
|
111 | 279 |
]. |
223 | 280 |
pasteOffset := pasteOffset + 4 |
89 | 281 |
]. |
223 | 282 |
view realize. |
283 |
newSel add:view. |
|
60 | 284 |
]. |
285 |
||
165 | 286 |
self withinTransaction:#paste objects:newSel do:[ |
287 |
undoHistory addUndoSelector:#undoCreate: |
|
288 |
withArgs:(newSel collect:[:v|(self propertyOfView:v) identifier]) |
|
289 |
]. |
|
134 | 290 |
|
165 | 291 |
self realizeAllSubViews. |
285 | 292 |
newSel do:[:v| v raise]. |
165 | 293 |
inputView raise. |
294 |
self elementChangedSize:frame. |
|
285 | 295 |
|
296 |
newSel size == 1 ifTrue:[newSel := newSel at:1]. |
|
223 | 297 |
]. |
298 |
^ newSel |
|
89 | 299 |
! |
300 |
||
301 |
pasteWithLayout |
|
302 |
"add the objects in the paste-buffer to the object view; don't change the |
|
303 |
layout |
|
304 |
" |
|
223 | 305 |
|sel| |
306 |
||
307 |
sel := self pasteSpecifications:(self getSelection) keepLayout:true. |
|
89 | 308 |
|
223 | 309 |
sel notNil ifTrue:[ |
310 |
self select:sel. |
|
311 |
]. |
|
60 | 312 |
! ! |
313 |
||
314 |
!UIPainterView methodsFor:'drag & drop'! |
|
315 |
||
288 | 316 |
canDrop:something |
317 |
"returns true if something can be droped |
|
318 |
" |
|
319 |
(something size == 1 and:[self enabled and:[self numberOfSelections <= 1]]) ifTrue:[ |
|
320 |
^ something first theObject isKindOf:UISpecification |
|
223 | 321 |
]. |
322 |
^ false |
|
323 |
! |
|
324 |
||
285 | 325 |
canPaste |
326 |
"returns true if something to be past exists and can be paste into |
|
327 |
the selection if exists |
|
328 |
" |
|
329 |
^ self canPaste:(self getSelection) |
|
330 |
! |
|
331 |
||
223 | 332 |
canPaste:something |
333 |
"returns true if something could be paste |
|
334 |
" |
|
335 |
|el size| |
|
336 |
||
337 |
((size := self numberOfSelections) <= 1 and:[self enabled]) ifFalse:[ |
|
338 |
^ false |
|
339 |
]. |
|
340 |
something isCollection ifTrue:[something notEmpty ifTrue:[el := something first]] |
|
341 |
ifFalse:[el := something]. |
|
342 |
||
343 |
(el isKindOf:UISpecification) ifFalse:[ |
|
344 |
^ false |
|
345 |
]. |
|
346 |
||
347 |
size == 1 ifTrue:[ |
|
348 |
^ self canPasteInto:(self singleSelection) |
|
349 |
]. |
|
350 |
^ true |
|
351 |
||
352 |
! |
|
353 |
||
354 |
canPasteInto:aView |
|
355 |
"can paste into a view |
|
356 |
" |
|
285 | 357 |
|prop| |
60 | 358 |
|
223 | 359 |
aView notNil ifTrue:[ |
285 | 360 |
(prop := self propertyRespondsToView:aView) notNil ifTrue:[ |
361 |
^ prop spec class supportsSubComponents |
|
362 |
]. |
|
363 |
^ aView specClass supportsSubComponents. |
|
89 | 364 |
]. |
365 |
^ false |
|
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
89
diff
changeset
|
366 |
|
60 | 367 |
! |
368 |
||
369 |
drop:anObjectOrCollection at:aPoint |
|
278 | 370 |
|spec newSel oldSel dragOffset| |
371 |
||
288 | 372 |
self selection notNil ifTrue:[ |
373 |
oldSel := self singleSelection. |
|
374 |
||
375 |
(self canPasteInto:oldSel) ifFalse:[ |
|
376 |
oldSel := nil. |
|
377 |
self setSelection:nil withRedraw:true |
|
378 |
] |
|
231 | 379 |
]. |
89 | 380 |
spec := (anObjectOrCollection at:1) theObject. |
278 | 381 |
dragOffset := DragAndDropManager dragOffsetQuerySignal raise. |
382 |
newSel := self pasteSpecifications:spec keepLayout:false at:aPoint - dragOffset. |
|
60 | 383 |
|
223 | 384 |
oldSel isNil ifTrue:[self select:newSel] |
385 |
ifFalse:[self select:oldSel] |
|
60 | 386 |
! ! |
387 |
||
361 | 388 |
!UIPainterView methodsFor:'event handling'! |
389 |
||
390 |
keyPress:key x:x y:y view:aView |
|
376 | 391 |
"a delegated keyEvent from aView" |
392 |
||
361 | 393 |
self keyPress:key x:x y:y |
394 |
||
376 | 395 |
"Modified: / 31.10.1997 / 20:27:22 / cg" |
361 | 396 |
! |
397 |
||
398 |
keyRelease:key x:x y:y view:aView |
|
376 | 399 |
"a delegated keyEvent from aView" |
400 |
||
361 | 401 |
self keyRelease:key x:x y:y |
402 |
||
376 | 403 |
"Modified: / 31.10.1997 / 20:27:32 / cg" |
361 | 404 |
! ! |
405 |
||
78 | 406 |
!UIPainterView methodsFor:'generating output'! |
407 |
||
352 | 408 |
aspectMethods |
409 |
"extract a list of aspect methods - for browsing" |
|
410 |
||
411 |
|cls methods skip selector protoSpec| |
|
412 |
||
413 |
className isNil ifTrue:[ |
|
414 |
self warn:'set the class first'. |
|
415 |
^ #() |
|
416 |
]. |
|
417 |
||
418 |
cls := self resolveName:className. |
|
419 |
methods := IdentitySet new. |
|
420 |
||
421 |
treeView propertiesDo:[:aProp| |
|
422 |
|selector| |
|
423 |
||
424 |
(selector := aProp model) notNil ifTrue:[ |
|
425 |
selector isArray ifFalse:[ |
|
426 |
selector := selector asSymbol. |
|
427 |
(cls implements:selector) ifTrue:[ |
|
428 |
skip := false. |
|
429 |
(cls isSubclassOf:SimpleDialog) ifTrue:[ |
|
430 |
skip := SimpleDialog implements:selector asSymbol |
|
431 |
]. |
|
432 |
skip ifFalse:[ |
|
433 |
methods add:(cls compiledMethodAt:selector) |
|
434 |
]. |
|
435 |
]. |
|
436 |
]. |
|
437 |
]. |
|
438 |
||
439 |
(selector := aProp menu) notNil ifTrue:[ |
|
440 |
selector isArray ifFalse:[ |
|
441 |
selector := selector asSymbol. |
|
442 |
(cls implements:selector) ifTrue:[ |
|
443 |
methods add:(cls compiledMethodAt:selector) |
|
444 |
] |
|
445 |
]. |
|
446 |
]. |
|
447 |
||
448 |
(aProp spec aspectSelectors) do:[:aSel | |
|
449 |
|selector| |
|
450 |
||
451 |
aSel isArray ifFalse:[ |
|
452 |
selector := aSel asSymbol. |
|
453 |
(cls implements:selector) ifTrue:[ |
|
454 |
methods add:(cls compiledMethodAt:selector) |
|
455 |
] |
|
456 |
]. |
|
457 |
]. |
|
458 |
aProp spec actionSelectors do:[:aSel| |
|
459 |
|selector| |
|
460 |
||
461 |
aSel isArray ifFalse:[ |
|
462 |
selector := aSel asSymbol. |
|
463 |
(cls implements:selector) ifTrue:[ |
|
464 |
methods add:(cls compiledMethodAt:selector) |
|
465 |
] |
|
466 |
]. |
|
467 |
]. |
|
468 |
aProp spec valueSelectors do:[:aSel| |
|
469 |
|selector| |
|
470 |
||
471 |
aSel isArray ifFalse:[ |
|
472 |
selector := aSel asSymbol. |
|
473 |
(cls implements:selector) ifTrue:[ |
|
474 |
methods add:(cls compiledMethodAt:selector) |
|
475 |
] |
|
476 |
]. |
|
477 |
] |
|
478 |
]. |
|
479 |
||
480 |
protoSpec := treeView canvasSpec. |
|
481 |
||
482 |
(selector := protoSpec menu) notNil ifTrue:[ |
|
483 |
selector isArray ifFalse:[ |
|
484 |
selector := selector asSymbol. |
|
485 |
(cls implements:selector) ifTrue:[ |
|
486 |
methods add:(cls compiledMethodAt:selector) |
|
487 |
] |
|
488 |
]. |
|
489 |
]. |
|
490 |
||
491 |
^ methods |
|
492 |
||
493 |
"Created: / 25.10.1997 / 18:58:25 / cg" |
|
494 |
"Modified: / 26.10.1997 / 15:06:18 / cg" |
|
495 |
! |
|
496 |
||
60 | 497 |
generateActionMethodFor:aspect spec:protoSpec inClass:targetClass |
288 | 498 |
|selector args showIt code alreadyInSuperclass| |
499 |
||
500 |
selector := aspect asSymbol. |
|
141 | 501 |
|
288 | 502 |
alreadyInSuperclass := targetClass superclass canUnderstand:selector. |
503 |
||
504 |
(selector numArgs) == 1 ifFalse:[ |
|
505 |
args := ''. |
|
149 | 506 |
showIt := ' ...''.\'. |
507 |
] ifTrue:[ |
|
288 | 508 |
args := 'anArgument'. |
149 | 509 |
showIt := ''' , anArgument printString , '' ...''.\'. |
510 |
]. |
|
141 | 511 |
|
288 | 512 |
code := '!!' , targetClass name , ' methodsFor:''actions''!!\\' , |
513 |
aspect , args , '\' , |
|
352 | 514 |
' "automatically generated by UIPainter ..."\\' , |
515 |
' "*** the code below performs no action"\' , |
|
516 |
' "*** (except for some feedback on the Transcript)"\' , |
|
517 |
' "*** Please change as required and accept in the browser."\' , |
|
288 | 518 |
'\' . |
519 |
||
520 |
alreadyInSuperclass ifTrue:[ |
|
521 |
code := code , |
|
522 |
' "action for ' , aspect , ' is already provided in a superclass."\' , |
|
523 |
' "It may be redefined here ..."\\'. |
|
524 |
] ifFalse:[ |
|
525 |
code := code , |
|
526 |
' "action to be added ..."\\'. |
|
527 |
]. |
|
528 |
||
529 |
code := code , |
|
530 |
' Transcript showCR:self class name, '': '. |
|
531 |
alreadyInSuperclass ifTrue:[ |
|
532 |
code := code , 'inherited '. |
|
533 |
]. |
|
534 |
code := code , 'action for ' , aspect , showIt. |
|
535 |
||
536 |
alreadyInSuperclass ifTrue:[ |
|
537 |
code := code , |
|
538 |
' super ' , aspect , args , '.\'. |
|
539 |
]. |
|
540 |
||
541 |
code := code , |
|
542 |
'!! !!\\'. |
|
543 |
^ code withCRs |
|
544 |
||
352 | 545 |
"Modified: / 25.10.1997 / 19:18:50 / cg" |
60 | 546 |
! |
547 |
||
548 |
generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass |
|
352 | 549 |
|modelClass modelValue modelGen| |
134 | 550 |
|
149 | 551 |
modelClass := protoSpec defaultModelClassFor:aspect. |
352 | 552 |
modelValue := protoSpec defaultModelValueFor:aspect. |
553 |
||
554 |
modelValue isNil ifTrue:[ |
|
555 |
modelGen := modelClass name , ' new' |
|
556 |
] ifFalse:[ |
|
557 |
modelGen := modelValue storeString , ' asValue' |
|
558 |
]. |
|
134 | 559 |
|
60 | 560 |
^ ('!!' , targetClass name , ' methodsFor:''aspects''!!\\' , |
561 |
aspect , '\' , |
|
352 | 562 |
' "automatically generated by UIPainter ..."\\' , |
563 |
' "*** the code below creates a default model when invoked."\' , |
|
564 |
' "*** (which may not be the one you wanted)"\' , |
|
565 |
' "*** Please change as required and accept in the browser."\' , |
|
60 | 566 |
'\' , |
567 |
' |holder|\' , |
|
568 |
'\' , |
|
569 |
' (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' , |
|
352 | 570 |
' builder aspectAt:#' , aspect , ' put:(holder := ' , ' ' , modelGen , ').\' , |
60 | 571 |
' ].\' , |
572 |
' ^ holder\' , |
|
573 |
'!! !!\\') withCRs |
|
352 | 574 |
|
575 |
"Modified: / 26.10.1997 / 19:01:15 / cg" |
|
60 | 576 |
! |
577 |
||
578 |
generateAspectMethods |
|
352 | 579 |
"generate aspect, action & menu methods |
580 |
- but do not overwrite existing ones. |
|
581 |
Return a string ready to compile into the application class." |
|
582 |
||
583 |
|cls code skip menuSelector protoSpec thisCode| |
|
60 | 584 |
|
78 | 585 |
code := ''. |
586 |
||
60 | 587 |
className isNil ifTrue:[ |
69 | 588 |
self warn:'set the class first'. |
78 | 589 |
^ code |
60 | 590 |
]. |
330 | 591 |
cls := self resolveName:className. |
60 | 592 |
|
316 | 593 |
treeView propertiesDo:[:aProp| |
352 | 594 |
|modelSelector menuSelector| |
595 |
||
134 | 596 |
protoSpec := aProp spec. |
175 | 597 |
|
78 | 598 |
(modelSelector := aProp model) notNil ifTrue:[ |
352 | 599 |
(modelSelector isArray not) ifTrue:[ |
600 |
(cls implements:modelSelector asSymbol) ifFalse:[ |
|
601 |
skip := false. |
|
602 |
(cls isSubclassOf:SimpleDialog) ifTrue:[ |
|
603 |
skip := SimpleDialog implements:modelSelector asSymbol |
|
158
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
604 |
]. |
352 | 605 |
skip ifFalse:[ |
606 |
"/ kludge .. |
|
607 |
(protoSpec isMemberOf:ActionButtonSpec) ifTrue:[ |
|
608 |
thisCode := (self generateActionMethodFor:modelSelector spec:protoSpec inClass:cls). |
|
609 |
] ifFalse:[ |
|
610 |
thisCode := (self generateAspectMethodFor:modelSelector spec:protoSpec inClass:cls). |
|
611 |
]. |
|
612 |
code := code , thisCode |
|
613 |
]. |
|
158
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
614 |
]. |
62 | 615 |
]. |
616 |
]. |
|
617 |
||
78 | 618 |
(menuSelector := aProp menu) notNil ifTrue:[ |
352 | 619 |
(menuSelector isArray not) ifTrue:[ |
620 |
thisCode := self generateMenuMethodFor:menuSelector spec:protoSpec inClass:cls. |
|
621 |
thisCode size ~~ 0 ifTrue:[ |
|
622 |
code := code , thisCode |
|
623 |
] |
|
60 | 624 |
] |
111 | 625 |
]. |
626 |
||
627 |
aProp spec aspectSelectors do:[:aSel| |
|
352 | 628 |
(aSel isArray not) ifTrue:[ |
629 |
(cls implements:aSel asSymbol) ifFalse:[ |
|
630 |
thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls). |
|
631 |
code := code , thisCode |
|
632 |
] |
|
111 | 633 |
] |
634 |
]. |
|
137 | 635 |
aProp spec actionSelectors do:[:aSel| |
352 | 636 |
(aSel isArray not) ifTrue:[ |
637 |
(cls implements:aSel asSymbol) ifFalse:[ |
|
638 |
thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls). |
|
639 |
code := code , thisCode |
|
640 |
] |
|
137 | 641 |
] |
642 |
]. |
|
188
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
643 |
aProp spec valueSelectors do:[:aSel| |
352 | 644 |
(aSel isArray not) ifTrue:[ |
376 | 645 |
"/ uppercase: - assume its a globals name. |
646 |
aSel first isUppercase ifFalse:[ |
|
647 |
(cls implements:aSel asSymbol) ifFalse:[ |
|
648 |
thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls). |
|
649 |
code := code , thisCode |
|
650 |
] |
|
352 | 651 |
] |
188
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
652 |
] |
316 | 653 |
] |
654 |
]. |
|
655 |
||
656 |
protoSpec := treeView canvasSpec. |
|
657 |
||
658 |
(menuSelector := protoSpec menu) notNil ifTrue:[ |
|
352 | 659 |
(menuSelector isArray not) ifTrue:[ |
660 |
thisCode := self generateMenuMethodFor:menuSelector spec:protoSpec inClass:cls. |
|
661 |
thisCode size ~~ 0 ifTrue:[ |
|
662 |
code := code , thisCode |
|
663 |
] |
|
316 | 664 |
] |
665 |
]. |
|
666 |
||
352 | 667 |
^ code |
316 | 668 |
|
376 | 669 |
"Modified: / 31.10.1997 / 14:22:30 / cg" |
670 |
! |
|
671 |
||
672 |
generateHookMethodFor:selectorSpec comment:commentWhen note:noteOrNil defaultCode:defaultCode inClass:targetClass |
|
673 |
^ ('!!' , targetClass name , ' methodsFor:''hooks''!!\\' , |
|
674 |
selectorSpec , '\' , |
|
675 |
' "automatically generated by UIPainter ..."\\' , |
|
676 |
' "*** the code here does nothing. It is invoked when"\' , |
|
677 |
' "*** ' , commentWhen , '"\' , |
|
678 |
' "*** Please change as required and accept in the browser."\' , |
|
679 |
'\' , |
|
680 |
' "specific code to be added below ..."\' , |
|
681 |
' "' , (noteOrNil ? '') , '"\' , |
|
682 |
'\' , |
|
683 |
(defaultCode ? '^ self.') , |
|
684 |
'!! !!\\') withCRs |
|
685 |
||
686 |
"Modified: / 25.10.1997 / 19:22:17 / cg" |
|
687 |
"Created: / 31.10.1997 / 17:31:53 / cg" |
|
688 |
! |
|
689 |
||
690 |
generateHookMethods |
|
691 |
"generate hook methods |
|
692 |
- but do not overwrite existing ones. |
|
693 |
Return a string ready to compile into the application class." |
|
694 |
||
695 |
|cls code skip menuSelector protoSpec thisCode| |
|
696 |
||
697 |
code := ''. |
|
698 |
||
699 |
className isNil ifTrue:[ |
|
700 |
self warn:'set the class first'. |
|
701 |
^ code |
|
702 |
]. |
|
703 |
cls := self resolveName:className. |
|
704 |
||
705 |
code := code , (self generateHookMethodsInClass:cls). |
|
706 |
||
707 |
^ code |
|
708 |
||
709 |
"Created: / 31.10.1997 / 17:21:29 / cg" |
|
710 |
"Modified: / 31.10.1997 / 17:38:11 / cg" |
|
711 |
! |
|
712 |
||
713 |
generateHookMethodsInClass:targetClass |
|
714 |
|code| |
|
715 |
||
716 |
code := ''. |
|
717 |
||
718 |
(targetClass implements:#postBuildWith:) ifFalse:[ |
|
719 |
code := code |
|
720 |
, (self |
|
721 |
generateHookMethodFor:'postBuildWith:aBuilder' |
|
722 |
comment:'the widgets have been built, but before the view is opened' |
|
723 |
note:nil |
|
724 |
defaultCode:nil |
|
725 |
inClass:targetClass) |
|
726 |
]. |
|
727 |
(targetClass implements:#postOpenWith:) ifFalse:[ |
|
728 |
code := code |
|
729 |
, (self |
|
730 |
generateHookMethodFor:'postOpenWith:aBuilder' |
|
731 |
comment:'the topView has been opened, but before events are dispatched for it' |
|
732 |
note:nil |
|
733 |
defaultCode:nil |
|
734 |
inClass:targetClass) |
|
735 |
]. |
|
736 |
(targetClass implements:#closeRequest) ifFalse:[ |
|
737 |
code := code |
|
738 |
, (self |
|
739 |
generateHookMethodFor:'closeRequest' |
|
740 |
comment:'the topView has been asked to close' |
|
741 |
note:'return without the ''super closeRequest'' to stay open' |
|
742 |
defaultCode:'^ super closeRequest' |
|
743 |
inClass:targetClass) |
|
744 |
]. |
|
745 |
^ code |
|
746 |
||
747 |
"Modified: / 31.10.1997 / 17:30:34 / cg" |
|
748 |
"Created: / 31.10.1997 / 17:32:49 / cg" |
|
316 | 749 |
! |
750 |
||
751 |
generateMenuMethodFor:aspect spec:protoSpec inClass:aClass |
|
752 |
|code cperf performer category| |
|
753 |
||
754 |
(aClass implements:aspect asSymbol) ifFalse:[ |
|
755 |
code := MenuEditor generateCodeFor:aClass menuSelector:(aspect asSymbol). |
|
756 |
] ifTrue:[ |
|
757 |
code := '' |
|
758 |
]. |
|
111 | 759 |
|
316 | 760 |
(protoSpec respondsTo:#menuPerformer) ifTrue:[ |
761 |
performer := protoSpec menuPerformer. |
|
60 | 762 |
]. |
316 | 763 |
performer notNil ifTrue:[ |
764 |
performer := performer asSymbol. |
|
765 |
||
766 |
(aClass implements:performer) ifFalse:[ |
|
767 |
category := MenuEditor sourceCategory. |
|
768 |
||
769 |
cperf := Character excla asString |
|
770 |
, aClass name , ' methodsFor:' , category storeString |
|
771 |
, Character excla asString , '\\' |
|
772 |
, performer , '\' |
|
352 | 773 |
, ' "this menu spec was automatically generated by the UI MenuBuilder"\\' |
316 | 774 |
, ' ^ self\\' |
775 |
, '\' |
|
776 |
, Character excla asString |
|
777 |
, ' ' |
|
778 |
, Character excla asString |
|
779 |
, '\\'. |
|
780 |
||
781 |
code := code, cperf. |
|
782 |
] |
|
783 |
]. |
|
784 |
||
785 |
code size == 0 ifTrue:[ |
|
786 |
^ nil |
|
787 |
]. |
|
788 |
^ code withCRs |
|
352 | 789 |
|
790 |
"Modified: / 26.10.1997 / 14:44:20 / cg" |
|
60 | 791 |
! |
792 |
||
188
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
793 |
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
794 |
^ ('!!' , targetClass name , ' methodsFor:''values''!!\\' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
795 |
aspect , '\' , |
352 | 796 |
' "automatically generated by UIPainter ..."\\' , |
797 |
' "*** the code below returns a default value when invoked."\' , |
|
798 |
' "*** (which may not be the one you wanted)"\' , |
|
799 |
' "*** Please change as required and accept in the browser."\' , |
|
188
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
800 |
'\' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
801 |
' "value to be added below ..."\' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
802 |
' Transcript showCR:self class name , '': no value yet for ' , aspect , ' ...''.\' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
803 |
'\' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
804 |
'^ nil.' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
805 |
'!! !!\\') withCRs |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
806 |
|
352 | 807 |
"Modified: / 25.10.1997 / 19:22:17 / cg" |
188
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
808 |
! |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
809 |
|
78 | 810 |
generateWindowSpecMethodSource |
310 | 811 |
|spec str code category cls mthd| |
60 | 812 |
|
310 | 813 |
spec := OrderedCollection new. |
60 | 814 |
|
78 | 815 |
self subViews do:[:aView| |
816 |
aView ~~ inputView ifTrue:[ |
|
310 | 817 |
spec add:(self fullSpecFor:aView) |
60 | 818 |
] |
819 |
]. |
|
310 | 820 |
spec := treeView generateFullSpecForComponents:spec. |
821 |
str := WriteStream on:String new. |
|
822 |
UISpecification prettyPrintSpecArray:spec on:str indent:5. |
|
60 | 823 |
|
178
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
824 |
"/ if that method already exists, do not overwrite the category |
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
825 |
|
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
826 |
category := 'interface specs'. |
330 | 827 |
cls := self resolveName:className. |
828 |
||
829 |
cls notNil ifTrue:[ |
|
178
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
830 |
(mthd := cls class compiledMethodAt:methodName asSymbol) notNil ifTrue:[ |
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
831 |
category := mthd category. |
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
832 |
] |
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
833 |
]. |
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
834 |
|
238 | 835 |
code := '!!' |
178
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
836 |
, className , ' class methodsFor:' , category storeString |
238 | 837 |
, '!!' , '\\' |
60 | 838 |
|
839 |
, methodName , '\' |
|
840 |
, ' "this window spec was automatically generated by the ST/X UIPainter"\\' |
|
841 |
, ' "do not manually edit this - the painter/builder may not be able to\' |
|
842 |
, ' handle the specification if its corrupted."\\' |
|
843 |
, ' "\' |
|
844 |
, ' UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\' |
|
845 |
, ' ' , className , ' new openInterface:#' , methodName , '\' |
|
846 |
, ' "\'. |
|
847 |
||
848 |
methodName = 'windowSpec' ifTrue:[ |
|
849 |
code := code , ' "' , className , ' open"\' |
|
850 |
]. |
|
851 |
code := code |
|
852 |
, '\' |
|
853 |
, ' <resource: #canvas>\\' |
|
854 |
, ' ^\' |
|
855 |
, ' ', str contents |
|
856 |
, '\' |
|
238 | 857 |
, '!! !!' |
60 | 858 |
, '\\'. |
859 |
||
860 |
^ code withCRs |
|
861 |
||
862 |
"Modified: 5.9.1995 / 21:01:35 / claus" |
|
178
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
863 |
"Modified: 24.6.1997 / 19:12:44 / cg" |
60 | 864 |
! ! |
865 |
||
866 |
!UIPainterView methodsFor:'initialization'! |
|
867 |
||
868 |
initialize |
|
62 | 869 |
"setup attributes |
870 |
" |
|
60 | 871 |
super initialize. |
872 |
||
873 |
superclassName := 'ApplicationModel'. |
|
874 |
className := 'NewApplication'. |
|
875 |
methodName := 'windowSpec'. |
|
876 |
categoryName := 'Applications'. |
|
877 |
HandCursor := Cursor leftHand. |
|
878 |
||
879 |
! |
|
880 |
||
881 |
setupFromSpec:specOrSpecArray |
|
78 | 882 |
|spec builder| |
60 | 883 |
|
238 | 884 |
treeView cvsSetupListDo:[ |
111 | 885 |
self removeAll. |
886 |
spec := UISpecification from:specOrSpecArray. |
|
887 |
builder := UIBuilder new. |
|
888 |
spec window setupView:self topView for:builder. |
|
889 |
self addSpec:(spec component) builder:builder in:self. |
|
890 |
self realizeAllSubViews. |
|
891 |
inputView raise. |
|
310 | 892 |
treeView setAttributesFromWindowSpec:(spec window). |
111 | 893 |
] |
223 | 894 |
! |
895 |
||
896 |
treeView:aTreeView |
|
361 | 897 |
treeView := aTreeView. |
898 |
||
899 |
treeView delegate:( |
|
376 | 900 |
"/ |
901 |
"/ I want to handle everything typed |
|
902 |
"/ in the treeView, except for Return and Cursor-keys |
|
903 |
"/ |
|
904 |
KeyboardForwarder |
|
905 |
toView:self |
|
906 |
condition:nil |
|
907 |
filter:[:k | (k isSymbol |
|
908 |
and:[k ~~ #Return |
|
909 |
and:[(k startsWith:#Cursor) not]]) |
|
910 |
] |
|
361 | 911 |
) |
912 |
||
376 | 913 |
"Modified: / 31.10.1997 / 20:22:09 / cg" |
60 | 914 |
! ! |
915 |
||
916 |
!UIPainterView methodsFor:'menus'! |
|
917 |
||
121 | 918 |
showMiddleButtonMenu |
919 |
"show the middle button menu; this returns nil |
|
62 | 920 |
" |
223 | 921 |
self enabled ifTrue:[ |
285 | 922 |
(MenuPanel fromSpec:(UIPainter menuCanvas) receiver:self) startUp |
111 | 923 |
]. |
121 | 924 |
^ nil |
60 | 925 |
|
62 | 926 |
|
927 |
||
60 | 928 |
! ! |
929 |
||
335 | 930 |
!UIPainterView methodsFor:'queries'! |
931 |
||
932 |
resolveName:aName |
|
933 |
|appl| |
|
934 |
||
935 |
appl := self application. |
|
936 |
||
937 |
appl notNil ifTrue:[ |
|
938 |
^ appl resolveName:aName |
|
939 |
]. |
|
940 |
^ Smalltalk resolveName:aName inClass:self class |
|
941 |
! ! |
|
942 |
||
60 | 943 |
!UIPainterView methodsFor:'removing components'! |
944 |
||
78 | 945 |
remove:anObject |
946 |
"remove anObject from the contents do redraw |
|
60 | 947 |
" |
134 | 948 |
anObject notNil ifTrue:[ |
238 | 949 |
treeView removeView:anObject. |
134 | 950 |
] |
60 | 951 |
! |
952 |
||
953 |
removeAll |
|
62 | 954 |
"remove all objects and properties |
955 |
" |
|
238 | 956 |
treeView cvsEventsDisabledDo:[ |
223 | 957 |
self select:nil. |
238 | 958 |
treeView removeAll. |
223 | 959 |
self removeUndoHistory. |
111 | 960 |
] |
60 | 961 |
! ! |
962 |
||
963 |
!UIPainterView methodsFor:'searching'! |
|
964 |
||
285 | 965 |
findContainerOfView:aView |
966 |
"returns the super view assigned to a view |
|
89 | 967 |
" |
285 | 968 |
|p| |
89 | 969 |
|
285 | 970 |
(p := self propertyOfParentForView:aView) isNil ifTrue:[ |
89 | 971 |
^ self |
972 |
]. |
|
285 | 973 |
^ p view |
89 | 974 |
! |
975 |
||
60 | 976 |
findObjectAt:aPoint |
977 |
"find the origin/corner of the currentWidget |
|
978 |
" |
|
285 | 979 |
|view prop| |
60 | 980 |
|
981 |
view := super findObjectAt:aPoint. |
|
285 | 982 |
prop := self propertyRespondsToView:view. |
60 | 983 |
|
285 | 984 |
prop notNil ifTrue:[^ prop view]. |
985 |
^ nil |
|
60 | 986 |
! |
987 |
||
988 |
findViewWithId:aViewId |
|
62 | 989 |
"finds view assigned to identifier and returns the view or nil |
60 | 990 |
" |
991 |
|prop| |
|
992 |
||
993 |
prop := self propertyOfIdentifier:aViewId. |
|
994 |
||
995 |
prop notNil ifTrue:[^ prop view] |
|
996 |
ifFalse:[^ nil] |
|
78 | 997 |
! |
998 |
||
999 |
propertyOfIdentifier:anId |
|
1000 |
"returns property assigned to unique identifier |
|
1001 |
" |
|
1002 |
anId notNil ifTrue:[ |
|
238 | 1003 |
^ treeView propertyDetect:[:p| p identifier == anId ] |
78 | 1004 |
]. |
1005 |
^ nil |
|
1006 |
! |
|
1007 |
||
1008 |
propertyOfName:aString |
|
1009 |
"returns property assigned to name |
|
1010 |
" |
|
111 | 1011 |
|name| |
1012 |
||
1013 |
aString isNil ifFalse:[ |
|
1014 |
name := aString string withoutSeparators. |
|
238 | 1015 |
^ treeView propertyDetect:[:p| p name = name ]. |
78 | 1016 |
]. |
1017 |
^ nil |
|
1018 |
! |
|
1019 |
||
285 | 1020 |
propertyOfParentForView:aSubView |
1021 |
"returns the property of the parent or nil |
|
1022 |
" |
|
1023 |
|item| |
|
1024 |
||
1025 |
(item := treeView detectItemRespondsToView:aSubView) notNil ifTrue:[ |
|
1026 |
(item := item parent) notNil ifTrue:[^ item contents] |
|
1027 |
]. |
|
1028 |
^ nil |
|
1029 |
! |
|
1030 |
||
78 | 1031 |
propertyOfView:aView |
1032 |
"returns property assigned to view |
|
1033 |
" |
|
1034 |
(aView isNil or:[aView == self]) ifFalse:[ |
|
238 | 1035 |
^ treeView propertyDetect:[:p| p view == aView ] |
78 | 1036 |
]. |
1037 |
^ nil |
|
1038 |
! |
|
1039 |
||
285 | 1040 |
propertyRespondsToView:aView |
1041 |
"detect the property responding to the argument a view. The property of the view or |
|
1042 |
the first subview providing the properties is returned. If no property is detected |
|
1043 |
nil is returned. |
|
1044 |
" |
|
1045 |
|item| |
|
1046 |
||
1047 |
item := treeView detectItemRespondsToView:aView. |
|
1048 |
||
1049 |
(item notNil and:[item parent notNil]) ifTrue:[ |
|
1050 |
^ item contents |
|
1051 |
]. |
|
1052 |
^ nil |
|
1053 |
! |
|
1054 |
||
111 | 1055 |
uniqueNameFor:aSpecOrString |
78 | 1056 |
"generate and return an unique name for a class |
1057 |
" |
|
1058 |
|next name size| |
|
1059 |
||
111 | 1060 |
aSpecOrString isString ifFalse:[name := aSpecOrString className asString] |
1061 |
ifTrue:[name := aSpecOrString]. |
|
78 | 1062 |
|
111 | 1063 |
(name endsWith:'Spec') ifTrue:[ |
1064 |
name := name copyFrom:1 to:(name size - 4). |
|
1065 |
] ifFalse:[ |
|
1066 |
name := name copy |
|
1067 |
]. |
|
78 | 1068 |
name at:1 put:(name at:1) asLowercase. |
111 | 1069 |
size := name size + 1. |
1070 |
next := 0. |
|
78 | 1071 |
|
238 | 1072 |
treeView propertiesDo:[:p| |
111 | 1073 |
|n| |
78 | 1074 |
n := p name. |
1075 |
||
1076 |
(n size >= size and:[n startsWith:name]) ifTrue:[ |
|
1077 |
next := next max:(p extractNumberStartingAt:size) |
|
1078 |
] |
|
1079 |
]. |
|
1080 |
next := next + 1. |
|
1081 |
name := name, next printString. |
|
1082 |
^ name |
|
1083 |
||
1084 |
||
1085 |
||
1086 |
! |
|
1087 |
||
1088 |
uniqueNameOf:aView |
|
111 | 1089 |
|prop| |
78 | 1090 |
|
111 | 1091 |
(prop := self propertyOfView:aView) notNil ifTrue:[ |
1092 |
prop name isNil ifTrue:[ |
|
1093 |
prop name:(self uniqueNameFor:(prop spec)). |
|
1094 |
]. |
|
1095 |
^ prop name |
|
78 | 1096 |
]. |
111 | 1097 |
^ 'self' |
78 | 1098 |
|
60 | 1099 |
! ! |
1100 |
||
223 | 1101 |
!UIPainterView methodsFor:'selection basics'! |
1102 |
||
1103 |
addToSelection:anObject |
|
1104 |
"add an object to the selection |
|
1105 |
" |
|
1106 |
(self enabled and:[(self isSelected:anObject) not]) ifTrue:[ |
|
1107 |
selection isCollection ifFalse:[ |
|
1108 |
selection isNil ifTrue:[ |
|
1109 |
selection := anObject |
|
1110 |
] ifFalse:[ |
|
1111 |
selection := OrderedCollection with:selection with:anObject |
|
1112 |
] |
|
1113 |
] ifTrue:[ |
|
1114 |
selection add:anObject |
|
1115 |
]. |
|
1116 |
self showSelected:anObject. |
|
238 | 1117 |
treeView cvsSelectionAdd:anObject. |
223 | 1118 |
] |
1119 |
||
1120 |
||
1121 |
! |
|
1122 |
||
1123 |
removeFromSelection:anObject |
|
1124 |
"remove an object from the selection |
|
1125 |
" |
|
1126 |
(self isSelected:anObject) ifTrue:[ |
|
1127 |
self showUnselected:anObject. |
|
1128 |
||
1129 |
selection size > 1 ifTrue:[ |
|
1130 |
selection remove:anObject ifAbsent:nil. |
|
1131 |
self showSelection. |
|
1132 |
] ifFalse:[ |
|
1133 |
selection := nil |
|
1134 |
]. |
|
238 | 1135 |
treeView cvsSelectionRemove:anObject. |
223 | 1136 |
] |
1137 |
||
1138 |
! |
|
1139 |
||
1140 |
select:something |
|
1141 |
"change selection to something |
|
1142 |
" |
|
1143 |
(self enabled and:[something ~= self selection]) ifTrue:[ |
|
1144 |
self setSelection:something withRedraw:true. |
|
238 | 1145 |
treeView cvsSelection:something |
223 | 1146 |
] |
1147 |
||
1148 |
! |
|
1149 |
||
285 | 1150 |
updateSelectionFromModel:aSelOrNil |
223 | 1151 |
"update selection from a new selection |
1152 |
" |
|
1153 |
selectionHiddenLevel == 0 ifTrue:[ |
|
285 | 1154 |
aSelOrNil size ~~ 0 ifTrue:[ |
1155 |
self selectionDo:[:el| (aSelOrNil includes:el) ifFalse:[self showUnselected:el] ] |
|
1156 |
] ifFalse:[ |
|
1157 |
self selectionDo:[:el| self showUnselected:el ] |
|
1158 |
] |
|
223 | 1159 |
]. |
285 | 1160 |
self setSelection:aSelOrNil withRedraw:false. |
223 | 1161 |
self showSelection |
1162 |
||
1163 |
! ! |
|
1164 |
||
78 | 1165 |
!UIPainterView methodsFor:'specification'! |
1166 |
||
1167 |
addSpec:aSpecification builder:aBuilder in:aFrame |
|
1168 |
"build view and subviews from aSpecification into a frame. The top view |
|
1169 |
is returned. The contained components of a spec are set to nil |
|
1170 |
" |
|
330 | 1171 |
|cls| |
212 | 1172 |
|
330 | 1173 |
cls := self resolveName:className. |
1174 |
||
1175 |
cls notNil ifTrue:[ |
|
1176 |
aBuilder applicationClass:cls. |
|
212 | 1177 |
]. |
78 | 1178 |
|
111 | 1179 |
aBuilder componentCreationHook:[:aView :aSpec :aBdr||sv p s n| |
78 | 1180 |
p := ViewProperty new. |
1181 |
s := aSpec copy. |
|
1182 |
p spec:s. |
|
1183 |
p view:aView. |
|
1184 |
||
1185 |
s class supportsSubComponents ifTrue:[ |
|
1186 |
s component:nil |
|
1187 |
]. |
|
1188 |
||
111 | 1189 |
n := s name. |
1190 |
||
1191 |
(n isNil or:[(self propertyOfName:n) notNil]) ifTrue:[ |
|
1192 |
s name:(self uniqueNameFor:s) |
|
78 | 1193 |
]. |
238 | 1194 |
treeView addProperty:p. |
78 | 1195 |
]. |
1196 |
||
1197 |
^ aSpecification buildViewWithLayoutFor:aBuilder in:aFrame. |
|
60 | 1198 |
|
212 | 1199 |
"Modified: 4.7.1997 / 23:48:55 / cg" |
78 | 1200 |
! |
1201 |
||
1202 |
fullSpecFor:anObject |
|
1203 |
"generate a full spec for an object |
|
62 | 1204 |
" |
78 | 1205 |
|mySpec subSpecs| |
1206 |
||
1207 |
mySpec := self specFor:anObject. |
|
1208 |
||
1209 |
(mySpec notNil and:[mySpec class supportsSubComponents]) ifTrue:[ |
|
1210 |
(anObject subViews notNil) ifTrue:[ |
|
1211 |
anObject subViews do:[:aSubView||spec| |
|
1212 |
spec := self fullSpecFor:aSubView. |
|
1213 |
spec notNil ifTrue:[ |
|
1214 |
subSpecs isNil ifTrue:[ |
|
1215 |
subSpecs := OrderedCollection new |
|
1216 |
]. |
|
1217 |
subSpecs add:spec. |
|
1218 |
]. |
|
1219 |
]. |
|
1220 |
subSpecs notNil ifTrue:[ |
|
1221 |
mySpec component:(SpecCollection new collection:subSpecs) |
|
1222 |
] |
|
1223 |
] |
|
1224 |
]. |
|
1225 |
^ mySpec |
|
1226 |
||
60 | 1227 |
|
1228 |
||
1229 |
||
1230 |
||
1231 |
||
1232 |
! |
|
1233 |
||
285 | 1234 |
rebuildView:aView fromSpec:aSpec withBuilder:aBuilder |
1235 |
|v| |
|
1236 |
||
1237 |
aSpec needsRebuildForAttributes ifTrue:[ |
|
1238 |
v := aSpec buildViewWithLayoutFor:aBuilder in:(self findContainerOfView:aView). |
|
1239 |
v realize. |
|
1240 |
aView destroy. |
|
1241 |
device sync. |
|
1242 |
device flush. |
|
1243 |
aView becomeSameAs:v. |
|
1244 |
inputView raise. |
|
1245 |
] ifFalse:[ |
|
1246 |
aSpec setAttributesIn:aView with:aBuilder. |
|
1247 |
self elementChangedSize:aView. |
|
1248 |
]. |
|
1249 |
||
1250 |
! |
|
1251 |
||
78 | 1252 |
specFor:anObject |
1253 |
"returns spec assigned to an object |
|
62 | 1254 |
" |
78 | 1255 |
|prop spec| |
60 | 1256 |
|
78 | 1257 |
(prop := self propertyOfView:anObject) notNil ifTrue:[ |
1258 |
spec := prop spec copy. |
|
1259 |
spec layoutFromView:anObject |
|
60 | 1260 |
]. |
78 | 1261 |
^ spec |
1262 |
||
1263 |
||
1264 |
||
60 | 1265 |
! |
1266 |
||
146 | 1267 |
specForSelection |
1268 |
"returns spec assigned to current single selection or nil |
|
1269 |
" |
|
1270 |
^ self specFor:(self singleSelection) |
|
1271 |
||
1272 |
||
1273 |
! |
|
1274 |
||
78 | 1275 |
updateFromSpec:aSpec |
1276 |
"update current selected view from specification |
|
62 | 1277 |
" |
327
0040d47658c6
check - warnings eliminated. Fix in InspectorList.st
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1278 |
|props name builder| |
78 | 1279 |
|
281 | 1280 |
aSpec class == WindowSpec ifTrue:[ |
310 | 1281 |
^ treeView canvasSpec:aSpec |
281 | 1282 |
]. |
1283 |
||
78 | 1284 |
self singleSelection notNil ifTrue:[ |
1285 |
self withSelectionHiddenDo:[ |
|
1286 |
self transaction:#specification selectionDo:[:aView| |
|
1287 |
builder := UIBuilder new. |
|
212 | 1288 |
className notNil ifTrue:[ |
330 | 1289 |
builder applicationClass:(self resolveName:className). |
212 | 1290 |
]. |
78 | 1291 |
props := self propertyOfView:aView. |
82 | 1292 |
name := (aSpec name) withoutSeparators. |
78 | 1293 |
|
82 | 1294 |
name = props name ifFalse:[ |
1295 |
(self propertyOfName:name) notNil ifTrue:[ |
|
1296 |
name := props name |
|
78 | 1297 |
] |
1298 |
]. |
|
82 | 1299 |
aSpec name:name. |
134 | 1300 |
self createUndoSpecModify:props. |
285 | 1301 |
self rebuildView:aView fromSpec:aSpec withBuilder:builder. |
78 | 1302 |
props spec:(aSpec copy). |
238 | 1303 |
treeView propertyChanged:props. |
78 | 1304 |
] |
111 | 1305 |
] |
82 | 1306 |
] |
212 | 1307 |
|
1308 |
"Modified: 4.7.1997 / 23:49:44 / cg" |
|
60 | 1309 |
! ! |
1310 |
||
285 | 1311 |
!UIPainterView methodsFor:'testing'! |
1312 |
||
1313 |
canChangeLayoutOfView:aView |
|
1314 |
"returns true if the view can change its layout which is dependant on |
|
1315 |
its parent view. |
|
1316 |
" |
|
1317 |
|item prnt| |
|
1318 |
||
1319 |
( (item := treeView itemOfView:aView) isNil |
|
1320 |
or:[(prnt := item parent) isNil] |
|
1321 |
) ifTrue:[ |
|
1322 |
^ false |
|
1323 |
]. |
|
1324 |
^ (prnt parent isNil or:[prnt contents spec class isLayoutContainer not]) |
|
1325 |
! |
|
1326 |
||
1327 |
canKeepLayoutInSelection |
|
1328 |
"returns true if layout can be kept during a paste operation |
|
1329 |
" |
|
1330 |
|prop| |
|
1331 |
||
1332 |
prop := self propertyOfView:(self singleSelection). |
|
1333 |
^ (prop isNil or:[prop spec class isLayoutContainer not]) |
|
1334 |
! |
|
1335 |
||
1336 |
canMove:something |
|
1337 |
"checks whether something is not nil and if all widgets derived from |
|
1338 |
something can change their layout ( move, align, ... operation ). |
|
1339 |
" |
|
1340 |
something notNil ifTrue:[ |
|
1341 |
self forEach:something do:[:aView| |
|
1342 |
(self canChangeLayoutOfView:aView) ifFalse:[^ false] |
|
1343 |
]. |
|
1344 |
^ true |
|
1345 |
]. |
|
1346 |
^ false |
|
1347 |
! |
|
1348 |
||
1349 |
canMoveOrAlignSelection |
|
1350 |
"returns true if a selection exists and all elements in the selection |
|
1351 |
can be moved or aligned |
|
1352 |
" |
|
1353 |
^ self canMove:(self selection) |
|
1354 |
||
1355 |
! ! |
|
1356 |
||
60 | 1357 |
!UIPainterView methodsFor:'transaction'! |
1358 |
||
1359 |
transaction:aType objects:something do:aOneArgBlock |
|
1360 |
"opens a transaction and evaluates a block within the transaction; the |
|
1361 |
argument to the block is a view from derived from something |
|
1362 |
" |
|
134 | 1363 |
self withinTransaction:aType objects:something do:[ |
1364 |
self forEach:something do:aOneArgBlock |
|
60 | 1365 |
] |
1366 |
! |
|
1367 |
||
134 | 1368 |
withinTransaction:aType objects:objects do:aNoneArgBlock |
1369 |
"evaluate a block with no arguments within a transaction |
|
60 | 1370 |
" |
134 | 1371 |
|text size prop| |
1372 |
||
1373 |
objects isNil ifTrue:[ ^ self ]. |
|
1374 |
||
1375 |
size := objects size. |
|
60 | 1376 |
|
134 | 1377 |
objects isCollection ifTrue:[ |
1378 |
size == 0 ifTrue:[ ^ self ]. |
|
1379 |
size == 1 ifTrue:[ prop := self propertyOfView:(objects first) ] |
|
1380 |
] ifFalse:[ |
|
1381 |
prop := self propertyOfView:objects |
|
1382 |
]. |
|
60 | 1383 |
|
134 | 1384 |
prop notNil ifTrue:[ |
1385 |
text := prop name |
|
1386 |
] ifFalse:[ |
|
1387 |
text := size printString, ' elements' |
|
60 | 1388 |
]. |
134 | 1389 |
|
1390 |
undoHistory withinTransaction:aType text:text do:[ |
|
1391 |
aNoneArgBlock value |
|
1392 |
] |
|
60 | 1393 |
! ! |
1394 |
||
1395 |
!UIPainterView methodsFor:'undo actions'! |
|
1396 |
||
134 | 1397 |
createUndoLayout:aView |
1398 |
"create undo action before changing a views layout |
|
60 | 1399 |
" |
134 | 1400 |
|lyt args prop| |
60 | 1401 |
|
1402 |
undoHistory isTransactionOpen ifTrue:[ |
|
1403 |
prop := self propertyOfView:aView. |
|
134 | 1404 |
|
60 | 1405 |
prop notNil ifTrue:[ |
134 | 1406 |
args := Array new:3. |
1407 |
args at:1 put:(prop identifier). |
|
1408 |
||
1409 |
(lyt := aView geometryLayout) notNil ifTrue:[ |
|
1410 |
args at:2 put:#geometryLayout: |
|
1411 |
] ifFalse:[ |
|
146 | 1412 |
lyt := aView extent. |
134 | 1413 |
args at:2 put:#extent: |
1414 |
]. |
|
1415 |
args at:3 put:(lyt copy). |
|
1416 |
undoHistory addUndoSelector:#undoLayout: withArgs:args. |
|
60 | 1417 |
] |
1418 |
] |
|
1419 |
! |
|
1420 |
||
134 | 1421 |
createUndoRemove:aView |
1422 |
"create undo method before deleting views |
|
60 | 1423 |
" |
285 | 1424 |
|prop pid| |
134 | 1425 |
|
1426 |
(prop := self propertyOfView:aView) notNil ifTrue:[ |
|
285 | 1427 |
(pid := self propertyOfParentForView:aView) notNil ifTrue:[ |
1428 |
pid := pid identifier |
|
1429 |
]. |
|
60 | 1430 |
|
134 | 1431 |
undoHistory addUndoSelector:#undoRemove: |
285 | 1432 |
withArgs:(Array with:(self fullSpecFor:aView) |
1433 |
with:(prop identifier) |
|
1434 |
with:pid) |
|
134 | 1435 |
] |
1436 |
! |
|
60 | 1437 |
|
134 | 1438 |
createUndoSpecModify:aProp |
1439 |
"undo method when changing the specification for an object |
|
1440 |
" |
|
1441 |
aProp notNil ifTrue:[ |
|
1442 |
undoHistory addUndoSelector:#undoSpecModify: |
|
1443 |
withArgs:(Array with:(aProp spec) with:(aProp identifier)) |
|
1444 |
] |
|
1445 |
! |
|
60 | 1446 |
|
134 | 1447 |
undoCreate:something |
1448 |
"undo method for creating or pasting an object |
|
1449 |
" |
|
1450 |
self forEach:something do:[:anId|self remove:(self findViewWithId:anId)]. |
|
1451 |
! |
|
60 | 1452 |
|
134 | 1453 |
undoLayout:args |
1454 |
"undo method to set the old layout; see 'createUndoLayout:' |
|
1455 |
" |
|
1456 |
|view| |
|
1457 |
||
1458 |
(view := self findViewWithId:(args at:1)) notNil ifTrue:[ |
|
146 | 1459 |
view perform:(args at:2) with:(args at:3). |
223 | 1460 |
self layoutChanged. |
60 | 1461 |
] |
1462 |
! |
|
1463 |
||
134 | 1464 |
undoRemove:args |
1465 |
"undo method when removing an object; see 'createUndoRemove:' |
|
1466 |
" |
|
1467 |
|frame prop view| |
|
1468 |
||
1469 |
(args at:3) notNil ifTrue:[ |
|
1470 |
frame := self findViewWithId:(args at:3). |
|
1471 |
]. |
|
1472 |
frame isNil ifTrue:[ |
|
1473 |
frame := self |
|
1474 |
]. |
|
1475 |
view := self addSpec:(args at:1) builder:(UIBuilder new) in:frame. |
|
1476 |
view realize. |
|
1477 |
inputView raise. |
|
1478 |
||
1479 |
prop := self propertyOfView:view. |
|
1480 |
prop identifier:(args at:2). |
|
1481 |
||
1482 |
! |
|
1483 |
||
1484 |
undoSpecModify:args |
|
1485 |
"undo method when changing a spec; see 'createUndoSpecModify:' |
|
60 | 1486 |
" |
327
0040d47658c6
check - warnings eliminated. Fix in InspectorList.st
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1487 |
|builder view spec props| |
60 | 1488 |
|
134 | 1489 |
props := self propertyOfIdentifier:(args at:2). |
60 | 1490 |
|
134 | 1491 |
props notNil ifTrue:[ |
1492 |
view := props view. |
|
1493 |
spec := args at:1. |
|
1494 |
builder := UIBuilder new. |
|
212 | 1495 |
className notNil ifTrue:[ |
330 | 1496 |
builder applicationClass:(self resolveName:className). |
212 | 1497 |
]. |
134 | 1498 |
props spec:spec. |
285 | 1499 |
self rebuildView:view fromSpec:spec withBuilder:builder. |
238 | 1500 |
treeView propertyChanged:props. |
211 | 1501 |
] |
1502 |
! ! |
|
1503 |
||
1504 |
!UIPainterView::ViewProperty class methodsFor:'instance creation'! |
|
1505 |
||
1506 |
new |
|
1507 |
Identifier notNil ifTrue:[Identifier := Identifier + 1] |
|
1508 |
ifFalse:[Identifier := 1]. |
|
1509 |
||
1510 |
^ self basicNew initialize |
|
1511 |
! ! |
|
1512 |
||
1513 |
!UIPainterView::ViewProperty methodsFor:'accessing'! |
|
1514 |
||
1515 |
identifier |
|
1516 |
"return the unique identifier assigned to property |
|
1517 |
" |
|
1518 |
^ identifier |
|
1519 |
! |
|
1520 |
||
1521 |
identifier:anIdentifier |
|
1522 |
"set the unique identifier assigned to property; called after an restore of |
|
1523 |
a deleted instance |
|
1524 |
" |
|
1525 |
identifier := anIdentifier |
|
1526 |
! |
|
1527 |
||
1528 |
spec |
|
1529 |
"return the value of the instance variable 'spec' (automatically generated)" |
|
1530 |
||
1531 |
^ spec! |
|
1532 |
||
1533 |
spec:something |
|
1534 |
"set the value of the instance variable 'spec' (automatically generated)" |
|
1535 |
||
1536 |
spec := something.! |
|
1537 |
||
1538 |
view |
|
1539 |
"return the value of the instance variable 'view' (automatically generated)" |
|
1540 |
||
1541 |
^ view! |
|
1542 |
||
1543 |
view:something |
|
1544 |
"set the value of the instance variable 'view' (automatically generated)" |
|
1545 |
||
1546 |
view := something.! ! |
|
1547 |
||
1548 |
!UIPainterView::ViewProperty methodsFor:'initialization'! |
|
1549 |
||
1550 |
initialize |
|
1551 |
super initialize. |
|
1552 |
identifier := Identifier |
|
1553 |
! ! |
|
1554 |
||
1555 |
!UIPainterView::ViewProperty methodsFor:'misc'! |
|
1556 |
||
1557 |
extractNumberStartingAt:anIndex |
|
1558 |
"return the number from the name starting at anIndex or 0. |
|
1559 |
" |
|
1560 |
|val| |
|
1561 |
||
1562 |
val := 0. |
|
1563 |
||
1564 |
self name from:anIndex do:[:c| |
|
1565 |
c isDigit ifTrue:[val := val * 10 + c digitValue] |
|
1566 |
ifFalse:[^ 0] |
|
1567 |
]. |
|
1568 |
^ val |
|
1569 |
||
1570 |
! ! |
|
1571 |
||
1572 |
!UIPainterView::ViewProperty methodsFor:'spec messages'! |
|
1573 |
||
1574 |
doesNotUnderstand:aMessage |
|
1575 |
spec notNil ifTrue:[ |
|
1576 |
(spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec] |
|
1577 |
]. |
|
1578 |
^ nil |
|
1579 |
! |
|
1580 |
||
1581 |
layout |
|
1582 |
spec layout |
|
1583 |
! |
|
1584 |
||
1585 |
layout:aLayout |
|
1586 |
spec layout:aLayout |
|
1587 |
! |
|
1588 |
||
1589 |
name |
|
1590 |
^ spec name |
|
1591 |
! |
|
1592 |
||
1593 |
name:aName |
|
1594 |
spec name:aName |
|
1595 |
! ! |
|
1596 |
||
60 | 1597 |
!UIPainterView class methodsFor:'documentation'! |
1598 |
||
1599 |
version |
|
1600 |
^ '$Header$' |
|
1601 |
! ! |