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