UIObjectView.st
changeset 1954 1344ec1f99eb
parent 1918 f5e8dfe30838
child 1959 fd6bf76e712a
--- a/UIObjectView.st	Tue Jan 10 14:32:38 2006 +0100
+++ b/UIObjectView.st	Tue Jan 10 22:01:26 2006 +0100
@@ -17,7 +17,7 @@
 ObjectView subclass:#UIObjectView
 	instanceVariableNames:'saveSelection undoHistory copiedExtent copiedLayout resizeData
 		clipChildren selectionHiddenLevel gridParameters
-		setOfSuperViewsSizeChanged'
+		setOfSuperViewsSizeChanged hasUndoHistoryHolder'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-UIPainter'
@@ -435,7 +435,8 @@
 resetModification
     "set modification state to false"
 
-    undoHistory resetModification
+    undoHistory resetModification.
+    self undoHistoryChanged.
 !
 
 testMode
@@ -452,6 +453,15 @@
     enableChannel value:(aBoolean not)
 ! !
 
+!UIObjectView methodsFor:'aspects'!
+
+hasUndoHistoryHolder
+    hasUndoHistoryHolder isNil ifTrue:[
+        hasUndoHistoryHolder := false asValue
+    ].
+    ^ hasUndoHistoryHolder
+! !
+
 !UIObjectView methodsFor:'blocked'!
 
 addObject:anObject
@@ -636,7 +646,8 @@
     setOfSuperViewsSizeChanged := IdentitySet new.
     self setDefaultActions.
 
-    undoHistory          := UndoHistory on:self.
+    undoHistory := UndoHistory on:self.
+
     self enableChannel:(true asValue).
     clipChildren         := true.
     selectionHiddenLevel := 0.
@@ -777,18 +788,17 @@
     |dX dY org delta|
 
     anObject notNil ifTrue:[
-	org := anObject computeOrigin.
-
-	delta := aPoint - org.
-	delta := (self alignToGrid:aPoint) - org.
-	dX := delta x.
-	dY := delta y.
-
-	undoHistory withoutTransactionDo:[
-	    self shiftLayout:anObject top:dY bottom:dY left:dX right:dX
-	]
+        org := anObject computeOrigin.
+
+        delta := aPoint - org.
+        delta := (self alignToGrid:aPoint) - org.
+        dX := delta x.
+        dY := delta y.
+
+        undoHistory withoutTransactionDo:[
+            self shiftLayout:anObject top:dY bottom:dY left:dX right:dX
+        ]
     ]
-
 !
 
 startObjectMoveAt:aPoint
@@ -972,6 +982,12 @@
     self invertOutlineOf:object
 ! !
 
+!UIObjectView methodsFor:'private'!
+
+undoHistoryChanged
+    self hasUndoHistoryHolder value:(self hasUndoHistory).
+! !
+
 !UIObjectView methodsFor:'private-handles'!
 
 handlesOf:aComponent do:aTwoArgAction
@@ -1007,88 +1023,83 @@
 !
 
 resize:aView bottom:aPoint
-    "resize a views bottom
-    "
+    "resize a views bottom"
+
     undoHistory withoutTransactionDo:[
-	self shiftLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y))
-    ]
+        self shiftLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y))
+    ].
 !
 
 resize:aView bottomLeft:aPoint
-    "resize a views bottom and left
-    "
+    "resize a views bottom and left"
+
     undoHistory withoutTransactionDo:[
-	self shiftLayout:aView top:0
-			    bottom:((aPoint y) - (aView computeCorner y))
-			      left:((aPoint x) - (aView computeOrigin x))
-			     right:0
+        self shiftLayout:aView top:0
+                            bottom:((aPoint y) - (aView computeCorner y))
+                              left:((aPoint x) - (aView computeOrigin x))
+                             right:0
 
     ]
-
-
 !
 
 resize:aView corner:aPoint
