author | ca |
Fri, 20 Jun 1997 19:29:36 +0200 | |
changeset 165 | f7df2a53d042 |
parent 162 | d3f0d5dd53b1 |
child 175 | 0b0b4d99e3e7 |
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 |
||
165 | 20 |
Object subclass:#ViewProperty |
21 |
instanceVariableNames:'view spec identifier' |
|
22 |
classVariableNames:'Identifier' |
|
119 | 23 |
poolDictionaries:'' |
24 |
privateIn:UIPainterView |
|
25 |
! |
|
26 |
||
165 | 27 |
MultiSelectionInList subclass:#ListHolder |
28 |
instanceVariableNames:'painter propertyList masterElement disabledChanged' |
|
29 |
classVariableNames:'' |
|
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. |
581 |
protoSpec isNil ifTrue:[ |
|
582 |
self halt. |
|
583 |
protoSpec := aProp view specClass basicNew. |
|
584 |
]. |
|
78 | 585 |
(modelSelector := aProp model) notNil ifTrue:[ |
60 | 586 |
(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
|
587 |
skip := false. |
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
588 |
(cls isSubclassOf:SimpleDialog) ifTrue:[ |
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
589 |
skip := SimpleDialog implements:modelSelector asSymbol |
60 | 590 |
]. |
158
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
591 |
skip ifFalse:[ |
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
592 |
"/ kludge .. |
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
593 |
(protoSpec isMemberOf:ActionButtonSpec) ifTrue:[ |
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
594 |
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
|
595 |
] ifFalse:[ |
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
596 |
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
|
597 |
]. |
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
598 |
code := code , thisCode |
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
599 |
]. |
62 | 600 |
]. |
601 |
]. |
|
602 |
||
78 | 603 |
(menuSelector := aProp menu) notNil ifTrue:[ |
62 | 604 |
(cls implements:menuSelector asSymbol) ifFalse:[ |
605 |
"/ kludge .. |
|
606 |
thisCode := (self generateAspectMethodFor:menuSelector spec:protoSpec inClass:cls). |
|
607 |
code := code , thisCode |
|
60 | 608 |
] |
111 | 609 |
]. |
610 |
||
611 |
aProp spec aspectSelectors do:[:aSel| |
|
612 |
(cls implements:aSel asSymbol) ifFalse:[ |
|
613 |
"/ kludge .. |
|
614 |
thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls). |
|
615 |
code := code , thisCode |
|
616 |
] |
|
617 |
]. |
|
137 | 618 |
aProp spec actionSelectors do:[:aSel| |
619 |
(cls implements:aSel asSymbol) ifFalse:[ |
|
620 |
"/ kludge .. |
|
621 |
thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls). |
|
622 |
code := code , thisCode |
|
623 |
] |
|
624 |
]. |
|
111 | 625 |
|
60 | 626 |
]. |
627 |
^ code |
|
628 |
||
158
6e7f892308ae
do not generate accept/cancel and help action methods,
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
629 |
"Modified: 17.6.1997 / 14:07:36 / cg" |
89 | 630 |
! |
60 | 631 |
|
632 |
generateClassDefinition |
|
633 |
|defCode| |
|
634 |
||
635 |
defCode := superclassName , ' subclass:#' , className , '\'. |
|
636 |
defCode := defCode , ' instanceVariableNames:'''. |
|
637 |
defCode := defCode , self subviewVariableNames , '''\'. |
|
638 |
defCode := defCode , ' classVariableNames:''''\'. |
|
639 |
defCode := defCode , ' poolDictionaries:''''\'. |
|
640 |
defCode := defCode , ' category:''' , categoryName , '''\'. |
|
641 |
defCode := defCode , Character excla asString , '\\'. |
|
642 |
||
643 |
^ defCode withCRs |
|
644 |
||
645 |
||
646 |
||
89 | 647 |
! |
60 | 648 |
|
649 |
generateCode |
|
650 |
"generate code for the windowSpec method" |
|
651 |
||
652 |
|code| |
|
653 |
||
134 | 654 |
self resetModification. |
655 |
||
60 | 656 |
code := ''. |
657 |
||
658 |
"/ (Smalltalk classNamed:className asSymbol) isNil ifTrue:[ |
|
659 |
"/ code := code , self generateClassDefinition. |
|
660 |
"/ ]. |
|
661 |
"/ code := code , self generateInitMethod. |
|
662 |
||
663 |
code := code , self generateWindowSpecMethodSource. |
|
664 |
||
665 |
"/ code := code , self generateAspectMethods. |
|
666 |
||
667 |
^ code withCRs |
|
668 |
||
669 |
"Modified: 5.9.1995 / 20:57:53 / claus" |
|
89 | 670 |
! |
60 | 671 |
|
672 |
generateInitCodeForView:aView |
|
673 |
|code c name p outlets moreCode sym typ val| |
|
674 |
||
675 |
" <name> := <ViewClass> in:<name-of-superview>" |
|
676 |
||
677 |
code := ''. |
|
678 |
||
679 |
p := self propertyOfView:aView. |
|
680 |
name := p at:#variableName. |
|
681 |
c := ' ' , name , ' := ' , |
|
78 | 682 |
(aView class name) , ' in:' , (self uniqueNameOf:(aView superView)) , '.\'. |
60 | 683 |
|
684 |
" <name> origin:(...) extent:(...)" |
|
685 |
||
686 |
c := c , ' ' , name , ' origin:(', aView origin printString , ')' |
|
687 |
, ' extent:(', aView extent printString , ').\'. |
|
688 |
||
689 |
moreCode := p at:#initCode ifAbsent:nil. |
|
690 |
moreCode notNil ifTrue:[ |
|
691 |
c := c , moreCode , '\' withCRs |
|
692 |
]. |
|
693 |
||
694 |
code := code , c withCRs. |
|
695 |
||
696 |
" <name> <symbol>:<value>" |
|
697 |
||
698 |
outlets := p at:#outlets ifAbsent:[nil]. |
|
699 |
outlets notNil ifTrue:[ |
|
700 |
outlets do:[:selectorOutlet | |
|
701 |
sym := selectorOutlet at:#selector. |
|
702 |
typ := selectorOutlet at:#type. |
|
703 |
val := selectorOutlet at:#value. |
|
704 |
c := ' ' , name , ' ' , sym. |
|
705 |
(typ == #number) ifTrue:[ |
|
706 |
c := c , val printString |
|
707 |
]. |
|
708 |
(typ == #string) ifTrue:[ |
|
709 |
c := c , '''' , val , '''' |
|
710 |
]. |
|
711 |
(typ == #text) ifTrue:[ |
|
712 |
c := c , '''' , val asString , '''' |
|
713 |
]. |
|
714 |
(typ == #strings) ifTrue:[ |
|
715 |
c := c , '#( '. |
|
716 |
val asText do:[:aString | |
|
717 |
c := c , '''' , aString , ''' ' |
|
718 |
]. |
|
719 |
c := c , ')' |
|
720 |
]. |
|
721 |
(typ == #block) ifTrue:[ |
|
722 |
c := c , val |
|
723 |
]. |
|
724 |
(typ == #color) ifTrue:[ |
|
725 |
c := c , '(Color name:''' , val , ''')' |
|
726 |
]. |
|
727 |
c := c , '.' , Character cr asString. |
|
728 |
code := code , c |
|
729 |
] |
|
730 |
]. |
|
731 |
||
732 |
self subviewsOf:aView do:[:v | |
|
733 |
code := code , (self generateInitCodeForView:v) |
|
734 |
]. |
|
735 |
^ code. |
|
736 |
||
737 |
"Modified: 5.9.1995 / 20:06:07 / claus" |
|
738 |
! |
|
739 |
||
740 |
generateInitMethod |
|
741 |
|defCode code| |
|
742 |
||
743 |
defCode := Character excla asString , |
|
744 |
className , ' methodsFor:''initialization''' , |
|
745 |
Character excla asString , '\\'. |
|
746 |
||
747 |
defCode := defCode , 'initialize\'. |
|
748 |
defCode := defCode , ' super initialize.\'. |
|
749 |
defCode := defCode , ' self setupSubViews.\'. |
|
750 |
defCode := defCode , ' self setupLocalStuff\'. |
|
751 |
defCode := defCode , Character excla asString , '\\'. |
|
752 |
||
753 |
defCode := defCode , 'setupSubViews\'. |
|
754 |
code := defCode withCRs. |
|
755 |
||
756 |
self subviewsOf:self do:[:v | |
|
757 |
code := code , (self generateInitCodeForView:v) |
|
758 |
]. |
|
759 |
code := code , ' ^ self\' withCRs. |
|
760 |
||
761 |
defCode := Character excla asString , '\\'. |
|
762 |
defCode := defCode , 'setupLocalStuff\'. |
|
763 |
defCode := defCode , ' ^ self\'. |
|
764 |
defCode := defCode , Character excla asString , ' ' , |
|
765 |
Character excla asString , '\\'. |
|
766 |
||
767 |
code := code , defCode withCRs. |
|
768 |
^ code. |
|
769 |
||
770 |
||
771 |
||
772 |
||
773 |
! |
|
774 |
||
78 | 775 |
generateWindowSpecMethodSource |
776 |
|t s spec specArray str code| |
|
60 | 777 |
|
78 | 778 |
specArray := OrderedCollection new. |
60 | 779 |
|
78 | 780 |
self subViews do:[:aView| |
781 |
aView ~~ inputView ifTrue:[ |
|
782 |
specArray add:(self fullSpecFor:aView) |
|
60 | 783 |
] |
784 |
]. |
|
78 | 785 |
spec := FullSpec new. |
786 |
spec fromBuilder:self components:(SpecCollection new collection:specArray). |
|
60 | 787 |
specArray := spec literalArrayEncoding. |
788 |
||
789 |
str := WriteStream on:String new. |
|
86 | 790 |
UISpecification prettyPrintSpecArray:specArray on:str indent:5. |
60 | 791 |
|
792 |
code := Character excla asString |
|
793 |
, className , ' class methodsFor:''interface specs''' |
|
794 |
, Character excla asString , '\\' |
|
795 |
||
796 |
, methodName , '\' |
|
797 |
, ' "this window spec was automatically generated by the ST/X UIPainter"\\' |
|
798 |
, ' "do not manually edit this - the painter/builder may not be able to\' |
|
799 |
, ' handle the specification if its corrupted."\\' |
|
800 |
, ' "\' |
|
801 |
, ' UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\' |
|
802 |
, ' ' , className , ' new openInterface:#' , methodName , '\' |
|
803 |
, ' "\'. |
|
804 |
||
805 |
methodName = 'windowSpec' ifTrue:[ |
|
806 |
code := code , ' "' , className , ' open"\' |
|
807 |
]. |
|
808 |
code := code |
|
809 |
, '\' |
|
810 |
, ' <resource: #canvas>\\' |
|
811 |
, ' ^\' |
|
812 |
, ' ', str contents |
|
813 |
, '\' |
|
814 |
, Character excla asString |
|
815 |
, ' ' |
|
816 |
, Character excla asString |
|
817 |
, '\\'. |
|
818 |
||
819 |
^ code withCRs |
|
820 |
||
821 |
"Modified: 5.9.1995 / 21:01:35 / claus" |
|
89 | 822 |
! |
60 | 823 |
|
824 |
storeContentsOn:aStream |
|
111 | 825 |
listHolder propertiesDo:[:p| p storeOn:aStream] |
60 | 826 |
! |
827 |
||
828 |
subviewsOf:aView do:aBlock |
|
829 |
|subs v| |
|
830 |
||
831 |
(subs := aView subViews) notNil ifTrue:[ |
|
832 |
subs do:[:v| |
|
833 |
(v ~~ inputView and:[v notNil]) ifTrue:[ |
|
111 | 834 |
(listHolder detectProperty:[:p|p view == v]) notNil ifTrue:[ |
60 | 835 |
(v superView == aView) ifTrue:[ |
836 |
aBlock value:v |
|
837 |
] |
|
838 |
] |
|
839 |
] |
|
840 |
] |
|
841 |
] |
|
842 |
||
843 |
! ! |
|
844 |
||
845 |
!UIPainterView methodsFor:'initialization'! |
|
846 |
||
137 | 847 |
destroy |
848 |
"remove dependencies |
|
849 |
" |
|
850 |
listHolder notNil ifTrue:[ |
|
851 |
listHolder removeDependent:self. |
|
852 |
]. |
|
853 |
super destroy. |
|
854 |
! |
|
855 |
||
60 | 856 |
initialize |
62 | 857 |
"setup attributes |
858 |
" |
|
60 | 859 |
super initialize. |
860 |
||
861 |
superclassName := 'ApplicationModel'. |
|
862 |
className := 'NewApplication'. |
|
863 |
methodName := 'windowSpec'. |
|
864 |
categoryName := 'Applications'. |
|
111 | 865 |
listHolder := ListHolder for:self. |
60 | 866 |
HandCursor := Cursor leftHand. |
867 |
||
868 |
! |
|
869 |
||
78 | 870 |
initializeCreatedObject:anObject |
871 |
"set default properties for a created object |
|
872 |
" |
|
873 |
|props spec cls| |
|
60 | 874 |
|
78 | 875 |
cls := anObject class. |
876 |
spec := anObject specClass fromView:anObject. |
|
877 |
props := ViewProperty new. |
|
878 |
props view:anObject. |
|
879 |
props spec:spec. |
|
111 | 880 |
props name:(self uniqueNameFor:spec). |
881 |
listHolder add:props. |
|
60 | 882 |
|
82 | 883 |
((spec respondsTo:#label:) and:[self supportsLabel:anObject]) ifTrue:[ |
78 | 884 |
anObject label:(props name). |
885 |
spec label:(props name) |
|
60 | 886 |
]. |
887 |
||
134 | 888 |
undoHistory withinTransaction:#create text:(props name) do:[ |
889 |
undoHistory addUndoSelector:#undoCreate: withArgs:(props identifier) |
|
60 | 890 |
]. |
891 |
! |
|
892 |
||
893 |
setupFromSpec:specOrSpecArray |
|
78 | 894 |
|spec builder| |
60 | 895 |
|
111 | 896 |
listHolder disableNotificationsWhileEvaluating:[ |
897 |
self removeAll. |
|
898 |
spec := UISpecification from:specOrSpecArray. |
|
899 |
builder := UIBuilder new. |
|
900 |
spec window setupView:self topView for:builder. |
|
901 |
self addSpec:(spec component) builder:builder in:self. |
|
902 |
self realizeAllSubViews. |
|
903 |
inputView raise. |
|
904 |
] |
|
60 | 905 |
! ! |
906 |
||
907 |
!UIPainterView methodsFor:'menus'! |
|
908 |
||
121 | 909 |
showMiddleButtonMenu |
910 |
"show the middle button menu; this returns nil |
|
62 | 911 |
" |
111 | 912 |
|menu canPaste| |
60 | 913 |
|
121 | 914 |
self enabled ifFalse:[ |
915 |
^ nil |
|
916 |
]. |
|
111 | 917 |
menu := MenuPanel fromSpec:(self class menu) receiver:self. |
60 | 918 |
|
919 |
canPaste := self canPaste:(self getSelection). |
|
920 |
||
128 | 921 |
self hasSelection ifTrue:[ |
922 |
canPaste := (canPaste and:[self canPasteInto:(self selection)]) |
|
923 |
] ifFalse:[ |
|
111 | 924 |
menu disableAll |
925 |
]. |
|
128 | 926 |
menu enabledAt:#paste put:canPaste. |
134 | 927 |
menu enabledAt:#undo put:(undoHistory isEmpty not). |
121 | 928 |
menu startUp. |
929 |
^ nil |
|
60 | 930 |
|
62 | 931 |
|
932 |
||
60 | 933 |
! ! |
934 |
||
935 |
!UIPainterView methodsFor:'removing components'! |
|
936 |
||
78 | 937 |
remove:anObject |
938 |
"remove anObject from the contents do redraw |
|
60 | 939 |
" |
134 | 940 |
anObject notNil ifTrue:[ |
941 |
listHolder remove:anObject |
|
942 |
] |
|
60 | 943 |
! |
944 |
||
945 |
removeAll |
|
62 | 946 |
"remove all objects and properties |
947 |
" |
|
111 | 948 |
listHolder disableNotificationsWhileEvaluating:[ |
131 | 949 |
self select:nil. |
134 | 950 |
listHolder removeAll. |
951 |
self removeUndoHistory. |
|
111 | 952 |
] |
60 | 953 |
! ! |
954 |
||
955 |
!UIPainterView methodsFor:'searching'! |
|
956 |
||
89 | 957 |
findContainerViewAt:aPoint |
958 |
"find container view responds to aPoint. |
|
959 |
" |
|
960 |
|view| |
|
961 |
||
962 |
(view := self findObjectAt:aPoint) isNil ifTrue:[ |
|
963 |
^ self |
|
964 |
]. |
|
965 |
||
966 |
[(view specClass supportsSubComponents or:[(view := view superView) == self]) |
|
967 |
] whileFalse:[ |
|
968 |
[(self propertyOfView:view) isNil] whileTrue:[ |
|
969 |
(view := view superView) == self ifTrue:[^ self] |
|
970 |
]. |
|
971 |
]. |
|
972 |
^ view |
|
973 |
! |
|
974 |
||
60 | 975 |
findObjectAt:aPoint |
976 |
"find the origin/corner of the currentWidget |
|
977 |
" |
|
978 |
|view| |
|
979 |
||
980 |
view := super findObjectAt:aPoint. |
|
981 |
||
982 |
view notNil ifTrue:[ |
|
983 |
"can be a view within a view not visible |
|
984 |
" |
|
985 |
[ (self propertyOfView:view) isNil ] whileTrue:[ |
|
986 |
(view := view superView) == self ifTrue:[^ nil] |
|
987 |
] |
|
988 |
]. |
|
989 |
^ view |
|
990 |
! |
|
991 |
||
992 |
findViewWithId:aViewId |
|
62 | 993 |
"finds view assigned to identifier and returns the view or nil |
60 | 994 |
" |
995 |
|prop| |
|
996 |
||
997 |
prop := self propertyOfIdentifier:aViewId. |
|
998 |
||
999 |
prop notNil ifTrue:[^ prop view] |
|
1000 |
ifFalse:[^ nil] |
|
78 | 1001 |
! |
1002 |
||
1003 |
propertyOfIdentifier:anId |
|
1004 |
"returns property assigned to unique identifier |
|
1005 |
" |
|
1006 |
anId notNil ifTrue:[ |
|
111 | 1007 |
^ listHolder detectProperty:[:p| p identifier == anId ] |
78 | 1008 |
]. |
1009 |
^ nil |
|
1010 |
! |
|
1011 |
||
1012 |
propertyOfName:aString |
|
1013 |
"returns property assigned to name |
|
1014 |
" |
|
111 | 1015 |
|name| |
1016 |
||
1017 |
aString isNil ifFalse:[ |
|
1018 |
name := aString string withoutSeparators. |
|
1019 |
||
1020 |
name = 'self' ifFalse:[ |
|
1021 |
^ listHolder detectProperty:[:p| p name = name ]. |
|
1022 |
] |
|
78 | 1023 |
]. |
1024 |
^ nil |
|
1025 |
! |
|
1026 |
||
1027 |
propertyOfView:aView |
|
1028 |
"returns property assigned to view |
|
1029 |
" |
|
1030 |
(aView isNil or:[aView == self]) ifFalse:[ |
|
111 | 1031 |
^ listHolder detectProperty:[:p| p view == aView ] |
78 | 1032 |
]. |
1033 |
^ nil |
|
1034 |
! |
|
1035 |
||
111 | 1036 |
uniqueNameFor:aSpecOrString |
78 | 1037 |
"generate and return an unique name for a class |
1038 |
" |
|
1039 |
|next name size| |
|
1040 |
||
111 | 1041 |
aSpecOrString isString ifFalse:[name := aSpecOrString className asString] |
1042 |
ifTrue:[name := aSpecOrString]. |
|
78 | 1043 |
|
111 | 1044 |
(name endsWith:'Spec') ifTrue:[ |
1045 |
name := name copyFrom:1 to:(name size - 4). |
|
1046 |
] ifFalse:[ |
|
1047 |
name := name copy |
|
1048 |
]. |
|
78 | 1049 |
name at:1 put:(name at:1) asLowercase. |
111 | 1050 |
size := name size + 1. |
1051 |
next := 0. |
|
78 | 1052 |
|
111 | 1053 |
listHolder propertiesDo:[:p| |
1054 |
|n| |
|
78 | 1055 |
n := p name. |
1056 |
||
1057 |
(n size >= size and:[n startsWith:name]) ifTrue:[ |
|
1058 |
next := next max:(p extractNumberStartingAt:size) |
|
1059 |
] |
|
1060 |
]. |
|
1061 |
next := next + 1. |
|
1062 |
name := name, next printString. |
|
1063 |
^ name |
|
1064 |
||
1065 |
||
1066 |
||
1067 |
! |
|
1068 |
||
1069 |
uniqueNameOf:aView |
|
111 | 1070 |
|prop| |
78 | 1071 |
|
111 | 1072 |
(prop := self propertyOfView:aView) notNil ifTrue:[ |
1073 |
prop name isNil ifTrue:[ |
|
1074 |
prop name:(self uniqueNameFor:(prop spec)). |
|
1075 |
]. |
|
1076 |
^ prop name |
|
78 | 1077 |
]. |
111 | 1078 |
^ 'self' |
78 | 1079 |
|
60 | 1080 |
! ! |
1081 |
||
71 | 1082 |
!UIPainterView methodsFor:'selection'! |
1083 |
||
1084 |
addTreeFrom:aView to:aCollection |
|
1085 |
"add aView and contained subcomponents to collection |
|
1086 |
" |
|
78 | 1087 |
(self propertyOfView:aView) notNil ifTrue:[ |
71 | 1088 |
aCollection add:aView. |
1089 |
||
1090 |
(aView subViews notNil) ifTrue:[ |
|
1091 |
aView subViews do:[:subView| |
|
1092 |
self addTreeFrom:subView to:aCollection |
|
1093 |
] |
|
1094 |
]. |
|
1095 |
] |
|
1096 |
||
1097 |
! |
|
1098 |
||
1099 |
selectSubComponents |
|
1100 |
"select all subcomponents for current selection |
|
1101 |
" |
|
1102 |
|startAtView aCollection| |
|
1103 |
||
1104 |
aCollection := OrderedCollection new. |
|
1105 |
startAtView := self singleSelection. |
|
1106 |
||
1107 |
startAtView isNil ifTrue:[ |
|
1108 |
self subViews notNil ifTrue:[ |
|
1109 |
self subViews do:[:subView| |
|
1110 |
subView ~~ inputView ifTrue:[ |
|
1111 |
self addTreeFrom:subView to:aCollection |
|
1112 |
] |
|
1113 |
] |
|
1114 |
] |
|
1115 |
] ifFalse:[ |
|
1116 |
self addTreeFrom:startAtView to:aCollection |
|
1117 |
]. |
|
1118 |
||
1119 |
aCollection size > 1 ifTrue:[ |
|
128 | 1120 |
self updateSelectionFrom:aCollection. |
111 | 1121 |
self selectionChanged |
71 | 1122 |
] |
1123 |
! ! |
|
1124 |
||
78 | 1125 |
!UIPainterView methodsFor:'specification'! |
1126 |
||
1127 |
addSpec:aSpecification builder:aBuilder in:aFrame |
|
1128 |
"build view and subviews from aSpecification into a frame. The top view |
|
1129 |
is returned. The contained components of a spec are set to nil |
|
1130 |
" |
|
1131 |
aBuilder applicationClass:(Smalltalk classNamed:className). |
|
1132 |
||
111 | 1133 |
aBuilder componentCreationHook:[:aView :aSpec :aBdr||sv p s n| |
78 | 1134 |
p := ViewProperty new. |
1135 |
s := aSpec copy. |
|
1136 |
p spec:s. |
|
1137 |
p view:aView. |
|
1138 |
||
1139 |
s class supportsSubComponents ifTrue:[ |
|
1140 |
s component:nil |
|
1141 |
]. |
|
1142 |
||
111 | 1143 |
n := s name. |
1144 |
||
1145 |
(n isNil or:[(self propertyOfName:n) notNil]) ifTrue:[ |
|
1146 |
s name:(self uniqueNameFor:s) |
|
78 | 1147 |
]. |
111 | 1148 |
listHolder add:p |
78 | 1149 |
]. |
1150 |
||
1151 |
^ aSpecification buildViewWithLayoutFor:aBuilder in:aFrame. |
|
60 | 1152 |
|
78 | 1153 |
! |
1154 |
||
1155 |
fullSpecFor:anObject |
|
1156 |
"generate a full spec for an object |
|
62 | 1157 |
" |
78 | 1158 |
|mySpec subSpecs| |
1159 |
||
1160 |
mySpec := self specFor:anObject. |
|
1161 |
||
1162 |
(mySpec notNil and:[mySpec class supportsSubComponents]) ifTrue:[ |
|
1163 |
(anObject subViews notNil) ifTrue:[ |
|
1164 |
anObject subViews do:[:aSubView||spec| |
|
1165 |
spec := self fullSpecFor:aSubView. |
|
1166 |
spec notNil ifTrue:[ |
|
1167 |
subSpecs isNil ifTrue:[ |
|
1168 |
subSpecs := OrderedCollection new |
|
1169 |
]. |
|
1170 |
subSpecs add:spec. |
|
1171 |
]. |
|
1172 |
]. |
|
1173 |
subSpecs notNil ifTrue:[ |
|
1174 |
mySpec component:(SpecCollection new collection:subSpecs) |
|
1175 |
] |
|
1176 |
] |
|
1177 |
]. |
|
1178 |
^ mySpec |
|
1179 |
||
60 | 1180 |
|
1181 |
||
1182 |
||
1183 |
||
1184 |
||
1185 |
! |
|
1186 |
||
78 | 1187 |
specFor:anObject |
1188 |
"returns spec assigned to an object |
|
62 | 1189 |
" |
78 | 1190 |
|prop spec| |
60 | 1191 |
|
78 | 1192 |
(prop := self propertyOfView:anObject) notNil ifTrue:[ |
1193 |
spec := prop spec copy. |
|
1194 |
spec layoutFromView:anObject |
|
60 | 1195 |
]. |
78 | 1196 |
^ spec |
1197 |
||
1198 |
||
1199 |
||
60 | 1200 |
! |
1201 |
||
146 | 1202 |
specForSelection |
1203 |
"returns spec assigned to current single selection or nil |
|
1204 |
" |
|
1205 |
^ self specFor:(self singleSelection) |
|
1206 |
||
1207 |
||
1208 |
! |
|
1209 |
||
78 | 1210 |
updateFromSpec:aSpec |
1211 |
"update current selected view from specification |
|
62 | 1212 |
" |
78 | 1213 |
|props name builder v| |
1214 |
||
1215 |
self singleSelection notNil ifTrue:[ |
|
1216 |
self withSelectionHiddenDo:[ |
|
1217 |
self transaction:#specification selectionDo:[:aView| |
|
1218 |
builder := UIBuilder new. |
|
1219 |
props := self propertyOfView:aView. |
|
82 | 1220 |
name := (aSpec name) withoutSeparators. |
78 | 1221 |
|
82 | 1222 |
name = props name ifFalse:[ |
1223 |
(self propertyOfName:name) notNil ifTrue:[ |
|
1224 |
name := props name |
|
78 | 1225 |
] |
1226 |
]. |
|
82 | 1227 |
aSpec name:name. |
134 | 1228 |
self createUndoSpecModify:props. |
78 | 1229 |
|
1230 |
aSpec needsRebuildForAttributes ifTrue:[ |
|
1231 |
v := aSpec buildViewWithLayoutFor:builder in:aView superView. |
|
1232 |
v realize. |
|
1233 |
aView destroy. |
|
1234 |
device sync. device flush. |
|
1235 |
aView becomeSameAs:v. |
|
1236 |
inputView raise. |
|
1237 |
] ifFalse:[ |
|
1238 |
aSpec setAttributesIn:aView with:builder. |
|
1239 |
self elementChangedSize:aView. |
|
1240 |
]. |
|
1241 |
props spec:(aSpec copy). |
|
111 | 1242 |
listHolder propertyChanged:props. |
78 | 1243 |
] |
111 | 1244 |
] |
82 | 1245 |
] |
60 | 1246 |
! ! |
1247 |
||
1248 |
!UIPainterView methodsFor:'testing'! |
|
1249 |
||
1250 |
isHorizontalResizable:aComponent |
|
62 | 1251 |
"returns true if instance is horizontal resizeable |
1252 |
" |
|
60 | 1253 |
(aComponent isKindOf:ScrollBar) ifTrue:[ |
1254 |
^ aComponent orientation == #horizontal |
|
1255 |
]. |
|
1256 |
(aComponent isKindOf:Scroller) ifTrue:[ |
|
1257 |
^ aComponent orientation == #horizontal |
|
1258 |
]. |
|
1259 |
(aComponent isKindOf:Slider) ifTrue:[ |
|
1260 |
^ aComponent orientation == #horizontal |
|
1261 |
]. |
|
1262 |
^ true |
|
1263 |
||
1264 |
||
1265 |
! |
|
1266 |
||
1267 |
isVerticalResizable:aComponent |
|
62 | 1268 |
"returns true if instance is vertical resizeable |
1269 |
" |
|
60 | 1270 |
(aComponent isKindOf:EditField) ifTrue:[ |
1271 |
^ false |
|
1272 |
]. |
|
1273 |
(aComponent isKindOf:ComboBoxView) ifTrue:[ |
|
1274 |
^ false |
|
1275 |
]. |
|
1276 |
(aComponent isKindOf:CheckBox) ifTrue:[ |
|
1277 |
^ false |
|
1278 |
]. |
|
1279 |
(aComponent isKindOf:ScrollBar) ifTrue:[ |
|
1280 |
^ aComponent orientation == #vertical |
|
1281 |
]. |
|
1282 |
(aComponent isKindOf:Scroller) ifTrue:[ |
|
1283 |
^ aComponent orientation == #vertical |
|
1284 |
]. |
|
1285 |
(aComponent isKindOf:Slider) ifTrue:[ |
|
1286 |
^ aComponent orientation == #vertical |
|
1287 |
]. |
|
1288 |
^ true |
|
1289 |
||
1290 |
||
82 | 1291 |
! |
1292 |
||
1293 |
supportsLabel:aComponent |
|
1294 |
"returns true if component supports label |
|
1295 |
" |
|
1296 |
(aComponent respondsTo:#label:) ifTrue:[ |
|
1297 |
( (aComponent isKindOf:ArrowButton) |
|
1298 |
or:[aComponent isKindOf:CheckToggle] |
|
1299 |
) ifFalse:[ |
|
1300 |
^ true |
|
1301 |
] |
|
1302 |
]. |
|
1303 |
^ false |
|
60 | 1304 |
! ! |
1305 |
||
1306 |
!UIPainterView methodsFor:'transaction'! |
|
1307 |
||
1308 |
transaction:aType objects:something do:aOneArgBlock |
|
1309 |
"opens a transaction and evaluates a block within the transaction; the |
|
1310 |
argument to the block is a view from derived from something |
|
1311 |
" |
|
134 | 1312 |
self withinTransaction:aType objects:something do:[ |
1313 |
self forEach:something do:aOneArgBlock |
|
60 | 1314 |
] |
1315 |
! |
|
1316 |
||
134 | 1317 |
withinTransaction:aType objects:objects do:aNoneArgBlock |
1318 |
"evaluate a block with no arguments within a transaction |
|
60 | 1319 |
" |
134 | 1320 |
|text size prop| |
1321 |
||
1322 |
objects isNil ifTrue:[ ^ self ]. |
|
1323 |
||
1324 |
size := objects size. |
|
60 | 1325 |
|
134 | 1326 |
objects isCollection ifTrue:[ |
1327 |
size == 0 ifTrue:[ ^ self ]. |
|
1328 |
size == 1 ifTrue:[ prop := self propertyOfView:(objects first) ] |
|
1329 |
] ifFalse:[ |
|
1330 |
prop := self propertyOfView:objects |
|
1331 |
]. |
|
60 | 1332 |
|
134 | 1333 |
prop notNil ifTrue:[ |
1334 |
text := prop name |
|
1335 |
] ifFalse:[ |
|
1336 |
text := size printString, ' elements' |
|
60 | 1337 |
]. |
134 | 1338 |
|
1339 |
undoHistory withinTransaction:aType text:text do:[ |
|
1340 |
aNoneArgBlock value |
|
1341 |
] |
|
60 | 1342 |
! ! |
1343 |
||
1344 |
!UIPainterView methodsFor:'undo actions'! |
|
1345 |
||
134 | 1346 |
createUndoLayout:aView |
1347 |
"create undo action before changing a views layout |
|
60 | 1348 |
" |
134 | 1349 |
|lyt args prop| |
60 | 1350 |
|
1351 |
undoHistory isTransactionOpen ifTrue:[ |
|
1352 |
prop := self propertyOfView:aView. |
|
134 | 1353 |
|
60 | 1354 |
prop notNil ifTrue:[ |
134 | 1355 |
args := Array new:3. |
1356 |
args at:1 put:(prop identifier). |
|
1357 |
||
1358 |
(lyt := aView geometryLayout) notNil ifTrue:[ |
|
1359 |
args at:2 put:#geometryLayout: |
|
1360 |
] ifFalse:[ |
|
146 | 1361 |
lyt := aView extent. |
134 | 1362 |
args at:2 put:#extent: |
1363 |
]. |
|
1364 |
args at:3 put:(lyt copy). |
|
1365 |
undoHistory addUndoSelector:#undoLayout: withArgs:args. |
|
60 | 1366 |
] |
1367 |
] |
|
1368 |
! |
|
1369 |
||
134 | 1370 |
createUndoRemove:aView |
1371 |
"create undo method before deleting views |
|
60 | 1372 |
" |
134 | 1373 |
|frame prop pId spec| |
1374 |
||
1375 |
(prop := self propertyOfView:aView) notNil ifTrue:[ |
|
1376 |
spec := self fullSpecFor:aView. |
|
1377 |
frame := aView superView. |
|
60 | 1378 |
|
134 | 1379 |
(self canPasteInto:frame) ifTrue:[ |
1380 |
(frame := self propertyOfView:frame) notNil ifTrue:[ |
|
1381 |
pId := frame identifier |
|
1382 |
] |
|
1383 |
]. |
|
1384 |
undoHistory addUndoSelector:#undoRemove: |
|
1385 |
withArgs:(Array with:spec with:(prop identifier) with:pId) |
|
1386 |
] |
|
1387 |
! |
|
60 | 1388 |
|
134 | 1389 |
createUndoSpecModify:aProp |
1390 |
"undo method when changing the specification for an object |
|
1391 |
" |
|
1392 |
aProp notNil ifTrue:[ |
|
1393 |
undoHistory addUndoSelector:#undoSpecModify: |
|
1394 |
withArgs:(Array with:(aProp spec) with:(aProp identifier)) |
|
1395 |
] |
|
1396 |
! |
|
60 | 1397 |
|
134 | 1398 |
undoCreate:something |
1399 |
"undo method for creating or pasting an object |
|
1400 |
" |
|
1401 |
self forEach:something do:[:anId|self remove:(self findViewWithId:anId)]. |
|
1402 |
! |
|
60 | 1403 |
|
134 | 1404 |
undoLayout:args |
1405 |
"undo method to set the old layout; see 'createUndoLayout:' |
|
1406 |
" |
|
1407 |
|view| |
|
1408 |
||
1409 |
(view := self findViewWithId:(args at:1)) notNil ifTrue:[ |
|
146 | 1410 |
view perform:(args at:2) with:(args at:3). |
1411 |
self changed:#layout. |
|
60 | 1412 |
] |
1413 |
! |
|
1414 |
||
134 | 1415 |
undoRemove:args |
1416 |
"undo method when removing an object; see 'createUndoRemove:' |
|
1417 |
" |
|
1418 |
|frame prop view| |
|
1419 |
||
1420 |
(args at:3) notNil ifTrue:[ |
|
1421 |
frame := self findViewWithId:(args at:3). |
|
1422 |
]. |
|
1423 |
frame isNil ifTrue:[ |
|
1424 |
frame := self |
|
1425 |
]. |
|
1426 |
view := self addSpec:(args at:1) builder:(UIBuilder new) in:frame. |
|
1427 |
view realize. |
|
1428 |
inputView raise. |
|
1429 |
||
1430 |
prop := self propertyOfView:view. |
|
1431 |
prop identifier:(args at:2). |
|
1432 |
||
1433 |
! |
|
1434 |
||
1435 |
undoSpecModify:args |
|
1436 |
"undo method when changing a spec; see 'createUndoSpecModify:' |
|
60 | 1437 |
" |
80
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1438 |
|builder view spec v props| |
60 | 1439 |
|
134 | 1440 |
props := self propertyOfIdentifier:(args at:2). |
60 | 1441 |
|
134 | 1442 |
props notNil ifTrue:[ |
1443 |
view := props view. |
|
1444 |
spec := args at:1. |
|
1445 |
builder := UIBuilder new. |
|
1446 |
props spec:spec. |
|
80
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1447 |
|
134 | 1448 |
spec needsRebuildForAttributes ifTrue:[ |
1449 |
v := spec buildViewWithLayoutFor:builder in:view superView. |
|
1450 |
v realize. |
|
1451 |
view destroy. |
|
1452 |
view become:v |
|
1453 |
] ifFalse:[ |
|
1454 |
spec setAttributesIn:view with:builder. |
|
1455 |
self elementChangedSize:view. |
|
1456 |
]. |
|
1457 |
listHolder propertyChanged:props. |
|
1458 |
] |
|
60 | 1459 |
|
1460 |
! ! |
|
1461 |
||
165 | 1462 |
!UIPainterView::ViewProperty class methodsFor:'documentation'! |
1463 |
||
1464 |
version |
|
1465 |
^ '$Header$' |
|
1466 |
! ! |
|
1467 |
||
1468 |
!UIPainterView::ViewProperty class methodsFor:'instance creation'! |
|
1469 |
||
1470 |
new |
|
1471 |
Identifier notNil ifTrue:[Identifier := Identifier + 1] |
|
1472 |
ifFalse:[Identifier := 1]. |
|
1473 |
||
1474 |
^ self basicNew initialize |
|
1475 |
! ! |
|
1476 |
||
1477 |
!UIPainterView::ViewProperty methodsFor:'accessing'! |
|
1478 |
||
1479 |
identifier |
|
1480 |
"return the unique identifier assigned to property |
|
1481 |
" |
|
1482 |
^ identifier |
|
1483 |
! |
|
1484 |
||
1485 |
identifier:anIdentifier |
|
1486 |
"set the unique identifier assigned to property; called after an restore of |
|
1487 |
a deleted instance |
|
1488 |
" |
|
1489 |
identifier := anIdentifier |
|
1490 |
! |
|
1491 |
||
1492 |
spec |
|
1493 |
"return the value of the instance variable 'spec' (automatically generated)" |
|
1494 |
||
1495 |
^ spec! |
|
1496 |
||
1497 |
spec:something |
|
1498 |
"set the value of the instance variable 'spec' (automatically generated)" |
|
1499 |
||
1500 |
spec := something.! |
|
1501 |
||
1502 |
view |
|
1503 |
"return the value of the instance variable 'view' (automatically generated)" |
|
1504 |
||
1505 |
^ view! |
|
1506 |
||
1507 |
view:something |
|
1508 |
"set the value of the instance variable 'view' (automatically generated)" |
|
1509 |
||
1510 |
view := something.! ! |
|
1511 |
||
1512 |
!UIPainterView::ViewProperty methodsFor:'initialization'! |
|
1513 |
||
1514 |
initialize |
|
1515 |
super initialize. |
|
1516 |
identifier := Identifier |
|
1517 |
! ! |
|
1518 |
||
1519 |
!UIPainterView::ViewProperty methodsFor:'misc'! |
|
1520 |
||
1521 |
extractNumberStartingAt:anIndex |
|
1522 |
"return the number from the name starting at anIndex or 0. |
|
1523 |
" |
|
1524 |
|val| |
|
1525 |
||
1526 |
val := 0. |
|
1527 |
||
1528 |
self name from:anIndex do:[:c| |
|
1529 |
c isDigit ifTrue:[val := val * 10 + c digitValue] |
|
1530 |
ifFalse:[^ 0] |
|
1531 |
]. |
|
1532 |
^ val |
|
1533 |
||
1534 |
! ! |
|
1535 |
||
1536 |
!UIPainterView::ViewProperty methodsFor:'spec messages'! |
|
1537 |
||
1538 |
doesNotUnderstand:aMessage |
|
1539 |
spec notNil ifTrue:[ |
|
1540 |
(spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec] |
|
1541 |
]. |
|
1542 |
^ nil |
|
1543 |
! |
|
1544 |
||
1545 |
layout |
|
1546 |
spec layout |
|
1547 |
! |
|
1548 |
||
1549 |
layout:aLayout |
|
1550 |
spec layout:aLayout |
|
1551 |
! |
|
1552 |
||
1553 |
name |
|
1554 |
^ spec name |
|
1555 |
! |
|
1556 |
||
1557 |
name:aName |
|
1558 |
spec name:aName |
|
1559 |
! ! |
|
1560 |
||
111 | 1561 |
!UIPainterView::ListHolder class methodsFor:'instance creation'! |
1562 |
||
1563 |
for:aPainter |
|
1564 |
^ self new for:aPainter |
|
1565 |
! ! |
|
1566 |
||
1567 |
!UIPainterView::ListHolder methodsFor:'accessing'! |
|
1568 |
||
1569 |
painter |
|
1570 |
"returns painter |
|
1571 |
" |
|
1572 |
^ painter |
|
1573 |
! |
|
1574 |
||
1575 |
propertyAt:anIndex |
|
1576 |
"returns property at an index |
|
1577 |
" |
|
1578 |
^ propertyList at:anIndex |
|
1579 |
! ! |
|
1580 |
||
1581 |
!UIPainterView::ListHolder methodsFor:'adding & removing'! |
|
1582 |
||
1583 |
add:aProperty |
|
1584 |
"add property and update list |
|
1585 |
" |
|
1586 |
|idx list name last| |
|
1587 |
||
1588 |
list := self list. |
|
1589 |
idx := self findParentProperty:aProperty. |
|
1590 |
name := aProperty name. |
|
1591 |
||
1592 |
idx == 0 ifTrue:[ |
|
1593 |
last := list size |
|
1594 |
] ifFalse:[ |
|
1595 |
last := self lastInGroupStartingAt:idx. |
|
1596 |
name := (String new:(4+((list at:idx) leftIndent))), name. |
|
1597 |
]. |
|
1598 |
propertyList add:aProperty afterIndex:last. |
|
1599 |
list add:name afterIndex:last. |
|
1600 |
self changed:#size |
|
1601 |
||
1602 |
||
1603 |
! |
|
1604 |
||
1605 |
remove:aView |
|
1606 |
"remove all view relevant resources |
|
1607 |
" |
|
1608 |
|start| |
|
1609 |
||
1610 |
aView notNil ifTrue:[ |
|
1611 |
start := self findProperty:[:p| p view == aView ]. |
|
1612 |
||
1613 |
start ~~ 0 ifTrue:[ |
|
1614 |
self basicRemove:start. |
|
1615 |
self changed:#size. |
|
1616 |
] |
|
1617 |
] |
|
1618 |
! |
|
1619 |
||
1620 |
removeAll |
|
1621 |
masterElement := nil. |
|
1622 |
self selection:#(). |
|
1623 |
||
1624 |
[propertyList notEmpty] whileTrue:[ |
|
1625 |
self basicRemove:1 |
|
1626 |
]. |
|
1627 |
self changed:#size. |
|
1628 |
||
1629 |
! ! |
|
1630 |
||
1631 |
!UIPainterView::ListHolder methodsFor:'change & update'! |
|
1632 |
||
1633 |
changed:aParameter |
|
1634 |
"notify all dependents that the receiver has changed somehow. |
|
1635 |
Each dependent gets a '#update:'-message with aParameter |
|
1636 |
as argument. In case of disabled no notifications are raised |
|
1637 |
" |
|
1638 |
disabledChanged ifFalse:[ |
|
1639 |
super changed:aParameter |
|
1640 |
] |
|
1641 |
! |
|
1642 |
||
1643 |
disableNotificationsWhileEvaluating:aBlock |
|
1644 |
"perform block without notification; after evaluation of block, |
|
1645 |
a #size changed notification is raised |
|
1646 |
" |
|
1647 |
|oldState| |
|
1648 |
||
1649 |
oldState := disabledChanged. |
|
1650 |
disabledChanged := true. |
|
1651 |
aBlock value. |
|
1652 |
disabledChanged := oldState. |
|
1653 |
self changed:#size. |
|
1654 |
! |
|
1655 |
||
1656 |
propertyChanged:aProperty |
|
1657 |
"property list changed; update list names |
|
1658 |
" |
|
1659 |
|list idx oldName newName wspName view indent mid| |
|
1660 |
||
1661 |
view := aProperty view. |
|
1662 |
idx := self findProperty:[:p| p view == view ]. |
|
1663 |
||
1664 |
idx == 0 ifTrue:[ |
|
1665 |
^ self error |
|
1666 |
]. |
|
1667 |
||
1668 |
list := self list. |
|
1669 |
oldName := list at:idx. |
|
1670 |
wspName := oldName string withoutSeparators. |
|
1671 |
newName := aProperty name. |
|
1672 |
||
1673 |
wspName = newName ifFalse:[ |
|
1674 |
mid := self masterElement. |
|
1675 |
list at:idx put:((String new:(oldName leftIndent)), newName). |
|
1676 |
||
1677 |
idx == mid ifTrue:[ |
|
1678 |
masterElement := nil. |
|
1679 |
self masterElement:idx |
|
1680 |
]. |
|
1681 |
]. |
|
1682 |
self changed:#property |
|
1683 |
||
1684 |
! ! |
|
1685 |
||
1686 |
!UIPainterView::ListHolder methodsFor:'enumerating'! |
|
1687 |
||
1688 |
propertiesDo:aBlock |
|
1689 |
"evaluate a block for each property |
|
1690 |
" |
|
1691 |
propertyList do:aBlock |
|
1692 |
! ! |
|
1693 |
||
1694 |
!UIPainterView::ListHolder methodsFor:'initialization'! |
|
1695 |
||
1696 |
for:aPainter |
|
1697 |
"initialize for a painter |
|
1698 |
" |
|
119 | 1699 |
painter := aPainter. |
121 | 1700 |
disabledChanged := false. |
111 | 1701 |
self list:(OrderedCollection new). |
1702 |
propertyList := OrderedCollection new. |
|
1703 |
self selection:#(). |
|
1704 |
self addDependent:painter. |
|
1705 |
||
1706 |
! ! |
|
1707 |
||
1708 |
!UIPainterView::ListHolder methodsFor:'private'! |
|
1709 |
||
1710 |
basicRemove:start |
|
1711 |
"remove all resources assigned to a group starting at start; |
|
1712 |
no notifications are raised |
|
1713 |
" |
|
1714 |
|end view superView| |
|
1715 |
||
1716 |
end := self lastInGroupStartingAt:start. |
|
1717 |
view := (propertyList at:start) view. |
|
1718 |
||
1719 |
view notNil ifTrue:[ |
|
1720 |
superView := view superView. |
|
1721 |
view destroy. |
|
1722 |
superView sizeChanged:nil. |
|
1723 |
]. |
|
1724 |
||
1725 |
propertyList removeFromIndex:start toIndex:end. |
|
1726 |
self list removeFromIndex:start toIndex:end. |
|
1727 |
! |
|
1728 |
||
1729 |
masterElement |
|
1730 |
"returns index of master |
|
1731 |
" |
|
1732 |
^ self indexOfName:masterElement. |
|
1733 |
! |
|
1734 |
||
1735 |
masterElement:newIndex |
|
1736 |
"change master of selection |
|
1737 |
" |
|
1738 |
|name list oldIdx| |
|
1739 |
||
1740 |
(oldIdx := self masterElement) ~~ newIndex ifTrue:[ |
|
1741 |
list := self list. |
|
1742 |
||
1743 |
oldIdx ~~ 0 ifTrue:[ |
|
1744 |
list at:oldIdx put:masterElement |
|
1745 |
]. |
|
1746 |
newIndex ~~ 0 ifTrue:[ |
|
1747 |
masterElement := list at:newIndex. |
|
1748 |
name := Text string:masterElement. |
|
1749 |
name emphasizeFrom:(1+(name leftIndent)) with:#(#bold #underline). |
|
1750 |
list at:newIndex put:name. |
|
1751 |
] ifFalse:[ |
|
1752 |
masterElement := nil |
|
1753 |
]. |
|
1754 |
self changed:#list. |
|
1755 |
] |
|
1756 |
! ! |
|
1757 |
||
1758 |
!UIPainterView::ListHolder methodsFor:'searching'! |
|
1759 |
||
1760 |
detectProperty:aBlock |
|
1761 |
"find the property, for which evaluation of the argument, aBlock |
|
1762 |
returns true; return the property or nil if none detected |
|
1763 |
" |
|
1764 |
|idx| |
|
1765 |
||
1766 |
idx := self findProperty:aBlock. |
|
1767 |
idx ~~ 0 ifTrue:[ ^ propertyList at:idx ]. |
|
1768 |
^ nil |
|
1769 |
! |
|
1770 |
||
1771 |
findParentProperty:aChildProp |
|
1772 |
"returns index of parent or 0 |
|
1773 |
" |
|
1774 |
|view index| |
|
1775 |
||
1776 |
view := aChildProp view. |
|
1777 |
||
1778 |
view notNil ifTrue:[ |
|
1779 |
[ (view := view superView) notNil ] whileTrue:[ |
|
1780 |
index := self findProperty:[:aProp| aProp view == view ]. |
|
1781 |
index ~~ 0 ifTrue:[ |
|
1782 |
^ index |
|
1783 |
] |
|
1784 |
] |
|
1785 |
]. |
|
1786 |
^ 0 |
|
1787 |
||
1788 |
||
1789 |
! |
|
1790 |
||
1791 |
findProperty:aBlock |
|
1792 |
"find the first property, for which evaluation of the argument, aBlock |
|
1793 |
returns true; return its index or 0 if none detected |
|
1794 |
" |
|
1795 |
^ propertyList findFirst:aBlock |
|
1796 |
! |
|
1797 |
||
1798 |
indexOfName:aString |
|
1799 |
"returns index assigned to a string or 0 |
|
1800 |
" |
|
1801 |
|name list size| |
|
1802 |
||
1803 |
aString notNil ifTrue:[ |
|
1804 |
name := aString string withoutSeparators. |
|
1805 |
size := name size. |
|
1806 |
list := self list. |
|
1807 |
||
1808 |
list keysAndValuesDo:[:anIndex :aName| |
|
1809 |
|el| |
|
1810 |
||
1811 |
el := aName string. |
|
1812 |
(el endsWith:name) ifTrue:[ |
|
1813 |
(el size - el leftIndent) == name size ifTrue:[ |
|
1814 |
^ anIndex |
|
1815 |
] |
|
1816 |
] |
|
1817 |
] |
|
1818 |
]. |
|
1819 |
^ 0 |
|
1820 |
||
1821 |
! |
|
1822 |
||
1823 |
lastInGroupStartingAt:start |
|
1824 |
"returns last index of a group |
|
1825 |
" |
|
1826 |
|end list idt| |
|
1827 |
||
1828 |
list := self list. |
|
1829 |
||
1830 |
start < list size ifTrue:[ |
|
1831 |
idt := (list at:start) leftIndent. |
|
1832 |
end := list findFirst:[:el|(el leftIndent) <= idt] startingAt:(start+1). |
|
1833 |
end ~~ 0 ifTrue:[ |
|
1834 |
^ end - 1 |
|
1835 |
] |
|
1836 |
]. |
|
1837 |
^ list size |
|
1838 |
! ! |
|
1839 |
||
1840 |
!UIPainterView::ListHolder methodsFor:'selection'! |
|
1841 |
||
1842 |
selectGroup |
|
1843 |
"select all elements assigned to master |
|
1844 |
" |
|
1845 |
|start end sel size| |
|
1846 |
||
119 | 1847 |
painter enabled ifTrue:[ |
111 | 1848 |
(start := self masterElement) ~~ 0 ifTrue:[ |
1849 |
end := self lastInGroupStartingAt:start. |
|
1850 |
size := end - start + 1. |
|
1851 |
sel := Array new:size. |
|
1852 |
||
1853 |
1 to:size do:[:i| |
|
1854 |
sel at:i put:start. |
|
1855 |
start := start + 1 |
|
1856 |
]. |
|
1857 |
self selectionIndex:sel. |
|
1858 |
] ifFalse:[ |
|
1859 |
(self selectionIndex) size == 0 ifFalse:[ |
|
1860 |
self selectionIndex:#() |
|
1861 |
]. |
|
1862 |
] |
|
1863 |
] |
|
1864 |
! |
|
1865 |
||
1866 |
selectedProperty |
|
1867 |
"returns current selected instance; in case of multiple selection |
|
1868 |
or no selection nil is returned |
|
1869 |
" |
|
1870 |
|selection| |
|
1871 |
selection := self selectionIndex. |
|
1872 |
||
1873 |
selection size == 1 ifTrue:[ |
|
137 | 1874 |
propertyList size ~~ 0 ifTrue:[ |
1875 |
^ propertyList at:(selection first) |
|
1876 |
] |
|
111 | 1877 |
]. |
1878 |
^ nil |
|
1879 |
! |
|
1880 |
||
1881 |
selectionIndex:aList |
|
1882 |
|masterIndex aSel| |
|
1883 |
||
119 | 1884 |
painter enabled ifTrue:[aSel := aList] |
1885 |
ifFalse:[aSel := nil]. |
|
111 | 1886 |
|
1887 |
aSel size ~~ 0 ifTrue:[masterIndex := aSel at:1] |
|
1888 |
ifFalse:[masterIndex := 0]. |
|
1889 |
||
1890 |
self masterElement:masterIndex. |
|
1891 |
super selectionIndex:aSel |
|
1892 |
! ! |
|
1893 |
||
60 | 1894 |
!UIPainterView class methodsFor:'documentation'! |
1895 |
||
1896 |
version |
|
1897 |
^ '$Header$' |
|
1898 |
! ! |