Author: alanmc
Date: 2007-07-27 16:16:33 -0400 (Fri, 27 Jul 2007)
New Revision: 82884

Added:
   trunk/lunareclipse/Controller/UndoActions/UndoGroup.cs
Removed:
   trunk/lunareclipse/Controller/UndoActions/UndoMoveShape.cs
Modified:
   trunk/lunareclipse/ChangeLog
   trunk/lunareclipse/Controller/UndoActions/UndoActionBase.cs
   trunk/lunareclipse/Controller/UndoActions/UndoAddObject.cs
   trunk/lunareclipse/Controller/UndoActions/UndoPropertyChange.cs
   trunk/lunareclipse/LunarEclipse.mdp
   trunk/lunareclipse/Model/Draw/SelectionDraw.cs
Log:
* Model/Draw/SelectionDraw.cs, Controller/UndoActions/UndoMoveShape.cs,
  Controller/UndoActions/UndoActionBase.cs,
  Controller/UndoActions/UndoPropertyChange.cs,
  Controller/UndoActions/UndoGroup.cs,
  Controller/UndoActions/UndoAddObject.cs, LunarEclipse.mdp: Now
  using the new UndoGroup. Greatly simplifies the undo logic for
  events that change multiple properties at the same time.

Modified: trunk/lunareclipse/ChangeLog
===================================================================
--- trunk/lunareclipse/ChangeLog        2007-07-27 20:12:56 UTC (rev 82883)
+++ trunk/lunareclipse/ChangeLog        2007-07-27 20:16:33 UTC (rev 82884)
@@ -1,5 +1,15 @@
 2007-07-27  Alan McGovern <[EMAIL PROTECTED]> 
 
+       * Model/Draw/SelectionDraw.cs, Controller/UndoActions/UndoMoveShape.cs,
+         Controller/UndoActions/UndoActionBase.cs,
+         Controller/UndoActions/UndoPropertyChange.cs,
+         Controller/UndoActions/UndoGroup.cs,
+         Controller/UndoActions/UndoAddObject.cs, LunarEclipse.mdp: Now
+         using the new UndoGroup. Greatly simplifies the undo logic for
+         events that change multiple properties at the same time.
+
+2007-07-27  Alan McGovern <[EMAIL PROTECTED]> 
+
        * Properties/PropertyGroupBrushes.cs: Cosmetic
 
 2007-07-27  Alan McGovern <[EMAIL PROTECTED]> 

Modified: trunk/lunareclipse/Controller/UndoActions/UndoActionBase.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoActions/UndoActionBase.cs 2007-07-27 
20:12:56 UTC (rev 82883)
+++ trunk/lunareclipse/Controller/UndoActions/UndoActionBase.cs 2007-07-27 
20:16:33 UTC (rev 82884)
@@ -6,14 +6,10 @@
 
 using System;
 
