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