*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Tue, 10 Jan 2006 22:01:26 +0100
changeset 1954 1344ec1f99eb
parent 1953 3b5022bccca4
child 1955 91610d2b87f7
*** empty log message ***
UIObjectView.st
UIPainter.st
UIPainterView.st
--- 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.
 ! !
--- a/UIPainter.st	Tue Jan 10 14:32:38 2006 +0100
+++ b/UIPainter.st	Tue Jan 10 22:01:26 2006 +0100
@@ -2396,6 +2396,10 @@
     ^ self painter hasUndoHistory
 !
 
+hasUndoHistoryHolder
+    ^ self painter hasUndoHistoryHolder
+!
+
 helpIcon
 
     ^Icon helpIcon
--- a/UIPainterView.st	Tue Jan 10 14:32:38 2006 +0100
+++ b/UIPainterView.st	Tue Jan 10 22:01:26 2006 +0100
@@ -465,7 +465,8 @@
 
     self withinTransaction:#paste objects:newSel do:[
         undoHistory addUndoSelector:#undoCreate:
-                           withArgs:(newSel collect:[:v|(self propertyOfView:v) identifier])
+                           withArgs:(newSel collect:[:v|(self propertyOfView:v) identifier]).
+        self undoHistoryChanged.
     ].
 
     self realizeAllSubViews.
@@ -2198,7 +2199,7 @@
     ]
 !
 
-withinTransaction:aType objects:objects do:aNoneArgBlock
+withinTransaction:aType objects:objects do:aNoArgBlock
     "evaluate a block with no arguments within a transaction
     "
     |text size prop|
@@ -2208,21 +2209,20 @@
     size := objects size.
 
     objects isCollection ifTrue:[
-	size == 0 ifTrue:[ ^ self ].
-	size == 1 ifTrue:[ prop := self propertyOfView:(objects first) ]
+        size == 0 ifTrue:[ ^ self ].
+        size == 1 ifTrue:[ prop := self propertyOfView:(objects first) ]
     ] ifFalse:[
-	prop := self propertyOfView:objects
+        prop := self propertyOfView:objects
     ].
 
     prop notNil ifTrue:[
-	text := prop name
+        text := prop name
     ] ifFalse:[
-	text := size printString, ' elements'
+        text := size printString, ' elements'
     ].
 
-    undoHistory withinTransaction:aType text:text do:[
-	aNoneArgBlock value
-    ]
+    undoHistory withinTransaction:aType text:text do:aNoArgBlock.
+    self undoHistoryChanged.
 ! !
 
 !UIPainterView methodsFor:'undo actions'!
@@ -2233,21 +2233,22 @@
     |lyt args prop|
 
     undoHistory isTransactionOpen ifTrue:[
-	prop := self propertyOfView:aView.
-
-	prop notNil ifTrue:[
-	    args := Array new:3.
-	    args at:1 put:(prop identifier).
-
-	    (lyt := aView geometryLayout) notNil ifTrue:[
-		args at:2 put:#geometryLayout:
-	    ] ifFalse:[
-		lyt := aView extent.
-		args at:2 put:#extent:
-	    ].
-	    args at:3 put:(lyt copy).
-	    undoHistory addUndoSelector:#undoLayout: withArgs:args.
-	]
+        prop := self propertyOfView:aView.
+
+        prop notNil ifTrue:[
+            args := Array new:3.
+            args at:1 put:(prop identifier).
+
+            (lyt := aView geometryLayout) notNil ifTrue:[
+                args at:2 put:#geometryLayout:
+            ] ifFalse:[
+                lyt := aView extent.
+                args at:2 put:#extent:
+            ].
+            args at:3 put:(lyt copy).
+            undoHistory addUndoSelector:#undoLayout: withArgs:args.
+            self undoHistoryChanged.
+        ]
     ]
 !
 
@@ -2257,14 +2258,15 @@
     |prop pid|
 
     (prop := self propertyOfView:aView) notNil ifTrue:[
-	(pid := self propertyOfParentForView:aView) notNil ifTrue:[
-	    pid := pid identifier
-	].
-
-	undoHistory addUndoSelector:#undoRemove:
-			   withArgs:(Array with:(self fullSpecFor:aView)
-			       with:(prop identifier)
-			       with:pid)
+        (pid := self propertyOfParentForView:aView) notNil ifTrue:[
+            pid := pid identifier
+        ].
+
+        undoHistory addUndoSelector:#undoRemove:
+                           withArgs:(Array with:(self fullSpecFor:aView)
+                               with:(prop identifier)
+                               with:pid).
+        self undoHistoryChanged.
     ]
 !
 
@@ -2272,8 +2274,9 @@
     "undo method when changing the specification for an object
     "
     aProp notNil ifTrue:[
-	undoHistory addUndoSelector:#undoSpecModify:
-			   withArgs:(Array with:(aProp spec) with:(aProp identifier))
+        undoHistory addUndoSelector:#undoSpecModify:
+                           withArgs:(Array with:(aProp spec) with:(aProp identifier)).
+        self undoHistoryChanged.
     ]
 !