-namespace LunarEclipse
+namespace LunarEclipse.Controller
 {
     public abstract class UndoActionBase
     {
-        protected UndoActionBase()
-        {
-        }
-        
         public abstract void Undo();
         public abstract void Redo();
     }

Modified: trunk/lunareclipse/Controller/UndoActions/UndoAddObject.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoActions/UndoAddObject.cs  2007-07-27 
20:12:56 UTC (rev 82883)
+++ trunk/lunareclipse/Controller/UndoActions/UndoAddObject.cs  2007-07-27 
20:16:33 UTC (rev 82884)
@@ -7,7 +7,7 @@
 using System;
 using System.Collections;
 using System.Windows;
-namespace LunarEclipse
+namespace LunarEclipse.Controller
 {
     public class UndoAddObject : UndoActionBase
     {

Added: trunk/lunareclipse/Controller/UndoActions/UndoGroup.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoActions/UndoGroup.cs      2007-07-27 
20:12:56 UTC (rev 82883)
+++ trunk/lunareclipse/Controller/UndoActions/UndoGroup.cs      2007-07-27 
20:16:33 UTC (rev 82884)
@@ -0,0 +1,38 @@
+// UndoGroup.cs created with MonoDevelop
+// User: alan at 1:29 PM 7/27/2007
+//
+// To change standard headers go to Edit->Preferences->Coding->Standard Headers
+//
+
+using System;
+using System.Collections.Generic;
+
+namespace LunarEclipse.Controller
+{
+       public class UndoGroup : UndoActionBase
+       {
+               private List<UndoActionBase> undos;
+               
+               public List<UndoActionBase> Undos
+               {
+                       get { return undos; }
+               }
+               
+               public UndoGroup()
+               {
+                       undos = new List<UndoActionBase>();
+               }
+               
+               public override void Undo ()
+               {
+                       for(int i = undos.Count - 1; i >= 0; i--)
+                               undos[i].Undo();
+               }
+               
+               public override void Redo ()
+               {
+                       for (int i= 0; i < undos.Count; i++)
+                               undos[i].Redo();
+               }
+       }
+}

Deleted: trunk/lunareclipse/Controller/UndoActions/UndoMoveShape.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoActions/UndoMoveShape.cs  2007-07-27 
20:12:56 UTC (rev 82883)
+++ trunk/lunareclipse/Controller/UndoActions/UndoMoveShape.cs  2007-07-27 
20:16:33 UTC (rev 82884)
@@ -1,47 +0,0 @@
-// /home/alan/Projects/LunarEclipse/Controller/UndoActions/UndoMoveShape.cs 
created with MonoDevelop
-// User: alan at 2:20 PM 6/29/2007
-//
-// To change standard headers go to Edit->Preferences->Coding->Standard Headers
-//
-
-using System;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Media;
-
-namespace LunarEclipse
-{
-    public class UndoMoveShape : UndoActionBase
-    {
-        private Point offset;
-        private Visual[] shapes;
-        
-        internal UndoMoveShape(Visual[] shapes, Point offset)
-        {
-            this.shapes = shapes;
-            this.offset = offset;
-        }
-        
-        
-        public override void Redo ()
-        {
-            foreach(Visual shape in shapes)
-            {
-                Point location = new 
Point((double)shape.GetValue(Canvas.LeftProperty), 
(double)shape.GetValue(Canvas.TopProperty));
-                shape.SetValue<double>(Canvas.LeftProperty, location.X - 
offset.X);
-                shape.SetValue<double>(Canvas.TopProperty, location.Y - 
offset.Y);
-            }
-        }
-
-
-        public override void Undo ()
-        {
-            foreach(Visual shape in shapes)
-            {
-                Point location = new 
Point((double)shape.GetValue(Canvas.LeftProperty), 
(double)shape.GetValue(Canvas.TopProperty));
-                shape.SetValue<double>(Canvas.LeftProperty, location.X + 
offset.X);
-                shape.SetValue<double>(Canvas.TopProperty, location.Y + 
offset.Y);
-            }
-        }
-    }
-}

Modified: trunk/lunareclipse/Controller/UndoActions/UndoPropertyChange.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoActions/UndoPropertyChange.cs     
2007-07-27 20:12:56 UTC (rev 82883)
+++ trunk/lunareclipse/Controller/UndoActions/UndoPropertyChange.cs     
2007-07-27 20:16:33 UTC (rev 82884)
@@ -8,7 +8,7 @@
 using System.Windows;
 using System.Windows.Controls;
 
-namespace LunarEclipse
+namespace LunarEclipse.Controller
 {
     public class UndoPropertyChange : UndoActionBase
     {
@@ -16,6 +16,17 @@
         private DependencyProperty property;
         private object oldvalue;
         private object newvalue;
+               
+               public object OldValue
+               {
+                       get { return oldvalue; }
+                       set { oldvalue = value; }
+               }
+               public object NewValue
+               {
+                       get { return newvalue; }
+                       set { newvalue = value; }
+               }
         
         public UndoPropertyChange(DependencyObject item, DependencyProperty 
property, object oldvalue, object newvalue)
         {

Modified: trunk/lunareclipse/LunarEclipse.mdp
===================================================================
--- trunk/lunareclipse/LunarEclipse.mdp 2007-07-27 20:12:56 UTC (rev 82883)
+++ trunk/lunareclipse/LunarEclipse.mdp 2007-07-27 20:16:33 UTC (rev 82884)
@@ -49,7 +49,6 @@
     <File name="./Properties/PropertyGroupAppearance.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./Properties/IPropertyGroup.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./Properties/PropertyGroupLayout.cs" subtype="Code" 
buildaction="Compile" />
-    <File name="./Controller/UndoActions/UndoMoveShape.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./Model/SelectedBorder.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./Serialization/ReflectionHelper.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./Model/ZIndexComparer.cs" subtype="Code" 
buildaction="Compile" />
@@ -66,6 +65,7 @@
     <File name="./Controller/Recorder.cs" subtype="Code" buildaction="Compile" 
/>
     <File name="./Model/Draw/RecordDraw.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./Model/TransformType.cs" subtype="Code" buildaction="Compile" 
/>
+    <File name="./Controller/UndoActions/UndoGroup.cs" subtype="Code" 
buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, 
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Modified: trunk/lunareclipse/Model/Draw/SelectionDraw.cs
===================================================================
--- trunk/lunareclipse/Model/Draw/SelectionDraw.cs      2007-07-27 20:12:56 UTC 
(rev 82883)
+++ trunk/lunareclipse/Model/Draw/SelectionDraw.cs      2007-07-27 20:16:33 UTC 
(rev 82884)
@@ -36,9 +36,9 @@
         private Visual clickedOnShape;
         private bool prepared;
         private Dictionary<Visual, SelectedBorder> selectedObjects;
-        private double initialRotation = 0;
         private bool shapeMoved;
         private bool shapeAdded;
+               private UndoGroup undoGroup;
         
         public Dictionary<Visual, SelectedBorder> SelectedObjects
         {
@@ -79,9 +79,8 @@
             shapeMoved = false;
             if(clickedOnShape == null)
                 return;
-            
-            RotateTransform t = 
this.clickedOnShape.GetValue(Canvas.RenderTransformProperty) as RotateTransform;
-            this.initialRotation = (t != null) ? t.Angle : 0;
+                       
+                       undoGroup = new UndoGroup();
         }
         
         private List<Visual> GetSelectedObjects(MouseEventArgs e)
@@ -132,7 +131,6 @@
          
             if(!prepared)
             {
-                Console.WriteLine("Preparing");
                 foreach(Visual v in this.controller.Canvas.Children)
                 {
                     UIElement e = v as UIElement;
@@ -148,7 +146,6 @@
 
        private void ClickedOnVisual(object sender, MouseEventArgs e)
        {
-            Console.WriteLine("Clicky");
             if(sender is SelectedBorder)
                 this.clickedOnShape = ((SelectedBorder)sender).Child;
             else
@@ -232,29 +229,6 @@
                 }
             }
             
-            // If we did move some shapes using a click+drag, then we need to 
push
-            // an undo action onto the stack for the group of items which were 
moved
-            if(shapeMoved)
-            {
-                Point start = mouseStart;
-                start.Offset(-mouseLocation.X, -mouseLocation.Y);
-
-                Visual[] movedShapes = new Visual[selectedObjects.Keys.Count];
-                selectedObjects.Keys.CopyTo(movedShapes, 0);
-                controller.UndoEngine.PushUndo(new UndoMoveShape(movedShapes, 
start));
-            }
-            
-            // If we have clicked on a shape, check to see if it was rotated
-            // if it was push an undo action for that rotation
-            if(this.clickedOnShape != null)
-            {
-                               
-                               RotateTransform t =(RotateTransform) 
((TransformGroup)clickedOnShape.GetValue(Canvas.RenderTransformProperty)).Children[(int)TransformType.Rotate];
-                               Console.WriteLine("Clicked: {0}, {1}", 
clickedOnShape, t == null);
-                               if(t.Angle != this.initialRotation)
-                    this.controller.UndoEngine.PushUndo(new 
UndoRotation(this.clickedOnShape, initialRotation, t.Angle));
-            }
-            
             // Reset all the 'move types' to be a standard move. This is 
needed so
             // that on the nextMouseDown, a standard move will be performed 
unless
             // the user clicks on one of the handles for 
stretching/skewing/rotating
@@ -262,7 +236,9 @@
                 keypair.Value.Handle = null;
             
             // Reset the clicked on shape = null
-            this.clickedOnShape = null;
+            clickedOnShape = null;
+                       if(undoGroup.Undos.Count > 0)
+                               controller.UndoEngine.PushUndo(undoGroup);
         }
         
         private void DeselectAll()
@@ -305,7 +281,11 @@
             if(border.Handle == null)
                        {
                                shapeMoved = true;
-                border.Child.SetValue<double>(Canvas.LeftProperty, oldLeft + 
offset.X);
+                               
+                               undoGroup.Undos.Add(new 
UndoPropertyChange(border.Child,Canvas.LeftProperty, oldLeft, oldLeft + 
offset.X));
+                               undoGroup.Undos.Add(new 
UndoPropertyChange(border.Child, Canvas.TopProperty, oldTop, oldTop + 
offset.Y));
+                
+                               
border.Child.SetValue<double>(Canvas.LeftProperty, oldLeft + offset.X);
                 border.Child.SetValue<double>(Canvas.TopProperty, oldTop + 
offset.Y);
             }
             
@@ -316,8 +296,10 @@
                                border.Handle == border.RotateHandle4)
             {
                 Point center;
-                center = new 
Point((double)border.Child.GetValue(Canvas.WidthProperty) * 0.5 + 
(double)border.Child.GetValue(Canvas.LeftProperty),
-                                   
(double)border.Child.GetValue(Canvas.HeightProperty) * 0.5 + 
(double)border.Child.GetValue(Canvas.TopProperty));
+                center = new 
Point((double)border.Child.GetValue(Canvas.WidthProperty) * 0.5 + 
+                                                  
(double)border.Child.GetValue(Canvas.LeftProperty),
+                                   
(double)border.Child.GetValue(Canvas.HeightProperty) * 0.5 + 
+                                                  
(double)border.Child.GetValue(Canvas.TopProperty));
                
                 Point mouseStart = new Point(Position.X - offset.X, Position.Y 
- offset.Y);
                 
@@ -330,8 +312,12 @@
                 // don't apply the change and wait for the next mouse move 
which
                 // will give a proper angle
                 if(!double.IsNaN(difference))
+                               {
+                                       undoGroup.Undos.Add(new 
UndoRotation(border.Child, border.Rotate.Angle,
+                                                                            
border.Rotate.Angle + Converter.RadiansToDegrees(difference))); 
                     border.Rotate.Angle += 
Converter.RadiansToDegrees(difference);
-            }
+                               }
+                       }
             
                        else
                        {
@@ -368,6 +354,12 @@
                        offset = new Point(mouseDistanceTravelled * 
Math.Cos(mouseAngle - Converter.DegreesToRadians(angle)),
                                           mouseDistanceTravelled * 
Math.Sin(mouseAngle - Converter.DegreesToRadians(angle)));
                        
+                       // Create the necessary undo's to be able to completely 
undo this change.
+                       UndoPropertyChange undoWidth = new 
UndoPropertyChange(b.Child, Canvas.WidthProperty, oldWidth, null);
+                       UndoPropertyChange undoHeight = new 
UndoPropertyChange(b.Child, Canvas.HeightProperty, oldHeight, null);
+                       UndoPropertyChange undoLeft = new 
UndoPropertyChange(b.Child, Canvas.LeftProperty, oldLeft, null);
+                       UndoPropertyChange undoTop = new 
UndoPropertyChange(b.Child, Canvas.TopProperty, oldTop, null);
+                       
                        // When resizing shapes, we need to do some crazy maths 
to make sure
                        // that when we resize, the shape doesn't 'float' 
around the canvas.
                        if(b.Handle == b.WidthHandle1 && (oldWidth + offset.X) 
>= 0)
@@ -396,6 +388,16 @@
                                b.Child.SetValue<double>(Canvas.LeftProperty, 
oldLeft - offset.Y * sinAngle / 2.0 );
                                b.Child.SetValue<double>(Canvas.TopProperty, 
oldTop -  offset.Y * (1 - cosAngle) / 2.0);
                        }
-        }
-    }
+                       
+                       undoHeight.NewValue = 
b.Child.GetValue(Canvas.HeightProperty);
+                       undoLeft.NewValue = 
b.Child.GetValue(Canvas.LeftProperty);
+                       undoTop.NewValue = b.Child.GetValue(Canvas.TopProperty);
+                       undoWidth.NewValue = 
b.Child.GetValue(Canvas.WidthProperty);
+                       
+                       this.undoGroup.Undos.Add(undoHeight);
+                       this.undoGroup.Undos.Add(undoLeft);
+                       this.undoGroup.Undos.Add(undoTop);
+                       this.undoGroup.Undos.Add(undoWidth);
+               }
+       }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to