775 "move anObject to newOrigin, aPoint |
786 "move anObject to newOrigin, aPoint |
776 " |
787 " |
777 |dX dY org delta| |
788 |dX dY org delta| |
778 |
789 |
779 anObject notNil ifTrue:[ |
790 anObject notNil ifTrue:[ |
780 org := anObject computeOrigin. |
791 org := anObject computeOrigin. |
781 |
792 |
782 delta := aPoint - org. |
793 delta := aPoint - org. |
783 delta := (self alignToGrid:aPoint) - org. |
794 delta := (self alignToGrid:aPoint) - org. |
784 dX := delta x. |
795 dX := delta x. |
785 dY := delta y. |
796 dY := delta y. |
786 |
797 |
787 undoHistory withoutTransactionDo:[ |
798 undoHistory withoutTransactionDo:[ |
788 self shiftLayout:anObject top:dY bottom:dY left:dX right:dX |
799 self shiftLayout:anObject top:dY bottom:dY left:dX right:dX |
789 ] |
800 ] |
790 ] |
801 ] |
791 |
|
792 ! |
802 ! |
793 |
803 |
794 startObjectMoveAt:aPoint |
804 startObjectMoveAt:aPoint |
795 "start object(s) move at a point |
805 "start object(s) move at a point |
796 " |
806 " |
1005 aView clear; redraw |
1021 aView clear; redraw |
1006 ]. |
1022 ]. |
1007 ! |
1023 ! |
1008 |
1024 |
1009 resize:aView bottom:aPoint |
1025 resize:aView bottom:aPoint |
1010 "resize a views bottom |
1026 "resize a views bottom" |
1011 " |
1027 |
1012 undoHistory withoutTransactionDo:[ |
1028 undoHistory withoutTransactionDo:[ |
1013 self shiftLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y)) |
1029 self shiftLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y)) |
1014 ] |
1030 ]. |
1015 ! |
1031 ! |
1016 |
1032 |
1017 resize:aView bottomLeft:aPoint |
1033 resize:aView bottomLeft:aPoint |
1018 "resize a views bottom and left |
1034 "resize a views bottom and left" |
1019 " |
1035 |
1020 undoHistory withoutTransactionDo:[ |
1036 undoHistory withoutTransactionDo:[ |
1021 self shiftLayout:aView top:0 |
1037 self shiftLayout:aView top:0 |
1022 bottom:((aPoint y) - (aView computeCorner y)) |
1038 bottom:((aPoint y) - (aView computeCorner y)) |
1023 left:((aPoint x) - (aView computeOrigin x)) |
1039 left:((aPoint x) - (aView computeOrigin x)) |
1024 right:0 |
1040 right:0 |
1025 |
1041 |
1026 ] |
1042 ] |
1027 |
|
1028 |
|
1029 ! |
1043 ! |
1030 |
1044 |
1031 resize:aView corner:aPoint |
1045 resize:aView corner:aPoint |
1032 "resize a views corner |
1046 "resize a views corner" |
1033 " |
1047 |
1034 |delta| |
1048 |delta| |
1035 |
1049 |
1036 delta := aPoint - aView computeCorner. |
1050 delta := aPoint - aView computeCorner. |
1037 |
1051 |
1038 undoHistory withoutTransactionDo:[ |
1052 undoHistory withoutTransactionDo:[ |
1039 self shiftLayout:aView top:0 bottom:(delta y) left:0 right:(delta x) |
1053 self shiftLayout:aView top:0 bottom:(delta y) left:0 right:(delta x) |
1040 ] |
1054 ] |
1041 ! |
1055 ! |
1042 |
1056 |
1043 resize:aView left:aPoint |
1057 resize:aView left:aPoint |
1044 "resize a views left |
1058 "resize a views left" |
1045 " |
1059 |
1046 undoHistory withoutTransactionDo:[ |
1060 undoHistory withoutTransactionDo:[ |
1047 self shiftLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0 |
1061 self shiftLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0 |
1048 ] |
1062 ] |
1049 |
|
1050 ! |
1063 ! |
1051 |
1064 |
1052 resize:aView origin:aPoint |
1065 resize:aView origin:aPoint |
1053 "resize a views origin |
1066 "resize a views origin" |
1054 " |
1067 |
1055 |delta| |
1068 |delta| |
1056 |
1069 |
1057 delta := aPoint - aView computeOrigin. |
1070 delta := aPoint - aView computeOrigin. |
1058 |
1071 |
1059 undoHistory withoutTransactionDo:[ |
1072 undoHistory withoutTransactionDo:[ |
1060 self shiftLayout:aView top:(delta y) bottom:0 left:(delta x) right:0 |
1073 self shiftLayout:aView top:(delta y) bottom:0 left:(delta x) right:0 |
1061 ] |
1074 ] |
1062 |
|
1063 ! |
1075 ! |
1064 |
1076 |
1065 resize:aView right:aPoint |
1077 resize:aView right:aPoint |
1066 "resize a views right |
1078 "resize a views right" |
1067 " |
1079 |
1068 undoHistory withoutTransactionDo:[ |
1080 undoHistory withoutTransactionDo:[ |
1069 self shiftLayout:aView left:0 right:((aPoint x) - (aView computeCorner x)) |
1081 self shiftLayout:aView left:0 right:((aPoint x) - (aView computeCorner x)) |
1070 ] |
1082 ] |
1071 ! |
1083 ! |
1072 |
1084 |
1073 resize:aView top:aPoint |
1085 resize:aView top:aPoint |
1074 "resize a views top |
1086 "resize a views top" |
1075 " |
1087 |
1076 undoHistory withoutTransactionDo:[ |
1088 undoHistory withoutTransactionDo:[ |
1077 self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0 |
1089 self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0 |
1078 ] |
1090 ] |
1079 ! |
1091 ! |
1080 |
1092 |
1081 resize:aView topRight:aPoint |
1093 resize:aView topRight:aPoint |
1082 "resize a views top and right |
1094 "resize a views top and right" |
1083 " |
1095 |
1084 undoHistory withoutTransactionDo:[ |
1096 undoHistory withoutTransactionDo:[ |
1085 self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) |
1097 self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) |
1086 bottom:0 |
1098 bottom:0 |
1087 left:0 |
1099 left:0 |
1088 right:((aPoint x) - (aView computeCorner x)) |
1100 right:((aPoint x) - (aView computeCorner x)) |
1089 |
1101 |
1090 ] |
1102 ] |
1091 |
|
1092 ! ! |
1103 ! ! |
1093 |
1104 |
1094 !UIObjectView methodsFor:'private-shift layout'! |
1105 !UIObjectView methodsFor:'private-shift layout'! |
1095 |
1106 |
1096 shiftLayout:aView left:l right:r |
1107 shiftLayout:aView left:l right:r |
2108 of one selection the object is aligned to the top/bottom of its superview |
2119 of one selection the object is aligned to the top/bottom of its superview |
2109 " |
2120 " |
2110 |tmost bmost sel| |
2121 |tmost bmost sel| |
2111 |
2122 |
2112 (sel := self moveableSelection) notNil ifTrue:[ |
2123 (sel := self moveableSelection) notNil ifTrue:[ |
2113 self withSelectionHiddenDo:[ |
2124 self withSelectionHiddenDo:[ |
2114 self numberOfSelections > 1 ifTrue:[ |
2125 self numberOfSelections > 1 ifTrue:[ |
2115 tmost := (sel first) computeOrigin y. |
2126 tmost := (sel first) computeOrigin y. |
2116 bmost := (sel first) computeCorner y. |
2127 bmost := (sel first) computeCorner y. |
2117 |
2128 |
2118 self transaction:#alignTopBottom selectionDo:[:aView| |
2129 self transaction:#alignTopBottom selectionDo:[:aView| |
2119 |layout| |
2130 |layout| |
2120 layout := self class asLayoutFrameFromView:aView. |
2131 layout := self class asLayoutFrameFromView:aView. |
2121 |
2132 |
2122 layout notNil ifTrue:[ |
2133 layout notNil ifTrue:[ |
2123 self createUndoLayout:aView. |
2134 self createUndoLayout:aView. |
2124 aView geometryLayout:layout. |
2135 aView geometryLayout:layout. |
2125 |
2136 |
2126 undoHistory withoutTransactionDo:[ |
2137 undoHistory withoutTransactionDo:[ |
2127 self shiftLayout:aView top:(tmost - (aView computeOrigin y)) |
2138 self shiftLayout:aView top:(tmost - (aView computeOrigin y)) |
2128 bottom:(bmost - (aView computeCorner y)). |
2139 bottom:(bmost - (aView computeCorner y)). |
2129 ]. |
2140 ]. |
2130 self elementChangedSize:aView |
2141 self elementChangedSize:aView |
2131 ] |
2142 ] |
2132 ] |
2143 ] |
2133 ] ifFalse:[ |
2144 ] ifFalse:[ |
2134 self extentToFrame:#TopBottom do:[:aLayout| |
2145 self extentToFrame:#TopBottom do:[:aLayout| |
2135 aLayout topOffset:0. |
2146 aLayout topOffset:0. |
2136 aLayout topFraction:0.0. |
2147 aLayout topFraction:0.0. |
2137 aLayout bottomOffset:0. |
2148 aLayout bottomOffset:0. |
2138 aLayout bottomFraction:1.0. |
2149 aLayout bottomFraction:1.0. |
2139 ] |
2150 ] |
2140 ] |
2151 ] |
2141 ]. |
2152 ]. |
2142 self layoutChanged |
2153 self layoutChanged |
2143 ] |
2154 ] |
2144 ! |
2155 ! |
2145 |
2156 |
2146 centerSelection:aOneArgBlockXorY orientation:orientation |
2157 centerSelection:aOneArgBlockXorY orientation:orientation |
2147 "center selection horizontal or vertical dependant on the block result( x or y). |
2158 "center selection horizontal or vertical dependant on the block result( x or y). |
2315 ! ! |
2326 ! ! |
2316 |
2327 |
2317 !UIObjectView methodsFor:'user actions-undo history'! |
2328 !UIObjectView methodsFor:'user actions-undo history'! |
2318 |
2329 |
2319 enableUndoHistory:aState |
2330 enableUndoHistory:aState |
2320 "enable or disable undo history |
2331 "enable or disable undo history" |
2321 " |
2332 |
2322 undoHistory enabled:aState |
2333 undoHistory enabled:aState |
2323 ! |
2334 ! |
2324 |
2335 |
2325 openUndoMenu |
2336 openUndoMenu |
2326 "open undo menu |
|
2327 " |
|
2328 self select:nil. |
2337 self select:nil. |
2329 undoHistory openUndoMenu |
2338 undoHistory openUndoMenu |
2330 ! |
2339 ! |
2331 |
2340 |
2332 removeUndoHistory |
2341 removeUndoHistory |
2333 "delete total undo history |
2342 "delete total undo history" |
2334 " |
2343 |
2335 undoHistory on:self |
2344 undoHistory initializeFor:self. |
|
2345 self undoHistoryChanged |
2336 ! |
2346 ! |
2337 |
2347 |
2338 undoLast |
2348 undoLast |
2339 "undo last action |
2349 "undo last action" |
2340 " |
2350 |
2341 |newSel oldSel| |
2351 |newSel oldSel| |
2342 |
2352 |
2343 undoHistory isEmpty ifFalse:[ |
2353 undoHistory notEmpty ifTrue:[ |
2344 self hasSelection ifTrue:[ |
2354 self hasSelection ifTrue:[ |
2345 oldSel := OrderedCollection new. |
2355 oldSel := OrderedCollection new. |
2346 newSel := OrderedCollection new. |
2356 newSel := OrderedCollection new. |
2347 |
2357 |
2348 self selectionDo:[:aView||p| |
2358 self selectionDo:[:aView||p| |
2349 (p := self propertyOfView:aView) notNil ifTrue:[ |
2359 (p := self propertyOfView:aView) notNil ifTrue:[ |
2350 oldSel add:(p identifier) |
2360 oldSel add:(p identifier) |
2351 ] |
2361 ] |
2352 ]. |
2362 ]. |
2353 self setSelection:nil withRedraw:true. |
2363 self setSelection:nil withRedraw:true. |
2354 ]. |
2364 ]. |
2355 |
2365 |
2356 self withSelectionHiddenDo:[undoHistory undoLast:1]. |
2366 self withSelectionHiddenDo:[undoHistory undoLast:1]. |
2357 |
2367 |
2358 oldSel notNil ifTrue:[ |
2368 oldSel notNil ifTrue:[ |
2359 oldSel do:[:id||v| |
2369 oldSel do:[:id||v| |
2360 (v := self findViewWithId:id) notNil ifTrue:[newSel add:v] |
2370 (v := self findViewWithId:id) notNil ifTrue:[newSel add:v] |
2361 ]. |
2371 ]. |
2362 self select:newSel. |
2372 self select:newSel. |
2363 ] |
2373 ]. |
|
2374 self undoHistoryChanged. |
2364 ]. |
2375 ]. |
2365 ! ! |
2376 ! ! |
2366 |
2377 |
2367 !UIObjectView::PostEventHandler methodsFor:'event handling'! |
2378 !UIObjectView::PostEventHandler methodsFor:'event handling'! |
2368 |
2379 |
2449 |
2460 |
2450 on:aPainter |
2461 on:aPainter |
2451 |history| |
2462 |history| |
2452 |
2463 |
2453 history := self new. |
2464 history := self new. |
2454 history on:aPainter. |
2465 history initializeFor:aPainter. |
2455 ^ history |
2466 ^ history |
2456 |
|
2457 |
|
2458 ! ! |
2467 ! ! |
2459 |
2468 |
2460 !UIObjectView::UndoHistory methodsFor:'accessing'! |
2469 !UIObjectView::UndoHistory methodsFor:'accessing'! |
2461 |
2470 |
2462 addUndoSelector:aSelector withArgs:anArray |
2471 addUndoSelector:aSelector withArgs:anArray |
2463 "add a selector with arguments to the current opened transaction; in case that no |
2472 "add a selector with arguments to the current opened transaction; in case that no |
2464 transaction is opened or disabled the block will not be kept in the history. |
2473 transaction is opened or disabled the block will not be kept in the history." |
2465 " |
2474 |
2466 self isTransactionOpen ifTrue:[ |
2475 self isTransactionOpen ifTrue:[ |
2467 transaction add:(Association key:aSelector value:anArray) |
2476 transaction add:(Association key:aSelector value:anArray) |
2468 ] |
2477 ] |
2469 |
|
2470 |
|
2471 ! ! |
2478 ! ! |
2472 |
2479 |
2473 !UIObjectView::UndoHistory methodsFor:'accessing-behavior'! |
2480 !UIObjectView::UndoHistory methodsFor:'accessing-behavior'! |
2474 |
2481 |
2475 enabled |
2482 enabled |
2479 enabled:aState |
2486 enabled:aState |
2480 enabled := aState |
2487 enabled := aState |
2481 ! |
2488 ! |
2482 |
2489 |
2483 resetModification |
2490 resetModification |
2484 "set modification state to false |
2491 "set modification state to false" |
2485 " |
2492 |
2486 "/ startIdentifier := identifier |
2493 "/ startIdentifier := identifier |
2487 |
2494 |
2488 identifier := startIdentifier := 0. |
2495 identifier := startIdentifier := 0. |
2489 history := OrderedCollection new. |
2496 history := OrderedCollection new. |
2490 ! ! |
2497 ! ! |
2491 |
2498 |
2492 !UIObjectView::UndoHistory methodsFor:'activation & deactivation'! |
2499 !UIObjectView::UndoHistory methodsFor:'activation & deactivation'! |
2493 |
2500 |
2494 withinTransaction:aType text:aTextOrNil do:aBlock |
2501 withinTransaction:aType text:aTextOrNil do:aBlock |
2495 "open a transaction; perform the block; at least close the transaction |
2502 "open a transaction; perform the block; at least close the transaction" |
2496 " |
2503 |
2497 (enabled and:[transaction isNil]) ifTrue:[ |
2504 (enabled and:[transaction isNil]) ifTrue:[ |
2498 transaction := Transaction type:aType text:aTextOrNil. |
2505 transaction := Transaction type:aType text:aTextOrNil. |
2499 |
2506 |
2500 aBlock value. |
2507 aBlock value. |
2501 |
2508 |
2502 transaction isEmpty ifFalse:[ |
2509 transaction isEmpty ifFalse:[ |
2503 identifier := identifier + 1. |
2510 identifier := identifier + 1. |
2504 transaction identifier:identifier. |
2511 transaction identifier:identifier. |
2505 history addLast:transaction. |
2512 history addLast:transaction. |
2506 history size > (self class maxHistorySize) ifTrue:[history removeFirst] |
2513 history size > (self class maxHistorySize) ifTrue:[history removeFirst] |
2507 ]. |
2514 ]. |
2508 transaction := nil |
2515 transaction := nil |
2509 |
2516 |
2510 ] ifFalse:[ |
2517 ] ifFalse:[ |
2511 aBlock value |
2518 aBlock value |
2512 ] |
2519 ] |
2513 ! |
2520 ! |
2514 |
2521 |
2515 withoutTransactionDo:aNoneArgBlock |
2522 withoutTransactionDo:aNoArgBlock |
2516 "evaluate the block without opening a transaction or keeping changes |
2523 "evaluate the block without opening a transaction or keeping changes |
2517 within a still opened transaction |
2524 within a still opened transaction" |
2518 " |
2525 |
2519 |oldState| |
2526 |oldState| |
2520 |
2527 |
2521 oldState := enabled. |
2528 oldState := enabled. |
2522 enabled := false. |
2529 enabled := false. |
2523 aNoneArgBlock value. |
2530 aNoArgBlock value. |
2524 enabled := oldState. |
2531 enabled := oldState. |
2525 ! ! |
2532 ! ! |
2526 |
2533 |
2527 !UIObjectView::UndoHistory methodsFor:'initialization'! |
2534 !UIObjectView::UndoHistory methodsFor:'initialization'! |
2528 |
2535 |
2529 on:aPainter |
2536 initializeFor:aPainter |
2530 "setup for a painter and delete all existing history records |
2537 "setup for a painter and delete all existing history records" |
2531 " |
2538 |
2532 identifier := 0. |
2539 identifier := 0. |
2533 startIdentifier := 0. |
2540 startIdentifier := 0. |
2534 |
2541 |
2535 painter := aPainter. |
2542 painter := aPainter. |
2536 history := OrderedCollection new. |
2543 history := OrderedCollection new. |
2537 transaction := nil. |
2544 transaction := nil. |
2538 enabled := true. |
2545 enabled := true. |
2539 |
2546 ! |
2540 |
2547 |
|
2548 on:aPainter |
|
2549 self halt. |
|
2550 self initializeFor:aPainter |
2541 ! ! |
2551 ! ! |
2542 |
2552 |
2543 !UIObjectView::UndoHistory methodsFor:'menu'! |
2553 !UIObjectView::UndoHistory methodsFor:'menu'! |
2544 |
2554 |
2545 openUndoMenu |
2555 openUndoMenu |
2621 "Modified: / 30.10.2001 / 13:46:33 / cg" |
2635 "Modified: / 30.10.2001 / 13:46:33 / cg" |
2622 ! |
2636 ! |
2623 |
2637 |
2624 undoLast:nTransactions |
2638 undoLast:nTransactions |
2625 "undo last n transactions; an open transaction will be closed; |
2639 "undo last n transactions; an open transaction will be closed; |
2626 transactions during undo are disabled |
2640 transactions during undo are disabled" |
2627 " |
2641 |
2628 |repeatTimes transaction actions| |
2642 |repeatTimes transaction actions| |
2629 |
2643 |
2630 transaction := nil. |
2644 transaction := nil. |
2631 enabled := false. |
2645 enabled := false. |
2632 repeatTimes := nTransactions min:(history size). |
2646 repeatTimes := nTransactions min:(history size). |
2633 |
2647 |
2634 repeatTimes timesRepeat:[ |
2648 repeatTimes timesRepeat:[ |
2635 transaction := history removeLast. |
2649 transaction := history removeLast. |
2636 actions := transaction actions. |
2650 actions := transaction actions. |
2637 |
2651 |
2638 actions isCollection ifTrue:[ |
2652 actions isCollection ifTrue:[ |
2639 actions reverseDo:[:aBlock| |
2653 actions reverseDo:[:aBlock| |
2640 painter perform:(aBlock key) with:(aBlock value) |
2654 painter perform:(aBlock key) with:(aBlock value) |
2641 ] |
2655 ] |
2642 ] ifFalse:[ |
2656 ] ifFalse:[ |
2643 painter perform:(actions key) with:(actions value) |
2657 painter perform:(actions key) with:(actions value) |
2644 ] |
2658 ] |
2645 ]. |
2659 ]. |
2646 enabled := true. |
2660 enabled := true. |
2647 ! ! |
2661 ! ! |
2648 |
2662 |
2649 !UIObjectView::UndoHistory::Transaction class methodsFor:'documentation'! |
2663 !UIObjectView::UndoHistory::Transaction class methodsFor:'documentation'! |