1 ObjectView subclass:#UIObjectView |
1 ObjectView subclass:#UIObjectView |
2 instanceVariableNames:'inputView testMode undoHistory copiedExtent resizedObject |
2 instanceVariableNames:'inputView testMode undoHistory copiedExtent actionData |
3 resizeSelector createInWidget createFrame createdObject |
|
4 createClass clipChildren' |
3 createClass clipChildren' |
5 classVariableNames:'' |
4 classVariableNames:'' |
6 poolDictionaries:'' |
5 poolDictionaries:'' |
7 category:'Interface-UIPainter' |
6 category:'Interface-UIPainter' |
8 ! |
7 ! |
9 |
8 |
10 Object subclass:#UndoHistory |
9 Object subclass:#UndoHistory |
11 instanceVariableNames:'history transaction enabled modifiedAction' |
10 instanceVariableNames:'history transaction enabled' |
12 classVariableNames:'' |
11 classVariableNames:'' |
13 poolDictionaries:'' |
12 poolDictionaries:'' |
14 privateIn:UIObjectView |
13 privateIn:UIObjectView |
|
14 ! |
|
15 |
|
16 Object subclass:#Transaction |
|
17 instanceVariableNames:'type text actions' |
|
18 classVariableNames:'' |
|
19 poolDictionaries:'' |
|
20 privateIn:UIObjectView::UndoHistory |
15 ! |
21 ! |
16 |
22 |
17 |
23 |
18 !UIObjectView class methodsFor:'defaults'! |
24 !UIObjectView class methodsFor:'defaults'! |
19 |
25 |
213 inputView enableButtonEvents. |
235 inputView enableButtonEvents. |
214 inputView enableButtonMotionEvents. |
236 inputView enableButtonMotionEvents. |
215 |
237 |
216 self setDefaultActions. |
238 self setDefaultActions. |
217 |
239 |
218 undoHistory := UndoHistory new. |
240 undoHistory := UndoHistory new. |
219 |
241 testMode := false. |
220 undoHistory modifiedAction:[:what| |
|
221 self changed:#undoHistory with:what |
|
222 ]. |
|
223 |
|
224 testMode := false. |
|
225 clipChildren := true. |
242 clipChildren := true. |
226 |
243 |
227 (self class gridShown) ifTrue:[ |
244 (self class gridShown) ifTrue:[ |
228 super showGrid |
245 super showGrid |
229 ]. |
246 ]. |
291 |
308 |
292 ! ! |
309 ! ! |
293 |
310 |
294 !UIObjectView methodsFor:'object creation'! |
311 !UIObjectView methodsFor:'object creation'! |
295 |
312 |
|
313 actionCreate:anObject frame:aFrame delta:aDelta |
|
314 "create and initialize action data |
|
315 " |
|
316 |extent x y selectors values| |
|
317 |
|
318 "minimum extent |
|
319 " |
|
320 extent := self extent. |
|
321 x := extent x // 3. |
|
322 y := extent y // 3. |
|
323 extent := anObject preferredExtent. |
|
324 |
|
325 (extent x > x) ifTrue:[extent x:x]. |
|
326 (extent y > y) ifTrue:[extent y:y]. |
|
327 |
|
328 "setup structure |
|
329 " |
|
330 selectors := #( object frame delta vertical horizontal minExtent ). |
|
331 values := Array new:(selectors size). |
|
332 |
|
333 values at:1 put:anObject. |
|
334 values at:2 put:aFrame. |
|
335 values at:3 put:aDelta. |
|
336 values at:4 put:(self isVerticalResizable:anObject). |
|
337 values at:5 put:(self isHorizontalResizable:anObject). |
|
338 values at:6 put:extent. |
|
339 |
|
340 actionData := Structure newWith:selectors values:values. |
|
341 |
|
342 |
|
343 "can change cursor dependent on vertical/horizontal resizing |
|
344 " |
|
345 oldCursor := cursor. |
|
346 self cursor:(Cursor leftHand). |
|
347 |
|
348 |
|
349 |
|
350 ! |
|
351 |
|
352 createWidgetWithClass:aClass |
|
353 "prepare to create new widgets |
|
354 " |
|
355 createClass := aClass. |
|
356 pressAction := [:pressPoint | self startCreate:pressPoint]. |
|
357 self cursor:Cursor origin. |
|
358 |
|
359 |
|
360 ! |
|
361 |
296 doDragCreate:aPoint |
362 doDragCreate:aPoint |
297 "do a widget create drag |
363 "do a widget create drag |
298 " |
364 " |
299 |p| |
365 |frame object extent minimum| |
300 |
366 |
301 p := self alignToGrid:aPoint. |
367 frame := actionData frame. |
302 createFrame corner:(p - (createInWidget originRelativeTo:self)). |
368 frame corner:((self alignToGrid:aPoint) - (actionData delta)). |
303 |
369 |
304 (createFrame extent x < 10) ifTrue:[ |
370 object := actionData object. |
305 createFrame extent x:10 |
371 minimum := actionData minExtent. |
306 ]. |
372 extent := frame extent. |
307 |
373 |
308 (createFrame extent y < 10) ifTrue:[ |
374 ((extent x < minimum x) or:[actionData horizontal not]) ifTrue:[ |
309 createFrame extent y:10 |
375 extent x:(minimum x) |
310 ]. |
376 ]. |
311 |
377 |
312 self invertOutlineOf:createdObject. |
378 ((extent y < minimum y) or:[actionData vertical not]) ifTrue:[ |
313 createdObject origin:(createFrame origin) extent:(createFrame extent). |
379 extent y:(minimum y) |
314 self invertOutlineOf:createdObject. |
380 ]. |
|
381 |
|
382 frame extent:extent. |
|
383 |
|
384 self invertOutlineOf:object. |
|
385 object origin:(frame origin) extent:(frame extent). |
|
386 self invertOutlineOf:object. |
315 ! |
387 ! |
316 |
388 |
317 endCreate |
389 endCreate |
318 "end a widget create drag |
390 "end a widget create drag |
319 " |
391 " |
320 |layout x y| |
392 |layout x y| |
321 |
393 |
322 self invertOutlineOf:createdObject. |
394 self invertOutlineOf:(actionData object). |
323 inputView raise. |
395 inputView raise. |
324 |
396 |
325 layout := createdObject bounds asLayout. |
397 layout := (actionData object) bounds asLayout. |
326 createdObject geometryLayout:layout. |
398 (actionData object) geometryLayout:layout. |
327 |
399 |
328 self changed:#tree. |
400 self changed:#tree. |
329 self select:createdObject. |
401 self select:(actionData object). |
330 createdObject := nil. |
402 actionData := nil. |
331 |
403 |
332 self setDefaultActions. |
404 self setDefaultActions. |
333 |
405 |
334 ! |
406 ! |
335 |
407 |
338 ! |
410 ! |
339 |
411 |
340 startCreate:aPoint |
412 startCreate:aPoint |
341 "start a widget create |
413 "start a widget create |
342 " |
414 " |
343 |startPoint| |
415 |widget object start frame delta| |
344 |
416 |
345 createClass isNil ifTrue:[ |
417 createClass isNil ifTrue:[ |
346 ^ self setDefaultActions |
418 ^ self setDefaultActions |
347 ]. |
419 ]. |
348 (selection isKindOf:Collection) ifTrue:[ |
420 (selection isKindOf:Collection) ifTrue:[ |
349 self unselect. |
421 self unselect. |
350 ^ self setDefaultActions. |
422 ^ self setDefaultActions. |
351 ]. |
423 ]. |
352 |
424 |
353 startPoint := self alignToGrid:aPoint. |
|
354 motionAction := [:movePoint| self doDragCreate:movePoint]. |
425 motionAction := [:movePoint| self doDragCreate:movePoint]. |
355 releaseAction := [ self endCreate]. |
426 releaseAction := [ self endCreate]. |
356 |
427 |
357 selection notNil ifTrue:[ |
428 selection notNil ifTrue:[ |
358 ( (self isPoint:aPoint containedIn:selection) |
429 ( (self isPoint:aPoint containedIn:selection) |
359 and:[selection specClass basicNew supportsSubComponents] |
430 and:[self supportsSubComponents:selection] |
360 ) ifFalse:[ |
431 ) ifFalse:[ |
361 self unselect |
432 self unselect |
362 ] |
433 ] |
363 ]. |
434 ]. |
364 |
435 |
365 oldCursor := cursor. |
436 widget := selection ? self. |
366 self cursor:(Cursor leftHand). |
437 object := createClass new. |
367 |
438 widget addSubView:object. |
368 createInWidget := selection ? self. |
439 |
369 createdObject := createClass new. |
440 start := self alignToGrid:aPoint. |
370 createInWidget addSubView:createdObject. |
441 delta := widget originRelativeTo:self. |
371 |
442 frame := Rectangle origin:(start - delta) corner:start. |
372 createFrame := Rectangle origin:(startPoint - (createInWidget originRelativeTo:self)) |
443 |
373 corner:startPoint. |
444 object origin:(frame origin). |
374 |
445 self setupCreatedObject:object. |
375 createdObject origin:(createFrame origin). |
446 object realize. |
376 |
447 |
377 undoHistory transactionNamed:'create' do:[ |
448 self actionCreate:object frame:frame delta:delta. |
378 self setupCreatedObject:createdObject. |
449 self invertOutlineOf:object. |
379 ]. |
450 |
380 createdObject realize. |
451 |
381 self invertOutlineOf:createdObject. |
|
382 ! ! |
452 ! ! |
383 |
453 |
384 !UIObjectView methodsFor:'object moving'! |
454 !UIObjectView methodsFor:'object moving'! |
385 |
455 |
386 doObjectMove:aPoint |
456 doObjectMove:aPoint |
417 self setDefaultActions. |
487 self setDefaultActions. |
418 self changed:#layout. |
488 self changed:#layout. |
419 ]. |
489 ]. |
420 ! |
490 ! |
421 |
491 |
|
492 moveObject:anObject to:aPoint |
|
493 "move anObject to newOrigin, aPoint |
|
494 " |
|
495 |dX dY org delta| |
|
496 |
|
497 anObject notNil ifTrue:[ |
|
498 org := anObject computeOrigin. |
|
499 |
|
500 delta := aPoint - org. |
|
501 delta := (self alignToGrid:aPoint) - org. |
|
502 dX := delta x. |
|
503 dY := delta y. |
|
504 |
|
505 undoHistory disabledTransitionDo:[ |
|
506 self shifLayout:anObject top:dY bottom:dY left:dX right:dX |
|
507 ] |
|
508 ] |
|
509 |
|
510 ! |
|
511 |
422 startObjectMoveAt:aPoint |
512 startObjectMoveAt:aPoint |
423 |
513 |
424 self startObjectMove:selection at:aPoint. |
514 self startObjectMove:selection at:aPoint. |
425 |
515 |
426 selection size == 0 ifTrue:[ |
516 selection size == 0 ifTrue:[ |
432 |
522 |
433 moveDelta := movedObject collect:[:aView| |
523 moveDelta := movedObject collect:[:aView| |
434 aPoint - aView computeOrigin |
524 aPoint - aView computeOrigin |
435 ]. |
525 ]. |
436 |
526 |
437 undoHistory transactionNamed:'move' do:[ |
527 selection := movedObject. |
438 movedObject do:[:aView| |
528 self transaction:#move selectionDo:[:aView| |
439 self invertOutlineOf:aView. |
529 self invertOutlineOf:aView. |
440 self undoBlockPositionChanged:aView |
530 self undoBlockPositionChanged:aView |
441 ] |
531 ]. |
442 ] |
532 selection := nil |
|
533 |
443 ! |
534 ! |
444 |
535 |
445 startSelectMoreOrMove:aPoint |
536 startSelectMoreOrMove:aPoint |
446 "add/remove to/from selection" |
537 "add/remove to/from selection" |
447 |
538 |
499 ]. |
590 ]. |
500 |
591 |
501 "prepare move operation for an object |
592 "prepare move operation for an object |
502 " |
593 " |
503 motionAction := [:movePoint| |
594 motionAction := [:movePoint| |
504 (aPoint dist:movePoint) > 2.0 ifTrue:[ |
595 (aPoint dist:movePoint) > 4.0 ifTrue:[ |
505 self startObjectMoveAt:aPoint |
596 self startObjectMoveAt:aPoint |
506 ] |
597 ] |
507 ]. |
598 ]. |
|
599 ! ! |
|
600 |
|
601 !UIObjectView methodsFor:'object resize'! |
|
602 |
|
603 actionResize:anObject selector:aSelector |
|
604 "create and initialize action for resize |
|
605 " |
|
606 |selector delta| |
|
607 |
|
608 delta := anObject container originRelativeTo:self. |
|
609 selector := ('resize:', aSelector, ':') asSymbol. |
|
610 |
|
611 actionData := Structure with:(#object->anObject) |
|
612 with:(#selector->selector) |
|
613 with:(#delta->delta). |
|
614 |
|
615 "can change cursor dependent on vertical/horizontal resizing |
|
616 " |
|
617 oldCursor := cursor. |
|
618 self cursor:(Cursor leftHand). |
|
619 |
|
620 |
|
621 |
|
622 ! |
|
623 |
|
624 doDragResize:aPoint |
|
625 "do a widget resize drag" |
|
626 |
|
627 |p object| |
|
628 |
|
629 object := actionData object. |
|
630 |
|
631 self invertOutlineOf:object. |
|
632 p := (self alignToGrid:aPoint) - (actionData delta). |
|
633 self perform:(actionData selector) with:object with:p. |
|
634 object geometryLayout:(object geometryLayout). |
|
635 self invertOutlineOf:object |
|
636 |
|
637 ! |
|
638 |
|
639 endResize |
|
640 "cleanup after object resize" |
|
641 |
|
642 self invertOutlineOf:(actionData object). |
|
643 self setDefaultActions. |
|
644 self select:(actionData object). |
|
645 actionData := nil |
|
646 |
|
647 "Modified: 5.9.1995 / 17:11:17 / claus" |
|
648 |
|
649 ! |
|
650 |
|
651 startResizeBorder:b of:selection |
|
652 "resize selected view |
|
653 " |
|
654 |object| |
|
655 |
|
656 object := self singleSelection. |
|
657 self actionResize:object selector:b. |
|
658 |
|
659 self transaction:#extent selectionDo:[:aView| |
|
660 self undoBlockDimensionChanged:aView |
|
661 ]. |
|
662 super unselect. |
|
663 |
|
664 motionAction := [:movePoint | self doDragResize:movePoint]. |
|
665 releaseAction := [self endResize]. |
|
666 self invertOutlineOf:object |
508 ! ! |
667 ! ! |
509 |
668 |
510 !UIObjectView methodsFor:'private handles'! |
669 !UIObjectView methodsFor:'private handles'! |
511 |
670 |
512 handlesOf:aComponent do:aBlock |
671 handlesOf:aComponent do:aBlock |
629 undoHistory disabledTransitionDo:[ |
787 undoHistory disabledTransitionDo:[ |
630 self shifLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y)) |
788 self shifLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y)) |
631 ] |
789 ] |
632 ! |
790 ! |
633 |
791 |
|
792 resize:aView bottomLeft:aPoint |
|
793 |
|
794 undoHistory disabledTransitionDo:[ |
|
795 self shifLayout:aView top:0 |
|
796 bottom:((aPoint y) - (aView computeCorner y)) |
|
797 left:((aPoint x) - (aView computeOrigin x)) |
|
798 right:0 |
|
799 |
|
800 ] |
|
801 |
|
802 |
|
803 ! |
|
804 |
634 resize:aView corner:aPoint |
805 resize:aView corner:aPoint |
635 |delta| |
806 |delta| |
636 |
807 |
637 delta := aPoint - aView computeCorner. |
808 delta := aPoint - aView computeCorner. |
638 |
809 |
647 self shifLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0 |
818 self shifLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0 |
648 ] |
819 ] |
649 |
820 |
650 ! |
821 ! |
651 |
822 |
|
823 resize:aView origin:aPoint |
|
824 |delta| |
|
825 |
|
826 delta := aPoint - aView computeOrigin. |
|
827 |
|
828 undoHistory disabledTransitionDo:[ |
|
829 self shifLayout:aView top:(delta y) bottom:0 left:(delta x) right:0 |
|
830 ] |
|
831 |
|
832 ! |
|
833 |
652 resize:aView right:aPoint |
834 resize:aView right:aPoint |
653 |
835 |
654 undoHistory disabledTransitionDo:[ |
836 undoHistory disabledTransitionDo:[ |
655 self shifLayout:aView left:0 right:((aPoint x) - (aView computeCorner x)) |
837 self shifLayout:aView left:0 right:((aPoint x) - (aView computeCorner x)) |
656 ] |
838 ] |
659 resize:aView top:aPoint |
841 resize:aView top:aPoint |
660 |
842 |
661 undoHistory disabledTransitionDo:[ |
843 undoHistory disabledTransitionDo:[ |
662 self shifLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0 |
844 self shifLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0 |
663 ] |
845 ] |
|
846 ! |
|
847 |
|
848 resize:aView topRight:aPoint |
|
849 |
|
850 undoHistory disabledTransitionDo:[ |
|
851 self shifLayout:aView top:((aPoint y) - (aView computeOrigin y)) |
|
852 bottom:0 |
|
853 left:0 |
|
854 right:((aPoint x) - (aView computeCorner x)) |
|
855 |
|
856 ] |
|
857 |
664 ! ! |
858 ! ! |
665 |
859 |
666 !UIObjectView methodsFor:'private shift-layout'! |
860 !UIObjectView methodsFor:'private shift-layout'! |
667 |
861 |
668 shifLayout:aView left:l right:r |
862 shifLayout:aView left:l right:r |
669 "shift layout for a view; in case of an open transaction, the |
863 "shift layout for a view; in case of an open transaction, the undo |
670 undoAction will be defined |
864 action is registered |
671 " |
865 " |
672 self shifLayout:aView top:0 bottom:0 left:l right:r |
866 self shifLayout:aView top:0 bottom:0 left:l right:r |
673 |
867 |
674 ! |
868 ! |
675 |
869 |
676 shifLayout:aView top:t bottom:b |
870 shifLayout:aView top:t bottom:b |
677 "shift layout for a view; in case of an open transaction, the |
871 "shift layout for a view; in case of an open transaction, the undo |
678 undoAction will be defined |
872 action is registered |
679 " |
873 " |
680 self shifLayout:aView top:t bottom:b left:0 right:0 |
874 self shifLayout:aView top:t bottom:b left:0 right:0 |
681 |
875 |
682 |
876 |
683 ! |
877 ! |
684 |
878 |
685 shifLayout:aView top:t bottom:b left:l right:r |
879 shifLayout:aView top:t bottom:b left:l right:r |
686 "shift layout for a view; in case of an open transaction, the |
880 "shift layout for a view; in case of an open transaction, the undo |
687 undoAction will be defined |
881 action is registered |
688 " |
882 " |
689 |layout| |
883 |layout| |
690 |
884 |
691 self undoBlockPositionChanged:aView. |
885 self undoBlockPositionChanged:aView. |
692 |
886 |
701 ]. |
895 ]. |
702 |
896 |
703 aView geometryLayout:layout. |
897 aView geometryLayout:layout. |
704 |
898 |
705 |
899 |
706 |
|
707 ! ! |
|
708 |
|
709 !UIObjectView methodsFor:'private undo-actions'! |
|
710 |
|
711 undoBlockDimensionChanged:aView |
|
712 |
|
713 undoHistory isTransactionOpen ifTrue:[ |
|
714 |layout| |
|
715 |
|
716 layout := aView geometryLayout copy. |
|
717 |
|
718 undoHistory addUndoBlock:[ |
|
719 aView geometryLayout:layout. |
|
720 aView superView sizeChanged:nil. |
|
721 ] |
|
722 ] |
|
723 |
|
724 ! |
|
725 |
|
726 undoBlockPositionChanged:aView |
|
727 |
|
728 undoHistory isTransactionOpen ifTrue:[ |
|
729 |layout| |
|
730 |
|
731 layout := aView geometryLayout copy. |
|
732 undoHistory addUndoBlock:[aView geometryLayout:layout] |
|
733 ] |
|
734 |
900 |
735 ! ! |
901 ! ! |
736 |
902 |
737 !UIObjectView methodsFor:'searching'! |
903 !UIObjectView methodsFor:'searching'! |
738 |
904 |
919 |
1085 |
920 isVerticalResizable:aComponent |
1086 isVerticalResizable:aComponent |
921 ^ self subclassResponsibility |
1087 ^ self subclassResponsibility |
922 |
1088 |
923 |
1089 |
924 ! ! |
1090 ! |
925 |
1091 |
926 !UIObjectView methodsFor:'user actions'! |
1092 supportsSubComponents:something |
927 |
1093 "returns true if somrthing supports subcomponents |
928 createWidgetWithClass:aClass |
1094 " |
929 "prepare to create new widgets |
1095 |specClass| |
930 " |
1096 |
931 createClass := aClass. |
1097 something notNil ifTrue:[ |
932 pressAction := [:pressPoint | self startCreate:pressPoint]. |
1098 something isCollection ifFalse:[ |
933 self cursor:Cursor origin. |
1099 specClass := something specClass |
934 |
1100 ] ifTrue:[ |
935 |
1101 something size == 1 ifTrue:[ |
936 ! |
1102 specClass := (something at:1) specClass |
937 |
1103 ] |
938 undoAction |
1104 ]. |
939 undoHistory notEmpty ifTrue:[ |
1105 specClass notNil ifTrue:[ |
940 self unselect. |
1106 ^ specClass basicNew supportsSubComponents |
941 undoHistory undoLast |
1107 ] |
942 ] |
1108 ]. |
|
1109 ^ false |
|
1110 ! ! |
|
1111 |
|
1112 !UIObjectView methodsFor:'transaction & undo'! |
|
1113 |
|
1114 transaction:aType objects:something do:aOneArgBlock |
|
1115 "opens a transaction and evaluates a block within the transaction; the |
|
1116 argument to the block is a view from derived from something |
|
1117 " |
|
1118 self subclassResponsibility |
|
1119 |
|
1120 |
|
1121 ! |
|
1122 |
|
1123 transaction:aType selectionDo:aOneArgBlock |
|
1124 "opens a transaction and evaluates a block within the transaction; the |
|
1125 argument to the block is a view from the selection |
|
1126 " |
|
1127 self transaction:aType objects:selection do:aOneArgBlock |
|
1128 |
|
1129 |
|
1130 ! |
|
1131 |
|
1132 undoBlockDimensionChanged:aView |
|
1133 |
|
1134 undoHistory isTransactionOpen ifTrue:[ |
|
1135 |layout| |
|
1136 |
|
1137 layout := aView geometryLayout copy. |
|
1138 |
|
1139 undoHistory addUndoBlock:[ |
|
1140 aView geometryLayout:layout. |
|
1141 aView superView sizeChanged:nil. |
|
1142 ] |
|
1143 ] |
|
1144 |
|
1145 ! |
|
1146 |
|
1147 undoBlockPositionChanged:aView |
|
1148 |
|
1149 undoHistory isTransactionOpen ifTrue:[ |
|
1150 |layout| |
|
1151 |
|
1152 layout := aView geometryLayout copy. |
|
1153 undoHistory addUndoBlock:[aView geometryLayout:layout] |
|
1154 ] |
|
1155 |
|
1156 ! |
|
1157 |
|
1158 undoLast |
|
1159 self undoLast:1 |
|
1160 ! |
|
1161 |
|
1162 undoLast:n |
|
1163 |
|
1164 self unselect. |
|
1165 undoHistory undoLast:n. |
|
1166 self changed:#tree |
943 |
1167 |
944 |
1168 |
945 ! ! |
1169 ! ! |
946 |
1170 |
947 !UIObjectView methodsFor:'user actions - dimension'! |
1171 !UIObjectView methodsFor:'user actions - dimension'! |
981 ] |
1205 ] |
982 |
1206 |
983 ! |
1207 ! |
984 |
1208 |
985 setDimension:aLayout |
1209 setDimension:aLayout |
986 |undoText| |
1210 |type| |
987 |
1211 |
988 undoText := 'change layout'. |
|
989 aLayout isLayout ifTrue:[ |
1212 aLayout isLayout ifTrue:[ |
990 undoText := 'change to layout frame'. |
1213 aLayout isLayoutFrame ifTrue:[ |
991 aLayout isAlignmentOrigin ifTrue:[ |
1214 type := #layoutFrame |
992 undoText := 'change to layout alignOrigin'. |
|
993 ] ifFalse:[ |
1215 ] ifFalse:[ |
994 aLayout isAlignmentOrigin ifTrue:[ |
1216 aLayout isAlignmentOrigin ifTrue:[ |
995 undoText := 'change to layout origin'. |
1217 type := #layoutAlignOrigin. |
|
1218 ] ifFalse:[ |
|
1219 type := #layoutOrigin |
996 ] |
1220 ] |
997 ] |
1221 ] |
998 ]. |
1222 ] ifFalse:[ |
999 |
1223 type := #layout |
1000 self transition:undoText dimensionDo:[:v| v geometryLayout:(aLayout copy)] |
1224 ]. |
|
1225 |
|
1226 self transition:type dimensionDo:[:v| v geometryLayout:(aLayout copy)] |
1001 |
1227 |
1002 ! |
1228 ! |
1003 |
1229 |
1004 setToDefaultExtent |
1230 setToDefaultExtent |
1005 self transition:'default extent' dimensionDo:[:v| |
1231 self transition:#extent dimensionDo:[:v| |
1006 self resize:v corner:(v computeOrigin + (v preferredExtent)) |
1232 self resize:v corner:(v computeOrigin + (v preferredExtent)) |
1007 ] |
1233 ] |
1008 |
1234 |
1009 ! |
1235 ! |
1010 |
1236 |
1020 self resize:v right:(v computeOrigin + (v preferredExtent)) |
1246 self resize:v right:(v computeOrigin + (v preferredExtent)) |
1021 ] |
1247 ] |
1022 |
1248 |
1023 ! |
1249 ! |
1024 |
1250 |
1025 transition:what dimensionDo:aOneArgBlock |
1251 transition:aType dimensionDo:aOneArgBlock |
1026 "change dimension within a transaction for the selected elements by evaluating |
1252 "change dimension within a transaction for the selected elements by evaluating |
1027 the block with the argument a view. |
1253 the block with the argument a view. |
1028 " |
1254 " |
1029 self selectionHiddenDo:[ |
1255 self selectionHiddenDo:[ |
1030 undoHistory transactionNamed:what do:[ |
1256 self transaction:aType selectionDo:[:aView| |
1031 self selectionDo:[:aView| |
1257 self undoBlockDimensionChanged:aView. |
1032 self undoBlockDimensionChanged:aView. |
1258 aOneArgBlock value:aView. |
1033 aOneArgBlock value:aView. |
1259 aView superView sizeChanged:nil |
1034 self elementChangedLayout:aView. |
1260 ]. |
1035 ] |
1261 self changed:#layout |
1036 ] |
|
1037 ] |
1262 ] |
1038 ! ! |
1263 ! ! |
1039 |
1264 |
1040 !UIObjectView methodsFor:'user actions - move'! |
1265 !UIObjectView methodsFor:'user actions - move'! |
1041 |
1266 |
1042 basicMoveSelectionHorizontal:n |
1267 basicMoveSelectionHorizontal:n |
1043 "move left: n < 0 |
1268 "move left: n < 0 |
1044 move right: n > 0 |
1269 move right: n > 0 |
1045 " |
1270 " |
1046 self selectionHiddenDo:[ |
1271 self selectionHiddenDo:[ |
1047 undoHistory transactionNamed:'move' do:[ |
1272 self transaction:#move selectionDo:[:v| self shifLayout:v left:n right:n]. |
1048 self selectionDo:[:aView|self shifLayout:aView left:n right:n] |
|
1049 ]. |
|
1050 self changed:#layout |
1273 self changed:#layout |
1051 ] |
1274 ] |
1052 |
1275 |
1053 |
1276 |
1054 ! |
1277 ! |
1056 basicMoveSelectionVertical:n |
1279 basicMoveSelectionVertical:n |
1057 "move up: n < 0 |
1280 "move up: n < 0 |
1058 move down: n > 0 |
1281 move down: n > 0 |
1059 " |
1282 " |
1060 self selectionHiddenDo:[ |
1283 self selectionHiddenDo:[ |
1061 undoHistory transactionNamed:'move' do:[ |
1284 self transaction:#move selectionDo:[:v| self shifLayout:v top:n bottom:n ]. |
1062 self selectionDo:[:aView| self shifLayout:aView top:n bottom:n ] |
|
1063 ]. |
|
1064 self changed:#layout |
1285 self changed:#layout |
1065 ] |
1286 ] |
1066 |
1287 |
1067 |
1288 |
1068 |
|
1069 ! |
|
1070 |
|
1071 moveObject:anObject to:aPoint |
|
1072 "move anObject to newOrigin, aPoint |
|
1073 " |
|
1074 |dX dY org delta| |
|
1075 |
|
1076 anObject notNil ifTrue:[ |
|
1077 org := anObject computeOrigin. |
|
1078 |
|
1079 delta := aPoint - org. |
|
1080 delta := (self alignToGrid:aPoint) - org. |
|
1081 dX := delta x. |
|
1082 dY := delta y. |
|
1083 |
|
1084 undoHistory disabledTransitionDo:[ |
|
1085 self shifLayout:anObject top:dY bottom:dY left:dX right:dX |
|
1086 ]. |
|
1087 self elementChangedLayout:anObject. |
|
1088 ] |
|
1089 |
1289 |
1090 ! |
1290 ! |
1091 |
1291 |
1092 moveSelectionDown |
1292 moveSelectionDown |
1093 self moveSelectionDown:1 |
1293 self moveSelectionDown:1 |
1168 |
1368 |
1169 self selectionHiddenDo:[ |
1369 self selectionHiddenDo:[ |
1170 bmost := 0. |
1370 bmost := 0. |
1171 self selectionDo:[:v| bmost := bmost max:(v computeCorner y)]. |
1371 self selectionDo:[:v| bmost := bmost max:(v computeCorner y)]. |
1172 |
1372 |
1173 undoHistory transactionNamed:'align' do:[ |
1373 self transaction:#align selectionDo:[:v| |
1174 self selectionDo:[:v| |
1374 (delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[ |
1175 (delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[ |
1375 self shifLayout:v top:delta bottom:delta. |
1176 self shifLayout:v top:delta bottom:delta |
|
1177 ] |
|
1178 ] |
1376 ] |
1179 ]. |
1377 ]. |
1180 self changed:#layout |
1378 self changed:#layout |
1181 ] |
1379 ] |
1182 |
1380 |
1195 centerX := centerX + (v computeCorner x + v computeOrigin x). |
1393 centerX := centerX + (v computeCorner x + v computeOrigin x). |
1196 counter := counter + 1. |
1394 counter := counter + 1. |
1197 ]. |
1395 ]. |
1198 centerX := centerX // (counter * 2). |
1396 centerX := centerX // (counter * 2). |
1199 |
1397 |
1200 undoHistory transactionNamed:'align' do:[ |
1398 self transaction:#align selectionDo:[:v| |
1201 |newX oldX delta| |
1399 |newX oldX delta| |
1202 |
1400 |
1203 self selectionDo:[:v| |
1401 oldX := v computeOrigin x. |
1204 oldX := v computeOrigin x. |
1402 newX := centerX - ((v computeCorner x - oldX) // 2). |
1205 newX := centerX - ((v computeCorner x - oldX) // 2). |
1403 delta := newX - oldX. |
1206 delta := newX - oldX. |
1404 |
1207 |
1405 self shifLayout:v left:delta right:delta |
1208 self shifLayout:v left:delta right:delta |
|
1209 ] |
|
1210 ]. |
1406 ]. |
1211 self changed:#layout |
1407 self changed:#layout |
1212 ] |
1408 ] |
1213 |
1409 |
1214 |
1410 |
1226 centerY := centerY + (v computeCorner y + v computeOrigin y). |
1422 centerY := centerY + (v computeCorner y + v computeOrigin y). |
1227 counter := counter + 1. |
1423 counter := counter + 1. |
1228 ]. |
1424 ]. |
1229 centerY := centerY // (counter * 2). |
1425 centerY := centerY // (counter * 2). |
1230 |
1426 |
1231 undoHistory transactionNamed:'align' do:[ |
1427 self transaction:#align selectionDo:[:v| |
1232 |newY oldY delta| |
1428 |newY oldY delta| |
1233 |
1429 |
1234 self selectionDo:[:v| |
1430 oldY := v computeOrigin y. |
1235 oldY := v computeOrigin y. |
1431 newY := centerY - ((v computeCorner y - oldY) // 2). |
1236 newY := centerY - ((v computeCorner y - oldY) // 2). |
1432 delta := newY - oldY. |
1237 delta := newY - oldY. |
1433 |
1238 |
1434 self shifLayout:v top:delta bottom:delta |
1239 self shifLayout:v top:delta bottom:delta |
|
1240 ] |
|
1241 ]. |
1435 ]. |
1242 self changed:#layout |
1436 self changed:#layout |
1243 ] |
1437 ] |
1244 ! |
1438 ! |
1245 |
1439 |
1247 |lmost delta| |
1441 |lmost delta| |
1248 |
1442 |
1249 self selectionHiddenDo:[ |
1443 self selectionHiddenDo:[ |
1250 lmost := self selectionFindMinimum:[:v| v computeOrigin x]. |
1444 lmost := self selectionFindMinimum:[:v| v computeOrigin x]. |
1251 |
1445 |
1252 undoHistory transactionNamed:'align' do:[ |
1446 self transaction:#align selectionDo:[:v| |
1253 self selectionDo:[:v| |
1447 (delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[ |
1254 (delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[ |
1448 self shifLayout:v left:delta right:delta |
1255 self shifLayout:v left:delta right:delta |
|
1256 ] |
|
1257 ] |
1449 ] |
1258 ]. |
1450 ]. |
1259 self changed:#layout |
1451 self changed:#layout |
1260 ] |
1452 ] |
1261 |
1453 |
1267 self selectionHiddenDo:[ |
1459 self selectionHiddenDo:[ |
1268 lmost := self selectionFindMinimum:[:v| v computeOrigin x]. |
1460 lmost := self selectionFindMinimum:[:v| v computeOrigin x]. |
1269 rmost := 0. |
1461 rmost := 0. |
1270 self selectionDo:[:v | rmost := rmost max:(v computeCorner x)]. |
1462 self selectionDo:[:v | rmost := rmost max:(v computeCorner x)]. |
1271 |
1463 |
1272 undoHistory transactionNamed:'align' do:[ |
1464 self transaction:#align selectionDo:[:v| |
1273 self selectionDo:[:v| |
1465 self shifLayout:v left:(lmost - (v computeOrigin x)) |
1274 self shifLayout:v left:(lmost - (v computeOrigin x)) |
1466 right:(rmost - (v computeCorner x)) |
1275 right:(rmost - (v computeCorner x)) |
|
1276 ] |
|
1277 ]. |
1467 ]. |
1278 self changed:#layout |
1468 self changed:#layout |
1279 ] |
1469 ] |
1280 ! |
1470 ! |
1281 |
1471 |
1284 |
1474 |
1285 self selectionHiddenDo:[ |
1475 self selectionHiddenDo:[ |
1286 rmost := 0. |
1476 rmost := 0. |
1287 self selectionDo:[:v| rmost := rmost max:(v computeCorner x)]. |
1477 self selectionDo:[:v| rmost := rmost max:(v computeCorner x)]. |
1288 |
1478 |
1289 undoHistory transactionNamed:'align' do:[ |
1479 self transaction:#align selectionDo:[:v| |
1290 self selectionDo:[:v| |
1480 (delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[ |
1291 (delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[ |
1481 self shifLayout:v left:delta right:delta |
1292 self shifLayout:v left:delta right:delta |
|
1293 ] |
|
1294 ] |
1482 ] |
1295 ]. |
1483 ]. |
1296 self changed:#layout |
1484 self changed:#layout |
1297 ] |
1485 ] |
1298 |
1486 |
1302 |tmost delta| |
1490 |tmost delta| |
1303 |
1491 |
1304 self selectionHiddenDo:[ |
1492 self selectionHiddenDo:[ |
1305 tmost := self selectionFindMinimum:[:v| v computeOrigin y]. |
1493 tmost := self selectionFindMinimum:[:v| v computeOrigin y]. |
1306 |
1494 |
1307 undoHistory transactionNamed:'align' do:[ |
1495 self transaction:#align selectionDo:[:v| |
1308 self selectionDo:[:v||delta| |
1496 (delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[ |
1309 (delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[ |
1497 self shifLayout:v top:delta bottom:delta |
1310 self shifLayout:v top:delta bottom:delta |
|
1311 ] |
|
1312 ] |
1498 ] |
1313 ]. |
1499 ]. |
1314 self changed:#layout |
1500 self changed:#layout |
1315 ] |
1501 ] |
1316 |
1502 |
1322 self selectionHiddenDo:[ |
1508 self selectionHiddenDo:[ |
1323 tmost := self selectionFindMinimum:[:v| v computeOrigin y]. |
1509 tmost := self selectionFindMinimum:[:v| v computeOrigin y]. |
1324 bmost := 0. |
1510 bmost := 0. |
1325 self selectionDo:[:v| bmost := bmost max:(v computeCorner y)]. |
1511 self selectionDo:[:v| bmost := bmost max:(v computeCorner y)]. |
1326 |
1512 |
1327 undoHistory transactionNamed:'align' do:[ |
1513 self transaction:#align selectionDo:[:v| |
1328 self selectionDo:[:v| |
1514 self shifLayout:v top:(tmost - (v computeOrigin y)) |
1329 self shifLayout:v top:(tmost - (v computeOrigin y)) |
1515 bottom:(bmost - (v computeCorner y)) |
1330 bottom:(bmost - (v computeCorner y)) |
|
1331 ] |
|
1332 ]. |
1516 ]. |
1333 self changed:#layout |
1517 self changed:#layout |
1334 ] |
1518 ] |
1335 ! |
1519 ! |
1336 |
1520 |
1337 centerSelection:aOneArgBlockXorY |
1521 centerSelection:aOneArgBlockXorY orientation:orientation |
1338 "center selection horizontal or vertical dependant on the block result( x or y). |
1522 "center selection horizontal or vertical dependant on the block result( x or y). |
1339 The argument to the block is the point. |
1523 The argument to the block is the point. |
1340 " |
1524 " |
1341 |superview min max delta val| |
1525 |superview min max delta val| |
1342 |
1526 |
1364 max := (min + val - max) // 2. |
1548 max := (min + val - max) // 2. |
1365 |
1549 |
1366 max == min ifFalse:[ |
1550 max == min ifFalse:[ |
1367 delta := max - min. |
1551 delta := max - min. |
1368 |
1552 |
1369 undoHistory transactionNamed:'center' do:[ |
1553 self transaction:#center selectionDo:[:v| |
1370 self selectionDo:[:aView| |
1554 orientation == #y ifTrue:[ |
1371 self shifLayout:aView top:delta bottom:delta] |
1555 self shifLayout:v top:delta bottom:delta |
1372 ] |
1556 ] ifFalse:[ |
1373 ]. |
1557 self shifLayout:v left:delta right:delta |
1374 self changed:#layout |
1558 ] |
|
1559 ]. |
|
1560 self changed:#layout |
|
1561 ] |
1375 ] |
1562 ] |
1376 |
1563 |
1377 |
1564 |
1378 ! |
1565 ! |
1379 |
1566 |
1380 centerSelectionHor |
1567 centerSelectionHor |
1381 "center selection horizontal |
1568 "center selection horizontal |
1382 " |
1569 " |
1383 self centerSelection:[:aPoint| aPoint x] |
1570 self centerSelection:[:aPoint| aPoint x] orientation:#x |
1384 |
1571 |
1385 |
1572 |
1386 ! |
1573 ! |
1387 |
1574 |
1388 centerSelectionVer |
1575 centerSelectionVer |
1389 "center selection vertical |
1576 "center selection vertical |
1390 " |
1577 " |
1391 self centerSelection:[:aPoint| aPoint y] |
1578 self centerSelection:[:aPoint| aPoint y] orientation:#y |
1392 ! |
1579 ! |
1393 |
1580 |
1394 spreadSelectionHor |
1581 spreadSelectionHor |
1395 |sumWidths min max viewsInOrder topsInOrder count space| |
1582 |sumWidths min max viewsInOrder topsInOrder count space| |
1396 |
1583 |
1414 topsInOrder := viewsInOrder collect:[:aView | aView left]. |
1601 topsInOrder := viewsInOrder collect:[:aView | aView left]. |
1415 topsInOrder sortWith:viewsInOrder. |
1602 topsInOrder sortWith:viewsInOrder. |
1416 |
1603 |
1417 space := (((max - min) - sumWidths) / (count - 1)) rounded asInteger. |
1604 space := (((max - min) - sumWidths) / (count - 1)) rounded asInteger. |
1418 |
1605 |
1419 undoHistory transactionNamed:'spread' do:[ |
1606 self transaction:#spread objects:viewsInOrder do:[:aView| |
1420 viewsInOrder do:[:aView | |
1607 |delta| |
1421 |delta| |
1608 |
1422 |
1609 delta := min - aView computeOrigin x. |
1423 delta := min - aView computeOrigin x. |
1610 self shifLayout:aView left:delta right:delta. |
1424 self shifLayout:aView left:delta right:delta. |
1611 min := min + aView computeExtent x + space |
1425 min := min + aView computeExtent x + space |
|
1426 ] |
|
1427 ]. |
1612 ]. |
1428 self changed:#layout |
1613 self changed:#layout |
1429 ] |
1614 ] |
1430 |
1615 |
1431 ! |
1616 ! |
1453 topsInOrder := viewsInOrder collect:[:aView|aView top]. |
1638 topsInOrder := viewsInOrder collect:[:aView|aView top]. |
1454 topsInOrder sortWith:viewsInOrder. |
1639 topsInOrder sortWith:viewsInOrder. |
1455 |
1640 |
1456 space := (((max - min) - sumHeights) / (count - 1)) rounded asInteger. |
1641 space := (((max - min) - sumHeights) / (count - 1)) rounded asInteger. |
1457 |
1642 |
1458 undoHistory transactionNamed:'spread' do:[ |
1643 self transaction:#spread objects:viewsInOrder do:[:aView| |
1459 viewsInOrder do:[:aView||delta| |
1644 |delta| |
1460 delta := min - aView computeOrigin y. |
1645 |
1461 self shifLayout:aView top:delta bottom:delta. |
1646 delta := min - aView computeOrigin y. |
1462 min := min + aView height + space |
1647 self shifLayout:aView top:delta bottom:delta. |
1463 ] |
1648 min := min + aView height + space |
1464 ]. |
1649 ]. |
1465 self changed:#layout |
1650 self changed:#layout |
1466 ] |
1651 ] |
1467 ! ! |
|
1468 |
|
1469 !UIObjectView methodsFor:'user actions - resize'! |
|
1470 |
|
1471 doDragResize:aPoint |
|
1472 "do a widget resize drag" |
|
1473 |
|
1474 |p| |
|
1475 |
|
1476 self invertOutlineOf:resizedObject. |
|
1477 p := (self alignToGrid:aPoint) - (resizedObject container originRelativeTo:self). |
|
1478 self perform:('x' , resizeSelector , ':') asSymbol with:p. |
|
1479 resizedObject geometryLayout:(resizedObject geometryLayout). |
|
1480 self invertOutlineOf:resizedObject |
|
1481 |
|
1482 "Modified: 5.9.1995 / 17:11:46 / claus" |
|
1483 |
|
1484 ! |
|
1485 |
|
1486 endResize |
|
1487 "cleanup after object resize" |
|
1488 |
|
1489 self invertOutlineOf:resizedObject. |
|
1490 self setDefaultActions. |
|
1491 self select:resizedObject. |
|
1492 resizedObject := nil |
|
1493 |
|
1494 "Modified: 5.9.1995 / 17:11:17 / claus" |
|
1495 |
|
1496 ! |
|
1497 |
|
1498 startResizeBorder:b of:selection at:aPoint |
|
1499 "resize selected view |
|
1500 " |
|
1501 resizedObject := self singleSelection. |
|
1502 |
|
1503 resizedObject notNil ifTrue:[ |
|
1504 resizeSelector := b. |
|
1505 super unselect. |
|
1506 |
|
1507 undoHistory transactionNamed:'extent' do:[ |
|
1508 self undoBlockDimensionChanged:resizedObject. |
|
1509 ]. |
|
1510 |
|
1511 motionAction := [:movePoint | self doDragResize:movePoint]. |
|
1512 releaseAction := [self endResize]. |
|
1513 self invertOutlineOf:resizedObject |
|
1514 ] |
|
1515 ! |
|
1516 |
|
1517 xbottom:aPoint |
|
1518 self resize:resizedObject bottom:aPoint |
|
1519 |
|
1520 ! |
|
1521 |
|
1522 xbottomLeft:aPoint |
|
1523 self resize:resizedObject left:aPoint. |
|
1524 self resize:resizedObject bottom:aPoint. |
|
1525 |
|
1526 ! |
|
1527 |
|
1528 xcorner:aPoint |
|
1529 self resize:resizedObject corner:aPoint. |
|
1530 |
|
1531 ! |
|
1532 |
|
1533 xleft:aPoint |
|
1534 self resize:resizedObject left:aPoint |
|
1535 |
|
1536 ! |
|
1537 |
|
1538 xorigin:aPoint |
|
1539 self resize:resizedObject left:aPoint. |
|
1540 self resize:resizedObject top:aPoint. |
|
1541 |
|
1542 ! |
|
1543 |
|
1544 xright:aPoint |
|
1545 self resize:resizedObject right:aPoint |
|
1546 |
|
1547 ! |
|
1548 |
|
1549 xtop:aPoint |
|
1550 self resize:resizedObject top:aPoint |
|
1551 |
|
1552 ! |
|
1553 |
|
1554 xtopRight:aPoint |
|
1555 self resize:resizedObject right:aPoint. |
|
1556 self resize:resizedObject top:aPoint. |
|
1557 |
|
1558 ! ! |
1652 ! ! |
1559 |
1653 |
1560 !UIObjectView::UndoHistory class methodsFor:'constants'! |
1654 !UIObjectView::UndoHistory class methodsFor:'constants'! |
1561 |
1655 |
1562 maxHistorySize |
1656 maxHistorySize |
1597 ! |
1686 ! |
1598 |
1687 |
1599 reinitialize |
1688 reinitialize |
1600 "reinitialize all attributes |
1689 "reinitialize all attributes |
1601 " |
1690 " |
1602 history := OrderedCollection new. |
1691 history := OrderedCollection new. |
1603 transaction := nil. |
1692 transaction := nil. |
1604 enabled := true. |
1693 enabled := true. |
1605 |
1694 |
1606 |
1695 |
1607 ! ! |
1696 ! ! |
1608 |
1697 |
1609 !UIObjectView::UndoHistory methodsFor:'notifications'! |
1698 !UIObjectView::UndoHistory methodsFor:'menu'! |
1610 |
1699 |
1611 modified |
1700 popupMenu |
1612 "raise notification; history changed |
1701 "returns a submenu for undo |
1613 " |
1702 " |
1614 modifiedAction notNil ifTrue:[ |
1703 |labels| |
1615 |what| |
1704 |
1616 |
1705 labels := OrderedCollection new:(history size). |
1617 history isEmpty ifTrue:[what := nil] |
1706 history reverseDo:[:aRecord| labels add:(aRecord asString) ]. |
1618 ifFalse:[what := history last first]. |
1707 |
1619 |
1708 ^ PopUpMenu labels:labels selectors:#undoLast:. |
1620 modifiedAction value:what |
|
1621 ] |
|
1622 |
|
1623 |
1709 |
1624 ! ! |
1710 ! ! |
1625 |
1711 |
1626 !UIObjectView::UndoHistory methodsFor:'testing'! |
1712 !UIObjectView::UndoHistory methodsFor:'testing'! |
1627 |
1713 |
1648 !UIObjectView::UndoHistory methodsFor:'transaction'! |
1734 !UIObjectView::UndoHistory methodsFor:'transaction'! |
1649 |
1735 |
1650 addUndoBlock:anUndoBlock |
1736 addUndoBlock:anUndoBlock |
1651 "undo block to restore changes; add block to current transaction |
1737 "undo block to restore changes; add block to current transaction |
1652 " |
1738 " |
1653 enabled ifTrue:[ |
|
1654 transaction isNil ifTrue:[ |
|
1655 "no existing transaction |
|
1656 " |
|
1657 self halt |
|
1658 ] ifFalse:[ |
|
1659 (transaction at:2) add:anUndoBlock |
|
1660 ] |
|
1661 ] |
|
1662 |
|
1663 |
|
1664 ! |
|
1665 |
|
1666 closeTransaction |
|
1667 "close current transaction |
|
1668 " |
|
1669 self isTransactionOpen ifTrue:[ |
1739 self isTransactionOpen ifTrue:[ |
1670 transaction last isEmpty ifTrue:[ |
1740 transaction add:anUndoBlock |
1671 "empty undo transaction |
|
1672 " |
|
1673 transaction := nil |
|
1674 ] ifFalse:[ |
|
1675 history addLast:transaction. |
|
1676 transaction := nil. |
|
1677 |
|
1678 history size > (self class maxHistorySize) ifTrue:[ |
|
1679 history removeFirst |
|
1680 ]. |
|
1681 self modified |
|
1682 ] |
|
1683 ] |
1741 ] |
1684 |
1742 |
1685 |
1743 |
1686 ! |
1744 ! |
1687 |
1745 |
1694 enabled := false. |
1752 enabled := false. |
1695 aBlock value. |
1753 aBlock value. |
1696 enabled := oldState. |
1754 enabled := oldState. |
1697 ! |
1755 ! |
1698 |
1756 |
1699 openTransaction:what |
1757 transaction:aType do:aBlock |
1700 "open a new transaction |
1758 self transaction:aType text:nil do:aBlock |
1701 " |
1759 ! |
1702 enabled ifTrue:[ |
1760 |
1703 transaction notNil ifTrue:[ |
1761 transaction:aType text:aTextOrNil do:aBlock |
1704 "transaction within transaction |
|
1705 " |
|
1706 self halt. |
|
1707 ] ifFalse:[ |
|
1708 transaction := Array with:what with:OrderedCollection new |
|
1709 ] |
|
1710 ] |
|
1711 |
|
1712 ! |
|
1713 |
|
1714 transactionNamed:what do:aBlock |
|
1715 "open a transaction; perform the block; at least close the transaction |
1762 "open a transaction; perform the block; at least close the transaction |
1716 " |
1763 " |
1717 self isTransactionOpen ifFalse:[ |
1764 (enabled and:[transaction isNil]) ifTrue:[ |
1718 self openTransaction:what. |
1765 transaction := Transaction type:aType text:aTextOrNil. |
|
1766 |
1719 aBlock value. |
1767 aBlock value. |
1720 self closeTransaction |
1768 |
1721 ] ifTrue:[ |
1769 transaction isEmpty ifFalse:[ |
|
1770 history addLast:transaction. |
|
1771 history size > (self class maxHistorySize) ifTrue:[history removeFirst] |
|
1772 ]. |
|
1773 transaction := nil |
|
1774 |
|
1775 ] ifFalse:[ |
1722 aBlock value |
1776 aBlock value |
1723 ] |
1777 ] |
1724 ! ! |
1778 ! ! |
1725 |
1779 |
1726 !UIObjectView::UndoHistory methodsFor:'undo'! |
1780 !UIObjectView::UndoHistory methodsFor:'undo'! |
1727 |
|
1728 undoLast |
|
1729 "undo last transactions; an open transaction will be closed; |
|
1730 transactions during undo are disabled |
|
1731 " |
|
1732 self undoLast:1 |
|
1733 |
|
1734 |
|
1735 ! |
|
1736 |
1781 |
1737 undoLast:nTransactions |
1782 undoLast:nTransactions |
1738 "undo last n transactions; an open transaction will be closed; |
1783 "undo last n transactions; an open transaction will be closed; |
1739 transactions during undo are disabled |
1784 transactions during undo are disabled |
1740 " |
1785 " |
1741 |actions n| |
1786 |n| |
1742 |
1787 |
1743 transaction := nil. |
1788 transaction := nil. |
1744 n := nTransactions min:(history size). |
1789 n := nTransactions min:(history size). |
1745 |
1790 |
1746 n ~~ 0 ifTrue:[ |
1791 n ~~ 0 ifTrue:[ |
1747 enabled := false. |
1792 enabled := false. |
1748 |
1793 n timesRepeat:[ (history removeLast) undo ]. |
1749 n timesRepeat:[ |
|
1750 actions := (history removeLast) last. |
|
1751 |
|
1752 actions reverseDo:[:aUndoBlock| |
|
1753 aUndoBlock value |
|
1754 ] |
|
1755 ]. |
|
1756 enabled := true. |
1794 enabled := true. |
1757 self modified. |
1795 ] |
1758 ] |
1796 |
1759 |
1797 |
1760 |
1798 ! ! |
|
1799 |
|
1800 !UIObjectView::UndoHistory::Transaction class methodsFor:'instance creation'! |
|
1801 |
|
1802 type:aType text:aTextOrNil |
|
1803 ^ self new type:aType text:aTextOrNil |
|
1804 |
|
1805 |
|
1806 ! ! |
|
1807 |
|
1808 !UIObjectView::UndoHistory::Transaction methodsFor:'accessing'! |
|
1809 |
|
1810 asString |
|
1811 "returns printable string |
|
1812 " |
|
1813 |string| |
|
1814 |
|
1815 string := type asString. |
|
1816 |
|
1817 text notNil ifTrue:[^ string, ' ', text ] |
|
1818 ifFalse:[^ string ] |
|
1819 ! |
|
1820 |
|
1821 text |
|
1822 "returns text or nil assigned to transition |
|
1823 " |
|
1824 ^ text |
|
1825 ! |
|
1826 |
|
1827 type |
|
1828 "returns type assigned to transition |
|
1829 " |
|
1830 ^ type |
|
1831 ! |
|
1832 |
|
1833 type:aType |
|
1834 "change type assigned to transition |
|
1835 " |
|
1836 type := aType |
|
1837 ! ! |
|
1838 |
|
1839 !UIObjectView::UndoHistory::Transaction methodsFor:'add & undo'! |
|
1840 |
|
1841 add:anUndoBlock |
|
1842 "add an undo action to the transition |
|
1843 " |
|
1844 actions isNil ifTrue:[ |
|
1845 actions := anUndoBlock |
|
1846 ] ifFalse:[ |
|
1847 actions isCollection ifFalse:[ |
|
1848 |temp| |
|
1849 |
|
1850 temp := OrderedCollection new. |
|
1851 temp add:actions. |
|
1852 actions := temp. |
|
1853 ]. |
|
1854 actions add:anUndoBlock. |
|
1855 ] |
|
1856 ! |
|
1857 |
|
1858 undo |
|
1859 "undo transition |
|
1860 " |
|
1861 actions notNil ifTrue:[ |
|
1862 actions isCollection ifFalse:[ |
|
1863 actions value |
|
1864 ] ifTrue:[ |
|
1865 actions reverseDo:[:anUndoBlock| anUndoBlock value ] |
|
1866 ] |
|
1867 ] |
|
1868 ! ! |
|
1869 |
|
1870 !UIObjectView::UndoHistory::Transaction methodsFor:'initialization'! |
|
1871 |
|
1872 type:aType text:aTextOrNil |
|
1873 "initialize transition |
|
1874 " |
|
1875 type := aType. |
|
1876 text := aTextOrNil. |
|
1877 ! ! |
|
1878 |
|
1879 !UIObjectView::UndoHistory::Transaction methodsFor:'testing'! |
|
1880 |
|
1881 isEmpty |
|
1882 "returns true if no undo action is registered |
|
1883 " |
|
1884 ^ actions isNil |
|
1885 ! |
|
1886 |
|
1887 notEmpty |
|
1888 "returns true if any undo action is registered |
|
1889 " |
|
1890 ^ actions notNil |
1761 ! ! |
1891 ! ! |
1762 |
1892 |
1763 !UIObjectView class methodsFor:'documentation'! |
1893 !UIObjectView class methodsFor:'documentation'! |
1764 |
1894 |
1765 version |
1895 version |