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