author | ca |
Tue, 27 May 1997 15:16:55 +0200 | |
changeset 132 | 8649766ce095 |
parent 131 | 715b3dbba87d |
child 134 | d5ab85ec27fd |
permissions | -rw-r--r-- |
60 | 1 |
ObjectView subclass:#UIObjectView |
123 | 2 |
instanceVariableNames:'saveSelection inputView enableChannel undoHistory copiedExtent |
3 |
copiedLayout actionData createClass clipChildren |
|
4 |
selectionHiddenLevel setOfSuperViewsSizeChanged' |
|
60 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
7 |
category:'Interface-UIPainter' |
|
8 |
! |
|
9 |
||
10 |
Object subclass:#UndoHistory |
|
11 |
instanceVariableNames:'history transaction enabled' |
|
12 |
classVariableNames:'' |
|
13 |
poolDictionaries:'' |
|
14 |
privateIn:UIObjectView |
|
15 |
! |
|
16 |
||
54 | 17 |
Object subclass:#Transaction |
18 |
instanceVariableNames:'type text actions' |
|
19 |
classVariableNames:'' |
|
20 |
poolDictionaries:'' |
|
21 |
privateIn:UIObjectView::UndoHistory |
|
22 |
! |
|
23 |
||
128 | 24 |
!UIObjectView class methodsFor:'documentation'! |
25 |
||
26 |
documentation |
|
27 |
" |
|
131 | 28 |
buildIn view used by the UIPainter; it provides all services for creating, deleting |
29 |
moving and changing layouts of painted components on a canvas. |
|
128 | 30 |
|
31 |
[see also:] |
|
32 |
UIBuilder |
|
33 |
UIPainterView |
|
34 |
" |
|
35 |
||
36 |
! ! |
|
60 | 37 |
|
63 | 38 |
!UIObjectView class methodsFor:'conversion'! |
39 |
||
40 |
asLayoutFrameFromView:aView |
|
41 |
"convert layout from aView to a frameLayout. On success the frameLayout is |
|
42 |
returned otherwise nil |
|
43 |
" |
|
68 | 44 |
|lF lO rF rO tF tO bF bO type layout newLyt| |
45 |
||
46 |
type := self layoutType:aView. |
|
47 |
layout := aView geometryLayout. |
|
48 |
||
91 | 49 |
layout isNil ifTrue:[ |
50 |
type == #Extent ifTrue:[ |
|
51 |
layout := aView bounds asLayout |
|
52 |
] |
|
53 |
]. |
|
54 |
||
68 | 55 |
(type isNil or:[layout isNil]) ifTrue:[ |
63 | 56 |
^ nil |
57 |
]. |
|
58 |
||
68 | 59 |
type == #LayoutFrame ifTrue:[ |
60 |
^ layout copy |
|
61 |
]. |
|
62 |
||
63 |
layout isLayout ifFalse:[ |
|
64 |
type == #Rectangle ifTrue:[ |
|
63 | 65 |
lO := layout left. |
66 |
tO := layout top. |
|
67 |
rO := layout right. |
|
68 |
bO := layout bottom. |
|
69 |
] ifFalse:[ |
|
70 |
lO := layout x. |
|
71 |
tO := layout y. |
|
72 |
rO := lO + aView extent x. |
|
73 |
bO := tO + aView extent y. |
|
74 |
]. |
|
68 | 75 |
|
76 |
^ LayoutFrame leftFraction:0 offset:lO rightFraction:0 offset:rO |
|
77 |
topFraction:0 offset:tO bottomFraction:0 offset:bO |
|
63 | 78 |
]. |
79 |
||
68 | 80 |
lF := layout leftFraction. |
81 |
lO := layout leftOffset. |
|
82 |
tF := layout topFraction. |
|
83 |
tO := layout topOffset. |
|
84 |
bF := tF. |
|
85 |
bO := tO + aView extent y. |
|
86 |
rF := lF. |
|
87 |
rO := lO + aView extent x. |
|
88 |
||
89 |
newLyt := LayoutFrame leftFraction:lF offset:lO rightFraction:rF offset:rO |
|
90 |
topFraction:tF offset:tO bottomFraction:bF offset:bO. |
|
91 |
||
92 |
( (type == #AlignmentOrigin) |
|
93 |
and:[layout leftAlignmentFraction ~~ 0 |
|
94 |
or:[layout topAlignmentFraction ~~ 0]] |
|
95 |
) ifTrue:[ |
|
96 |
|svRc prBd dlta| |
|
97 |
||
98 |
svRc := aView superView viewRectangle. |
|
99 |
prBd := aView preferredBounds. |
|
100 |
dlta := ( ((layout rectangleRelativeTo:svRc preferred:prBd) corner) |
|
101 |
- ((newLyt rectangleRelativeTo:svRc preferred:prBd) corner) |
|
102 |
) rounded. |
|
103 |
||
104 |
newLyt leftOffset:(lO + dlta x). |
|
105 |
newLyt rightOffset:(rO + dlta x). |
|
106 |
newLyt topOffset:(tO + dlta y). |
|
107 |
newLyt bottomOffset:(bO + dlta y). |
|
108 |
]. |
|
109 |
^ newLyt. |
|
91 | 110 |
|
111 |
"Modified: 28.3.1997 / 19:52:48 / cg" |
|
63 | 112 |
! ! |
113 |
||
60 | 114 |
!UIObjectView class methodsFor:'defaults'! |
115 |
||
116 |
defaultGrid |
|
117 |
^ 4 @ 4 |
|
118 |
||
119 |
! |
|
120 |
||
121 |
gridShown |
|
122 |
^ false |
|
123 |
||
124 |
! |
|
125 |
||
126 |
handleSize |
|
127 |
"size of blob drawn for handles" |
|
128 |
^ 4 |
|
129 |
||
130 |
! |
|
131 |
||
132 |
hitDelta |
|
133 |
^ 4 |
|
134 |
||
135 |
! ! |
|
136 |
||
61 | 137 |
!UIObjectView class methodsFor:'queries'! |
138 |
||
139 |
layoutType:aView |
|
140 |
"returns layout type of aView or nil |
|
141 |
" |
|
113 | 142 |
|layout spec superView| |
143 |
||
144 |
aView notNil ifTrue:[ |
|
145 |
layout := aView geometryLayout. |
|
146 |
layout notNil ifTrue:[ |
|
147 |
layout isLayout ifTrue:[ |
|
148 |
layout isLayoutFrame ifTrue:[ ^ #LayoutFrame ]. |
|
149 |
layout isAlignmentOrigin ifTrue:[ ^ #AlignmentOrigin ]. |
|
150 |
layout isLayoutOrigin ifTrue:[ ^ #LayoutOrigin ]. |
|
151 |
] ifFalse:[ |
|
152 |
layout isRectangle ifTrue:[ ^ #Rectangle ]. |
|
153 |
layout isPoint ifTrue:[ ^ #Point ]. |
|
154 |
] |
|
61 | 155 |
] ifFalse:[ |
113 | 156 |
(superView := aView superView) notNil ifTrue:[ |
157 |
spec := superView specClass. |
|
158 |
spec canResizeSubComponents ifTrue:[ |
|
159 |
^ #Extent |
|
160 |
] |
|
161 |
] |
|
61 | 162 |
] |
163 |
]. |
|
164 |
^ nil |
|
165 |
||
67 | 166 |
"Modified: 28.2.1997 / 13:02:16 / cg" |
61 | 167 |
! ! |
168 |
||
60 | 169 |
!UIObjectView methodsFor:'accessing'! |
170 |
||
119 | 171 |
enableChannel |
172 |
"returns the channel which keeps false if running test otherwise true |
|
173 |
" |
|
174 |
^ enableChannel |
|
113 | 175 |
! |
176 |
||
60 | 177 |
gridAlign |
61 | 178 |
"returns state of aligning to grid |
179 |
" |
|
60 | 180 |
^ aligning |
181 |
||
182 |
! |
|
183 |
||
184 |
gridAlign:aBool |
|
61 | 185 |
"change state of aligning to grid |
186 |
" |
|
60 | 187 |
aBool ifTrue:[self alignOn] |
188 |
ifFalse:[self alignOff] |
|
189 |
||
190 |
! |
|
191 |
||
192 |
gridParameters |
|
193 |
"used by defineGrid, and in a separate method for |
|
194 |
easier redefinition in subclasses. |
|
195 |
Returns the grid parameters in an array of 7 elements, |
|
196 |
which control the appearance of the grid-pattern. |
|
197 |
the elements are: |
|
198 |
||
199 |
bigStepH number of pixels horizontally between 2 major steps |
|
200 |
bigStepV number of pixels vertically between 2 major steps |
|
201 |
littleStepH number of pixels horizontally between 2 minor steps |
|
202 |
littleStepV number of pixels vertically between 2 minor steps |
|
203 |
gridAlignH number of pixels for horizontal grid align (pointer snap) |
|
204 |
gridAlignV number of pixels for vertical grid align (pointer snap) |
|
205 |
docBounds true, if document boundary should be shown |
|
206 |
||
207 |
if littleStepH/V are nil, only bigSteps are drawn. |
|
208 |
" |
|
209 |
||
210 |
^ #(10 10 nil nil 10 10 false) |
|
211 |
||
212 |
||
213 |
! |
|
214 |
||
215 |
gridShown:aBool |
|
61 | 216 |
"change visibility of grid |
217 |
" |
|
60 | 218 |
aBool ifTrue:[self showGrid] |
219 |
ifFalse:[self hideGrid] |
|
220 |
! |
|
221 |
||
222 |
hideGrid |
|
61 | 223 |
"hide grid |
224 |
" |
|
60 | 225 |
gridShown ifTrue:[ |
61 | 226 |
self withSelectionHiddenDo:[super hideGrid] |
60 | 227 |
] |
228 |
||
229 |
||
230 |
! |
|
231 |
||
232 |
showGrid |
|
61 | 233 |
"show grid |
234 |
" |
|
235 |
self withSelectionHiddenDo:[super showGrid] |
|
119 | 236 |
! ! |
237 |
||
238 |
!UIObjectView methodsFor:'accessing behavior'! |
|
239 |
||
240 |
enabled |
|
241 |
^ enableChannel value |
|
242 |
! |
|
243 |
||
244 |
enabled:aState |
|
245 |
"set the modification / test mode |
|
246 |
" |
|
247 |
(aState == enableChannel value) ifFalse:[ |
|
123 | 248 |
aState ifFalse:[ |
131 | 249 |
saveSelection := self selection. |
250 |
self select:nil. |
|
128 | 251 |
enableChannel value:aState. |
252 |
inputView unrealize. |
|
119 | 253 |
] ifTrue:[ |
254 |
inputView raise. |
|
123 | 255 |
inputView realize. |
128 | 256 |
enableChannel value:aState. |
123 | 257 |
self select:saveSelection. |
258 |
] |
|
119 | 259 |
] |
260 |
||
261 |
||
262 |
||
60 | 263 |
! |
264 |
||
265 |
testMode |
|
61 | 266 |
"returns true if running test |
60 | 267 |
" |
119 | 268 |
^ enableChannel value not |
60 | 269 |
|
270 |
||
271 |
! |
|
272 |
||
273 |
testMode:aBoolean |
|
61 | 274 |
"change test mode |
60 | 275 |
" |
119 | 276 |
self enabled:(aBoolean not) |
60 | 277 |
! ! |
278 |
||
279 |
!UIObjectView methodsFor:'blocked'! |
|
280 |
||
281 |
addObject:anObject |
|
61 | 282 |
"add the argument, anObject to the contents - with redraw |
283 |
" |
|
60 | 284 |
self halt |
285 |
||
286 |
! |
|
287 |
||
288 |
addObjectWithoutRedraw:anObject |
|
61 | 289 |
"add the argument, anObject to the contents - with redraw |
290 |
" |
|
60 | 291 |
self halt |
292 |
||
293 |
! ! |
|
294 |
||
295 |
!UIObjectView methodsFor:'event handling'! |
|
296 |
||
61 | 297 |
elementChangedSize:aView |
298 |
"some element has changed its size; collect them during selectionHiddenLevel |
|
299 |
is on |
|
300 |
" |
|
301 |
selectionHiddenLevel ~~ 0 ifTrue:[ |
|
302 |
setOfSuperViewsSizeChanged add:aView superView |
|
303 |
] ifFalse:[ |
|
304 |
aView superView sizeChanged:nil |
|
305 |
] |
|
60 | 306 |
! |
307 |
||
308 |
exposeX:x y:y width:w height:h |
|
309 |
"handle an expose event from device; redraw selection |
|
310 |
" |
|
311 |
super exposeX:x y:y width:w height:h. |
|
132 | 312 |
|
313 |
" |
|
314 |
catch expose events for all subviews associated with |
|
315 |
a selected instance |
|
316 |
" |
|
317 |
||
318 |
self selectionDo:[:aComponent | |
|
319 |
aComponent withAllSubViewsDo:[:v | |
|
320 |
self sensor flushExposeEventsFor:v. |
|
321 |
v exposeX:0 y:0 width:9999 height:9999. |
|
322 |
]. |
|
323 |
||
324 |
self showSelected:aComponent |
|
325 |
] |
|
60 | 326 |
|
327 |
! |
|
328 |
||
329 |
keyPress:key x:x y:y |
|
61 | 330 |
"any key pressed |
331 |
" |
|
78 | 332 |
<resource: #keyboard ( #Delete #BackSpace #Cut #Copy #Paste ) > |
60 | 333 |
|
334 |
(key == #Cut or:[key == #Delete or:[key == #BackSpace]]) ifTrue: [ |
|
335 |
^ self deleteSelection |
|
336 |
]. |
|
337 |
||
78 | 338 |
key == #Copy ifTrue:[ ^ self copySelection]. |
339 |
key == #Paste ifTrue:[ ^ self pasteBuffer]. |
|
60 | 340 |
! |
341 |
||
342 |
processEvent:anEvent |
|
343 |
"catch expose events for components, and redraw its handles after |
|
344 |
the redraw when this happens |
|
345 |
" |
|
128 | 346 |
(anEvent type == #damage and:[self isSelected:(anEvent view)]) ifTrue:[ |
347 |
self showSelected:(anEvent view) |
|
60 | 348 |
]. |
349 |
^ false. |
|
350 |
||
351 |
||
352 |
! |
|
353 |
||
354 |
sizeChanged:how |
|
61 | 355 |
"size of a view(s) changed |
356 |
" |
|
60 | 357 |
self withSelectionHiddenDo:[ |
358 |
super sizeChanged:how |
|
359 |
] |
|
360 |
||
361 |
||
362 |
! ! |
|
363 |
||
364 |
!UIObjectView methodsFor:'initialization'! |
|
365 |
||
366 |
initialize |
|
61 | 367 |
"setup attributes |
368 |
" |
|
60 | 369 |
super initialize. |
370 |
||
371 |
"funny: since I do not want the created widgets to get pointer |
|
372 |
events, I put an InputView on top of them, which catches those events |
|
373 |
and passes them back to me - have to take care, that this inputView |
|
374 |
is always on top |
|
375 |
" |
|
376 |
inputView := InputView origin:0.0@0.0 extent:1.0@1.0 in:self. |
|
61 | 377 |
setOfSuperViewsSizeChanged := IdentitySet new. |
60 | 378 |
|
379 |
inputView eventReceiver:self. |
|
380 |
inputView enableButtonEvents. |
|
381 |
inputView enableButtonMotionEvents. |
|
382 |
||
383 |
self setDefaultActions. |
|
384 |
||
119 | 385 |
undoHistory := UndoHistory new. |
386 |
enableChannel := true asValue. |
|
387 |
clipChildren := true. |
|
61 | 388 |
selectionHiddenLevel := 0. |
60 | 389 |
|
390 |
(self class gridShown) ifTrue:[ |
|
391 |
super showGrid |
|
392 |
]. |
|
393 |
||
394 |
! |
|
395 |
||
396 |
realize |
|
397 |
super realize. |
|
398 |
self windowGroup postEventHook:self |
|
399 |
||
400 |
! ! |
|
401 |
||
402 |
!UIObjectView methodsFor:'misc'! |
|
403 |
||
404 |
cursor:aCursor |
|
61 | 405 |
"set cursor |
406 |
" |
|
60 | 407 |
inputView realized ifTrue:[ |
408 |
inputView cursor:aCursor |
|
409 |
]. |
|
410 |
super cursor:aCursor |
|
411 |
||
412 |
||
413 |
! |
|
414 |
||
415 |
invertOutlineOf:anObject |
|
61 | 416 |
"invert outline of an object |
417 |
" |
|
60 | 418 |
|wasClipped delta| |
419 |
||
420 |
(wasClipped := clipChildren) ifTrue:[ |
|
421 |
self clippedByChildren:(clipChildren := false). |
|
422 |
]. |
|
423 |
delta := (anObject originRelativeTo:self) - anObject origin. |
|
424 |
||
425 |
self xoring:[ |
|
426 |
self displayRectangle:((anObject origin + delta) extent:anObject extent). |
|
427 |
]. |
|
428 |
||
429 |
wasClipped ifTrue:[ |
|
430 |
self clippedByChildren:(clipChildren := true). |
|
431 |
]. |
|
432 |
||
433 |
"Modified: 5.9.1995 / 12:25:25 / claus" |
|
434 |
||
435 |
||
436 |
! |
|
437 |
||
78 | 438 |
minSetOfSuperViews:setOfViews |
439 |
||
440 |
setOfViews isCollection ifFalse:[ |
|
441 |
setOfViews notNil ifTrue:[^ Array with:setOfViews] |
|
442 |
ifFalse:[^ nil] |
|
72 | 443 |
]. |
444 |
||
78 | 445 |
^ setOfViews select:[:aView| |
446 |
(setOfViews detect:[:v|aView isComponentOf:v] ifNone:nil) isNil |
|
447 |
] |
|
72 | 448 |
! |
449 |
||
60 | 450 |
setDefaultActions |
61 | 451 |
"set default actions |
452 |
" |
|
60 | 453 |
pressAction := [:pressPoint | self startSelectOrMove:pressPoint]. |
454 |
shiftPressAction := [:pressPoint | self startSelectMoreOrMove:pressPoint]. |
|
455 |
motionAction := [:movePoint | nil]. |
|
456 |
releaseAction := [nil]. |
|
457 |
keyPressAction := nil. |
|
458 |
||
459 |
self cursor:Cursor normal. |
|
460 |
||
461 |
! ! |
|
462 |
||
463 |
!UIObjectView methodsFor:'object creation'! |
|
464 |
||
465 |
actionCreate:anObject frame:aFrame delta:aDelta |
|
466 |
"create and initialize action data |
|
467 |
" |
|
468 |
|extent x y selectors values| |
|
469 |
||
470 |
"minimum extent |
|
471 |
" |
|
82 | 472 |
(anObject specClass supportsSubComponents) ifTrue:[ |
84 | 473 |
extent := 25@25 |
82 | 474 |
] ifFalse:[ |
475 |
extent := self extent. |
|
476 |
x := extent x // 3. |
|
477 |
y := extent y // 3. |
|
478 |
extent := anObject preferredExtent. |
|
479 |
||
480 |
(extent x > x) ifTrue:[extent x:x]. |
|
481 |
(extent y > y) ifTrue:[extent y:y]. |
|
482 |
]. |
|
60 | 483 |
|
484 |
"setup structure |
|
485 |
" |
|
486 |
selectors := #( object frame delta vertical horizontal minExtent ). |
|
487 |
values := Array new:(selectors size). |
|
488 |
||
489 |
values at:1 put:anObject. |
|
490 |
values at:2 put:aFrame. |
|
491 |
values at:3 put:aDelta. |
|
492 |
values at:4 put:(self isVerticalResizable:anObject). |
|
493 |
values at:5 put:(self isHorizontalResizable:anObject). |
|
494 |
values at:6 put:extent. |
|
495 |
||
496 |
actionData := Structure newWith:selectors values:values. |
|
497 |
||
498 |
||
499 |
"can change cursor dependent on vertical/horizontal resizing |
|
500 |
" |
|
501 |
oldCursor := cursor. |
|
502 |
self cursor:(Cursor leftHand). |
|
503 |
||
504 |
||
505 |
||
506 |
! |
|
507 |
||
508 |
createWidgetWithClass:aClass |
|
509 |
"prepare to create new widgets |
|
510 |
" |
|
89 | 511 |
aClass notNil ifTrue:[ |
512 |
createClass := aClass. |
|
513 |
pressAction := [:aPoint| self startCreate:aPoint]. |
|
514 |
self cursor:Cursor origin. |
|
515 |
] |
|
60 | 516 |
|
517 |
! |
|
518 |
||
519 |
doDragCreate:aPoint |
|
520 |
"do a widget create drag |
|
521 |
" |
|
522 |
|frame object extent minimum| |
|
523 |
||
524 |
frame := actionData frame. |
|
525 |
frame corner:((self alignToGrid:aPoint) - (actionData delta)). |
|
526 |
||
527 |
object := actionData object. |
|
528 |
minimum := actionData minExtent. |
|
529 |
extent := frame extent. |
|
530 |
||
531 |
((extent x < minimum x) or:[actionData horizontal not]) ifTrue:[ |
|
532 |
extent x:(minimum x) |
|
533 |
]. |
|
534 |
||
535 |
((extent y < minimum y) or:[actionData vertical not]) ifTrue:[ |
|
536 |
extent y:(minimum y) |
|
537 |
]. |
|
538 |
||
539 |
frame extent:extent. |
|
540 |
||
541 |
self invertOutlineOf:object. |
|
542 |
object origin:(frame origin) extent:(frame extent). |
|
543 |
self invertOutlineOf:object. |
|
544 |
! |
|
545 |
||
546 |
endCreate |
|
547 |
"end a widget create drag |
|
548 |
" |
|
89 | 549 |
|object specClass| |
60 | 550 |
|
551 |
object := actionData object. |
|
552 |
self invertOutlineOf:object. |
|
553 |
inputView raise. |
|
554 |
||
89 | 555 |
self setupInitialLayoutFor:object. |
60 | 556 |
self select:object. |
557 |
actionData := nil. |
|
558 |
||
559 |
self setDefaultActions. |
|
560 |
||
561 |
! |
|
562 |
||
78 | 563 |
initializeCreatedObject:anObject |
60 | 564 |
self subclassResponsibility |
565 |
! |
|
566 |
||
89 | 567 |
setupInitialLayoutFor:anObject |
568 |
"setup initial layout for an object; !!!! some kludge !!!! |
|
569 |
" |
|
570 |
|spec topSpec| |
|
571 |
||
572 |
topSpec := anObject superView specClass basicNew. |
|
573 |
||
574 |
topSpec class isLayoutContainer ifFalse:[ |
|
575 |
||
576 |
"/ ... KLUDGE .... |
|
577 |
||
578 |
spec := anObject specClass. |
|
579 |
||
580 |
( spec == ViewSpec |
|
581 |
or:[spec == SubCanvasSpec |
|
582 |
or:[spec == TextEditorSpec |
|
583 |
or:[spec == SequenceViewSpec]]] |
|
584 |
) ifTrue:[ |
|
585 |
anObject geometryLayout:(anObject bounds asLayout). |
|
586 |
^ self |
|
587 |
] |
|
588 |
]. |
|
589 |
topSpec setupInitialLayoutFor:anObject. |
|
590 |
||
591 |
! |
|
592 |
||
60 | 593 |
startCreate:aPoint |
594 |
"start a widget create |
|
595 |
" |
|
596 |
|widget object start frame delta| |
|
597 |
||
131 | 598 |
self select:nil. |
89 | 599 |
widget := self findContainerViewAt:aPoint. |
60 | 600 |
|
601 |
motionAction := [:movePoint| self doDragCreate:movePoint]. |
|
602 |
releaseAction := [ self endCreate]. |
|
603 |
||
604 |
object := createClass new. |
|
76 | 605 |
(widget isKindOf:ScrollableView) ifTrue:[ |
606 |
widget scrolledView:object |
|
607 |
] ifFalse:[ |
|
608 |
widget addSubView:object. |
|
609 |
]. |
|
60 | 610 |
|
611 |
start := self alignToGrid:aPoint. |
|
612 |
delta := widget originRelativeTo:self. |
|
613 |
frame := Rectangle origin:(start - delta) corner:start. |
|
614 |
||
615 |
object origin:(frame origin). |
|
78 | 616 |
self initializeCreatedObject:object. |
82 | 617 |
self actionCreate:object frame:frame delta:delta. |
618 |
object extent:(actionData minExtent). |
|
60 | 619 |
object realize. |
620 |
self invertOutlineOf:object. |
|
621 |
! ! |
|
622 |
||
623 |
!UIObjectView methodsFor:'object moving'! |
|
624 |
||
625 |
doObjectMove:aPoint |
|
626 |
"move selection |
|
627 |
" |
|
628 |
movedObject notNil ifTrue:[ |
|
629 |
movedObject keysAndValuesDo:[:nr :aView| |
|
630 |
self invertOutlineOf:aView. |
|
631 |
self moveObject:aView to:(aPoint - (moveDelta at:nr)). |
|
632 |
self invertOutlineOf:aView. |
|
633 |
] |
|
634 |
] |
|
635 |
||
636 |
! |
|
637 |
||
638 |
endObjectMove |
|
61 | 639 |
"cleanup after object(s) move |
640 |
" |
|
60 | 641 |
movedObject notNil ifTrue:[ |
128 | 642 |
movedObject do:[:aView|self invertOutlineOf:aView]. |
643 |
||
644 |
movedObject size == 1 ifTrue:[ |
|
645 |
movedObject := movedObject first |
|
60 | 646 |
]. |
128 | 647 |
|
648 |
self setSelection:movedObject withRedraw:true. |
|
60 | 649 |
movedObject := nil. |
650 |
self setDefaultActions. |
|
651 |
self changed:#layout. |
|
652 |
]. |
|
653 |
! |
|
654 |
||
655 |
moveObject:anObject to:aPoint |
|
656 |
"move anObject to newOrigin, aPoint |
|
657 |
" |
|
658 |
|dX dY org delta| |
|
659 |
||
660 |
anObject notNil ifTrue:[ |
|
661 |
org := anObject computeOrigin. |
|
662 |
||
663 |
delta := aPoint - org. |
|
664 |
delta := (self alignToGrid:aPoint) - org. |
|
665 |
dX := delta x. |
|
666 |
dY := delta y. |
|
667 |
||
668 |
undoHistory disabledTransitionDo:[ |
|
669 |
self shiftLayout:anObject top:dY bottom:dY left:dX right:dX |
|
670 |
] |
|
671 |
] |
|
672 |
||
673 |
! |
|
674 |
||
675 |
startObjectMoveAt:aPoint |
|
61 | 676 |
"start object(s) move at a point |
677 |
" |
|
128 | 678 |
self startObjectMove:(self selection) at:aPoint. |
679 |
movedObject := self selection. |
|
680 |
||
681 |
movedObject isCollection ifFalse:[ |
|
682 |
movedObject := Array with:movedObject |
|
60 | 683 |
]. |
128 | 684 |
self setSelection:nil withRedraw:true. |
60 | 685 |
|
686 |
moveDelta := movedObject collect:[:aView| |
|
687 |
aPoint - aView computeOrigin |
|
688 |
]. |
|
689 |
||
690 |
self transaction:#move objects:movedObject do:[:aView| |
|
691 |
self invertOutlineOf:aView. |
|
692 |
self undoLayoutView:aView |
|
693 |
]. |
|
694 |
||
695 |
! |
|
696 |
||
697 |
startSelectMoreOrMove:aPoint |
|
698 |
"add/remove to/from selection" |
|
699 |
||
700 |
|anObject| |
|
701 |
||
119 | 702 |
self enabled ifFalse:[^ self]. |
60 | 703 |
|
704 |
anObject := self findObjectAt:aPoint. |
|
705 |
anObject notNil ifTrue:[ |
|
706 |
(self isSelected:anObject) ifTrue:[ |
|
707 |
self removeFromSelection:anObject |
|
708 |
] ifFalse:[ |
|
709 |
self addToSelection:anObject |
|
710 |
] |
|
711 |
] |
|
712 |
! |
|
713 |
||
714 |
startSelectOrMove:aPoint |
|
61 | 715 |
"a button is pressed at a point; start moving or selection |
60 | 716 |
" |
61 | 717 |
|aView b| |
60 | 718 |
|
119 | 719 |
self enabled ifFalse:[^ self]. |
60 | 720 |
|
61 | 721 |
aView := self singleSelection. |
722 |
||
723 |
aView notNil ifTrue:[ |
|
724 |
(aView superView specClass canResizeSubComponents) ifTrue:[ |
|
725 |
b := self whichHandleOf:aView isHitBy:aPoint. |
|
726 |
||
727 |
(b notNil and:[b ~~ #view]) ifTrue:[ |
|
728 |
^ self startResizeBorder:b of:aView. |
|
729 |
] |
|
100 | 730 |
]. |
731 |
||
732 |
(self sensor ctrlDown and:[self canMove:aView]) ifFalse:[ |
|
733 |
aView := nil |
|
60 | 734 |
] |
735 |
]. |
|
736 |
||
100 | 737 |
aView isNil ifTrue:[ |
738 |
(aView := self findObjectAt:aPoint) isNil ifTrue:[ |
|
131 | 739 |
^ self select:nil |
100 | 740 |
]. |
741 |
||
742 |
(self canMove:aView) ifFalse:[ |
|
128 | 743 |
^ self select:aView |
100 | 744 |
] |
61 | 745 |
]. |
746 |
||
747 |
(self isSelected:aView) ifFalse:[ |
|
748 |
self select:aView. |
|
60 | 749 |
]. |
750 |
||
751 |
(self numberOfSelections ~~ 1) ifTrue:[ |
|
752 |
releaseAction := [ |
|
753 |
self setDefaultActions. |
|
61 | 754 |
self select:aView |
60 | 755 |
] |
756 |
] ifFalse:[ |
|
757 |
releaseAction := [self setDefaultActions] |
|
758 |
]. |
|
759 |
||
760 |
"prepare move operation for an object |
|
761 |
" |
|
61 | 762 |
|
60 | 763 |
motionAction := [:movePoint| |
72 | 764 |
(aPoint dist:movePoint) > 8.0 ifTrue:[ |
60 | 765 |
self startObjectMoveAt:aPoint |
766 |
] |
|
767 |
]. |
|
768 |
! ! |
|
769 |
||
770 |
!UIObjectView methodsFor:'object resize'! |
|
771 |
||
772 |
actionResize:anObject selector:aSelector |
|
773 |
"create and initialize action for resize |
|
774 |
" |
|
775 |
|selector delta| |
|
776 |
||
777 |
delta := anObject container originRelativeTo:self. |
|
778 |
selector := ('resize:', aSelector, ':') asSymbol. |
|
779 |
||
780 |
actionData := Structure with:(#object->anObject) |
|
781 |
with:(#selector->selector) |
|
782 |
with:(#delta->delta). |
|
783 |
||
784 |
"can change cursor dependent on vertical/horizontal resizing |
|
785 |
" |
|
786 |
oldCursor := cursor. |
|
787 |
self cursor:(Cursor leftHand). |
|
788 |
||
789 |
||
790 |
||
791 |
! |
|
792 |
||
793 |
doDragResize:aPoint |
|
61 | 794 |
"do a widget resize drag |
795 |
" |
|
60 | 796 |
|p object| |
797 |
||
798 |
object := actionData object. |
|
799 |
||
800 |
self invertOutlineOf:object. |
|
801 |
p := (self alignToGrid:aPoint) - (actionData delta). |
|
79 | 802 |
|
60 | 803 |
self perform:(actionData selector) with:object with:p. |
79 | 804 |
"/ object geometryLayout:(object geometryLayout). |
60 | 805 |
self invertOutlineOf:object |
806 |
||
807 |
! |
|
808 |
||
809 |
endResize |
|
61 | 810 |
"cleanup after object resize |
811 |
" |
|
812 |
|object| |
|
813 |
||
814 |
object := actionData object. |
|
815 |
actionData := nil. |
|
816 |
||
817 |
self invertOutlineOf:object. |
|
60 | 818 |
self setDefaultActions. |
61 | 819 |
self elementChangedSize:object. |
128 | 820 |
self setSelection:object withRedraw:true. |
60 | 821 |
self changed:#layout. |
822 |
! |
|
823 |
||
824 |
startResizeBorder:b of:selection |
|
825 |
"resize selected view |
|
826 |
" |
|
827 |
|object| |
|
828 |
||
829 |
object := self singleSelection. |
|
830 |
self actionResize:object selector:b. |
|
831 |
||
72 | 832 |
self transaction:#resize selectionDo:[:aView| |
60 | 833 |
self undoLayoutView:aView |
834 |
]. |
|
128 | 835 |
self setSelection:nil withRedraw:true. |
60 | 836 |
|
837 |
motionAction := [:movePoint | self doDragResize:movePoint]. |
|
838 |
releaseAction := [self endResize]. |
|
839 |
self invertOutlineOf:object |
|
840 |
! ! |
|
841 |
||
842 |
!UIObjectView methodsFor:'private handles'! |
|
843 |
||
61 | 844 |
handlesOf:aView do:aBlock |
845 |
|dlta type v h| |
|
846 |
||
847 |
dlta := (aView originRelativeTo:self) - aView origin. |
|
848 |
type := self class layoutType:aView. |
|
849 |
||
850 |
(type == #LayoutFrame or:[type == #Rectangle]) ifTrue:[ |
|
851 |
v := self isVerticalResizable:aView. |
|
852 |
h := self isHorizontalResizable:aView. |
|
853 |
||
854 |
h ifTrue:[ aBlock value:(aView leftCenter + dlta) value:#left. |
|
855 |
aBlock value:(aView rightCenter + dlta) value:#right. |
|
856 |
]. |
|
857 |
v ifTrue:[ aBlock value:(aView topCenter + dlta) value:#top. |
|
858 |
aBlock value:(aView bottomCenter + dlta) value:#bottom. |
|
859 |
]. |
|
860 |
||
861 |
(h and:[v]) ifTrue:[ |
|
862 |
aBlock value:(aView origin + dlta) value:#origin. |
|
863 |
aBlock value:(aView topRight + dlta) value:#topRight. |
|
864 |
aBlock value:(aView bottomLeft + dlta) value:#bottomLeft. |
|
865 |
aBlock value:(aView corner + dlta) value:#corner. |
|
866 |
^ self |
|
867 |
] |
|
60 | 868 |
]. |
869 |
||
61 | 870 |
aBlock value:(aView origin + dlta) value:#view. |
871 |
aBlock value:(aView topRight + dlta) value:#view. |
|
872 |
aBlock value:(aView bottomLeft + dlta) value:#view. |
|
873 |
||
874 |
type == #Extent ifTrue:[ |
|
875 |
v := self isVerticalResizable:aView. |
|
876 |
h := self isHorizontalResizable:aView. |
|
877 |
||
878 |
v ifTrue:[aBlock value:(aView bottomCenter + dlta) value:#bottom]. |
|
879 |
h ifTrue:[aBlock value:(aView rightCenter + dlta) value:#right ]. |
|
880 |
||
881 |
(h and:[v]) ifTrue:[ |
|
882 |
aBlock value:(aView corner + dlta) value:#corner. |
|
883 |
^ self |
|
884 |
] |
|
60 | 885 |
]. |
61 | 886 |
aBlock value:(aView corner + dlta) value:#view. |
60 | 887 |
! |
888 |
||
889 |
showSelected:aComponent |
|
61 | 890 |
"show object selected |
891 |
" |
|
132 | 892 |
|wasClipped delta| |
60 | 893 |
|
894 |
self paint:Color black. |
|
895 |
||
896 |
(wasClipped := clipChildren) ifTrue:[ |
|
897 |
self clippedByChildren:(clipChildren := false). |
|
898 |
]. |
|
899 |
||
900 |
self handlesOf:aComponent do:[:pnt :what | |
|
901 |
what == #view ifTrue:[self displayRectangle:(pnt - (4@4) extent:7@7)] |
|
902 |
ifFalse:[self fillRectangle:(pnt - (4@4) extent:7@7)] |
|
903 |
]. |
|
904 |
||
905 |
wasClipped ifTrue:[ |
|
906 |
self clippedByChildren:(clipChildren := true). |
|
907 |
]. |
|
132 | 908 |
|
60 | 909 |
! |
910 |
||
911 |
showUnselected:aComponent |
|
61 | 912 |
"show object unselected |
913 |
" |
|
132 | 914 |
|wasClipped delta r| |
60 | 915 |
|
916 |
(wasClipped := clipChildren) ifTrue:[ |
|
917 |
self clippedByChildren:(clipChildren := false). |
|
918 |
]. |
|
919 |
||
920 |
self handlesOf:aComponent do:[:pnt :what | |
|
921 |
self clearRectangle:(pnt - (4@4) extent:7@7). |
|
922 |
]. |
|
923 |
||
924 |
wasClipped ifTrue:[ |
|
925 |
self clippedByChildren:(clipChildren := true). |
|
926 |
]. |
|
927 |
||
928 |
"/ must redraw all components which are affected b the handles |
|
929 |
||
930 |
r := (aComponent originRelativeTo:self) - (4@4) |
|
931 |
extent:(aComponent extent + (4@4)). |
|
932 |
||
933 |
subViews do:[:anotherComponent | |
|
934 |
|absOrg absFrame| |
|
935 |
||
936 |
anotherComponent ~~ inputView ifTrue:[ |
|
937 |
absOrg := anotherComponent originRelativeTo:self. |
|
938 |
absFrame := absOrg extent:(anotherComponent extent). |
|
939 |
(absFrame intersects:r) ifTrue:[ |
|
940 |
anotherComponent withAllSubViewsDo:[:v | |
|
95 | 941 |
v shown ifTrue:[ |
132 | 942 |
v fill:v viewBackground. |
95 | 943 |
v exposeX:0 y:0 width:9999 height:9999. |
944 |
] |
|
60 | 945 |
] |
946 |
] |
|
947 |
] |
|
948 |
] |
|
949 |
||
95 | 950 |
"Modified: 8.4.1997 / 00:32:26 / cg" |
60 | 951 |
! |
952 |
||
953 |
whichHandleOf:aView isHitBy:aPoint |
|
61 | 954 |
"returns kind of handle or nil |
955 |
" |
|
60 | 956 |
|bounds| |
957 |
||
958 |
self handlesOf:aView do:[:pnt :what | |
|
959 |
((pnt - (4@4) extent:7@7) containsPoint:aPoint) ifTrue:[ |
|
960 |
^ what |
|
961 |
]. |
|
962 |
]. |
|
963 |
||
964 |
^ nil |
|
965 |
||
966 |
"Modified: 5.9.1995 / 14:39:34 / claus" |
|
967 |
||
968 |
! ! |
|
969 |
||
970 |
!UIObjectView methodsFor:'private resizing-subviews'! |
|
971 |
||
972 |
resize:aView bottom:aPoint |
|
61 | 973 |
"resize a views bottom |
974 |
" |
|
60 | 975 |
undoHistory disabledTransitionDo:[ |
976 |
self shiftLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y)) |
|
977 |
] |
|
978 |
! |
|
979 |
||
980 |
resize:aView bottomLeft:aPoint |
|
61 | 981 |
"resize a views bottom and left |
982 |
" |
|
60 | 983 |
undoHistory disabledTransitionDo:[ |
984 |
self shiftLayout:aView top:0 |
|
985 |
bottom:((aPoint y) - (aView computeCorner y)) |
|
986 |
left:((aPoint x) - (aView computeOrigin x)) |
|
987 |
right:0 |
|
988 |
||
989 |
] |
|
990 |
||
991 |
||
992 |
! |
|
993 |
||
994 |
resize:aView corner:aPoint |
|
61 | 995 |
"resize a views corner |
996 |
" |
|
60 | 997 |
|delta| |
998 |
||
999 |
delta := aPoint - aView computeCorner. |
|
1000 |
||
1001 |
undoHistory disabledTransitionDo:[ |
|
1002 |
self shiftLayout:aView top:0 bottom:(delta y) left:0 right:(delta x) |
|
1003 |
] |
|
1004 |
! |
|
1005 |
||
1006 |
resize:aView left:aPoint |
|
61 | 1007 |
"resize a views left |
1008 |
" |
|
60 | 1009 |
undoHistory disabledTransitionDo:[ |
1010 |
self shiftLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0 |
|
1011 |
] |
|
1012 |
||
1013 |
! |
|
1014 |
||
1015 |
resize:aView origin:aPoint |
|
61 | 1016 |
"resize a views origin |
1017 |
" |
|
60 | 1018 |
|delta| |
1019 |
||
1020 |
delta := aPoint - aView computeOrigin. |
|
1021 |
||
1022 |
undoHistory disabledTransitionDo:[ |
|
1023 |
self shiftLayout:aView top:(delta y) bottom:0 left:(delta x) right:0 |
|
1024 |
] |
|
1025 |
||
1026 |
! |
|
1027 |
||
1028 |
resize:aView right:aPoint |
|
61 | 1029 |
"resize a views right |
1030 |
" |
|
60 | 1031 |
undoHistory disabledTransitionDo:[ |
1032 |
self shiftLayout:aView left:0 right:((aPoint x) - (aView computeCorner x)) |
|
1033 |
] |
|
1034 |
! |
|
1035 |
||
1036 |
resize:aView top:aPoint |
|
61 | 1037 |
"resize a views top |
1038 |
" |
|
60 | 1039 |
undoHistory disabledTransitionDo:[ |
1040 |
self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0 |
|
1041 |
] |
|
1042 |
! |
|
1043 |
||
1044 |
resize:aView topRight:aPoint |
|
61 | 1045 |
"resize a views top and right |
1046 |
" |
|
60 | 1047 |
undoHistory disabledTransitionDo:[ |
1048 |
self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) |
|
1049 |
bottom:0 |
|
1050 |
left:0 |
|
1051 |
right:((aPoint x) - (aView computeCorner x)) |
|
1052 |
||
1053 |
] |
|
1054 |
||
1055 |
! ! |
|
1056 |
||
1057 |
!UIObjectView methodsFor:'private shift-layout'! |
|
1058 |
||
1059 |
shiftLayout:aView left:l right:r |
|
1060 |
"shift layout for a view; in case of an open transaction, the undo |
|
1061 |
action is registered |
|
1062 |
" |
|
1063 |
self shiftLayout:aView top:0 bottom:0 left:l right:r |
|
1064 |
||
1065 |
! |
|
1066 |
||
1067 |
shiftLayout:aView top:t bottom:b |
|
1068 |
"shift layout for a view; in case of an open transaction, the undo |
|
1069 |
action is registered |
|
1070 |
" |
|
1071 |
self shiftLayout:aView top:t bottom:b left:0 right:0 |
|
1072 |
||
1073 |
||
1074 |
! |
|
1075 |
||
1076 |
shiftLayout:aView top:t bottom:b left:l right:r |
|
1077 |
"shift layout for a view; in case of an open transaction, the undo |
|
1078 |
action is registered |
|
1079 |
" |
|
79 | 1080 |
|type layout oldExt| |
61 | 1081 |
|
1082 |
type := self class layoutType:aView. |
|
1083 |
||
1084 |
type notNil ifTrue:[ |
|
1085 |
self undoLayoutView:aView. |
|
1086 |
||
1087 |
type == #Extent ifTrue:[ |
|
79 | 1088 |
oldExt := aView extent. |
1089 |
aView extent:(oldExt + ((r-l) @ (b-t))). |
|
1090 |
^ self |
|
60 | 1091 |
]. |
61 | 1092 |
|
78 | 1093 |
layout := aView geometryLayout copy. |
61 | 1094 |
|
1095 |
layout isLayout ifTrue:[ |
|
1096 |
layout leftOffset:(layout leftOffset + l) |
|
1097 |
topOffset:(layout topOffset + t). |
|
1098 |
||
1099 |
type == #LayoutFrame ifTrue:[ |
|
1100 |
layout bottomOffset:(layout bottomOffset + b). |
|
1101 |
layout rightOffset:(layout rightOffset + r). |
|
1102 |
] |
|
1103 |
] ifFalse:[ |
|
1104 |
type == #Rectangle ifTrue:[ |
|
1105 |
layout left:(layout left + l) |
|
1106 |
right:(layout right + r) |
|
1107 |
top:(layout top + t) |
|
1108 |
bottom:(layout bottom + b). |
|
1109 |
] ifFalse:[ "POINT" |
|
1110 |
layout x:(layout x + l) y:(layout y + t). |
|
1111 |
] |
|
1112 |
]. |
|
1113 |
aView geometryLayout:layout |
|
60 | 1114 |
] |
1115 |
! ! |
|
1116 |
||
1117 |
!UIObjectView methodsFor:'searching'! |
|
1118 |
||
89 | 1119 |
findContainerViewAt:aPoint |
1120 |
"find container view responds to aPoint. |
|
1121 |
" |
|
1122 |
^ self subclassResponsibility |
|
1123 |
||
1124 |
||
1125 |
! |
|
1126 |
||
60 | 1127 |
findObjectAt:aPoint |
1128 |
"find the origin/corner of the currentWidget |
|
1129 |
" |
|
1130 |
|view viewId lastId point listOfViews| |
|
1131 |
||
1132 |
viewId := rootView id. |
|
1133 |
point := aPoint + (device translatePoint:0@0 from:(self id) to:viewId). |
|
1134 |
||
1135 |
inputView lower. |
|
1136 |
||
1137 |
[viewId notNil] whileTrue:[ |
|
1138 |
lastId := viewId. |
|
1139 |
viewId := device viewIdFromPoint:point in:lastId |
|
1140 |
]. |
|
1141 |
||
1142 |
inputView raise. |
|
1143 |
||
1144 |
view := device viewFromId:lastId. |
|
1145 |
||
1146 |
view ~~ inputView ifTrue:[^ view]. |
|
1147 |
||
1148 |
"/ look for 'hidden' views ... |
|
1149 |
||
1150 |
listOfViews := OrderedCollection new. |
|
1151 |
self allSubViewsDo:[:aView | |
|
1152 |
|org| |
|
1153 |
||
1154 |
aView ~~ inputView ifTrue:[ |
|
1155 |
org := device translatePoint:0@0 from:(aView id) to:self id. |
|
1156 |
((org extent:aView extent) containsPoint:aPoint) ifTrue:[ |
|
1157 |
listOfViews add:aView. |
|
1158 |
] |
|
1159 |
] |
|
1160 |
]. |
|
1161 |
||
1162 |
listOfViews size > 0 ifTrue:[ |
|
1163 |
^ listOfViews last |
|
1164 |
]. |
|
1165 |
^ nil |
|
1166 |
||
1167 |
||
1168 |
! |
|
1169 |
||
1170 |
isPoint:aPoint containedIn:aView |
|
1171 |
"checks whether a point is covered by a view. |
|
1172 |
" |
|
1173 |
|p| |
|
1174 |
||
1175 |
p := device translatePoint:aPoint from:inputView id to:aView id. |
|
1176 |
||
1177 |
(p x >= 0 and:[p y >= 0]) ifTrue:[ |
|
1178 |
p := aView extent - p. |
|
1179 |
||
1180 |
(p x >= 0 and:[p y >= 0]) ifTrue:[ |
|
1181 |
^ true |
|
1182 |
] |
|
1183 |
]. |
|
1184 |
^ false |
|
1185 |
! |
|
1186 |
||
1187 |
whichBorderOf:aView isHitBy:aPoint |
|
1188 |
|p r bw org| |
|
1189 |
||
1190 |
bw := aView borderWidth. |
|
1191 |
p := aPoint - (aView superView originRelativeTo:self). |
|
1192 |
||
1193 |
r := Rectangle origin:(aView origin) |
|
1194 |
extent:(aView width @ bw). |
|
1195 |
(r containsPoint:p) ifTrue:[^ #top:]. |
|
1196 |
||
1197 |
r origin:(aView left @ (aView bottom + bw)) extent:(aView width @ bw). |
|
1198 |
(r containsPoint:p) ifTrue:[^ #bottom:]. |
|
1199 |
||
1200 |
r top:(aView top). |
|
1201 |
r extent:(bw @ aView height). |
|
1202 |
(r containsPoint:p) ifTrue:[^ #left:]. |
|
1203 |
||
1204 |
r origin:((aView right + bw) @ aView top). |
|
1205 |
(r containsPoint:p) ifTrue:[^ #right:]. |
|
1206 |
||
1207 |
^ nil |
|
1208 |
||
1209 |
||
1210 |
! ! |
|
1211 |
||
1212 |
!UIObjectView methodsFor:'selections'! |
|
1213 |
||
128 | 1214 |
moveableSelection |
131 | 1215 |
"checks whether the selection is not empty and all selected instances |
1216 |
can be moved. If true the selection is returned otherwise nil |
|
128 | 1217 |
" |
1218 |
|coll| |
|
1219 |
||
1220 |
self hasSelection ifTrue:[ |
|
1221 |
(self canMove:(coll := self selection)) ifTrue:[ |
|
1222 |
^ coll |
|
1223 |
] |
|
1224 |
]. |
|
1225 |
^ nil |
|
1226 |
! |
|
1227 |
||
60 | 1228 |
numberOfSelections |
131 | 1229 |
"return the number of selected instances |
61 | 1230 |
" |
128 | 1231 |
|coll size| |
1232 |
||
1233 |
coll := self selection. |
|
1234 |
size := coll size. |
|
1235 |
||
1236 |
(size ~~ 0 or:[coll isNil]) ifTrue:[^ size]. |
|
1237 |
^ 1 |
|
60 | 1238 |
! |
1239 |
||
1240 |
select:something |
|
61 | 1241 |
"change selection to something |
1242 |
" |
|
128 | 1243 |
(self enabled and:[something ~= self selection]) ifTrue:[ |
1244 |
self setSelection:something withRedraw:true. |
|
113 | 1245 |
self selectionChanged |
60 | 1246 |
] |
1247 |
||
113 | 1248 |
|
1249 |
||
60 | 1250 |
! |
1251 |
||
113 | 1252 |
selectionChanged |
1253 |
"called whenever the selection changed |
|
1254 |
" |
|
1255 |
self subclassResponsibility |
|
1256 |
||
1257 |
! |
|
1258 |
||
128 | 1259 |
selectionDo:aBlock |
1260 |
"apply block to every selected object |
|
1261 |
" |
|
1262 |
self forEach:(self selection) do:aBlock |
|
1263 |
||
1264 |
||
1265 |
! |
|
1266 |
||
61 | 1267 |
showSelection |
128 | 1268 |
"show the selection - draw handles |
1269 |
" |
|
61 | 1270 |
selectionHiddenLevel == 0 ifTrue:[ |
128 | 1271 |
self selectionDo:[:el| self showSelected:el ] |
60 | 1272 |
]. |
1273 |
! |
|
1274 |
||
1275 |
singleSelection |
|
131 | 1276 |
"checks whether one element is selected; in this case the element is |
1277 |
returned otherwise nil |
|
60 | 1278 |
" |
128 | 1279 |
|coll| |
1280 |
||
1281 |
(coll := self selection) isCollection ifFalse:[ |
|
1282 |
^ coll |
|
60 | 1283 |
]. |
128 | 1284 |
|
1285 |
coll size == 1 ifTrue:[ ^ coll first]. |
|
1286 |
^ nil |
|
60 | 1287 |
! |
1288 |
||
1289 |
singleSelectionDo:aBlock |
|
131 | 1290 |
"checks whether one element is selected; in this case the block |
1291 |
with argument the selected instance will be processed |
|
61 | 1292 |
" |
60 | 1293 |
|view| |
1294 |
||
1295 |
(view := self singleSelection) notNil ifTrue:[ |
|
1296 |
aBlock value:view |
|
1297 |
] |
|
1298 |
! |
|
1299 |
||
1300 |
unselect |
|
61 | 1301 |
"clear selection |
1302 |
" |
|
128 | 1303 |
self select:nil |
60 | 1304 |
! |
1305 |
||
1306 |
withSelectionHiddenDo:aBlock |
|
61 | 1307 |
"apply block with selection hidden (no handles) |
1308 |
" |
|
78 | 1309 |
|coll| |
1310 |
||
61 | 1311 |
selectionHiddenLevel := selectionHiddenLevel + 1. |
1312 |
||
1313 |
selectionHiddenLevel == 1 ifTrue:[ |
|
1314 |
self selectionDo:[:aView| self showUnselected:aView]. |
|
1315 |
device flush. |
|
1316 |
]. |
|
1317 |
||
1318 |
aBlock valueNowOrOnUnwindDo:[ |
|
1319 |
selectionHiddenLevel == 1 ifTrue:[ |
|
1320 |
setOfSuperViewsSizeChanged notEmpty ifTrue:[ |
|
78 | 1321 |
coll := self minSetOfSuperViews:setOfSuperViewsSizeChanged. |
1322 |
coll do:[:aView| aView sizeChanged:nil]. |
|
61 | 1323 |
setOfSuperViewsSizeChanged := IdentitySet new |
1324 |
]. |
|
1325 |
self selectionDo:[:aView| self showSelected:aView]. |
|
1326 |
]. |
|
1327 |
selectionHiddenLevel := selectionHiddenLevel - 1. |
|
1328 |
] |
|
1329 |
||
1330 |
! |
|
1331 |
||
1332 |
withoutSelectionDo:aBlock |
|
1333 |
"evaluate aBlock while selection is nilled |
|
1334 |
" |
|
60 | 1335 |
|sel| |
1336 |
||
128 | 1337 |
self hasSelection ifFalse:[ |
60 | 1338 |
aBlock value |
128 | 1339 |
] ifTrue:[ |
1340 |
sel := self selection. |
|
1341 |
self setSelection:nil withRedraw:true. |
|
60 | 1342 |
aBlock value. |
128 | 1343 |
self setSelection:sel withRedraw:true. |
60 | 1344 |
] |
1345 |
||
1346 |
||
1347 |
! ! |
|
1348 |
||
131 | 1349 |
!UIObjectView methodsFor:'selections basic'! |
1350 |
||
1351 |
addToSelection:anObject |
|
1352 |
"add an object to the selection |
|
1353 |
" |
|
1354 |
(self enabled and:[(self isSelected:anObject) not]) ifTrue:[ |
|
1355 |
selection isCollection ifFalse:[ |
|
1356 |
selection isNil ifTrue:[ |
|
1357 |
selection := anObject |
|
1358 |
] ifFalse:[ |
|
1359 |
selection := OrderedCollection with:selection with:anObject |
|
1360 |
] |
|
1361 |
] ifTrue:[ |
|
1362 |
selection add:anObject |
|
1363 |
]. |
|
1364 |
self showSelected:anObject. |
|
1365 |
self selectionChanged. |
|
1366 |
] |
|
1367 |
! |
|
1368 |
||
1369 |
removeFromSelection:anObject |
|
1370 |
"remove an object from the selection |
|
1371 |
" |
|
1372 |
(self isSelected:anObject) ifTrue:[ |
|
1373 |
self showUnselected:anObject. |
|
1374 |
||
1375 |
selection size > 1 ifTrue:[ |
|
1376 |
selection remove:anObject ifAbsent:nil. |
|
1377 |
self showSelection. |
|
1378 |
] ifFalse:[ |
|
1379 |
selection := nil |
|
1380 |
]. |
|
1381 |
self selectionChanged. |
|
1382 |
] |
|
1383 |
! |
|
1384 |
||
1385 |
selection |
|
1386 |
"returns the current selection |
|
1387 |
" |
|
1388 |
^ selection |
|
1389 |
||
1390 |
||
1391 |
! |
|
1392 |
||
1393 |
setSelection:aNewSelection withRedraw:doRedraw |
|
1394 |
"set a new selection without change notifications |
|
1395 |
" |
|
1396 |
doRedraw ifTrue:[ |
|
1397 |
self hideSelection. |
|
1398 |
selection := aNewSelection. |
|
1399 |
self showSelection |
|
1400 |
] ifFalse:[ |
|
1401 |
selection := aNewSelection |
|
1402 |
] |
|
1403 |
! ! |
|
1404 |
||
60 | 1405 |
!UIObjectView methodsFor:'testing'! |
1406 |
||
1407 |
canMove:something |
|
61 | 1408 |
"returns always true; all contained views can be moved |
1409 |
" |
|
1410 |
|sv| |
|
1411 |
||
1412 |
something notNil ifTrue:[ |
|
1413 |
self forEach:something do:[:v| |
|
1414 |
sv ~~ v superView ifTrue:[ |
|
1415 |
(sv notNil or:[v superView specClass isLayoutContainer]) ifTrue:[ |
|
1416 |
^ false |
|
1417 |
]. |
|
1418 |
sv := v superView |
|
1419 |
] |
|
1420 |
]. |
|
1421 |
^ true |
|
1422 |
]. |
|
1423 |
^ false |
|
60 | 1424 |
|
1425 |
! |
|
1426 |
||
1427 |
canPaste:something |
|
1428 |
"returns true if something could be paste |
|
1429 |
" |
|
1430 |
something notNil ifTrue:[ |
|
1431 |
something isCollection ifTrue:[ |
|
1432 |
something notEmpty ifTrue:[ |
|
1433 |
^ (something at:1) isKindOf:UISpecification |
|
1434 |
] |
|
1435 |
] ifFalse:[ |
|
1436 |
^ something isKindOf:UISpecification |
|
1437 |
] |
|
1438 |
]. |
|
1439 |
^ false |
|
1440 |
||
1441 |
! |
|
1442 |
||
61 | 1443 |
canPasteInto:something |
1444 |
"can paste into something ? |
|
1445 |
" |
|
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1446 |
|
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1447 |
|theView theSpec| |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1448 |
|
61 | 1449 |
something notNil ifTrue:[ |
1450 |
something isCollection ifFalse:[ |
|
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1451 |
theView := something |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1452 |
] ifTrue:[ |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1453 |
something size == 1 ifTrue:[ |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1454 |
theView := (something at:1) |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1455 |
] |
61 | 1456 |
]. |
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1457 |
theView notNil ifTrue:[ |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1458 |
theSpec := self specFor:theView. |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1459 |
theSpec isNil ifTrue:[ |
99 | 1460 |
^ theView specClass supportsSubComponents |
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1461 |
]. |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1462 |
^ theSpec class supportsSubComponents |
61 | 1463 |
] |
1464 |
]. |
|
1465 |
^ false |
|
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1466 |
|
99 | 1467 |
"Modified: 8.4.1997 / 01:19:14 / cg" |
61 | 1468 |
! |
1469 |
||
128 | 1470 |
hasSelection |
1471 |
"returns true if any selected object exists |
|
61 | 1472 |
" |
128 | 1473 |
^ self numberOfSelections ~~ 0 |
60 | 1474 |
|
1475 |
! |
|
1476 |
||
1477 |
hasUndos |
|
1478 |
"returns true if undoHistory not empty |
|
1479 |
" |
|
1480 |
^ undoHistory notEmpty |
|
1481 |
! |
|
1482 |
||
1483 |
isHorizontalResizable:aComponent |
|
61 | 1484 |
"returns true if instance is horizontal resizeable |
1485 |
" |
|
60 | 1486 |
^ self subclassResponsibility |
1487 |
||
1488 |
||
1489 |
! |
|
1490 |
||
128 | 1491 |
isSelected:anObject |
1492 |
"return true, if the argument, anObject is selected |
|
1493 |
" |
|
1494 |
anObject notNil ifTrue:[ |
|
1495 |
self selectionDo:[:el| el == anObject ifTrue:[^ true]] |
|
1496 |
]. |
|
1497 |
^ false |
|
1498 |
||
1499 |
! |
|
1500 |
||
60 | 1501 |
isVerticalResizable:aComponent |
61 | 1502 |
"returns true if instance is vertical resizeable |
60 | 1503 |
" |
61 | 1504 |
^ self subclassResponsibility |
1505 |
||
1506 |
||
82 | 1507 |
! |
1508 |
||
1509 |
supportsLabel:aComponent |
|
1510 |
"returns true if component supports label |
|
1511 |
" |
|
1512 |
^ self subclassResponsibility |
|
1513 |
||
1514 |
||
60 | 1515 |
! ! |
1516 |
||
1517 |
!UIObjectView methodsFor:'transaction'! |
|
1518 |
||
1519 |
transaction:aType objects:something do:aOneArgBlock |
|
1520 |
"opens a transaction and evaluates a block within the transaction; the |
|
1521 |
argument to the block is a view from derived from something |
|
1522 |
" |
|
1523 |
self subclassResponsibility |
|
1524 |
||
1525 |
||
1526 |
! |
|
1527 |
||
1528 |
transaction:aType selectionDo:aOneArgBlock |
|
1529 |
"opens a transaction and evaluates a block within the transaction; the |
|
1530 |
argument to the block is a view from the selection |
|
1531 |
" |
|
128 | 1532 |
self transaction:aType objects:(self selection) do:aOneArgBlock |
60 | 1533 |
|
1534 |
||
1535 |
! |
|
1536 |
||
1537 |
undoLayoutView:aView |
|
1538 |
"prepare undo action for a view changing its layout |
|
1539 |
" |
|
1540 |
self subclassResponsibility |
|
1541 |
||
1542 |
! ! |
|
1543 |
||
1544 |
!UIObjectView methodsFor:'user actions - arrange'! |
|
1545 |
||
1546 |
lowerSelection |
|
61 | 1547 |
"lower all objects in the selection |
1548 |
" |
|
60 | 1549 |
self selectionDo:[:aView| aView lower ]. |
1550 |
||
1551 |
||
1552 |
! |
|
1553 |
||
1554 |
raiseSelection |
|
61 | 1555 |
"raise all objects in the selection |
1556 |
" |
|
60 | 1557 |
self selectionDo:[:aView| aView raise ]. |
1558 |
inputView raise. |
|
1559 |
||
1560 |
||
1561 |
! ! |
|
1562 |
||
1563 |
!UIObjectView methodsFor:'user actions - dimension'! |
|
1564 |
||
1565 |
copyExtent |
|
61 | 1566 |
"copy the extent from the selected object |
1567 |
" |
|
60 | 1568 |
|object| |
1569 |
||
1570 |
object := self singleSelection. |
|
1571 |
||
1572 |
object notNil ifTrue:[ |
|
1573 |
copiedExtent := object computeExtent |
|
1574 |
] ifFalse:[ |
|
1575 |
self warn:'exactly one element must be selected'. |
|
1576 |
] |
|
1577 |
||
1578 |
||
1579 |
||
1580 |
! |
|
1581 |
||
89 | 1582 |
copyLayout |
1583 |
"copy the layout from the selected object |
|
1584 |
" |
|
1585 |
|object| |
|
1586 |
||
1587 |
object := self singleSelection. |
|
1588 |
||
1589 |
object notNil ifTrue:[ |
|
1590 |
copiedLayout := object geometryLayout copy |
|
1591 |
] ifFalse:[ |
|
1592 |
self warn:'exactly one element must be selected'. |
|
1593 |
] |
|
1594 |
||
1595 |
||
1596 |
||
1597 |
! |
|
1598 |
||
60 | 1599 |
pasteExtent |
61 | 1600 |
"paste the copied extent to all objects in the selection |
1601 |
" |
|
60 | 1602 |
copiedExtent notNil ifTrue:[ |
72 | 1603 |
self transition:#pasteExtent dimensionDo:[:v| |
60 | 1604 |
self resize:v corner:(v computeOrigin + copiedExtent) |
1605 |
] |
|
1606 |
] |
|
1607 |
! |
|
1608 |
||
1609 |
pasteHeight |
|
61 | 1610 |
"paste the copied extent height to all objects in the selection |
1611 |
" |
|
60 | 1612 |
copiedExtent notNil ifTrue:[ |
72 | 1613 |
self transition:#pasteHeight dimensionDo:[:v| |
60 | 1614 |
self resize:v bottom:(v computeOrigin + copiedExtent) |
1615 |
] |
|
1616 |
] |
|
1617 |
||
1618 |
! |
|
1619 |
||
89 | 1620 |
pasteLayout |
1621 |
"paste layout to all objects in the selection |
|
1622 |
" |
|
1623 |
copiedLayout notNil ifTrue:[ |
|
1624 |
self transition:#pasteLayout dimensionDo:[:v| |
|
1625 |
v geometryLayout:(copiedLayout copy) |
|
1626 |
] |
|
1627 |
] |
|
1628 |
! |
|
1629 |
||
60 | 1630 |
pasteWidth |
61 | 1631 |
"paste the copied extent width to all objects in the selection |
1632 |
" |
|
60 | 1633 |
copiedExtent notNil ifTrue:[ |
72 | 1634 |
self transition:#pasteWidth dimensionDo:[:v| |
60 | 1635 |
self resize:v right:(v computeOrigin + copiedExtent) |
1636 |
] |
|
1637 |
] |
|
1638 |
||
1639 |
! |
|
1640 |
||
1641 |
setDimension:aLayout |
|
61 | 1642 |
"change layout for all selected objects |
1643 |
" |
|
1644 |
self transition:#layout dimensionDo:[:v| |
|
1645 |
v geometryLayout:(aLayout copy) |
|
1646 |
]. |
|
1647 |
||
1648 |
! |
|
1649 |
||
1650 |
setExtent:anExtent |
|
1651 |
"change extent for all selected objects |
|
1652 |
" |
|
72 | 1653 |
self transition:#extent dimensionDo:[:v| |
67 | 1654 |
v geometryLayout:nil. |
61 | 1655 |
v extent:anExtent. |
67 | 1656 |
]. |
1657 |
||
1658 |
"Modified: 28.2.1997 / 12:49:00 / cg" |
|
60 | 1659 |
! |
1660 |
||
1661 |
setToDefaultExtent |
|
61 | 1662 |
"change extent of all selected views to their default extent |
1663 |
" |
|
72 | 1664 |
self transition:#defaultExtent dimensionDo:[:v| |
60 | 1665 |
self resize:v corner:(v computeOrigin + (v preferredExtent)) |
1666 |
] |
|
1667 |
||
1668 |
! |
|
1669 |
||
1670 |
setToDefaultHeight |
|
61 | 1671 |
"change height of all selected views to their default height |
1672 |
" |
|
72 | 1673 |
self transition:#defaultHeight dimensionDo:[:v| |
60 | 1674 |
self resize:v bottom:(v computeOrigin + (v preferredExtent)) |
1675 |
] |
|
1676 |
||
1677 |
! |
|
1678 |
||
1679 |
setToDefaultWidth |
|
61 | 1680 |
"change width of all selected views to their default width |
1681 |
" |
|
72 | 1682 |
self transition:#defaultWidth dimensionDo:[:v| |
60 | 1683 |
self resize:v right:(v computeOrigin + (v preferredExtent)) |
1684 |
] |
|
1685 |
||
1686 |
! |
|
1687 |
||
1688 |
transition:aType dimensionDo:aOneArgBlock |
|
1689 |
"change dimension within a transaction for the selected elements by evaluating |
|
1690 |
the block with the argument a view. |
|
1691 |
" |
|
61 | 1692 |
self withSelectionHiddenDo:[ |
60 | 1693 |
self transaction:aType selectionDo:[:aView| |
61 | 1694 |
(self class layoutType:aView) notNil ifTrue:[ |
1695 |
self undoLayoutView:aView. |
|
1696 |
aOneArgBlock value:aView. |
|
1697 |
self elementChangedSize:aView. |
|
1698 |
] |
|
1699 |
] |
|
1700 |
]. |
|
1701 |
self changed:#layout |
|
1702 |
||
60 | 1703 |
! ! |
1704 |
||
1705 |
!UIObjectView methodsFor:'user actions - move'! |
|
1706 |
||
113 | 1707 |
moveSelectionDown |
61 | 1708 |
"move selection down |
1709 |
" |
|
128 | 1710 |
|gridY n sel| |
1711 |
||
1712 |
self moveableSelection notNil ifTrue:[ |
|
61 | 1713 |
gridAlign notNil ifTrue:[gridY := gridAlign y]. |
1714 |
||
1715 |
self withSelectionHiddenDo:[ |
|
113 | 1716 |
self selectionDo:[:aView| |
61 | 1717 |
aligning ifTrue:[ |
113 | 1718 |
n := ((aView computeCorner y) \\ gridY). |
1719 |
||
1720 |
n ~~ 0 ifTrue:[ |
|
1721 |
n := gridY - n + 1. |
|
1722 |
] ifFalse:[ |
|
1723 |
n := gridY |
|
61 | 1724 |
] |
113 | 1725 |
] ifFalse:[ |
1726 |
n := 1 |
|
61 | 1727 |
]. |
1728 |
self shiftLayout:aView top:n bottom:n |
|
1729 |
] |
|
60 | 1730 |
]. |
1731 |
self changed:#layout |
|
1732 |
] |
|
1733 |
||
1734 |
! |
|
1735 |
||
113 | 1736 |
moveSelectionLeft |
60 | 1737 |
"move selection left |
1738 |
" |
|
113 | 1739 |
|gridX n| |
60 | 1740 |
|
128 | 1741 |
self moveableSelection notNil ifTrue:[ |
61 | 1742 |
gridAlign notNil ifTrue:[gridX := gridAlign x]. |
1743 |
||
1744 |
self withSelectionHiddenDo:[ |
|
113 | 1745 |
self selectionDo:[:aView| |
61 | 1746 |
aligning ifTrue:[ |
113 | 1747 |
n := ((aView computeOrigin x) \\ gridX). |
1748 |
n == 0 ifTrue:[n := gridX]. |
|
1749 |
n := n negated. |
|
1750 |
] ifFalse:[ |
|
1751 |
n := -1 |
|
61 | 1752 |
]. |
1753 |
self shiftLayout:aView left:n right:n |
|
1754 |
] |
|
60 | 1755 |
]. |
1756 |
self changed:#layout |
|
1757 |
] |
|
1758 |
! |
|
1759 |
||
113 | 1760 |
moveSelectionRight |
1761 |
"move selection right |
|
1762 |
" |
|
1763 |
|gridX n| |
|
1764 |
||
128 | 1765 |
self moveableSelection notNil ifTrue:[ |
113 | 1766 |
gridAlign notNil ifTrue:[gridX := gridAlign x]. |
1767 |
||
1768 |
self withSelectionHiddenDo:[ |
|
1769 |
self selectionDo:[:aView| |
|
1770 |
aligning ifTrue:[ |
|
1771 |
n := ((aView computeCorner x) \\ gridX). |
|
1772 |
||
1773 |
n ~~ 0 ifTrue:[n := n negated] |
|
1774 |
ifFalse:[n := gridX] |
|
1775 |
] ifFalse:[ |
|
1776 |
n := 1 |
|
1777 |
]. |
|
1778 |
self shiftLayout:aView left:n right:n |
|
1779 |
] |
|
1780 |
]. |
|
1781 |
self changed:#layout |
|
1782 |
] |
|
1783 |
! |
|
1784 |
||
1785 |
moveSelectionUp |
|
60 | 1786 |
"move selection up |
1787 |
" |
|
113 | 1788 |
|gridY n| |
60 | 1789 |
|
128 | 1790 |
self moveableSelection notNil ifTrue:[ |
61 | 1791 |
gridAlign notNil ifTrue:[gridY := gridAlign y]. |
1792 |
||
1793 |
self withSelectionHiddenDo:[ |
|
113 | 1794 |
self selectionDo:[:aView| |
61 | 1795 |
aligning ifTrue:[ |
113 | 1796 |
n := ((aView computeOrigin x) \\ gridY). |
1797 |
n == 0 ifTrue:[n := gridY]. |
|
1798 |
n := n negated. |
|
1799 |
] ifFalse:[ |
|
1800 |
n := -1 |
|
60 | 1801 |
]. |
61 | 1802 |
self shiftLayout:aView top:n bottom:n |
1803 |
] |
|
60 | 1804 |
]. |
1805 |
self changed:#layout |
|
1806 |
] |
|
1807 |
||
1808 |
! ! |
|
1809 |
||
1810 |
!UIObjectView methodsFor:'user actions - position'! |
|
1811 |
||
1812 |
alignSelectionBottom |
|
61 | 1813 |
"align selection to the bottom of the first object in the selection; in case |
1814 |
of one selection the object is aligned to the bottom of its superview |
|
1815 |
" |
|
128 | 1816 |
|bmost delta sel| |
1817 |
||
1818 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1819 |
self withSelectionHiddenDo:[ |
60 | 1820 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1821 |
bmost := (sel first) computeCorner y. |
60 | 1822 |
|
72 | 1823 |
self transaction:#alignBottom selectionDo:[:v| |
60 | 1824 |
(delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[ |
1825 |
self shiftLayout:v top:delta bottom:delta. |
|
1826 |
] |
|
1827 |
] |
|
1828 |
] ifFalse:[ |
|
72 | 1829 |
self extentToFrame:#Bottom do:[:aLayout| |
63 | 1830 |
aLayout bottomOffset:0. |
1831 |
aLayout bottomFraction:1.0 |
|
60 | 1832 |
] |
1833 |
] |
|
1834 |
]. |
|
1835 |
self changed:#layout |
|
1836 |
] |
|
1837 |
||
1838 |
||
1839 |
||
1840 |
! |
|
1841 |
||
1842 |
alignSelectionCenterHor |
|
61 | 1843 |
"align selection to the center/horizontal of the first object in the selection; in case |
1844 |
of one selection the object is aligned to the center/horizontal of its superview |
|
1845 |
" |
|
128 | 1846 |
|view center sel| |
1847 |
||
1848 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1849 |
self withSelectionHiddenDo:[ |
60 | 1850 |
view := self singleSelection. |
1851 |
||
1852 |
view notNil ifTrue:[ |
|
1853 |
view := view superView. |
|
1854 |
center := view computeExtent |
|
1855 |
] ifFalse:[ |
|
128 | 1856 |
view := sel first. |
60 | 1857 |
center := view computeCorner + view computeOrigin. |
1858 |
]. |
|
1859 |
center := center x // 2. |
|
1860 |
||
72 | 1861 |
self transaction:#alignCenterHorizontal selectionDo:[:v| |
60 | 1862 |
|newX oldX delta| |
1863 |
||
1864 |
oldX := v computeOrigin x. |
|
1865 |
newX := center - ((v computeCorner x - oldX) // 2). |
|
1866 |
delta := newX - oldX. |
|
1867 |
||
1868 |
self shiftLayout:v left:delta right:delta |
|
61 | 1869 |
] |
1870 |
]. |
|
1871 |
self changed:#layout |
|
60 | 1872 |
] |
1873 |
||
1874 |
||
1875 |
||
1876 |
! |
|
1877 |
||
1878 |
alignSelectionCenterVer |
|
61 | 1879 |
"align selection to the center/vertical of the first object in the selection; in case |
1880 |
of one selection the object is aligned to the center/vertical of its superview |
|
1881 |
" |
|
128 | 1882 |
|view center sel| |
1883 |
||
1884 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1885 |
self withSelectionHiddenDo:[ |
60 | 1886 |
view := self singleSelection. |
1887 |
||
1888 |
view notNil ifTrue:[ |
|
1889 |
view := view superView. |
|
1890 |
center := view computeExtent |
|
1891 |
] ifFalse:[ |
|
128 | 1892 |
view := sel first. |
60 | 1893 |
center := view computeCorner + view computeOrigin. |
1894 |
]. |
|
1895 |
center := center y // 2. |
|
1896 |
||
72 | 1897 |
self transaction:#alignCenterVertical selectionDo:[:v| |
60 | 1898 |
|newY oldY delta| |
1899 |
||
1900 |
oldY := v computeOrigin y. |
|
1901 |
newY := center - ((v computeCorner y - oldY) // 2). |
|
1902 |
delta := newY - oldY. |
|
1903 |
||
1904 |
self shiftLayout:v top:delta bottom:delta |
|
61 | 1905 |
] |
1906 |
]. |
|
1907 |
self changed:#layout |
|
60 | 1908 |
] |
1909 |
! |
|
1910 |
||
1911 |
alignSelectionLeft |
|
61 | 1912 |
"align selection to the left of the first object in the selection; in case |
1913 |
of one selection the object is aligned to the left of its superview |
|
1914 |
" |
|
128 | 1915 |
|lmost delta sel| |
1916 |
||
1917 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1918 |
self withSelectionHiddenDo:[ |
60 | 1919 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1920 |
lmost := (sel first) computeOrigin x. |
60 | 1921 |
|
72 | 1922 |
self transaction:#alignLeft selectionDo:[:v| |
60 | 1923 |
(delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[ |
1924 |
self shiftLayout:v left:delta right:delta |
|
1925 |
] |
|
1926 |
] |
|
1927 |
] ifFalse:[ |
|
72 | 1928 |
self extentToFrame:#Left do:[:aLayout| |
63 | 1929 |
aLayout leftOffset:0. |
1930 |
aLayout leftFraction:0.0. |
|
60 | 1931 |
] |
1932 |
] |
|
1933 |
]. |
|
1934 |
self changed:#layout |
|
1935 |
] |
|
1936 |
! |
|
1937 |
||
1938 |
alignSelectionLeftAndRight |
|
61 | 1939 |
"align selection to the left/right of the first object in the selection; in case |
1940 |
of one selection the object is aligned to the left/right of its superview |
|
1941 |
" |
|
128 | 1942 |
|lmost rmost sel| |
1943 |
||
1944 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1945 |
self withSelectionHiddenDo:[ |
60 | 1946 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1947 |
lmost := (sel first) computeOrigin x. |
1948 |
rmost := (sel first) computeCorner x. |
|
60 | 1949 |
|
72 | 1950 |
self transaction:#alignLeftRight selectionDo:[:aView| |
1951 |
|layout| |
|
1952 |
layout := self class asLayoutFrameFromView:aView. |
|
1953 |
||
1954 |
layout notNil ifTrue:[ |
|
1955 |
self undoLayoutView:aView. |
|
1956 |
aView geometryLayout:layout. |
|
1957 |
||
1958 |
undoHistory disabledTransitionDo:[ |
|
1959 |
self shiftLayout:aView left:(lmost - (aView computeOrigin x)) |
|
1960 |
right:(rmost - (aView computeCorner x)). |
|
1961 |
]. |
|
1962 |
self elementChangedSize:aView |
|
1963 |
] |
|
60 | 1964 |
] |
1965 |
] ifFalse:[ |
|
72 | 1966 |
self extentToFrame:#LeftRight do:[:aLayout| |
63 | 1967 |
aLayout leftOffset:0. |
1968 |
aLayout leftFraction:0.0. |
|
1969 |
aLayout rightOffset:0. |
|
1970 |
aLayout rightFraction:1.0. |
|
60 | 1971 |
] |
1972 |
] |
|
1973 |
]. |
|
1974 |
self changed:#layout |
|
61 | 1975 |
]. |
1976 |
||
60 | 1977 |
! |
1978 |
||
1979 |
alignSelectionRight |
|
61 | 1980 |
"align selection to the right of the first object in the selection; in case |
1981 |
of one selection the object is aligned to the right of its superview |
|
1982 |
" |
|
128 | 1983 |
|rmost delta sel| |
1984 |
||
1985 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1986 |
self withSelectionHiddenDo:[ |
60 | 1987 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1988 |
rmost := (sel first) computeCorner x. |
60 | 1989 |
|
72 | 1990 |
self transaction:#alignRight selectionDo:[:v| |
60 | 1991 |
(delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[ |
1992 |
self shiftLayout:v left:delta right:delta |
|
1993 |
] |
|
1994 |
] |
|
1995 |
] ifFalse:[ |
|
72 | 1996 |
self extentToFrame:#Right do:[:aLayout| |
63 | 1997 |
aLayout rightOffset:0. |
1998 |
aLayout rightFraction:1.0. |
|
60 | 1999 |
] |
2000 |
] |
|
2001 |
]. |
|
2002 |
self changed:#layout |
|
2003 |
] |
|
2004 |
! |
|
2005 |
||
2006 |
alignSelectionTop |
|
61 | 2007 |
"align selection to the top of the first object in the selection; in case |
2008 |
of one selection the object is aligned to the top of its superview |
|
2009 |
" |
|
128 | 2010 |
|tmost delta sel| |
2011 |
||
2012 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 2013 |
self withSelectionHiddenDo:[ |
60 | 2014 |
self numberOfSelections > 1 ifTrue:[ |
128 | 2015 |
tmost := (sel first) computeOrigin y. |
60 | 2016 |
|
72 | 2017 |
self transaction:#alignTop selectionDo:[:v| |
60 | 2018 |
(delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[ |
2019 |
self shiftLayout:v top:delta bottom:delta |
|
2020 |
] |
|
2021 |
] |
|
2022 |
] ifFalse:[ |
|
72 | 2023 |
self extentToFrame:#Top do:[:aLayout| |
63 | 2024 |
aLayout topOffset:0. |
2025 |
aLayout topFraction:0.0. |
|
60 | 2026 |
] |
2027 |
] |
|
2028 |
]. |
|
2029 |
self changed:#layout |
|
2030 |
] |
|
2031 |
||
2032 |
! |
|
2033 |
||
2034 |
alignSelectionTopAndBottom |
|
61 | 2035 |
"align selection to the top/bottom of the first object in the selection; in case |
2036 |
of one selection the object is aligned to the top/bottom of its superview |
|
2037 |
" |
|
128 | 2038 |
|tmost bmost sel| |
2039 |
||
2040 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 2041 |
self withSelectionHiddenDo:[ |
60 | 2042 |
self numberOfSelections > 1 ifTrue:[ |
128 | 2043 |
tmost := (sel first) computeOrigin y. |
2044 |
bmost := (sel first) computeCorner y. |
|
60 | 2045 |
|
72 | 2046 |
self transaction:#alignTopBottom selectionDo:[:aView| |
2047 |
|layout| |
|
2048 |
layout := self class asLayoutFrameFromView:aView. |
|
2049 |
||
2050 |
layout notNil ifTrue:[ |
|
2051 |
self undoLayoutView:aView. |
|
2052 |
aView geometryLayout:layout. |
|
2053 |
||
2054 |
undoHistory disabledTransitionDo:[ |
|
2055 |
self shiftLayout:aView top:(tmost - (aView computeOrigin y)) |
|
2056 |
bottom:(bmost - (aView computeCorner y)). |
|
2057 |
]. |
|
2058 |
self elementChangedSize:aView |
|
2059 |
] |
|
60 | 2060 |
] |
2061 |
] ifFalse:[ |
|
72 | 2062 |
self extentToFrame:#TopBottom do:[:aLayout| |
63 | 2063 |
aLayout topOffset:0. |
2064 |
aLayout topFraction:0.0. |
|
2065 |
aLayout bottomOffset:0. |
|
2066 |
aLayout bottomFraction:1.0. |
|
60 | 2067 |
] |
2068 |
] |
|
2069 |
]. |
|
2070 |
self changed:#layout |
|
2071 |
] |
|
2072 |
! |
|
2073 |
||
2074 |
centerSelection:aOneArgBlockXorY orientation:orientation |
|
2075 |
"center selection horizontal or vertical dependant on the block result( x or y). |
|
2076 |
The argument to the block is the point. |
|
2077 |
" |
|
2078 |
|superview min max delta val| |
|
2079 |
||
128 | 2080 |
(self moveableSelection) isNil ifTrue:[ |
61 | 2081 |
^ self |
2082 |
]. |
|
2083 |
||
2084 |
self withSelectionHiddenDo:[ |
|
60 | 2085 |
max := 0. |
2086 |
||
2087 |
self selectionDo:[:aView | |
|
2088 |
superview isNil ifTrue:[ |
|
2089 |
superview := aView superView |
|
2090 |
] ifFalse:[ |
|
2091 |
(aView superView == superview) ifFalse:[ |
|
2092 |
^ self notify:'views must have same superview'. |
|
2093 |
] |
|
2094 |
]. |
|
2095 |
val := aOneArgBlockXorY value:(aView computeOrigin). |
|
2096 |
||
2097 |
min isNil ifTrue:[min := val] |
|
2098 |
ifFalse:[min := min min:val]. |
|
2099 |
||
2100 |
val := aOneArgBlockXorY value:(aView computeCorner). |
|
2101 |
max := max max:val. |
|
2102 |
]. |
|
2103 |
||
2104 |
val := aOneArgBlockXorY value:(superview computeExtent). |
|
2105 |
max := (min + val - max) // 2. |
|
2106 |
||
2107 |
max == min ifFalse:[ |
|
72 | 2108 |
|type| |
2109 |
(orientation == #y) ifTrue:[type := #centerVertical] |
|
2110 |
ifFalse:[type := #centerHorizontal]. |
|
60 | 2111 |
delta := max - min. |
2112 |
||
72 | 2113 |
self transaction:type selectionDo:[:v| |
60 | 2114 |
orientation == #y ifTrue:[ |
2115 |
self shiftLayout:v top:delta bottom:delta |
|
2116 |
] ifFalse:[ |
|
2117 |
self shiftLayout:v left:delta right:delta |
|
2118 |
] |
|
61 | 2119 |
] |
2120 |
]. |
|
2121 |
self changed:#layout |
|
60 | 2122 |
] |
2123 |
||
2124 |
||
2125 |
! |
|
2126 |
||
2127 |
centerSelectionHor |
|
2128 |
"center selection horizontal |
|
2129 |
" |
|
2130 |
self centerSelection:[:aPoint| aPoint x] orientation:#x |
|
2131 |
||
2132 |
||
2133 |
! |
|
2134 |
||
2135 |
centerSelectionVer |
|
2136 |
"center selection vertical |
|
2137 |
" |
|
2138 |
self centerSelection:[:aPoint| aPoint y] orientation:#y |
|
2139 |
! |
|
2140 |
||
72 | 2141 |
extentToFrame:toWhat do:aBlock |
2142 |
"align to frame (Left Right ...) and perform the block on a frameLayout |
|
2143 |
" |
|
2144 |
|layout type| |
|
2145 |
||
2146 |
type := ('extent', toWhat asString) asSymbol. |
|
2147 |
||
2148 |
self transaction:type selectionDo:[:aView| |
|
2149 |
layout := self class asLayoutFrameFromView:aView. |
|
2150 |
||
2151 |
layout notNil ifTrue:[ |
|
2152 |
self undoLayoutView:aView. |
|
2153 |
aBlock value:layout. |
|
2154 |
aView geometryLayout:layout. |
|
2155 |
self elementChangedSize:aView. |
|
2156 |
] |
|
2157 |
] |
|
2158 |
! |
|
2159 |
||
60 | 2160 |
spreadSelectionHor |
61 | 2161 |
"spread multiple selection horizontal |
2162 |
" |
|
128 | 2163 |
|sumWidths min max viewsInOrder topsInOrder count space sel| |
2164 |
||
2165 |
sel := self moveableSelection. |
|
2166 |
||
2167 |
(sel notNil and:[self numberOfSelections > 1]) ifFalse:[ |
|
60 | 2168 |
^ self |
2169 |
]. |
|
2170 |
||
61 | 2171 |
self withSelectionHiddenDo:[ |
60 | 2172 |
count := 0. |
2173 |
sumWidths := 0. |
|
2174 |
max := 0. |
|
2175 |
||
2176 |
self selectionDo:[:aView | |
|
2177 |
sumWidths := sumWidths + aView width. |
|
2178 |
||
2179 |
min isNil ifTrue:[min := aView left] |
|
2180 |
ifFalse:[min := min min:(aView left)]. |
|
2181 |
||
2182 |
max := max max:(aView right). |
|
2183 |
count := count + 1 |
|
2184 |
]. |
|
128 | 2185 |
viewsInOrder := Array withAll:sel. |
60 | 2186 |
topsInOrder := viewsInOrder collect:[:aView | aView left]. |
2187 |
topsInOrder sortWith:viewsInOrder. |
|
2188 |
||
2189 |
space := (((max - min) - sumWidths) / (count - 1)) rounded asInteger. |
|
2190 |
||
72 | 2191 |
self transaction:#spreadHorizontal objects:viewsInOrder do:[:aView| |
60 | 2192 |
|delta| |
2193 |
||
2194 |
delta := min - aView computeOrigin x. |
|
2195 |
self shiftLayout:aView left:delta right:delta. |
|
2196 |
min := min + aView computeExtent x + space |
|
61 | 2197 |
] |
2198 |
]. |
|
2199 |
self changed:#layout |
|
60 | 2200 |
|
2201 |
! |
|
2202 |
||
2203 |
spreadSelectionVer |
|
61 | 2204 |
"spread multiple selection vertical |
2205 |
" |
|
128 | 2206 |
|sumHeights min max viewsInOrder topsInOrder count space sel| |
2207 |
||
2208 |
sel := self moveableSelection. |
|
2209 |
||
2210 |
(sel notNil and:[self numberOfSelections > 1]) ifFalse:[ |
|
60 | 2211 |
^ self |
2212 |
]. |
|
2213 |
||
61 | 2214 |
self withSelectionHiddenDo:[ |
60 | 2215 |
count := 0. |
2216 |
sumHeights := 0. |
|
2217 |
max := 0. |
|
2218 |
||
2219 |
self selectionDo:[:aView | |
|
2220 |
sumHeights := sumHeights + aView height. |
|
2221 |
||
2222 |
min isNil ifTrue:[min := aView top] |
|
2223 |
ifFalse:[min := min min:(aView top)]. |
|
2224 |
||
2225 |
max := max max:(aView bottom). |
|
2226 |
count := count + 1 |
|
2227 |
]. |
|
128 | 2228 |
viewsInOrder := Array withAll:sel. |
60 | 2229 |
topsInOrder := viewsInOrder collect:[:aView|aView top]. |
2230 |
topsInOrder sortWith:viewsInOrder. |
|
2231 |
||
2232 |
space := (((max - min) - sumHeights) / (count - 1)) rounded asInteger. |
|
2233 |
||
72 | 2234 |
self transaction:#spreadVertical objects:viewsInOrder do:[:aView| |
60 | 2235 |
|delta| |
2236 |
||
2237 |
delta := min - aView computeOrigin y. |
|
2238 |
self shiftLayout:aView top:delta bottom:delta. |
|
2239 |
min := min + aView height + space |
|
61 | 2240 |
] |
2241 |
]. |
|
2242 |
self changed:#layout |
|
60 | 2243 |
! ! |
2244 |
||
2245 |
!UIObjectView methodsFor:'user actions - undo history'! |
|
2246 |
||
72 | 2247 |
enableUndoHistory:aState |
2248 |
"enable or disable undo history |
|
2249 |
" |
|
2250 |
undoHistory enabled:aState |
|
2251 |
! |
|
2252 |
||
60 | 2253 |
openUndoMenu |
61 | 2254 |
"open undo menu |
2255 |
" |
|
131 | 2256 |
self select:nil. |
61 | 2257 |
|
2258 |
self withSelectionHiddenDo:[ |
|
2259 |
undoHistory openUndoMenu |
|
2260 |
]. |
|
60 | 2261 |
|
2262 |
! |
|
2263 |
||
2264 |
removeUndoHistory |
|
2265 |
"delete total undo history |
|
2266 |
" |
|
2267 |
undoHistory reinitialize |
|
2268 |
! |
|
2269 |
||
2270 |
undoLast |
|
61 | 2271 |
"undo last action |
2272 |
" |
|
131 | 2273 |
self select:nil. |
61 | 2274 |
|
2275 |
self withSelectionHiddenDo:[ |
|
2276 |
undoHistory undoLast:1 |
|
2277 |
]. |
|
113 | 2278 |
|
60 | 2279 |
! ! |
2280 |
||
2281 |
!UIObjectView::UndoHistory class methodsFor:'constants'! |
|
2282 |
||
2283 |
maxHistorySize |
|
2284 |
"returns maximum size of history before removing oldest |
|
2285 |
record |
|
2286 |
" |
|
2287 |
^ 50 |
|
2288 |
||
2289 |
||
2290 |
! ! |
|
2291 |
||
131 | 2292 |
!UIObjectView::UndoHistory class methodsFor:'documentation'! |
2293 |
||
2294 |
documentation |
|
2295 |
" |
|
2296 |
undo history used by the UIPainter-Tool; to each operation, an undo block |
|
2297 |
and some text is stored. In case of a required undo, the corresponding |
|
2298 |
undo block will be performed. |
|
2299 |
||
2300 |
[see also:] |
|
2301 |
UIObjectView |
|
2302 |
UIPainterView |
|
2303 |
" |
|
2304 |
||
2305 |
||
2306 |
! ! |
|
2307 |
||
60 | 2308 |
!UIObjectView::UndoHistory class methodsFor:'instance creation'! |
2309 |
||
2310 |
new |
|
2311 |
^ self basicNew initialize |
|
2312 |
||
2313 |
||
2314 |
! ! |
|
2315 |
||
2316 |
!UIObjectView::UndoHistory methodsFor:'accessing'! |
|
2317 |
||
72 | 2318 |
enabled |
2319 |
^ enabled |
|
2320 |
! |
|
2321 |
||
2322 |
enabled:aState |
|
2323 |
enabled := aState |
|
2324 |
! |
|
2325 |
||
60 | 2326 |
historySize |
2327 |
^ history size |
|
72 | 2328 |
! |
2329 |
||
2330 |
lastTypeAsString |
|
2331 |
"returns type of last undo asString or nil |
|
2332 |
" |
|
2333 |
history notEmpty ifTrue:[ |
|
2334 |
^ history last typeAsString |
|
2335 |
]. |
|
2336 |
^ nil |
|
2337 |
||
2338 |
||
60 | 2339 |
! ! |
2340 |
||
2341 |
!UIObjectView::UndoHistory methodsFor:'initialization'! |
|
2342 |
||
2343 |
initialize |
|
2344 |
super initialize. |
|
2345 |
self reinitialize. |
|
2346 |
||
2347 |
||
2348 |
! |
|
2349 |
||
2350 |
reinitialize |
|
2351 |
"reinitialize all attributes |
|
2352 |
" |
|
2353 |
history := OrderedCollection new. |
|
2354 |
transaction := nil. |
|
2355 |
enabled := true. |
|
2356 |
||
2357 |
||
2358 |
! ! |
|
2359 |
||
2360 |
!UIObjectView::UndoHistory methodsFor:'menu'! |
|
2361 |
||
2362 |
openUndoMenu |
|
72 | 2363 |
|list tabs top slv hzp inset selection okButton| |
60 | 2364 |
|
2365 |
history isEmpty ifTrue:[ |
|
2366 |
^ self |
|
2367 |
]. |
|
2368 |
||
2369 |
top := StandardSystemView new label:'undo history'; extent:250@350. |
|
2370 |
slv := ScrollableView for:SelectionInListView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
2371 |
hzp := HorizontalPanelView origin:0.0@1.0 corner:1.0@1.0 in:top. |
|
2372 |
hzp horizontalLayout:#fitSpace. |
|
2373 |
||
2374 |
(Button abortButtonIn:hzp) action:[ selection := nil. top destroy ]. |
|
2375 |
okButton := Button okButtonIn:hzp. |
|
2376 |
okButton label:'undo to end'. |
|
2377 |
okButton action:[ top destroy ]. |
|
2378 |
||
2379 |
inset := hzp preferredExtent y. |
|
2380 |
hzp topInset:(inset negated). |
|
2381 |
slv bottomInset:inset. |
|
2382 |
slv := slv scrolledView. |
|
2383 |
||
72 | 2384 |
tabs := TabulatorSpecification new. |
2385 |
tabs unit:#cm. |
|
2386 |
tabs positions:#(0 5). |
|
2387 |
tabs align:#(#left ##left). |
|
2388 |
||
60 | 2389 |
list := history collect:[:aTrans||e| |
2390 |
e := MultiColListEntry new. |
|
72 | 2391 |
e colAt:1 put:(aTrans typeAsString). |
60 | 2392 |
e colAt:2 put:(aTrans text ? ''). |
72 | 2393 |
e tabulatorSpecification:tabs. |
60 | 2394 |
e |
2395 |
]. |
|
2396 |
||
2397 |
slv list:list. |
|
2398 |
slv action:[:index | selection := index ]. |
|
2399 |
top openModal. |
|
2400 |
||
2401 |
selection notNil ifTrue:[ |
|
2402 |
self undoLast:(history size - selection + 1). |
|
2403 |
] |
|
2404 |
! ! |
|
2405 |
||
2406 |
!UIObjectView::UndoHistory methodsFor:'testing'! |
|
2407 |
||
2408 |
isEmpty |
|
2409 |
"returns true if undo history is empty |
|
2410 |
" |
|
2411 |
^ history isEmpty |
|
2412 |
||
2413 |
||
2414 |
! |
|
2415 |
||
2416 |
isTransactionOpen |
|
2417 |
^ (enabled and:[transaction notNil]) |
|
2418 |
! |
|
2419 |
||
2420 |
notEmpty |
|
2421 |
"returns true if undo history is not empty |
|
2422 |
" |
|
2423 |
^ history notEmpty |
|
2424 |
||
2425 |
||
2426 |
! ! |
|
2427 |
||
2428 |
!UIObjectView::UndoHistory methodsFor:'transaction'! |
|
2429 |
||
2430 |
addUndoBlock:anUndoBlock |
|
2431 |
"undo block to restore changes; add block to current transaction |
|
2432 |
" |
|
2433 |
self isTransactionOpen ifTrue:[ |
|
2434 |
transaction add:anUndoBlock |
|
2435 |
] |
|
2436 |
||
2437 |
||
2438 |
! |
|
2439 |
||
2440 |
disabledTransitionDo:aBlock |
|
2441 |
"disable transitions during evaluating the block |
|
2442 |
" |
|
2443 |
|oldState| |
|
2444 |
||
2445 |
oldState := enabled. |
|
2446 |
enabled := false. |
|
2447 |
aBlock value. |
|
2448 |
enabled := oldState. |
|
2449 |
! |
|
2450 |
||
2451 |
transaction:aType do:aBlock |
|
2452 |
self transaction:aType text:nil do:aBlock |
|
2453 |
! |
|
2454 |
||
2455 |
transaction:aType text:aTextOrNil do:aBlock |
|
2456 |
"open a transaction; perform the block; at least close the transaction |
|
2457 |
" |
|
2458 |
(enabled and:[transaction isNil]) ifTrue:[ |
|
2459 |
transaction := Transaction type:aType text:aTextOrNil. |
|
2460 |
||
2461 |
aBlock value. |
|
2462 |
||
2463 |
transaction isEmpty ifFalse:[ |
|
2464 |
history addLast:transaction. |
|
2465 |
history size > (self class maxHistorySize) ifTrue:[history removeFirst] |
|
2466 |
]. |
|
2467 |
transaction := nil |
|
2468 |
||
2469 |
] ifFalse:[ |
|
2470 |
aBlock value |
|
2471 |
] |
|
2472 |
! ! |
|
2473 |
||
2474 |
!UIObjectView::UndoHistory methodsFor:'undo'! |
|
2475 |
||
2476 |
undoLast:nTransactions |
|
2477 |
"undo last n transactions; an open transaction will be closed; |
|
2478 |
transactions during undo are disabled |
|
2479 |
" |
|
2480 |
|n| |
|
2481 |
||
2482 |
transaction := nil. |
|
2483 |
n := nTransactions min:(history size). |
|
2484 |
||
2485 |
n ~~ 0 ifTrue:[ |
|
2486 |
enabled := false. |
|
2487 |
n timesRepeat:[ (history removeLast) undo ]. |
|
2488 |
enabled := true. |
|
2489 |
] |
|
2490 |
||
2491 |
||
2492 |
! ! |
|
2493 |
||
2494 |
!UIObjectView::UndoHistory::Transaction class methodsFor:'documentation'! |
|
2495 |
||
131 | 2496 |
documentation |
2497 |
" |
|
2498 |
represents one undo record, keeping the associated type and printable text |
|
2499 |
and the undo action performed on an undo request |
|
2500 |
||
2501 |
[see also:] |
|
2502 |
UndoHistory |
|
2503 |
" |
|
2504 |
||
60 | 2505 |
! ! |
2506 |
||
54 | 2507 |
!UIObjectView::UndoHistory::Transaction class methodsFor:'instance creation'! |
2508 |
||
2509 |
type:aType text:aTextOrNil |
|
2510 |
^ self new type:aType text:aTextOrNil |
|
2511 |
||
2512 |
||
2513 |
! ! |
|
2514 |
||
2515 |
!UIObjectView::UndoHistory::Transaction methodsFor:'accessing'! |
|
2516 |
||
2517 |
text |
|
2518 |
"returns text or nil assigned to transition |
|
2519 |
" |
|
2520 |
^ text |
|
2521 |
! |
|
2522 |
||
2523 |
type |
|
2524 |
"returns type assigned to transition |
|
2525 |
" |
|
2526 |
^ type |
|
2527 |
! |
|
2528 |
||
2529 |
type:aType |
|
2530 |
"change type assigned to transition |
|
2531 |
" |
|
2532 |
type := aType |
|
72 | 2533 |
! |
2534 |
||
2535 |
typeAsString |
|
2536 |
"returns type as printable string |
|
2537 |
" |
|
2538 |
|line name size sep| |
|
2539 |
||
2540 |
line := type asString. |
|
2541 |
size := 0. |
|
2542 |
line do:[:c| (c isUppercase) ifTrue:[size := size+1] ]. |
|
2543 |
name := String new:(line size + size). |
|
2544 |
size := 1. |
|
2545 |
sep := Character space. |
|
2546 |
||
2547 |
line do:[:c| |
|
2548 |
(c isUppercase) ifFalse:[ |
|
2549 |
name at:size put:c |
|
2550 |
] ifTrue:[ |
|
2551 |
name at:size put:sep. |
|
2552 |
sep := $&. |
|
2553 |
size := size + 1. |
|
2554 |
name at:size put:(c asLowercase) |
|
2555 |
]. |
|
2556 |
size := size + 1 |
|
2557 |
]. |
|
2558 |
^ name |
|
54 | 2559 |
! ! |
2560 |
||
2561 |
!UIObjectView::UndoHistory::Transaction methodsFor:'add & undo'! |
|
2562 |
||
2563 |
add:anUndoBlock |
|
2564 |
"add an undo action to the transition |
|
2565 |
" |
|
2566 |
actions isNil ifTrue:[ |
|
2567 |
actions := anUndoBlock |
|
2568 |
] ifFalse:[ |
|
2569 |
actions isCollection ifFalse:[ |
|
2570 |
|temp| |
|
2571 |
||
2572 |
temp := OrderedCollection new. |
|
2573 |
temp add:actions. |
|
2574 |
actions := temp. |
|
47 | 2575 |
]. |
54 | 2576 |
actions add:anUndoBlock. |
2577 |
] |
|
2578 |
! |
|
2579 |
||
2580 |
undo |
|
2581 |
"undo transition |
|
2582 |
" |
|
2583 |
actions notNil ifTrue:[ |
|
2584 |
actions isCollection ifFalse:[ |
|
2585 |
actions value |
|
2586 |
] ifTrue:[ |
|
2587 |
actions reverseDo:[:anUndoBlock| anUndoBlock value ] |
|
2588 |
] |
|
47 | 2589 |
] |
54 | 2590 |
! ! |
2591 |
||
2592 |
!UIObjectView::UndoHistory::Transaction methodsFor:'initialization'! |
|
2593 |
||
2594 |
type:aType text:aTextOrNil |
|
2595 |
"initialize transition |
|
2596 |
" |
|
2597 |
type := aType. |
|
2598 |
text := aTextOrNil. |
|
2599 |
! ! |
|
2600 |
||
2601 |
!UIObjectView::UndoHistory::Transaction methodsFor:'testing'! |
|
2602 |
||
2603 |
isEmpty |
|
2604 |
"returns true if no undo action is registered |
|
2605 |
" |
|
2606 |
^ actions isNil |
|
2607 |
! |
|
2608 |
||
2609 |
notEmpty |
|
2610 |
"returns true if any undo action is registered |
|
2611 |
" |
|
2612 |
^ actions notNil |
|
47 | 2613 |
! ! |
2614 |
||
60 | 2615 |
!UIObjectView class methodsFor:'documentation'! |
2616 |
||
2617 |
version |
|
2618 |
^ '$Header$' |
|
2619 |
! ! |