-    "resize a views corner
-    "
+    "resize a views corner"
+
     |delta|
 
     delta := aPoint - aView computeCorner.
 
     undoHistory withoutTransactionDo:[
-	self shiftLayout:aView top:0 bottom:(delta y) left:0 right:(delta x)
+        self shiftLayout:aView top:0 bottom:(delta y) left:0 right:(delta x)
     ]
 !
 
 resize:aView left:aPoint
-    "resize a views left
-    "
+    "resize a views left"
+
     undoHistory withoutTransactionDo:[
-	self shiftLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0
+        self shiftLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0
     ]
-
 !
 
 resize:aView origin:aPoint
-    "resize a views origin
-    "
+    "resize a views origin"
+
     |delta|
 
     delta := aPoint - aView computeOrigin.
 
     undoHistory withoutTransactionDo:[
-	self shiftLayout:aView top:(delta y) bottom:0 left:(delta x) right:0
+        self shiftLayout:aView top:(delta y) bottom:0 left:(delta x) right:0
     ]
-
 !
 
 resize:aView right:aPoint
-    "resize a views right
-    "
+    "resize a views right"
+
     undoHistory withoutTransactionDo:[
-	self shiftLayout:aView left:0 right:((aPoint x) - (aView computeCorner x))
+        self shiftLayout:aView left:0 right:((aPoint x) - (aView computeCorner x))
     ]
 !
 
 resize:aView top:aPoint
-    "resize a views top
-    "
+    "resize a views top"
+
     undoHistory withoutTransactionDo:[
-	self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0
+        self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0
     ]
 !
 
 resize:aView topRight:aPoint
-    "resize a views top and right
-    "
+    "resize a views top and right"
+
     undoHistory withoutTransactionDo:[
-	self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y))
-			    bottom:0
-			      left:0
-			     right:((aPoint x) - (aView computeCorner x))
+        self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y))
+                            bottom:0
+                              left:0
+                             right:((aPoint x) - (aView computeCorner x))
 
     ]
-
 ! !
 
 !UIObjectView methodsFor:'private-shift layout'!
@@ -2030,7 +2041,7 @@
                         self createUndoLayout:aView.
                         aView geometryLayout:layout.
 
-                        undoHistory withoutTransactionDo:[    
+                        undoHistory withoutTransactionDo:[
                             self shiftLayout:aView left:(lmost - (aView computeOrigin x))
                                                   right:(rmost - (aView computeCorner x)).
                         ].
@@ -2110,36 +2121,36 @@
     |tmost bmost sel|
 
     (sel := self moveableSelection) notNil ifTrue:[
-	self withSelectionHiddenDo:[
-	    self numberOfSelections > 1 ifTrue:[
-		tmost := (sel first) computeOrigin y.
-		bmost := (sel first) computeCorner y.
-
-		self transaction:#alignTopBottom selectionDo:[:aView|
-		    |layout|
-		    layout := self class asLayoutFrameFromView:aView.
-
-		    layout notNil ifTrue:[
-			self createUndoLayout:aView.
-			aView geometryLayout:layout.
-
-			undoHistory withoutTransactionDo:[    
-			    self shiftLayout:aView top:(tmost - (aView computeOrigin y))
-						bottom:(bmost - (aView computeCorner y)).
-			].
-			self elementChangedSize:aView
-		    ]
-		]
-	    ] ifFalse:[
-		self extentToFrame:#TopBottom do:[:aLayout|
-		    aLayout topOffset:0.
-		    aLayout topFraction:0.0.
-		    aLayout bottomOffset:0.
-		    aLayout bottomFraction:1.0.
-		]
-	    ]
-	].
-	self layoutChanged
+        self withSelectionHiddenDo:[
+            self numberOfSelections > 1 ifTrue:[
+                tmost := (sel first) computeOrigin y.
+                bmost := (sel first) computeCorner y.
+
+                self transaction:#alignTopBottom selectionDo:[:aView|
+                    |layout|
+                    layout := self class asLayoutFrameFromView:aView.
+
+                    layout notNil ifTrue:[
+                        self createUndoLayout:aView.
+                        aView geometryLayout:layout.
+
+                        undoHistory withoutTransactionDo:[
+                            self shiftLayout:aView top:(tmost - (aView computeOrigin y))
+                                                bottom:(bmost - (aView computeCorner y)).
+                        ].
+                        self elementChangedSize:aView
+                    ]
+                ]
+            ] ifFalse:[
+                self extentToFrame:#TopBottom do:[:aLayout|
+                    aLayout topOffset:0.
+                    aLayout topFraction:0.0.
+                    aLayout bottomOffset:0.
+                    aLayout bottomFraction:1.0.
+                ]
+            ]
+        ].
+        self layoutChanged
     ]
 !
 
