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