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