author | ca |
Tue, 24 Jun 1997 16:14:11 +0200 | |
changeset 175 | 0b0b4d99e3e7 |
parent 165 | f7df2a53d042 |
child 178 | fb8451053c96 |
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 |
||
175 | 20 |
MultiSelectionInList subclass:#ListHolder |
21 |
instanceVariableNames:'painter propertyList masterElement disabledChanged' |
|
22 |
classVariableNames:'' |
|
119 | 23 |
poolDictionaries:'' |
24 |
privateIn:UIPainterView |
|
25 |
! |
|
26 |
||
175 | 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 |
]. |
|
111 | 619 |
|
60 | 620 |
]. |
621 |
^ code |
|
622 |
! |
|
623 |
||
78 | 624 |
generateWindowSpecMethodSource |
625 |
|t s spec specArray str code| |
|
60 | 626 |
|
78 | 627 |
specArray := OrderedCollection new. |
60 | 628 |
|
78 | 629 |
self subViews do:[:aView| |
630 |
aView ~~ inputView ifTrue:[ |
|
631 |
specArray add:(self fullSpecFor:aView) |
|
60 | 632 |
] |
633 |
]. |
|
78 | 634 |
spec := FullSpec new. |
635 |
spec fromBuilder:self components:(SpecCollection new collection:specArray). |
|
60 | 636 |
specArray := spec literalArrayEncoding. |
637 |
||
638 |
str := WriteStream on:String new. |
|
86 | 639 |
UISpecification prettyPrintSpecArray:specArray on:str indent:5. |
60 | 640 |
|
641 |
code := Character excla asString |
|
642 |
, className , ' class methodsFor:''interface specs''' |
|
643 |
, Character excla asString , '\\' |
|
644 |
||
645 |
, methodName , '\' |
|
646 |
, ' "this window spec was automatically generated by the ST/X UIPainter"\\' |
|
647 |
, ' "do not manually edit this - the painter/builder may not be able to\' |
|
648 |
, ' handle the specification if its corrupted."\\' |
|
649 |
, ' "\' |
|
650 |
, ' UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\' |
|
651 |
, ' ' , className , ' new openInterface:#' , methodName , '\' |
|
652 |
, ' "\'. |
|
653 |
||
654 |
methodName = 'windowSpec' ifTrue:[ |
|
655 |
code := code , ' "' , className , ' open"\' |
|
656 |
]. |
|
657 |
code := code |
|
658 |
, '\' |
|
659 |
, ' <resource: #canvas>\\' |
|
660 |
, ' ^\' |
|
661 |
, ' ', str contents |
|
662 |
, '\' |
|
663 |
, Character excla asString |
|
664 |
, ' ' |
|
665 |
, Character excla asString |
|
666 |
, '\\'. |
|
667 |
||
668 |
^ code withCRs |
|
669 |
||
670 |
"Modified: 5.9.1995 / 21:01:35 / claus" |
|
671 |
! ! |
|
672 |
||
673 |
!UIPainterView methodsFor:'initialization'! |
|
674 |
||
137 | 675 |
destroy |
676 |
"remove dependencies |
|
677 |
" |
|
678 |
listHolder notNil ifTrue:[ |
|
679 |
listHolder removeDependent:self. |
|
680 |
]. |
|
681 |
super destroy. |
|
682 |
! |
|
683 |
||
60 | 684 |
initialize |
62 | 685 |
"setup attributes |
686 |
" |
|
60 | 687 |
super initialize. |
688 |
||
689 |
superclassName := 'ApplicationModel'. |
|
690 |
className := 'NewApplication'. |
|
691 |
methodName := 'windowSpec'. |
|
692 |
categoryName := 'Applications'. |
|
111 | 693 |
listHolder := ListHolder for:self. |
60 | 694 |
HandCursor := Cursor leftHand. |
695 |
||
696 |
! |
|
697 |
||
698 |
setupFromSpec:specOrSpecArray |
|
78 | 699 |
|spec builder| |
60 | 700 |
|
111 | 701 |
listHolder disableNotificationsWhileEvaluating:[ |
702 |
self removeAll. |
|
703 |
spec := UISpecification from:specOrSpecArray. |
|
704 |
builder := UIBuilder new. |
|
705 |
spec window setupView:self topView for:builder. |
|
706 |
self addSpec:(spec component) builder:builder in:self. |
|
707 |
self realizeAllSubViews. |
|
708 |
inputView raise. |
|
709 |
] |
|
60 | 710 |
! ! |
711 |
||
712 |
!UIPainterView methodsFor:'menus'! |
|
713 |
||
121 | 714 |
showMiddleButtonMenu |
715 |
"show the middle button menu; this returns nil |
|
62 | 716 |
" |
111 | 717 |
|menu canPaste| |
60 | 718 |
|
121 | 719 |
self enabled ifFalse:[ |
720 |
^ nil |
|
721 |
]. |
|
111 | 722 |
menu := MenuPanel fromSpec:(self class menu) receiver:self. |
60 | 723 |
|
724 |
canPaste := self canPaste:(self getSelection). |
|
725 |
||
128 | 726 |
self hasSelection ifTrue:[ |
727 |
canPaste := (canPaste and:[self canPasteInto:(self selection)]) |
|
728 |
] ifFalse:[ |
|
111 | 729 |
menu disableAll |
730 |
]. |
|
128 | 731 |
menu enabledAt:#paste put:canPaste. |
134 | 732 |
menu enabledAt:#undo put:(undoHistory isEmpty not). |
121 | 733 |
menu startUp. |
734 |
^ nil |
|
60 | 735 |
|
62 | 736 |
|
737 |
||
60 | 738 |
! ! |
739 |
||
740 |
!UIPainterView methodsFor:'removing components'! |
|
741 |
||
78 | 742 |
remove:anObject |
743 |
"remove anObject from the contents do redraw |
|
60 | 744 |
" |
134 | 745 |
anObject notNil ifTrue:[ |
746 |
listHolder remove:anObject |
|
747 |
] |
|
60 | 748 |
! |
749 |
||
750 |
removeAll |
|
62 | 751 |
"remove all objects and properties |
752 |
" |
|
111 | 753 |
listHolder disableNotificationsWhileEvaluating:[ |
131 | 754 |
self select:nil. |
134 | 755 |
listHolder removeAll. |
756 |
self removeUndoHistory. |
|
111 | 757 |
] |
60 | 758 |
! ! |
759 |
||
760 |
!UIPainterView methodsFor:'searching'! |
|
761 |
||
89 | 762 |
findContainerViewAt:aPoint |
763 |
"find container view responds to aPoint. |
|
764 |
" |
|
765 |
|view| |
|
766 |
||
767 |
(view := self findObjectAt:aPoint) isNil ifTrue:[ |
|
768 |
^ self |
|
769 |
]. |
|
770 |
||
771 |
[(view specClass supportsSubComponents or:[(view := view superView) == self]) |
|
772 |
] whileFalse:[ |
|
773 |
[(self propertyOfView:view) isNil] whileTrue:[ |
|
774 |
(view := view superView) == self ifTrue:[^ self] |
|
775 |
]. |
|
776 |
]. |
|
777 |
^ view |
|
778 |
! |
|
779 |
||
60 | 780 |
findObjectAt:aPoint |
781 |
"find the origin/corner of the currentWidget |
|
782 |
" |
|
783 |
|view| |
|
784 |
||
785 |
view := super findObjectAt:aPoint. |
|
786 |
||
787 |
view notNil ifTrue:[ |
|
788 |
"can be a view within a view not visible |
|
789 |
" |
|
790 |
[ (self propertyOfView:view) isNil ] whileTrue:[ |
|
791 |
(view := view superView) == self ifTrue:[^ nil] |
|
792 |
] |
|
793 |
]. |
|
794 |
^ view |
|
795 |
! |
|
796 |
||
797 |
findViewWithId:aViewId |
|
62 | 798 |
"finds view assigned to identifier and returns the view or nil |
60 | 799 |
" |
800 |
|prop| |
|
801 |
||
802 |
prop := self propertyOfIdentifier:aViewId. |
|
803 |
||
804 |
prop notNil ifTrue:[^ prop view] |
|
805 |
ifFalse:[^ nil] |
|
78 | 806 |
! |
807 |
||
808 |
propertyOfIdentifier:anId |
|
809 |
"returns property assigned to unique identifier |
|
810 |
" |
|
811 |
anId notNil ifTrue:[ |
|
111 | 812 |
^ listHolder detectProperty:[:p| p identifier == anId ] |
78 | 813 |
]. |
814 |
^ nil |
|
815 |
! |
|
816 |
||
817 |
propertyOfName:aString |
|
818 |
"returns property assigned to name |
|
819 |
" |
|
111 | 820 |
|name| |
821 |
||
822 |
aString isNil ifFalse:[ |
|
823 |
name := aString string withoutSeparators. |
|
824 |
||
825 |
name = 'self' ifFalse:[ |
|
826 |
^ listHolder detectProperty:[:p| p name = name ]. |
|
827 |
] |
|
78 | 828 |
]. |
829 |
^ nil |
|
830 |
! |
|
831 |
||
832 |
propertyOfView:aView |
|
833 |
"returns property assigned to view |
|
834 |
" |
|
835 |
(aView isNil or:[aView == self]) ifFalse:[ |
|
111 | 836 |
^ listHolder detectProperty:[:p| p view == aView ] |
78 | 837 |
]. |
838 |
^ nil |
|
839 |
! |
|
840 |
||
111 | 841 |
uniqueNameFor:aSpecOrString |
78 | 842 |
"generate and return an unique name for a class |
843 |
" |
|
844 |
|next name size| |
|
845 |
||
111 | 846 |
aSpecOrString isString ifFalse:[name := aSpecOrString className asString] |
847 |
ifTrue:[name := aSpecOrString]. |
|
78 | 848 |
|
111 | 849 |
(name endsWith:'Spec') ifTrue:[ |
850 |
name := name copyFrom:1 to:(name size - 4). |
|
851 |
] ifFalse:[ |
|
852 |
name := name copy |
|
853 |
]. |
|
78 | 854 |
name at:1 put:(name at:1) asLowercase. |
111 | 855 |
size := name size + 1. |
856 |
next := 0. |
|
78 | 857 |
|
111 | 858 |
listHolder propertiesDo:[:p| |
859 |
|n| |
|
78 | 860 |
n := p name. |
861 |
||
862 |
(n size >= size and:[n startsWith:name]) ifTrue:[ |
|
863 |
next := next max:(p extractNumberStartingAt:size) |
|
864 |
] |
|
865 |
]. |
|
866 |
next := next + 1. |
|
867 |
name := name, next printString. |
|
868 |
^ name |
|
869 |
||
870 |
||
871 |
||
872 |
! |
|
873 |
||
874 |
uniqueNameOf:aView |
|
111 | 875 |
|prop| |
78 | 876 |
|
111 | 877 |
(prop := self propertyOfView:aView) notNil ifTrue:[ |
878 |
prop name isNil ifTrue:[ |
|
879 |
prop name:(self uniqueNameFor:(prop spec)). |
|
880 |
]. |
|
881 |
^ prop name |
|
78 | 882 |
]. |
111 | 883 |
^ 'self' |
78 | 884 |
|
60 | 885 |
! ! |
886 |
||
78 | 887 |
!UIPainterView methodsFor:'specification'! |
888 |
||
889 |
addSpec:aSpecification builder:aBuilder in:aFrame |
|
890 |
"build view and subviews from aSpecification into a frame. The top view |
|
891 |
is returned. The contained components of a spec are set to nil |
|
892 |
" |
|
893 |
aBuilder applicationClass:(Smalltalk classNamed:className). |
|
894 |
||
111 | 895 |
aBuilder componentCreationHook:[:aView :aSpec :aBdr||sv p s n| |
78 | 896 |
p := ViewProperty new. |
897 |
s := aSpec copy. |
|
898 |
p spec:s. |
|
899 |
p view:aView. |
|
900 |
||
901 |
s class supportsSubComponents ifTrue:[ |
|
902 |
s component:nil |
|
903 |
]. |
|
904 |
||
111 | 905 |
n := s name. |
906 |
||
907 |
(n isNil or:[(self propertyOfName:n) notNil]) ifTrue:[ |
|
908 |
s name:(self uniqueNameFor:s) |
|
78 | 909 |
]. |
111 | 910 |
listHolder add:p |
78 | 911 |
]. |
912 |
||
913 |
^ aSpecification buildViewWithLayoutFor:aBuilder in:aFrame. |
|
60 | 914 |
|
78 | 915 |
! |
916 |
||
917 |
fullSpecFor:anObject |
|
918 |
"generate a full spec for an object |
|
62 | 919 |
" |
78 | 920 |
|mySpec subSpecs| |
921 |
||
922 |
mySpec := self specFor:anObject. |
|
923 |
||
924 |
(mySpec notNil and:[mySpec class supportsSubComponents]) ifTrue:[ |
|
925 |
(anObject subViews notNil) ifTrue:[ |
|
926 |
anObject subViews do:[:aSubView||spec| |
|
927 |
spec := self fullSpecFor:aSubView. |
|
928 |
spec notNil ifTrue:[ |
|
929 |
subSpecs isNil ifTrue:[ |
|
930 |
subSpecs := OrderedCollection new |
|
931 |
]. |
|
932 |
subSpecs add:spec. |
|
933 |
]. |
|
934 |
]. |
|
935 |
subSpecs notNil ifTrue:[ |
|
936 |
mySpec component:(SpecCollection new collection:subSpecs) |
|
937 |
] |
|
938 |
] |
|
939 |
]. |
|
940 |
^ mySpec |
|
941 |
||
60 | 942 |
|
943 |
||
944 |
||
945 |
||
946 |
||
947 |
! |
|
948 |
||
78 | 949 |
specFor:anObject |
950 |
"returns spec assigned to an object |
|
62 | 951 |
" |
78 | 952 |
|prop spec| |
60 | 953 |
|
78 | 954 |
(prop := self propertyOfView:anObject) notNil ifTrue:[ |
955 |
spec := prop spec copy. |
|
956 |
spec layoutFromView:anObject |
|
60 | 957 |
]. |
78 | 958 |
^ spec |
959 |
||
960 |
||
961 |
||
60 | 962 |
! |
963 |
||
146 | 964 |
specForSelection |
965 |
"returns spec assigned to current single selection or nil |
|
966 |
" |
|
967 |
^ self specFor:(self singleSelection) |
|
968 |
||
969 |
||
970 |
! |
|
971 |
||
78 | 972 |
updateFromSpec:aSpec |
973 |
"update current selected view from specification |
|
62 | 974 |
" |
78 | 975 |
|props name builder v| |
976 |
||
977 |
self singleSelection notNil ifTrue:[ |
|
978 |
self withSelectionHiddenDo:[ |
|
979 |
self transaction:#specification selectionDo:[:aView| |
|
980 |
builder := UIBuilder new. |
|
981 |
props := self propertyOfView:aView. |
|
82 | 982 |
name := (aSpec name) withoutSeparators. |
78 | 983 |
|
82 | 984 |
name = props name ifFalse:[ |
985 |
(self propertyOfName:name) notNil ifTrue:[ |
|
986 |
name := props name |
|
78 | 987 |
] |
988 |
]. |
|
82 | 989 |
aSpec name:name. |
134 | 990 |
self createUndoSpecModify:props. |
78 | 991 |
|
992 |
aSpec needsRebuildForAttributes ifTrue:[ |
|
993 |
v := aSpec buildViewWithLayoutFor:builder in:aView superView. |
|
994 |
v realize. |
|
995 |
aView destroy. |
|
996 |
device sync. device flush. |
|
997 |
aView becomeSameAs:v. |
|
998 |
inputView raise. |
|
999 |
] ifFalse:[ |
|
1000 |
aSpec setAttributesIn:aView with:builder. |
|
1001 |
self elementChangedSize:aView. |
|
1002 |
]. |
|
1003 |
props spec:(aSpec copy). |
|
111 | 1004 |
listHolder propertyChanged:props. |
78 | 1005 |
] |
111 | 1006 |
] |
82 | 1007 |
] |
60 | 1008 |
! ! |
1009 |
||
1010 |
!UIPainterView methodsFor:'transaction'! |
|
1011 |
||
1012 |
transaction:aType objects:something do:aOneArgBlock |
|
1013 |
"opens a transaction and evaluates a block within the transaction; the |
|
1014 |
argument to the block is a view from derived from something |
|
1015 |
" |
|
134 | 1016 |
self withinTransaction:aType objects:something do:[ |
1017 |
self forEach:something do:aOneArgBlock |
|
60 | 1018 |
] |
1019 |
! |
|
1020 |
||
134 | 1021 |
withinTransaction:aType objects:objects do:aNoneArgBlock |
1022 |
"evaluate a block with no arguments within a transaction |
|
60 | 1023 |
" |
134 | 1024 |
|text size prop| |
1025 |
||
1026 |
objects isNil ifTrue:[ ^ self ]. |
|
1027 |
||
1028 |
size := objects size. |
|
60 | 1029 |
|
134 | 1030 |
objects isCollection ifTrue:[ |
1031 |
size == 0 ifTrue:[ ^ self ]. |
|
1032 |
size == 1 ifTrue:[ prop := self propertyOfView:(objects first) ] |
|
1033 |
] ifFalse:[ |
|
1034 |
prop := self propertyOfView:objects |
|
1035 |
]. |
|
60 | 1036 |
|
134 | 1037 |
prop notNil ifTrue:[ |
1038 |
text := prop name |
|
1039 |
] ifFalse:[ |
|
1040 |
text := size printString, ' elements' |
|
60 | 1041 |
]. |
134 | 1042 |
|
1043 |
undoHistory withinTransaction:aType text:text do:[ |
|
1044 |
aNoneArgBlock value |
|
1045 |
] |
|
60 | 1046 |
! ! |
1047 |
||
1048 |
!UIPainterView methodsFor:'undo actions'! |
|
1049 |
||
134 | 1050 |
createUndoLayout:aView |
1051 |
"create undo action before changing a views layout |
|
60 | 1052 |
" |
134 | 1053 |
|lyt args prop| |
60 | 1054 |
|
1055 |
undoHistory isTransactionOpen ifTrue:[ |
|
1056 |
prop := self propertyOfView:aView. |
|
134 | 1057 |
|
60 | 1058 |
prop notNil ifTrue:[ |
134 | 1059 |
args := Array new:3. |
1060 |
args at:1 put:(prop identifier). |
|
1061 |
||
1062 |
(lyt := aView geometryLayout) notNil ifTrue:[ |
|
1063 |
args at:2 put:#geometryLayout: |
|
1064 |
] ifFalse:[ |
|
146 | 1065 |
lyt := aView extent. |
134 | 1066 |
args at:2 put:#extent: |
1067 |
]. |
|
1068 |
args at:3 put:(lyt copy). |
|
1069 |
undoHistory addUndoSelector:#undoLayout: withArgs:args. |
|
60 | 1070 |
] |
1071 |
] |
|
1072 |
! |
|
1073 |
||
134 | 1074 |
createUndoRemove:aView |
1075 |
"create undo method before deleting views |
|
60 | 1076 |
" |
134 | 1077 |
|frame prop pId spec| |
1078 |
||
1079 |
(prop := self propertyOfView:aView) notNil ifTrue:[ |
|
1080 |
spec := self fullSpecFor:aView. |
|
1081 |
frame := aView superView. |
|
60 | 1082 |
|
134 | 1083 |
(self canPasteInto:frame) ifTrue:[ |
1084 |
(frame := self propertyOfView:frame) notNil ifTrue:[ |
|
1085 |
pId := frame identifier |
|
1086 |
] |
|
1087 |
]. |
|
1088 |
undoHistory addUndoSelector:#undoRemove: |
|
1089 |
withArgs:(Array with:spec with:(prop identifier) with:pId) |
|
1090 |
] |
|
1091 |
! |
|
60 | 1092 |
|
134 | 1093 |
createUndoSpecModify:aProp |
1094 |
"undo method when changing the specification for an object |
|
1095 |
" |
|
1096 |
aProp notNil ifTrue:[ |
|
1097 |
undoHistory addUndoSelector:#undoSpecModify: |
|
1098 |
withArgs:(Array with:(aProp spec) with:(aProp identifier)) |
|
1099 |
] |
|
1100 |
! |
|
60 | 1101 |
|
134 | 1102 |
undoCreate:something |
1103 |
"undo method for creating or pasting an object |
|
1104 |
" |
|
1105 |
self forEach:something do:[:anId|self remove:(self findViewWithId:anId)]. |
|
1106 |
! |
|
60 | 1107 |
|
134 | 1108 |
undoLayout:args |
1109 |
"undo method to set the old layout; see 'createUndoLayout:' |
|
1110 |
" |
|
1111 |
|view| |
|
1112 |
||
1113 |
(view := self findViewWithId:(args at:1)) notNil ifTrue:[ |
|
146 | 1114 |
view perform:(args at:2) with:(args at:3). |
1115 |
self changed:#layout. |
|
60 | 1116 |
] |
1117 |
! |
|
1118 |
||
134 | 1119 |
undoRemove:args |
1120 |
"undo method when removing an object; see 'createUndoRemove:' |
|
1121 |
" |
|
1122 |
|frame prop view| |
|
1123 |
||
1124 |
(args at:3) notNil ifTrue:[ |
|
1125 |
frame := self findViewWithId:(args at:3). |
|
1126 |
]. |
|
1127 |
frame isNil ifTrue:[ |
|
1128 |
frame := self |
|
1129 |
]. |
|
1130 |
view := self addSpec:(args at:1) builder:(UIBuilder new) in:frame. |
|
1131 |
view realize. |
|
1132 |
inputView raise. |
|
1133 |
||
1134 |
prop := self propertyOfView:view. |
|
1135 |
prop identifier:(args at:2). |
|
1136 |
||
1137 |
! |
|
1138 |
||
1139 |
undoSpecModify:args |
|
1140 |
"undo method when changing a spec; see 'createUndoSpecModify:' |
|
60 | 1141 |
" |
80
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1142 |
|builder view spec v props| |
60 | 1143 |
|
134 | 1144 |
props := self propertyOfIdentifier:(args at:2). |
60 | 1145 |
|
134 | 1146 |
props notNil ifTrue:[ |
1147 |
view := props view. |
|
1148 |
spec := args at:1. |
|
1149 |
builder := UIBuilder new. |
|
1150 |
props spec:spec. |
|
80
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1151 |
|
134 | 1152 |
spec needsRebuildForAttributes ifTrue:[ |
1153 |
v := spec buildViewWithLayoutFor:builder in:view superView. |
|
1154 |
v realize. |
|
1155 |
view destroy. |
|
1156 |
view become:v |
|
1157 |
] ifFalse:[ |
|
1158 |
spec setAttributesIn:view with:builder. |
|
1159 |
self elementChangedSize:view. |
|
1160 |
]. |
|
1161 |
listHolder propertyChanged:props. |
|
1162 |
] |
|
60 | 1163 |
|
1164 |
! ! |
|
1165 |
||
111 | 1166 |
!UIPainterView::ListHolder class methodsFor:'instance creation'! |
1167 |
||
1168 |
for:aPainter |
|
1169 |
^ self new for:aPainter |
|
1170 |
! ! |
|
1171 |
||
1172 |
!UIPainterView::ListHolder methodsFor:'accessing'! |
|
1173 |
||
1174 |
painter |
|
1175 |
"returns painter |
|
1176 |
" |
|
1177 |
^ painter |
|
1178 |
! |
|
1179 |
||
1180 |
propertyAt:anIndex |
|
1181 |
"returns property at an index |
|
1182 |
" |
|
1183 |
^ propertyList at:anIndex |
|
1184 |
! ! |
|
1185 |
||
1186 |
!UIPainterView::ListHolder methodsFor:'adding & removing'! |
|
1187 |
||
1188 |
add:aProperty |
|
1189 |
"add property and update list |
|
1190 |
" |
|
1191 |
|idx list name last| |
|
1192 |
||
1193 |
list := self list. |
|
1194 |
idx := self findParentProperty:aProperty. |
|
1195 |
name := aProperty name. |
|
1196 |
||
1197 |
idx == 0 ifTrue:[ |
|
1198 |
last := list size |
|
1199 |
] ifFalse:[ |
|
1200 |
last := self lastInGroupStartingAt:idx. |
|
1201 |
name := (String new:(4+((list at:idx) leftIndent))), name. |
|
1202 |
]. |
|
1203 |
propertyList add:aProperty afterIndex:last. |
|
1204 |
list add:name afterIndex:last. |
|
1205 |
self changed:#size |
|
1206 |
||
1207 |
||
1208 |
! |
|
1209 |
||
1210 |
remove:aView |
|
1211 |
"remove all view relevant resources |
|
1212 |
" |
|
1213 |
|start| |
|
1214 |
||
1215 |
aView notNil ifTrue:[ |
|
1216 |
start := self findProperty:[:p| p view == aView ]. |
|
1217 |
||
1218 |
start ~~ 0 ifTrue:[ |
|
1219 |
self basicRemove:start. |
|
1220 |
self changed:#size. |
|
1221 |
] |
|
1222 |
] |
|
1223 |
! |
|
1224 |
||
1225 |
removeAll |
|
1226 |
masterElement := nil. |
|
1227 |
self selection:#(). |
|
1228 |
||
1229 |
[propertyList notEmpty] whileTrue:[ |
|
1230 |
self basicRemove:1 |
|
1231 |
]. |
|
1232 |
self changed:#size. |
|
1233 |
||
1234 |
! ! |
|
1235 |
||
1236 |
!UIPainterView::ListHolder methodsFor:'change & update'! |
|
1237 |
||
1238 |
changed:aParameter |
|
1239 |
"notify all dependents that the receiver has changed somehow. |
|
1240 |
Each dependent gets a '#update:'-message with aParameter |
|
1241 |
as argument. In case of disabled no notifications are raised |
|
1242 |
" |
|
1243 |
disabledChanged ifFalse:[ |
|
1244 |
super changed:aParameter |
|
1245 |
] |
|
1246 |
! |
|
1247 |
||
1248 |
disableNotificationsWhileEvaluating:aBlock |
|
1249 |
"perform block without notification; after evaluation of block, |
|
1250 |
a #size changed notification is raised |
|
1251 |
" |
|
1252 |
|oldState| |
|
1253 |
||
1254 |
oldState := disabledChanged. |
|
1255 |
disabledChanged := true. |
|
1256 |
aBlock value. |
|
1257 |
disabledChanged := oldState. |
|
1258 |
self changed:#size. |
|
1259 |
! |
|
1260 |
||
1261 |
propertyChanged:aProperty |
|
1262 |
"property list changed; update list names |
|
1263 |
" |
|
1264 |
|list idx oldName newName wspName view indent mid| |
|
1265 |
||
1266 |
view := aProperty view. |
|
1267 |
idx := self findProperty:[:p| p view == view ]. |
|
1268 |
||
1269 |
idx == 0 ifTrue:[ |
|
1270 |
^ self error |
|
1271 |
]. |
|
1272 |
||
1273 |
list := self list. |
|
1274 |
oldName := list at:idx. |
|
1275 |
wspName := oldName string withoutSeparators. |
|
1276 |
newName := aProperty name. |
|
1277 |
||
1278 |
wspName = newName ifFalse:[ |
|
1279 |
mid := self masterElement. |
|
1280 |
list at:idx put:((String new:(oldName leftIndent)), newName). |
|
1281 |
||
1282 |
idx == mid ifTrue:[ |
|
1283 |
masterElement := nil. |
|
1284 |
self masterElement:idx |
|
1285 |
]. |
|
1286 |
]. |
|
1287 |
self changed:#property |
|
1288 |
||
1289 |
! ! |
|
1290 |
||
1291 |
!UIPainterView::ListHolder methodsFor:'enumerating'! |
|
1292 |
||
1293 |
propertiesDo:aBlock |
|
1294 |
"evaluate a block for each property |
|
1295 |
" |
|
1296 |
propertyList do:aBlock |
|
1297 |
! ! |
|
1298 |
||
1299 |
!UIPainterView::ListHolder methodsFor:'initialization'! |
|
1300 |
||
1301 |
for:aPainter |
|
1302 |
"initialize for a painter |
|
1303 |
" |
|
119 | 1304 |
painter := aPainter. |
121 | 1305 |
disabledChanged := false. |
111 | 1306 |
self list:(OrderedCollection new). |
1307 |
propertyList := OrderedCollection new. |
|
1308 |
self selection:#(). |
|
1309 |
self addDependent:painter. |
|
1310 |
||
1311 |
! ! |
|
1312 |
||
1313 |
!UIPainterView::ListHolder methodsFor:'private'! |
|
1314 |
||
1315 |
basicRemove:start |
|
1316 |
"remove all resources assigned to a group starting at start; |
|
1317 |
no notifications are raised |
|
1318 |
" |
|
1319 |
|end view superView| |
|
1320 |
||
1321 |
end := self lastInGroupStartingAt:start. |
|
1322 |
view := (propertyList at:start) view. |
|
1323 |
||
1324 |
view notNil ifTrue:[ |
|
1325 |
superView := view superView. |
|
1326 |
view destroy. |
|
1327 |
superView sizeChanged:nil. |
|
1328 |
]. |
|
1329 |
||
1330 |
propertyList removeFromIndex:start toIndex:end. |
|
1331 |
self list removeFromIndex:start toIndex:end. |
|
1332 |
! |
|
1333 |
||
1334 |
masterElement |
|
1335 |
"returns index of master |
|
1336 |
" |
|
1337 |
^ self indexOfName:masterElement. |
|
1338 |
! |
|
1339 |
||
1340 |
masterElement:newIndex |
|
1341 |
"change master of selection |
|
1342 |
" |
|
1343 |
|name list oldIdx| |
|
1344 |
||
1345 |
(oldIdx := self masterElement) ~~ newIndex ifTrue:[ |
|
1346 |
list := self list. |
|
1347 |
||
1348 |
oldIdx ~~ 0 ifTrue:[ |
|
1349 |
list at:oldIdx put:masterElement |
|
1350 |
]. |
|
1351 |
newIndex ~~ 0 ifTrue:[ |
|
1352 |
masterElement := list at:newIndex. |
|
1353 |
name := Text string:masterElement. |
|
1354 |
name emphasizeFrom:(1+(name leftIndent)) with:#(#bold #underline). |
|
1355 |
list at:newIndex put:name. |
|
1356 |
] ifFalse:[ |
|
1357 |
masterElement := nil |
|
1358 |
]. |
|
1359 |
self changed:#list. |
|
1360 |
] |
|
1361 |
! ! |
|
1362 |
||
1363 |
!UIPainterView::ListHolder methodsFor:'searching'! |
|
1364 |
||
1365 |
detectProperty:aBlock |
|
1366 |
"find the property, for which evaluation of the argument, aBlock |
|
1367 |
returns true; return the property or nil if none detected |
|
1368 |
" |
|
1369 |
|idx| |
|
1370 |
||
1371 |
idx := self findProperty:aBlock. |
|
1372 |
idx ~~ 0 ifTrue:[ ^ propertyList at:idx ]. |
|
1373 |
^ nil |
|
1374 |
! |
|
1375 |
||
1376 |
findParentProperty:aChildProp |
|
1377 |
"returns index of parent or 0 |
|
1378 |
" |
|
1379 |
|view index| |
|
1380 |
||
1381 |
view := aChildProp view. |
|
1382 |
||
1383 |
view notNil ifTrue:[ |
|
1384 |
[ (view := view superView) notNil ] whileTrue:[ |
|
1385 |
index := self findProperty:[:aProp| aProp view == view ]. |
|
1386 |
index ~~ 0 ifTrue:[ |
|
1387 |
^ index |
|
1388 |
] |
|
1389 |
] |
|
1390 |
]. |
|
1391 |
^ 0 |
|
1392 |
||
1393 |
||
1394 |
! |
|
1395 |
||
1396 |
findProperty:aBlock |
|
1397 |
"find the first property, for which evaluation of the argument, aBlock |
|
1398 |
returns true; return its index or 0 if none detected |
|
1399 |
" |
|
1400 |
^ propertyList findFirst:aBlock |
|
1401 |
! |
|
1402 |
||
1403 |
indexOfName:aString |
|
1404 |
"returns index assigned to a string or 0 |
|
1405 |
" |
|
1406 |
|name list size| |
|
1407 |
||
1408 |
aString notNil ifTrue:[ |
|
1409 |
name := aString string withoutSeparators. |
|
1410 |
size := name size. |
|
1411 |
list := self list. |
|
1412 |
||
1413 |
list keysAndValuesDo:[:anIndex :aName| |
|
1414 |
|el| |
|
1415 |
||
1416 |
el := aName string. |
|
1417 |
(el endsWith:name) ifTrue:[ |
|
1418 |
(el size - el leftIndent) == name size ifTrue:[ |
|
1419 |
^ anIndex |
|
1420 |
] |
|
1421 |
] |
|
1422 |
] |
|
1423 |
]. |
|
1424 |
^ 0 |
|
1425 |
||
1426 |
! |
|
1427 |
||
1428 |
lastInGroupStartingAt:start |
|
1429 |
"returns last index of a group |
|
1430 |
" |
|
1431 |
|end list idt| |
|
1432 |
||
1433 |
list := self list. |
|
1434 |
||
1435 |
start < list size ifTrue:[ |
|
1436 |
idt := (list at:start) leftIndent. |
|
1437 |
end := list findFirst:[:el|(el leftIndent) <= idt] startingAt:(start+1). |
|
1438 |
end ~~ 0 ifTrue:[ |
|
1439 |
^ end - 1 |
|
1440 |
] |
|
1441 |
]. |
|
1442 |
^ list size |
|
1443 |
! ! |
|
1444 |
||
1445 |
!UIPainterView::ListHolder methodsFor:'selection'! |
|
1446 |
||
1447 |
selectGroup |
|
1448 |
"select all elements assigned to master |
|
1449 |
" |
|
1450 |
|start end sel size| |
|
1451 |
||
119 | 1452 |
painter enabled ifTrue:[ |
111 | 1453 |
(start := self masterElement) ~~ 0 ifTrue:[ |
1454 |
end := self lastInGroupStartingAt:start. |
|
1455 |
size := end - start + 1. |
|
1456 |
sel := Array new:size. |
|
1457 |
||
1458 |
1 to:size do:[:i| |
|
1459 |
sel at:i put:start. |
|
1460 |
start := start + 1 |
|
1461 |
]. |
|
1462 |
self selectionIndex:sel. |
|
1463 |
] ifFalse:[ |
|
1464 |
(self selectionIndex) size == 0 ifFalse:[ |
|
1465 |
self selectionIndex:#() |
|
1466 |
]. |
|
1467 |
] |
|
1468 |
] |
|
1469 |
! |
|
1470 |
||
1471 |
selectedProperty |
|
1472 |
"returns current selected instance; in case of multiple selection |
|
1473 |
or no selection nil is returned |
|
1474 |
" |
|
1475 |
|selection| |
|
1476 |
selection := self selectionIndex. |
|
1477 |
||
1478 |
selection size == 1 ifTrue:[ |
|
137 | 1479 |
propertyList size ~~ 0 ifTrue:[ |
1480 |
^ propertyList at:(selection first) |
|
1481 |
] |
|
111 | 1482 |
]. |
1483 |
^ nil |
|
1484 |
! |
|
1485 |
||
1486 |
selectionIndex:aList |
|
1487 |
|masterIndex aSel| |
|
1488 |
||
119 | 1489 |
painter enabled ifTrue:[aSel := aList] |
1490 |
ifFalse:[aSel := nil]. |
|
111 | 1491 |
|
1492 |
aSel size ~~ 0 ifTrue:[masterIndex := aSel at:1] |
|
1493 |
ifFalse:[masterIndex := 0]. |
|
1494 |
||
1495 |
self masterElement:masterIndex. |
|
1496 |
super selectionIndex:aSel |
|
1497 |
! ! |
|
1498 |
||
175 | 1499 |
!UIPainterView::ViewProperty class methodsFor:'documentation'! |
1500 |
||
1501 |
version |
|
1502 |
^ '$Header$' |
|
1503 |
! ! |
|
1504 |
||
1505 |
!UIPainterView::ViewProperty class methodsFor:'instance creation'! |
|
1506 |
||
1507 |
new |
|
1508 |
Identifier notNil ifTrue:[Identifier := Identifier + 1] |
|
1509 |
ifFalse:[Identifier := 1]. |
|
1510 |
||
1511 |
^ self basicNew initialize |
|
1512 |
! ! |
|
1513 |
||
1514 |
!UIPainterView::ViewProperty methodsFor:'accessing'! |
|
1515 |
||
1516 |
identifier |
|
1517 |
"return the unique identifier assigned to property |
|
1518 |
" |
|
1519 |
^ identifier |
|
1520 |
! |
|
1521 |
||
1522 |
identifier:anIdentifier |
|
1523 |
"set the unique identifier assigned to property; called after an restore of |
|
1524 |
a deleted instance |
|
1525 |
" |
|
1526 |
identifier := anIdentifier |
|
1527 |
! |
|
1528 |
||
1529 |
spec |
|
1530 |
"return the value of the instance variable 'spec' (automatically generated)" |
|
1531 |
||
1532 |
^ spec! |
|
1533 |
||
1534 |
spec:something |
|
1535 |
"set the value of the instance variable 'spec' (automatically generated)" |
|
1536 |
||
1537 |
spec := something.! |
|
1538 |
||
1539 |
view |
|
1540 |
"return the value of the instance variable 'view' (automatically generated)" |
|
1541 |
||
1542 |
^ view! |
|
1543 |
||
1544 |
view:something |
|
1545 |
"set the value of the instance variable 'view' (automatically generated)" |
|
1546 |
||
1547 |
view := something.! ! |
|
1548 |
||
1549 |
!UIPainterView::ViewProperty methodsFor:'initialization'! |
|
1550 |
||
1551 |
initialize |
|
1552 |
super initialize. |
|
1553 |
identifier := Identifier |
|
1554 |
! ! |
|
1555 |
||
1556 |
!UIPainterView::ViewProperty methodsFor:'misc'! |
|
1557 |
||
1558 |
extractNumberStartingAt:anIndex |
|
1559 |
"return the number from the name starting at anIndex or 0. |
|
1560 |
" |
|
1561 |
|val| |
|
1562 |
||
1563 |
val := 0. |
|
1564 |
||
1565 |
self name from:anIndex do:[:c| |
|
1566 |
c isDigit ifTrue:[val := val * 10 + c digitValue] |
|
1567 |
ifFalse:[^ 0] |
|
1568 |
]. |
|
1569 |
^ val |
|
1570 |
||
1571 |
! ! |
|
1572 |
||
1573 |
!UIPainterView::ViewProperty methodsFor:'spec messages'! |
|
1574 |
||
1575 |
doesNotUnderstand:aMessage |
|
1576 |
spec notNil ifTrue:[ |
|
1577 |
(spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec] |
|
1578 |
]. |
|
1579 |
^ nil |
|
1580 |
! |
|
1581 |
||
1582 |
layout |
|
1583 |
spec layout |
|
1584 |
! |
|
1585 |
||
1586 |
layout:aLayout |
|
1587 |
spec layout:aLayout |
|
1588 |
! |
|
1589 |
||
1590 |
name |
|
1591 |
^ spec name |
|
1592 |
! |
|
1593 |
||
1594 |
name:aName |
|
1595 |
spec name:aName |
|
1596 |
! ! |
|
1597 |
||
60 | 1598 |
!UIPainterView class methodsFor:'documentation'! |
1599 |
||
1600 |
version |
|
1601 |
^ '$Header$' |
|
1602 |
! ! |