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