author | tz |
Fri, 23 Jan 1998 18:06:28 +0100 | |
changeset 469 | 28bcb1982ef9 |
parent 464 | dd67c1e99fed |
child 501 | 16d87a6511d4 |
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 |
288 | 505 |
|selector args showIt code alreadyInSuperclass| |
506 |
||
507 |
selector := aspect asSymbol. |
|
141 | 508 |
|
288 | 509 |
alreadyInSuperclass := targetClass superclass canUnderstand:selector. |
510 |
||
511 |
(selector numArgs) == 1 ifFalse:[ |
|
512 |
args := ''. |
|
149 | 513 |
showIt := ' ...''.\'. |
514 |
] ifTrue:[ |
|
288 | 515 |
args := 'anArgument'. |
149 | 516 |
showIt := ''' , anArgument printString , '' ...''.\'. |
517 |
]. |
|
141 | 518 |
|
288 | 519 |
code := '!!' , targetClass name , ' methodsFor:''actions''!!\\' , |
520 |
aspect , args , '\' , |
|
352 | 521 |
' "automatically generated by UIPainter ..."\\' , |
522 |
' "*** the code below performs no action"\' , |
|
523 |
' "*** (except for some feedback on the Transcript)"\' , |
|
524 |
' "*** Please change as required and accept in the browser."\' , |
|
288 | 525 |
'\' . |
526 |
||
527 |
alreadyInSuperclass ifTrue:[ |
|
528 |
code := code , |
|
529 |
' "action for ' , aspect , ' is already provided in a superclass."\' , |
|
530 |
' "It may be redefined here ..."\\'. |
|
531 |
] ifFalse:[ |
|
532 |
code := code , |
|
533 |
' "action to be added ..."\\'. |
|
534 |
]. |
|
535 |
||
536 |
code := code , |
|
537 |
' Transcript showCR:self class name, '': '. |
|
538 |
alreadyInSuperclass ifTrue:[ |
|
539 |
code := code , 'inherited '. |
|
540 |
]. |
|
541 |
code := code , 'action for ' , aspect , showIt. |
|
542 |
||
543 |
alreadyInSuperclass ifTrue:[ |
|
544 |
code := code , |
|
545 |
' super ' , aspect , args , '.\'. |
|
546 |
]. |
|
547 |
||
548 |
code := code , |
|
549 |
'!! !!\\'. |
|
550 |
^ code withCRs |
|
551 |
||
352 | 552 |
"Modified: / 25.10.1997 / 19:18:50 / cg" |
60 | 553 |
! |
554 |
||
555 |
generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass |
|
352 | 556 |
|modelClass modelValue modelGen| |
134 | 557 |
|
149 | 558 |
modelClass := protoSpec defaultModelClassFor:aspect. |
352 | 559 |
modelValue := protoSpec defaultModelValueFor:aspect. |
560 |
||
561 |
modelValue isNil ifTrue:[ |
|
562 |
modelGen := modelClass name , ' new' |
|
563 |
] ifFalse:[ |
|
564 |
modelGen := modelValue storeString , ' asValue' |
|
565 |
]. |
|
134 | 566 |
|
60 | 567 |
^ ('!!' , targetClass name , ' methodsFor:''aspects''!!\\' , |
568 |
aspect , '\' , |
|
352 | 569 |
' "automatically generated by UIPainter ..."\\' , |
570 |
' "*** the code below creates a default model when invoked."\' , |
|
571 |
' "*** (which may not be the one you wanted)"\' , |
|
572 |
' "*** Please change as required and accept in the browser."\' , |
|
60 | 573 |
'\' , |
574 |
' |holder|\' , |
|
575 |
'\' , |
|
576 |
' (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' , |
|
352 | 577 |
' builder aspectAt:#' , aspect , ' put:(holder := ' , ' ' , modelGen , ').\' , |
60 | 578 |
' ].\' , |
579 |
' ^ holder\' , |
|
580 |
'!! !!\\') withCRs |
|
352 | 581 |
|
582 |
"Modified: / 26.10.1997 / 19:01:15 / cg" |
|
60 | 583 |
! |
584 |
||
585 |
generateAspectMethods |
|
352 | 586 |
"generate aspect, action & menu methods |
587 |
- but do not overwrite existing ones. |
|
588 |
Return a string ready to compile into the application class." |
|
589 |
||
590 |
|cls code skip menuSelector protoSpec thisCode| |
|
60 | 591 |
|
78 | 592 |
code := ''. |
593 |
||
60 | 594 |
className isNil ifTrue:[ |
69 | 595 |
self warn:'set the class first'. |
78 | 596 |
^ code |
60 | 597 |
]. |
330 | 598 |
cls := self resolveName:className. |
60 | 599 |
|
316 | 600 |
treeView propertiesDo:[:aProp| |
352 | 601 |
|modelSelector menuSelector| |
602 |
||
134 | 603 |
protoSpec := aProp spec. |
175 | 604 |
|
78 | 605 |
(modelSelector := aProp model) notNil ifTrue:[ |
352 | 606 |
(modelSelector isArray not) ifTrue:[ |
607 |
(cls implements:modelSelector asSymbol) ifFalse:[ |
|
608 |
skip := false. |
|
609 |
(cls isSubclassOf:SimpleDialog) ifTrue:[ |
|
610 |
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
|
611 |
]. |
352 | 612 |
skip ifFalse:[ |
613 |
"/ kludge .. |
|
614 |
(protoSpec isMemberOf:ActionButtonSpec) ifTrue:[ |
|
615 |
thisCode := (self generateActionMethodFor:modelSelector spec:protoSpec inClass:cls). |
|
616 |
] ifFalse:[ |
|
617 |
thisCode := (self generateAspectMethodFor:modelSelector spec:protoSpec inClass:cls). |
|
618 |
]. |
|
619 |
code := code , thisCode |
|
620 |
]. |
|
158
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
621 |
]. |
62 | 622 |
]. |
623 |
]. |
|
624 |
||
78 | 625 |
(menuSelector := aProp menu) notNil ifTrue:[ |
352 | 626 |
(menuSelector isArray not) ifTrue:[ |
627 |
thisCode := self generateMenuMethodFor:menuSelector spec:protoSpec inClass:cls. |
|
628 |
thisCode size ~~ 0 ifTrue:[ |
|
629 |
code := code , thisCode |
|
630 |
] |
|
60 | 631 |
] |
111 | 632 |
]. |
633 |
||
634 |
aProp spec aspectSelectors do:[:aSel| |
|
352 | 635 |
(aSel isArray not) ifTrue:[ |
636 |
(cls implements:aSel asSymbol) ifFalse:[ |
|
637 |
thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls). |
|
638 |
code := code , thisCode |
|
639 |
] |
|
111 | 640 |
] |
641 |
]. |
|
137 | 642 |
aProp spec actionSelectors do:[:aSel| |
352 | 643 |
(aSel isArray not) ifTrue:[ |
644 |
(cls implements:aSel asSymbol) ifFalse:[ |
|
645 |
thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls). |
|
646 |
code := code , thisCode |
|
647 |
] |
|
137 | 648 |
] |
649 |
]. |
|
188
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
650 |
aProp spec valueSelectors do:[:aSel| |
352 | 651 |
(aSel isArray not) ifTrue:[ |
376 | 652 |
"/ uppercase: - assume its a globals name. |
653 |
aSel first isUppercase ifFalse:[ |
|
654 |
(cls implements:aSel asSymbol) ifFalse:[ |
|
655 |
thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls). |
|
656 |
code := code , thisCode |
|
657 |
] |
|
352 | 658 |
] |
188
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
659 |
] |
316 | 660 |
] |
661 |
]. |
|
662 |
||
663 |
protoSpec := treeView canvasSpec. |
|
664 |
||
665 |
(menuSelector := protoSpec menu) notNil ifTrue:[ |
|
352 | 666 |
(menuSelector isArray not) ifTrue:[ |
667 |
thisCode := self generateMenuMethodFor:menuSelector spec:protoSpec inClass:cls. |
|
668 |
thisCode size ~~ 0 ifTrue:[ |
|
669 |
code := code , thisCode |
|
670 |
] |
|
316 | 671 |
] |
672 |
]. |
|
673 |
||
352 | 674 |
^ code |
316 | 675 |
|
376 | 676 |
"Modified: / 31.10.1997 / 14:22:30 / cg" |
677 |
! |
|
678 |
||
679 |
generateHookMethodFor:selectorSpec comment:commentWhen note:noteOrNil defaultCode:defaultCode inClass:targetClass |
|
680 |
^ ('!!' , targetClass name , ' methodsFor:''hooks''!!\\' , |
|
681 |
selectorSpec , '\' , |
|
682 |
' "automatically generated by UIPainter ..."\\' , |
|
683 |
' "*** the code here does nothing. It is invoked when"\' , |
|
684 |
' "*** ' , commentWhen , '"\' , |
|
685 |
' "*** Please change as required and accept in the browser."\' , |
|
686 |
'\' , |
|
687 |
' "specific code to be added below ..."\' , |
|
688 |
' "' , (noteOrNil ? '') , '"\' , |
|
689 |
'\' , |
|
690 |
(defaultCode ? '^ self.') , |
|
691 |
'!! !!\\') withCRs |
|
692 |
||
693 |
"Modified: / 25.10.1997 / 19:22:17 / cg" |
|
694 |
"Created: / 31.10.1997 / 17:31:53 / cg" |
|
695 |
! |
|
696 |
||
697 |
generateHookMethods |
|
698 |
"generate hook methods |
|
699 |
- but do not overwrite existing ones. |
|
700 |
Return a string ready to compile into the application class." |
|
701 |
||
702 |
|cls code skip menuSelector protoSpec thisCode| |
|
703 |
||
704 |
code := ''. |
|
705 |
||
706 |
className isNil ifTrue:[ |
|
707 |
self warn:'set the class first'. |
|
708 |
^ code |
|
709 |
]. |
|
710 |
cls := self resolveName:className. |
|
711 |
||
712 |
code := code , (self generateHookMethodsInClass:cls). |
|
713 |
||
714 |
^ code |
|
715 |
||
716 |
"Created: / 31.10.1997 / 17:21:29 / cg" |
|
717 |
"Modified: / 31.10.1997 / 17:38:11 / cg" |
|
718 |
! |
|
719 |
||
720 |
generateHookMethodsInClass:targetClass |
|
721 |
|code| |
|
722 |
||
723 |
code := ''. |
|
724 |
||
725 |
(targetClass implements:#postBuildWith:) ifFalse:[ |
|
726 |
code := code |
|
727 |
, (self |
|
728 |
generateHookMethodFor:'postBuildWith:aBuilder' |
|
729 |
comment:'the widgets have been built, but before the view is opened' |
|
730 |
note:nil |
|
731 |
defaultCode:nil |
|
732 |
inClass:targetClass) |
|
733 |
]. |
|
734 |
(targetClass implements:#postOpenWith:) ifFalse:[ |
|
735 |
code := code |
|
736 |
, (self |
|
737 |
generateHookMethodFor:'postOpenWith:aBuilder' |
|
738 |
comment:'the topView has been opened, but before events are dispatched for it' |
|
739 |
note:nil |
|
740 |
defaultCode:nil |
|
741 |
inClass:targetClass) |
|
742 |
]. |
|
743 |
(targetClass implements:#closeRequest) ifFalse:[ |
|
744 |
code := code |
|
745 |
, (self |
|
746 |
generateHookMethodFor:'closeRequest' |
|
747 |
comment:'the topView has been asked to close' |
|
748 |
note:'return without the ''super closeRequest'' to stay open' |
|
749 |
defaultCode:'^ super closeRequest' |
|
750 |
inClass:targetClass) |
|
751 |
]. |
|
752 |
^ code |
|
753 |
||
754 |
"Modified: / 31.10.1997 / 17:30:34 / cg" |
|
755 |
"Created: / 31.10.1997 / 17:32:49 / cg" |
|
316 | 756 |
! |
757 |
||
758 |
generateMenuMethodFor:aspect spec:protoSpec inClass:aClass |
|
759 |
|code cperf performer category| |
|
760 |
||
761 |
(aClass implements:aspect asSymbol) ifFalse:[ |
|
762 |
code := MenuEditor generateCodeFor:aClass menuSelector:(aspect asSymbol). |
|
763 |
] ifTrue:[ |
|
764 |
code := '' |
|
765 |
]. |
|
111 | 766 |
|
316 | 767 |
(protoSpec respondsTo:#menuPerformer) ifTrue:[ |
768 |
performer := protoSpec menuPerformer. |
|
60 | 769 |
]. |
316 | 770 |
performer notNil ifTrue:[ |
771 |
performer := performer asSymbol. |
|
772 |
||
773 |
(aClass implements:performer) ifFalse:[ |
|
774 |
category := MenuEditor sourceCategory. |
|
775 |
||
776 |
cperf := Character excla asString |
|
777 |
, aClass name , ' methodsFor:' , category storeString |
|
778 |
, Character excla asString , '\\' |
|
779 |
, performer , '\' |
|
352 | 780 |
, ' "this menu spec was automatically generated by the UI MenuBuilder"\\' |
316 | 781 |
, ' ^ self\\' |
782 |
, '\' |
|
783 |
, Character excla asString |
|
784 |
, ' ' |
|
785 |
, Character excla asString |
|
786 |
, '\\'. |
|
787 |
||
788 |
code := code, cperf. |
|
789 |
] |
|
790 |
]. |
|
791 |
||
792 |
code size == 0 ifTrue:[ |
|
793 |
^ nil |
|
794 |
]. |
|
795 |
^ code withCRs |
|
352 | 796 |
|
797 |
"Modified: / 26.10.1997 / 14:44:20 / cg" |
|
60 | 798 |
! |
799 |
||
188
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
800 |
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
801 |
^ ('!!' , targetClass name , ' methodsFor:''values''!!\\' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
802 |
aspect , '\' , |
352 | 803 |
' "automatically generated by UIPainter ..."\\' , |
804 |
' "*** the code below returns a default value when invoked."\' , |
|
805 |
' "*** (which may not be the one you wanted)"\' , |
|
806 |
' "*** Please change as required and accept in the browser."\' , |
|
188
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
807 |
'\' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
808 |
' "value to be added below ..."\' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
809 |
' Transcript showCR:self class name , '': no value yet for ' , aspect , ' ...''.\' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
810 |
'\' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
811 |
'^ nil.' , |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
812 |
'!! !!\\') withCRs |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
813 |
|
352 | 814 |
"Modified: / 25.10.1997 / 19:22:17 / cg" |
188
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
815 |
! |
8091a35bccf1
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca
parents:
180
diff
changeset
|
816 |
|
78 | 817 |
generateWindowSpecMethodSource |
457 | 818 |
|spec str code category cls mthd specCode| |
60 | 819 |
|
310 | 820 |
spec := OrderedCollection new. |
60 | 821 |
|
78 | 822 |
self subViews do:[:aView| |
823 |
aView ~~ inputView ifTrue:[ |
|
310 | 824 |
spec add:(self fullSpecFor:aView) |
60 | 825 |
] |
826 |
]. |
|
310 | 827 |
spec := treeView generateFullSpecForComponents:spec. |
828 |
str := WriteStream on:String new. |
|
829 |
UISpecification prettyPrintSpecArray:spec on:str indent:5. |
|
464 | 830 |
specCode := str contents. |
457 | 831 |
|
832 |
(specCode includes:$!!) ifTrue:[ |
|
833 |
"/ oops - must be chunk format ... |
|
834 |
str := WriteStream on:String new. |
|
835 |
str nextPutAllAsChunk:specCode. |
|
836 |
specCode := str contents. |
|
837 |
]. |
|
60 | 838 |
|
178
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
839 |
"/ 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
|
840 |
|
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
841 |
category := 'interface specs'. |
330 | 842 |
cls := self resolveName:className. |
843 |
||
844 |
cls notNil ifTrue:[ |
|
178
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
845 |
(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
|
846 |
category := mthd category. |
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
847 |
] |
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
848 |
]. |
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
849 |
|
238 | 850 |
code := '!!' |
178
fb8451053c96
keep windowSpec methods category if it already exists
Claus Gittinger <cg@exept.de>
parents:
175
diff
changeset
|
851 |
, className , ' class methodsFor:' , category storeString |
238 | 852 |
, '!!' , '\\' |
60 | 853 |
|
854 |
, methodName , '\' |
|
855 |
, ' "this window spec was automatically generated by the ST/X UIPainter"\\' |
|
856 |
, ' "do not manually edit this - the painter/builder may not be able to\' |
|
857 |
, ' handle the specification if its corrupted."\\' |
|
858 |
, ' "\' |
|
859 |
, ' UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\' |
|
860 |
, ' ' , className , ' new openInterface:#' , methodName , '\' |
|
861 |
, ' "\'. |
|
862 |
||
863 |
methodName = 'windowSpec' ifTrue:[ |
|
864 |
code := code , ' "' , className , ' open"\' |
|
865 |
]. |
|
866 |
code := code |
|
867 |
, '\' |
|
868 |
, ' <resource: #canvas>\\' |
|
869 |
, ' ^\' |
|
457 | 870 |
, ' ', specCode |
60 | 871 |
, '\' |
238 | 872 |
, '!! !!' |
60 | 873 |
, '\\'. |
874 |
||
875 |
^ code withCRs |
|
876 |
||
877 |
"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
|
878 |
"Modified: 24.6.1997 / 19:12:44 / cg" |
60 | 879 |
! ! |
880 |
||
881 |
!UIPainterView methodsFor:'initialization'! |
|
882 |
||
883 |
initialize |
|
62 | 884 |
"setup attributes |
885 |
" |
|
60 | 886 |
super initialize. |
887 |
||
888 |
superclassName := 'ApplicationModel'. |
|
889 |
className := 'NewApplication'. |
|
890 |
methodName := 'windowSpec'. |
|
891 |
categoryName := 'Applications'. |
|
892 |
HandCursor := Cursor leftHand. |
|
893 |
||
894 |
! |
|
895 |
||
896 |
setupFromSpec:specOrSpecArray |
|
78 | 897 |
|spec builder| |
60 | 898 |
|
238 | 899 |
treeView cvsSetupListDo:[ |
111 | 900 |
self removeAll. |
901 |
spec := UISpecification from:specOrSpecArray. |
|
395 | 902 |
builder := UIBuilder new isEditing:true. |
903 |
||
111 | 904 |
spec window setupView:self topView for:builder. |
905 |
self addSpec:(spec component) builder:builder in:self. |
|
906 |
self realizeAllSubViews. |
|
907 |
inputView raise. |
|
310 | 908 |
treeView setAttributesFromWindowSpec:(spec window). |
111 | 909 |
] |
223 | 910 |
! |
911 |
||
912 |
treeView:aTreeView |
|
361 | 913 |
treeView := aTreeView. |
914 |
||
915 |
treeView delegate:( |
|
376 | 916 |
"/ |
917 |
"/ I want to handle everything typed |
|
918 |
"/ in the treeView, except for Return and Cursor-keys |
|
919 |
"/ |
|
920 |
KeyboardForwarder |
|
921 |
toView:self |
|
922 |
condition:nil |
|
923 |
filter:[:k | (k isSymbol |
|
924 |
and:[k ~~ #Return |
|
925 |
and:[(k startsWith:#Cursor) not]]) |
|
926 |
] |
|
361 | 927 |
) |
928 |
||
376 | 929 |
"Modified: / 31.10.1997 / 20:22:09 / cg" |
60 | 930 |
! ! |
931 |
||
932 |
!UIPainterView methodsFor:'menus'! |
|
933 |
||
121 | 934 |
showMiddleButtonMenu |
935 |
"show the middle button menu; this returns nil |
|
62 | 936 |
" |
223 | 937 |
self enabled ifTrue:[ |
445 | 938 |
(MenuPanel fromSpec:(UIPainter menuEdit) receiver:self) startUp |
111 | 939 |
]. |
121 | 940 |
^ nil |
60 | 941 |
|
62 | 942 |
|
943 |
||
60 | 944 |
! ! |
945 |
||
335 | 946 |
!UIPainterView methodsFor:'queries'! |
947 |
||
948 |
resolveName:aName |
|
949 |
|appl| |
|
950 |
||
951 |
appl := self application. |
|
952 |
||
953 |
appl notNil ifTrue:[ |
|
954 |
^ appl resolveName:aName |
|
955 |
]. |
|
956 |
^ Smalltalk resolveName:aName inClass:self class |
|
957 |
! ! |
|
958 |
||
60 | 959 |
!UIPainterView methodsFor:'removing components'! |
960 |
||
78 | 961 |
remove:anObject |
962 |
"remove anObject from the contents do redraw |
|
60 | 963 |
" |
134 | 964 |
anObject notNil ifTrue:[ |
238 | 965 |
treeView removeView:anObject. |
134 | 966 |
] |
60 | 967 |
! |
968 |
||
969 |
removeAll |
|
62 | 970 |
"remove all objects and properties |
971 |
" |
|
238 | 972 |
treeView cvsEventsDisabledDo:[ |
223 | 973 |
self select:nil. |
238 | 974 |
treeView removeAll. |
223 | 975 |
self removeUndoHistory. |
111 | 976 |
] |
60 | 977 |
! ! |
978 |
||
979 |
!UIPainterView methodsFor:'searching'! |
|
980 |
||
285 | 981 |
findContainerOfView:aView |
982 |
"returns the super view assigned to a view |
|
89 | 983 |
" |
285 | 984 |
|p| |
89 | 985 |
|
285 | 986 |
(p := self propertyOfParentForView:aView) isNil ifTrue:[ |
89 | 987 |
^ self |
988 |
]. |
|
285 | 989 |
^ p view |
89 | 990 |
! |
991 |
||
60 | 992 |
findObjectAt:aPoint |
993 |
"find the origin/corner of the currentWidget |
|
994 |
" |
|
285 | 995 |
|view prop| |
60 | 996 |
|
997 |
view := super findObjectAt:aPoint. |
|
285 | 998 |
prop := self propertyRespondsToView:view. |
60 | 999 |
|
285 | 1000 |
prop notNil ifTrue:[^ prop view]. |
1001 |
^ nil |
|
60 | 1002 |
! |
1003 |
||
1004 |
findViewWithId:aViewId |
|
62 | 1005 |
"finds view assigned to identifier and returns the view or nil |
60 | 1006 |
" |
1007 |
|prop| |
|
1008 |
||
1009 |
prop := self propertyOfIdentifier:aViewId. |
|
1010 |
||
1011 |
prop notNil ifTrue:[^ prop view] |
|
1012 |
ifFalse:[^ nil] |
|
78 | 1013 |
! |
1014 |
||
1015 |
propertyOfIdentifier:anId |
|
1016 |
"returns property assigned to unique identifier |
|
1017 |
" |
|
1018 |
anId notNil ifTrue:[ |
|
238 | 1019 |
^ treeView propertyDetect:[:p| p identifier == anId ] |
78 | 1020 |
]. |
1021 |
^ nil |
|
1022 |
! |
|
1023 |
||
1024 |
propertyOfName:aString |
|
1025 |
"returns property assigned to name |
|
1026 |
" |
|
111 | 1027 |
|name| |
1028 |
||
1029 |
aString isNil ifFalse:[ |
|
1030 |
name := aString string withoutSeparators. |
|
238 | 1031 |
^ treeView propertyDetect:[:p| p name = name ]. |
78 | 1032 |
]. |
1033 |
^ nil |
|
1034 |
! |
|
1035 |
||
285 | 1036 |
propertyOfParentForView:aSubView |
1037 |
"returns the property of the parent or nil |
|
1038 |
" |
|
1039 |
|item| |
|
1040 |
||
1041 |
(item := treeView detectItemRespondsToView:aSubView) notNil ifTrue:[ |
|
1042 |
(item := item parent) notNil ifTrue:[^ item contents] |
|
1043 |
]. |
|
1044 |
^ nil |
|
1045 |
! |
|
1046 |
||
78 | 1047 |
propertyOfView:aView |
1048 |
"returns property assigned to view |
|
1049 |
" |
|
1050 |
(aView isNil or:[aView == self]) ifFalse:[ |
|
238 | 1051 |
^ treeView propertyDetect:[:p| p view == aView ] |
78 | 1052 |
]. |
1053 |
^ nil |
|
1054 |
! |
|
1055 |
||
285 | 1056 |
propertyRespondsToView:aView |
1057 |
"detect the property responding to the argument a view. The property of the view or |
|
1058 |
the first subview providing the properties is returned. If no property is detected |
|
1059 |
nil is returned. |
|
1060 |
" |
|
1061 |
|item| |
|
1062 |
||
1063 |
item := treeView detectItemRespondsToView:aView. |
|
1064 |
||
1065 |
(item notNil and:[item parent notNil]) ifTrue:[ |
|
1066 |
^ item contents |
|
1067 |
]. |
|
1068 |
^ nil |
|
1069 |
! |
|
1070 |
||
111 | 1071 |
uniqueNameFor:aSpecOrString |
78 | 1072 |
"generate and return an unique name for a class |
1073 |
" |
|
1074 |
|next name size| |
|
1075 |
||
111 | 1076 |
aSpecOrString isString ifFalse:[name := aSpecOrString className asString] |
1077 |
ifTrue:[name := aSpecOrString]. |
|
78 | 1078 |
|
111 | 1079 |
(name endsWith:'Spec') ifTrue:[ |
1080 |
name := name copyFrom:1 to:(name size - 4). |
|
1081 |
] ifFalse:[ |
|
1082 |
name := name copy |
|
1083 |
]. |
|
78 | 1084 |
name at:1 put:(name at:1) asLowercase. |
111 | 1085 |
size := name size + 1. |
1086 |
next := 0. |
|
78 | 1087 |
|
238 | 1088 |
treeView propertiesDo:[:p| |
111 | 1089 |
|n| |
78 | 1090 |
n := p name. |
1091 |
||
1092 |
(n size >= size and:[n startsWith:name]) ifTrue:[ |
|
1093 |
next := next max:(p extractNumberStartingAt:size) |
|
1094 |
] |
|
1095 |
]. |
|
1096 |
next := next + 1. |
|
1097 |
name := name, next printString. |
|
1098 |
^ name |
|
1099 |
||
1100 |
||
1101 |
||
1102 |
! |
|
1103 |
||
1104 |
uniqueNameOf:aView |
|
111 | 1105 |
|prop| |
78 | 1106 |
|
111 | 1107 |
(prop := self propertyOfView:aView) notNil ifTrue:[ |
1108 |
prop name isNil ifTrue:[ |
|
1109 |
prop name:(self uniqueNameFor:(prop spec)). |
|
1110 |
]. |
|
1111 |
^ prop name |
|
78 | 1112 |
]. |
111 | 1113 |
^ 'self' |
78 | 1114 |
|
60 | 1115 |
! ! |
1116 |
||
223 | 1117 |
!UIPainterView methodsFor:'selection basics'! |
1118 |
||
1119 |
addToSelection:anObject |
|
1120 |
"add an object to the selection |
|
1121 |
" |
|
1122 |
(self enabled and:[(self isSelected:anObject) not]) ifTrue:[ |
|
1123 |
selection isCollection ifFalse:[ |
|
1124 |
selection isNil ifTrue:[ |
|
1125 |
selection := anObject |
|
1126 |
] ifFalse:[ |
|
1127 |
selection := OrderedCollection with:selection with:anObject |
|
1128 |
] |
|
1129 |
] ifTrue:[ |
|
1130 |
selection add:anObject |
|
1131 |
]. |
|
1132 |
self showSelected:anObject. |
|
238 | 1133 |
treeView cvsSelectionAdd:anObject. |
223 | 1134 |
] |
1135 |
||
1136 |
||
1137 |
! |
|
1138 |
||
1139 |
removeFromSelection:anObject |
|
1140 |
"remove an object from the selection |
|
1141 |
" |
|
1142 |
(self isSelected:anObject) ifTrue:[ |
|
1143 |
self showUnselected:anObject. |
|
1144 |
||
1145 |
selection size > 1 ifTrue:[ |
|
1146 |
selection remove:anObject ifAbsent:nil. |
|
1147 |
self showSelection. |
|
1148 |
] ifFalse:[ |
|
1149 |
selection := nil |
|
1150 |
]. |
|
238 | 1151 |
treeView cvsSelectionRemove:anObject. |
223 | 1152 |
] |
1153 |
||
1154 |
! |
|
1155 |
||
1156 |
select:something |
|
1157 |
"change selection to something |
|
1158 |
" |
|
1159 |
(self enabled and:[something ~= self selection]) ifTrue:[ |
|
1160 |
self setSelection:something withRedraw:true. |
|
238 | 1161 |
treeView cvsSelection:something |
223 | 1162 |
] |
1163 |
||
1164 |
! |
|
1165 |
||
285 | 1166 |
updateSelectionFromModel:aSelOrNil |
223 | 1167 |
"update selection from a new selection |
1168 |
" |
|
1169 |
selectionHiddenLevel == 0 ifTrue:[ |
|
285 | 1170 |
aSelOrNil size ~~ 0 ifTrue:[ |
1171 |
self selectionDo:[:el| (aSelOrNil includes:el) ifFalse:[self showUnselected:el] ] |
|
1172 |
] ifFalse:[ |
|
1173 |
self selectionDo:[:el| self showUnselected:el ] |
|
1174 |
] |
|
223 | 1175 |
]. |
285 | 1176 |
self setSelection:aSelOrNil withRedraw:false. |
223 | 1177 |
self showSelection |
1178 |
||
1179 |
! ! |
|
1180 |
||
78 | 1181 |
!UIPainterView methodsFor:'specification'! |
1182 |
||
1183 |
addSpec:aSpecification builder:aBuilder in:aFrame |
|
1184 |
"build view and subviews from aSpecification into a frame. The top view |
|
1185 |
is returned. The contained components of a spec are set to nil |
|
1186 |
" |
|
330 | 1187 |
|cls| |
212 | 1188 |
|
330 | 1189 |
cls := self resolveName:className. |
1190 |
||
1191 |
cls notNil ifTrue:[ |
|
1192 |
aBuilder applicationClass:cls. |
|
212 | 1193 |
]. |
78 | 1194 |
|
111 | 1195 |
aBuilder componentCreationHook:[:aView :aSpec :aBdr||sv p s n| |
78 | 1196 |
p := ViewProperty new. |
1197 |
s := aSpec copy. |
|
1198 |
p spec:s. |
|
1199 |
p view:aView. |
|
1200 |
||
1201 |
s class supportsSubComponents ifTrue:[ |
|
1202 |
s component:nil |
|
1203 |
]. |
|
1204 |
||
111 | 1205 |
n := s name. |
1206 |
||
1207 |
(n isNil or:[(self propertyOfName:n) notNil]) ifTrue:[ |
|
1208 |
s name:(self uniqueNameFor:s) |
|
78 | 1209 |
]. |
238 | 1210 |
treeView addProperty:p. |
78 | 1211 |
]. |
1212 |
||
1213 |
^ aSpecification buildViewWithLayoutFor:aBuilder in:aFrame. |
|
60 | 1214 |
|
212 | 1215 |
"Modified: 4.7.1997 / 23:48:55 / cg" |
78 | 1216 |
! |
1217 |
||
1218 |
fullSpecFor:anObject |
|
1219 |
"generate a full spec for an object |
|
62 | 1220 |
" |
78 | 1221 |
|mySpec subSpecs| |
1222 |
||
1223 |
mySpec := self specFor:anObject. |
|
1224 |
||
1225 |
(mySpec notNil and:[mySpec class supportsSubComponents]) ifTrue:[ |
|
1226 |
(anObject subViews notNil) ifTrue:[ |
|
1227 |
anObject subViews do:[:aSubView||spec| |
|
1228 |
spec := self fullSpecFor:aSubView. |
|
1229 |
spec notNil ifTrue:[ |
|
1230 |
subSpecs isNil ifTrue:[ |
|
1231 |
subSpecs := OrderedCollection new |
|
1232 |
]. |
|
1233 |
subSpecs add:spec. |
|
1234 |
]. |
|
1235 |
]. |
|
1236 |
subSpecs notNil ifTrue:[ |
|
1237 |
mySpec component:(SpecCollection new collection:subSpecs) |
|
1238 |
] |
|
1239 |
] |
|
1240 |
]. |
|
1241 |
^ mySpec |
|
1242 |
||
60 | 1243 |
|
1244 |
||
1245 |
||
1246 |
||
1247 |
||
1248 |
! |
|
1249 |
||
285 | 1250 |
rebuildView:aView fromSpec:aSpec withBuilder:aBuilder |
1251 |
|v| |
|
1252 |
||
1253 |
aSpec needsRebuildForAttributes ifTrue:[ |
|
1254 |
v := aSpec buildViewWithLayoutFor:aBuilder in:(self findContainerOfView:aView). |
|
1255 |
v realize. |
|
1256 |
aView destroy. |
|
1257 |
device sync. |
|
1258 |
device flush. |
|
1259 |
aView becomeSameAs:v. |
|
1260 |
inputView raise. |
|
1261 |
] ifFalse:[ |
|
1262 |
aSpec setAttributesIn:aView with:aBuilder. |
|
1263 |
self elementChangedSize:aView. |
|
1264 |
]. |
|
1265 |
||
1266 |
! |
|
1267 |
||
78 | 1268 |
specFor:anObject |
1269 |
"returns spec assigned to an object |
|
62 | 1270 |
" |
78 | 1271 |
|prop spec| |
60 | 1272 |
|
78 | 1273 |
(prop := self propertyOfView:anObject) notNil ifTrue:[ |
1274 |
spec := prop spec copy. |
|
1275 |
spec layoutFromView:anObject |
|
60 | 1276 |
]. |
78 | 1277 |
^ spec |
1278 |
||
1279 |
||
1280 |
||
60 | 1281 |
! |
1282 |
||
146 | 1283 |
specForSelection |
1284 |
"returns spec assigned to current single selection or nil |
|
1285 |
" |
|
1286 |
^ self specFor:(self singleSelection) |
|
1287 |
||
1288 |
||
1289 |
! |
|
1290 |
||
78 | 1291 |
updateFromSpec:aSpec |
1292 |
"update current selected view from specification |
|
62 | 1293 |
" |
327
0040d47658c6
check - warnings eliminated. Fix in InspectorList.st
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1294 |
|props name builder| |
78 | 1295 |
|
281 | 1296 |
aSpec class == WindowSpec ifTrue:[ |
310 | 1297 |
^ treeView canvasSpec:aSpec |
281 | 1298 |
]. |
1299 |
||
78 | 1300 |
self singleSelection notNil ifTrue:[ |
1301 |
self withSelectionHiddenDo:[ |
|
1302 |
self transaction:#specification selectionDo:[:aView| |
|
395 | 1303 |
builder := UIBuilder new isEditing:true. |
212 | 1304 |
className notNil ifTrue:[ |
330 | 1305 |
builder applicationClass:(self resolveName:className). |
212 | 1306 |
]. |
78 | 1307 |
props := self propertyOfView:aView. |
82 | 1308 |
name := (aSpec name) withoutSeparators. |
78 | 1309 |
|
82 | 1310 |
name = props name ifFalse:[ |
1311 |
(self propertyOfName:name) notNil ifTrue:[ |
|
1312 |
name := props name |
|
78 | 1313 |
] |
1314 |
]. |
|
82 | 1315 |
aSpec name:name. |
134 | 1316 |
self createUndoSpecModify:props. |
285 | 1317 |
self rebuildView:aView fromSpec:aSpec withBuilder:builder. |
78 | 1318 |
props spec:(aSpec copy). |
238 | 1319 |
treeView propertyChanged:props. |
78 | 1320 |
] |
111 | 1321 |
] |
82 | 1322 |
] |
212 | 1323 |
|
1324 |
"Modified: 4.7.1997 / 23:49:44 / cg" |
|
60 | 1325 |
! ! |
1326 |
||
285 | 1327 |
!UIPainterView methodsFor:'testing'! |
1328 |
||
1329 |
canChangeLayoutOfView:aView |
|
1330 |
"returns true if the view can change its layout which is dependant on |
|
1331 |
its parent view. |
|
1332 |
" |
|
1333 |
|item prnt| |
|
1334 |
||
1335 |
( (item := treeView itemOfView:aView) isNil |
|
1336 |
or:[(prnt := item parent) isNil] |
|
1337 |
) ifTrue:[ |
|
1338 |
^ false |
|
1339 |
]. |
|
1340 |
^ (prnt parent isNil or:[prnt contents spec class isLayoutContainer not]) |
|
1341 |
! |
|
1342 |
||
1343 |
canKeepLayoutInSelection |
|
1344 |
"returns true if layout can be kept during a paste operation |
|
1345 |
" |
|
1346 |
|prop| |
|
1347 |
||
1348 |
prop := self propertyOfView:(self singleSelection). |
|
1349 |
^ (prop isNil or:[prop spec class isLayoutContainer not]) |
|
1350 |
! |
|
1351 |
||
1352 |
canMove:something |
|
1353 |
"checks whether something is not nil and if all widgets derived from |
|
1354 |
something can change their layout ( move, align, ... operation ). |
|
1355 |
" |
|
1356 |
something notNil ifTrue:[ |
|
1357 |
self forEach:something do:[:aView| |
|
1358 |
(self canChangeLayoutOfView:aView) ifFalse:[^ false] |
|
1359 |
]. |
|
1360 |
^ true |
|
1361 |
]. |
|
1362 |
^ false |
|
1363 |
! |
|
1364 |
||
1365 |
canMoveOrAlignSelection |
|
1366 |
"returns true if a selection exists and all elements in the selection |
|
1367 |
can be moved or aligned |
|
1368 |
" |
|
1369 |
^ self canMove:(self selection) |
|
1370 |
||
1371 |
! ! |
|
1372 |
||
60 | 1373 |
!UIPainterView methodsFor:'transaction'! |
1374 |
||
1375 |
transaction:aType objects:something do:aOneArgBlock |
|
1376 |
"opens a transaction and evaluates a block within the transaction; the |
|
1377 |
argument to the block is a view from derived from something |
|
1378 |
" |
|
134 | 1379 |
self withinTransaction:aType objects:something do:[ |
1380 |
self forEach:something do:aOneArgBlock |
|
60 | 1381 |
] |
1382 |
! |
|
1383 |
||
134 | 1384 |
withinTransaction:aType objects:objects do:aNoneArgBlock |
1385 |
"evaluate a block with no arguments within a transaction |
|
60 | 1386 |
" |
134 | 1387 |
|text size prop| |
1388 |
||
1389 |
objects isNil ifTrue:[ ^ self ]. |
|
1390 |
||
1391 |
size := objects size. |
|
60 | 1392 |
|
134 | 1393 |
objects isCollection ifTrue:[ |
1394 |
size == 0 ifTrue:[ ^ self ]. |
|
1395 |
size == 1 ifTrue:[ prop := self propertyOfView:(objects first) ] |
|
1396 |
] ifFalse:[ |
|
1397 |
prop := self propertyOfView:objects |
|
1398 |
]. |
|
60 | 1399 |
|
134 | 1400 |
prop notNil ifTrue:[ |
1401 |
text := prop name |
|
1402 |
] ifFalse:[ |
|
1403 |
text := size printString, ' elements' |
|
60 | 1404 |
]. |
134 | 1405 |
|
1406 |
undoHistory withinTransaction:aType text:text do:[ |
|
1407 |
aNoneArgBlock value |
|
1408 |
] |
|
60 | 1409 |
! ! |
1410 |
||
1411 |
!UIPainterView methodsFor:'undo actions'! |
|
1412 |
||
134 | 1413 |
createUndoLayout:aView |
1414 |
"create undo action before changing a views layout |
|
60 | 1415 |
" |
134 | 1416 |
|lyt args prop| |
60 | 1417 |
|
1418 |
undoHistory isTransactionOpen ifTrue:[ |
|
1419 |
prop := self propertyOfView:aView. |
|
134 | 1420 |
|
60 | 1421 |
prop notNil ifTrue:[ |
134 | 1422 |
args := Array new:3. |
1423 |
args at:1 put:(prop identifier). |
|
1424 |
||
1425 |
(lyt := aView geometryLayout) notNil ifTrue:[ |
|
1426 |
args at:2 put:#geometryLayout: |
|
1427 |
] ifFalse:[ |
|
146 | 1428 |
lyt := aView extent. |
134 | 1429 |
args at:2 put:#extent: |
1430 |
]. |
|
1431 |
args at:3 put:(lyt copy). |
|
1432 |
undoHistory addUndoSelector:#undoLayout: withArgs:args. |
|
60 | 1433 |
] |
1434 |
] |
|
1435 |
! |
|
1436 |
||
134 | 1437 |
createUndoRemove:aView |
1438 |
"create undo method before deleting views |
|
60 | 1439 |
" |
285 | 1440 |
|prop pid| |
134 | 1441 |
|
1442 |
(prop := self propertyOfView:aView) notNil ifTrue:[ |
|
285 | 1443 |
(pid := self propertyOfParentForView:aView) notNil ifTrue:[ |
1444 |
pid := pid identifier |
|
1445 |
]. |
|
60 | 1446 |
|
134 | 1447 |
undoHistory addUndoSelector:#undoRemove: |
285 | 1448 |
withArgs:(Array with:(self fullSpecFor:aView) |
1449 |
with:(prop identifier) |
|
1450 |
with:pid) |
|
134 | 1451 |
] |
1452 |
! |
|
60 | 1453 |
|
134 | 1454 |
createUndoSpecModify:aProp |
1455 |
"undo method when changing the specification for an object |
|
1456 |
" |
|
1457 |
aProp notNil ifTrue:[ |
|
1458 |
undoHistory addUndoSelector:#undoSpecModify: |
|
1459 |
withArgs:(Array with:(aProp spec) with:(aProp identifier)) |
|
1460 |
] |
|
1461 |
! |
|
60 | 1462 |
|
134 | 1463 |
undoCreate:something |
1464 |
"undo method for creating or pasting an object |
|
1465 |
" |
|
1466 |
self forEach:something do:[:anId|self remove:(self findViewWithId:anId)]. |
|
1467 |
! |
|
60 | 1468 |
|
134 | 1469 |
undoLayout:args |
1470 |
"undo method to set the old layout; see 'createUndoLayout:' |
|
1471 |
" |
|
1472 |
|view| |
|
1473 |
||
1474 |
(view := self findViewWithId:(args at:1)) notNil ifTrue:[ |
|
146 | 1475 |
view perform:(args at:2) with:(args at:3). |
223 | 1476 |
self layoutChanged. |
60 | 1477 |
] |
1478 |
! |
|
1479 |
||
134 | 1480 |
undoRemove:args |
1481 |
"undo method when removing an object; see 'createUndoRemove:' |
|
1482 |
" |
|
1483 |
|frame prop view| |
|
1484 |
||
1485 |
(args at:3) notNil ifTrue:[ |
|
1486 |
frame := self findViewWithId:(args at:3). |
|
1487 |
]. |
|
1488 |
frame isNil ifTrue:[ |
|
1489 |
frame := self |
|
1490 |
]. |
|
395 | 1491 |
view := self addSpec:(args at:1) builder:(UIBuilder new isEditing:true) in:frame. |
134 | 1492 |
view realize. |
1493 |
inputView raise. |
|
1494 |
||
1495 |
prop := self propertyOfView:view. |
|
1496 |
prop identifier:(args at:2). |
|
1497 |
||
1498 |
! |
|
1499 |
||
1500 |
undoSpecModify:args |
|
1501 |
"undo method when changing a spec; see 'createUndoSpecModify:' |
|
60 | 1502 |
" |
327
0040d47658c6
check - warnings eliminated. Fix in InspectorList.st
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
1503 |
|builder view spec props| |
60 | 1504 |
|
134 | 1505 |
props := self propertyOfIdentifier:(args at:2). |
60 | 1506 |
|
134 | 1507 |
props notNil ifTrue:[ |
1508 |
view := props view. |
|
1509 |
spec := args at:1. |
|
395 | 1510 |
builder := UIBuilder new isEditing:true. |
1511 |
||
212 | 1512 |
className notNil ifTrue:[ |
330 | 1513 |
builder applicationClass:(self resolveName:className). |
212 | 1514 |
]. |
134 | 1515 |
props spec:spec. |
285 | 1516 |
self rebuildView:view fromSpec:spec withBuilder:builder. |
238 | 1517 |
treeView propertyChanged:props. |
211 | 1518 |
] |
1519 |
! ! |
|
1520 |
||
1521 |
!UIPainterView::ViewProperty class methodsFor:'instance creation'! |
|
1522 |
||
1523 |
new |
|
1524 |
Identifier notNil ifTrue:[Identifier := Identifier + 1] |
|
1525 |
ifFalse:[Identifier := 1]. |
|
1526 |
||
1527 |
^ self basicNew initialize |
|
1528 |
! ! |
|
1529 |
||
1530 |
!UIPainterView::ViewProperty methodsFor:'accessing'! |
|
1531 |
||
1532 |
identifier |
|
1533 |
"return the unique identifier assigned to property |
|
1534 |
" |
|
1535 |
^ identifier |
|
1536 |
! |
|
1537 |
||
1538 |
identifier:anIdentifier |
|
1539 |
"set the unique identifier assigned to property; called after an restore of |
|
1540 |
a deleted instance |
|
1541 |
" |
|
1542 |
identifier := anIdentifier |
|
1543 |
! |
|
1544 |
||
1545 |
spec |
|
1546 |
"return the value of the instance variable 'spec' (automatically generated)" |
|
1547 |
||
1548 |
^ spec! |
|
1549 |
||
1550 |
spec:something |
|
1551 |
"set the value of the instance variable 'spec' (automatically generated)" |
|
1552 |
||
1553 |
spec := something.! |
|
1554 |
||
1555 |
view |
|
1556 |
"return the value of the instance variable 'view' (automatically generated)" |
|
1557 |
||
1558 |
^ view! |
|
1559 |
||
1560 |
view:something |
|
1561 |
"set the value of the instance variable 'view' (automatically generated)" |
|
1562 |
||
1563 |
view := something.! ! |
|
1564 |
||
1565 |
!UIPainterView::ViewProperty methodsFor:'initialization'! |
|
1566 |
||
1567 |
initialize |
|
1568 |
super initialize. |
|
1569 |
identifier := Identifier |
|
1570 |
! ! |
|
1571 |
||
1572 |
!UIPainterView::ViewProperty methodsFor:'misc'! |
|
1573 |
||
1574 |
extractNumberStartingAt:anIndex |
|
1575 |
"return the number from the name starting at anIndex or 0. |
|
1576 |
" |
|
1577 |
|val| |
|
1578 |
||
1579 |
val := 0. |
|
1580 |
||
1581 |
self name from:anIndex do:[:c| |
|
1582 |
c isDigit ifTrue:[val := val * 10 + c digitValue] |
|
1583 |
ifFalse:[^ 0] |
|
1584 |
]. |
|
1585 |
^ val |
|
1586 |
||
1587 |
! ! |
|
1588 |
||
1589 |
!UIPainterView::ViewProperty methodsFor:'spec messages'! |
|
1590 |
||
1591 |
doesNotUnderstand:aMessage |
|
1592 |
spec notNil ifTrue:[ |
|
1593 |
(spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec] |
|
1594 |
]. |
|
1595 |
^ nil |
|
1596 |
! |
|
1597 |
||
1598 |
layout |
|
1599 |
spec layout |
|
1600 |
! |
|
1601 |
||
1602 |
layout:aLayout |
|
1603 |
spec layout:aLayout |
|
1604 |
! |
|
1605 |
||
1606 |
name |
|
1607 |
^ spec name |
|
1608 |
! |
|
1609 |
||
1610 |
name:aName |
|
1611 |
spec name:aName |
|
1612 |
! ! |
|
1613 |
||
60 | 1614 |
!UIPainterView class methodsFor:'documentation'! |
1615 |
||
1616 |
version |
|
1617 |
^ '$Header$' |
|
1618 |
! ! |