@@ -2317,50 +2328,50 @@
 !UIObjectView methodsFor:'user actions-undo history'!
 
 enableUndoHistory:aState
-    "enable or disable undo history
-    "
+    "enable or disable undo history"
+
     undoHistory enabled:aState
 !
 
 openUndoMenu
-    "open undo menu
-    "
     self select:nil.
     undoHistory openUndoMenu
 !
 
 removeUndoHistory
-    "delete total undo history
-    "
-    undoHistory on:self
+    "delete total undo history"
+
+    undoHistory initializeFor:self.
+    self undoHistoryChanged
 !
 
 undoLast
-    "undo last action
-    "
+    "undo last action"
+
     |newSel oldSel|
 
-    undoHistory isEmpty ifFalse:[
-	self hasSelection ifTrue:[
-	    oldSel := OrderedCollection new.
-	    newSel := OrderedCollection new.
-
-	    self selectionDo:[:aView||p|
-		(p := self propertyOfView:aView) notNil ifTrue:[
-		    oldSel add:(p identifier)
-		]
-	    ].
-	    self setSelection:nil withRedraw:true.
-	].
-
-	self withSelectionHiddenDo:[undoHistory undoLast:1].
-
-	oldSel notNil ifTrue:[
-	    oldSel do:[:id||v|
-		(v := self findViewWithId:id) notNil ifTrue:[newSel add:v]
-	    ].
-	    self select:newSel.
-	]
+    undoHistory notEmpty ifTrue:[
+        self hasSelection ifTrue:[
+            oldSel := OrderedCollection new.
+            newSel := OrderedCollection new.
+
+            self selectionDo:[:aView||p|
+                (p := self propertyOfView:aView) notNil ifTrue:[
+                    oldSel add:(p identifier)
+                ]
+            ].
+            self setSelection:nil withRedraw:true.
+        ].
+
+        self withSelectionHiddenDo:[undoHistory undoLast:1].
+
+        oldSel notNil ifTrue:[
+            oldSel do:[:id||v|
+                (v := self findViewWithId:id) notNil ifTrue:[newSel add:v]
+            ].
+            self select:newSel.
+        ].
+        self undoHistoryChanged.
     ].
 ! !
 
@@ -2451,23 +2462,19 @@
     |history|
 
     history := self new.
-    history on:aPainter.
-  ^ history
-
-
+    history initializeFor:aPainter.
+    ^ history
 ! !
 
 !UIObjectView::UndoHistory methodsFor:'accessing'!
 
 addUndoSelector:aSelector withArgs:anArray
     "add a selector with arguments to the current opened transaction; in case that no
-     transaction is opened or disabled the block will not be kept in the history.
-    "
+     transaction is opened or disabled the block will not be kept in the history."
+
     self isTransactionOpen ifTrue:[
-	transaction add:(Association key:aSelector value:anArray)
+        transaction add:(Association key:aSelector value:anArray)
     ]
-
-
 ! !
 
 !UIObjectView::UndoHistory methodsFor:'accessing-behavior'!
@@ -2481,8 +2488,8 @@
 !
 
 resetModification
-    "set modification state to false
-    "
+    "set modification state to false"
+
 "/    startIdentifier := identifier
 
     identifier := startIdentifier := 0.
@@ -2492,43 +2499,43 @@
 !UIObjectView::UndoHistory methodsFor:'activation & deactivation'!
 
 withinTransaction:aType text:aTextOrNil do:aBlock
-    "open a transaction; perform the block; at least close the transaction
-    "
+    "open a transaction; perform the block; at least close the transaction"
+
     (enabled and:[transaction isNil]) ifTrue:[
-	transaction := Transaction type:aType text:aTextOrNil.
-
-	aBlock value.
-
-	transaction isEmpty ifFalse:[
-	    identifier := identifier + 1.
-	    transaction identifier:identifier.
-	    history addLast:transaction.
-	    history size > (self class maxHistorySize) ifTrue:[history removeFirst]
-	].
-	transaction := nil
+        transaction := Transaction type:aType text:aTextOrNil.
+
+        aBlock value.
+
+        transaction isEmpty ifFalse:[
+            identifier := identifier + 1.
+            transaction identifier:identifier.
+            history addLast:transaction.
+            history size > (self class maxHistorySize) ifTrue:[history removeFirst]
+        ].
+        transaction := nil
 
     ] ifFalse:[
-	aBlock value
+        aBlock value
     ]
 !
 
-withoutTransactionDo:aNoneArgBlock
+withoutTransactionDo:aNoArgBlock
     "evaluate the block without opening a transaction or keeping changes
-     within a still opened transaction
-    "
+     within a still opened transaction"
+
     |oldState|
 
     oldState := enabled.
     enabled  := false.
-    aNoneArgBlock value.
+    aNoArgBlock value.
     enabled  := oldState.
 ! !
 
 !UIObjectView::UndoHistory methodsFor:'initialization'!
 
-on:aPainter
-    "setup for a painter and delete all existing history records
-    "
+initializeFor:aPainter
+    "setup for a painter and delete all existing history records"
+
     identifier      := 0.
     startIdentifier := 0.
 
@@ -2536,8 +2543,11 @@
     history     := OrderedCollection new.
     transaction := nil.
     enabled     := true.
-
-
+!
+
+on:aPainter
+    self halt.
+    self initializeFor:aPainter
 ! !
 
 !UIObjectView::UndoHistory methodsFor:'menu'!
@@ -2589,24 +2599,28 @@
 !UIObjectView::UndoHistory methodsFor:'testing'!
 
 isEmpty
-    "returns true if undo history is empty
-    "
+    "returns true if undo history is empty"
+
     ^ history isEmpty
-
-
 !
 
 isModified
-    "returns true if history is modified
-    "
+    "returns true if history is modified"
+
     self isEmpty ifTrue:[
-	^ false
+        ^ false
     ].
-  ^ history last identifier ~~ startIdentifier
+    ^ history last identifier ~~ startIdentifier
 !
 
 isTransactionOpen
     ^ (enabled and:[transaction notNil])
+!
+
+notEmpty
+    "returns true if undo history is not empty"
+
+    ^ history notEmpty
 ! !
 
 !UIObjectView::UndoHistory methodsFor:'undo'!
@@ -2623,8 +2637,8 @@
 
 undoLast:nTransactions
     "undo last n transactions; an open transaction will be closed;
-     transactions during undo are disabled
-    "
+     transactions during undo are disabled"
+
     |repeatTimes transaction actions|
 
     transaction := nil.
@@ -2632,16 +2646,16 @@
     repeatTimes := nTransactions min:(history size).
 
     repeatTimes timesRepeat:[
-	transaction := history removeLast.
-	actions     := transaction actions.
-
-	actions isCollection ifTrue:[
-	    actions reverseDo:[:aBlock|
-		painter perform:(aBlock key) with:(aBlock value)
-	    ]
-	] ifFalse:[
-	    painter perform:(actions key) with:(actions value)
-	]
+        transaction := history removeLast.
+        actions     := transaction actions.
+
+        actions isCollection ifTrue:[
+            actions reverseDo:[:aBlock|
+                painter perform:(aBlock key) with:(aBlock value)
+            ]
+        ] ifFalse:[
+            painter perform:(actions key) with:(actions value)
+        ]
     ].
     enabled := true.
 ! !