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