Author: alanmc
Date: 2007-07-27 18:33:27 -0400 (Fri, 27 Jul 2007)
New Revision: 82895
Modified:
trunk/lunareclipse/ChangeLog
trunk/lunareclipse/Controller/UndoActions/UndoActionBase.cs
trunk/lunareclipse/Controller/UndoActions/UndoAddObject.cs
trunk/lunareclipse/Controller/UndoActions/UndoGroup.cs
trunk/lunareclipse/Controller/UndoActions/UndoPropertyChange.cs
trunk/lunareclipse/Controller/UndoActions/UndoRotation.cs
trunk/lunareclipse/Controller/UndoEngine.cs
trunk/lunareclipse/Model/Draw/SelectionDraw.cs
Log:
Rather than storing an Undo item for every small change in one group, if there
is an existing undo object that changes the same property, it is updated instead
Modified: trunk/lunareclipse/ChangeLog
===================================================================
--- trunk/lunareclipse/ChangeLog 2007-07-27 22:27:20 UTC (rev 82894)
+++ trunk/lunareclipse/ChangeLog 2007-07-27 22:33:27 UTC (rev 82895)
@@ -1,5 +1,9 @@
2007-07-27 Alan McGovern <[EMAIL PROTECTED]>
+ Rather than storing an Undo item for every small change in one group,
if there is an existing undo object that changes the same property, it is
updated instead
+
+2007-07-27 Alan McGovern <[EMAIL PROTECTED]>
+
* Model/Draw/SelectionDraw.cs, Controller/UndoActions/UndoMoveShape.cs,
Controller/UndoActions/UndoActionBase.cs,
Controller/UndoActions/UndoPropertyChange.cs,
Modified: trunk/lunareclipse/Controller/UndoActions/UndoActionBase.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoActions/UndoActionBase.cs 2007-07-27
22:27:20 UTC (rev 82894)
+++ trunk/lunareclipse/Controller/UndoActions/UndoActionBase.cs 2007-07-27
22:33:27 UTC (rev 82895)
@@ -5,12 +5,26 @@
//
using System;
+using System.Windows;
namespace LunarEclipse.Controller
{
public abstract class UndoActionBase
{
- public abstract void Undo();
+ private DependencyObject target;
+
+ internal DependencyObject Target
+ {
+ get { return target; }
+ set { target = value; }
+ }
+
+ protected UndoActionBase(DependencyObject target)
+ {
+ this.target = target;
+ }
+
+ public abstract void Undo();
public abstract void Redo();
}
}
Modified: trunk/lunareclipse/Controller/UndoActions/UndoAddObject.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoActions/UndoAddObject.cs 2007-07-27
22:27:20 UTC (rev 82894)
+++ trunk/lunareclipse/Controller/UndoActions/UndoAddObject.cs 2007-07-27
22:33:27 UTC (rev 82895)
@@ -12,24 +12,23 @@
public class UndoAddObject : UndoActionBase
{
private DependencyObject collection;
- private DependencyObject item;
public UndoAddObject(DependencyObject collection, DependencyObject
item)
+ :base(item)
{
this.collection = collection;
- this.item = item;
}
public override void Redo ()
{
Type t = collection.GetType();
- t.GetMethod("Add").Invoke(collection, new object[] { item });
+ t.GetMethod("Add").Invoke(collection, new object[] { Target });
}
public override void Undo ()
{
Type t = collection.GetType();
- t.GetMethod("Remove").Invoke(collection, new object[] { item });
+ t.GetMethod("Remove").Invoke(collection, new object[] { Target });
}
}
}
Modified: trunk/lunareclipse/Controller/UndoActions/UndoGroup.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoActions/UndoGroup.cs 2007-07-27
22:27:20 UTC (rev 82894)
+++ trunk/lunareclipse/Controller/UndoActions/UndoGroup.cs 2007-07-27
22:33:27 UTC (rev 82895)
@@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
+using System.Collections;
namespace LunarEclipse.Controller
{
@@ -13,12 +14,14 @@
{
private List<UndoActionBase> undos;
- public List<UndoActionBase> Undos
+
+ public int Count
{
- get { return undos; }
+ get { return undos.Count; }
}
public UndoGroup()
+ :base(null)
{
undos = new List<UndoActionBase>();
}
@@ -34,5 +37,39 @@
for (int i= 0; i < undos.Count; i++)
undos[i].Redo();
}
+
+ public void Add(UndoActionBase undo)
+ {
+ // We need to do a check to see if this property has
already been changed
+ // in this group. If it has, then we update the
existing undo, otherwise
+ // we add it to the group
+ if(undo is UndoPropertyChange)
+ {
+ if(!UpdateExisting((UndoPropertyChange)undo))
+ undos.Add(undo);
+ }
+ else
+ {
+ undos.Add(undo);
+ }
+ }
+
+ private bool UpdateExisting(UndoPropertyChange undo)
+ {
+ for(int i=0; i < this.undos.Count; i++)
+ {
+ UndoPropertyChange existing = undos[i] as
UndoPropertyChange;
+ if(existing == null
+ || !existing.GetType().Equals(undo.GetType())
+ || existing.Target != undo.Target
+ || existing.TargetProperty !=
undo.TargetProperty)
+ continue;
+
+ existing.NewValue = undo.NewValue;
+ return true;
+ }
+
+ return false;
+ }
}
-}
+}
\ No newline at end of file
Modified: trunk/lunareclipse/Controller/UndoActions/UndoPropertyChange.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoActions/UndoPropertyChange.cs
2007-07-27 22:27:20 UTC (rev 82894)
+++ trunk/lunareclipse/Controller/UndoActions/UndoPropertyChange.cs
2007-07-27 22:33:27 UTC (rev 82895)
@@ -12,7 +12,6 @@
{
public class UndoPropertyChange : UndoActionBase
{
- private DependencyObject item;
private DependencyProperty property;
private object oldvalue;
private object newvalue;
@@ -27,10 +26,15 @@
get { return newvalue; }
set { newvalue = value; }
}
+
+ public DependencyProperty TargetProperty
+ {
+ get { return property; }
+ }
public UndoPropertyChange(DependencyObject item, DependencyProperty
property, object oldvalue, object newvalue)
- {
- this.item = item;
+ :base(item)
+ {
this.property = property;
this.oldvalue = oldvalue;
this.newvalue = newvalue;
@@ -38,13 +42,13 @@
public override void Redo ()
{
- item.SetValue<object>(property, newvalue);
+ Target.SetValue<object>(property, newvalue);
}
public override void Undo ()
{
- item.SetValue<object>(property, oldvalue);
+ Target.SetValue<object>(property, oldvalue);
}
}
}
Modified: trunk/lunareclipse/Controller/UndoActions/UndoRotation.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoActions/UndoRotation.cs 2007-07-27
22:27:20 UTC (rev 82894)
+++ trunk/lunareclipse/Controller/UndoActions/UndoRotation.cs 2007-07-27
22:33:27 UTC (rev 82895)
@@ -9,31 +9,32 @@
{
- public class UndoRotation : UndoActionBase
+ public class UndoRotation : UndoPropertyChange
{
- private double finalAngle;
- private double initialAngle;
- private Visual visual;
-
+ private Visual Visual
+ {
+ get { return (Visual)Target; }
+ }
+
public UndoRotation(Visual visual, double initialAngle, double
finalAngle)
+ :base(visual, null, initialAngle, finalAngle)
{
- this.finalAngle = finalAngle;
- this.initialAngle = initialAngle;
- this.visual = visual;
+
}
public override void Redo ()
{
- TransformGroup g =
(TransformGroup)visual.GetValue(Canvas.RenderTransformProperty);
+ TransformGroup g =
(TransformGroup)Visual.GetValue(Canvas.RenderTransformProperty);
RotateTransform t =
(RotateTransform)g.Children[(int)TransformType.Rotate];
- t.Angle = finalAngle;
+ t.Angle = (double)NewValue;
}
public override void Undo ()
{
- TransformGroup g =
(TransformGroup)visual.GetValue(Canvas.RenderTransformProperty);
+ TransformGroup g =
(TransformGroup)Visual.GetValue(Canvas.RenderTransformProperty);
RotateTransform t =
(RotateTransform)g.Children[(int)TransformType.Rotate];
- t.Angle = initialAngle;
+ t.Angle = (double)OldValue;
}
+
}
}
Modified: trunk/lunareclipse/Controller/UndoEngine.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoEngine.cs 2007-07-27 22:27:20 UTC (rev
82894)
+++ trunk/lunareclipse/Controller/UndoEngine.cs 2007-07-27 22:33:27 UTC (rev
82895)
@@ -45,6 +45,10 @@
internal void PushUndo(UndoActionBase action, bool clearRedo)
{
+ Console.WriteLine("Added: " + action.ToString());
+ if(action is UndoGroup)
+ Console.WriteLine("Count: {0}",
((UndoGroup)action).Count);
+
this.undo.Push(action);
RaiseUndoAdded();
Modified: trunk/lunareclipse/Model/Draw/SelectionDraw.cs
===================================================================
--- trunk/lunareclipse/Model/Draw/SelectionDraw.cs 2007-07-27 22:27:20 UTC
(rev 82894)
+++ trunk/lunareclipse/Model/Draw/SelectionDraw.cs 2007-07-27 22:33:27 UTC
(rev 82895)
@@ -237,7 +237,7 @@
// Reset the clicked on shape = null
clickedOnShape = null;
- if(undoGroup.Undos.Count > 0)
+ if(undoGroup.Count > 0)
controller.UndoEngine.PushUndo(undoGroup);
}
@@ -282,8 +282,8 @@
{
shapeMoved = true;
- 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));
+ undoGroup.Add(new
UndoPropertyChange(border.Child,Canvas.LeftProperty, oldLeft, oldLeft +
offset.X));
+ undoGroup.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);
@@ -313,7 +313,7 @@
// will give a proper angle
if(!double.IsNaN(difference))
{
- undoGroup.Undos.Add(new
UndoRotation(border.Child, border.Rotate.Angle,
+ undoGroup.Add(new
UndoRotation(border.Child, border.Rotate.Angle,
border.Rotate.Angle + Converter.RadiansToDegrees(difference)));
border.Rotate.Angle +=
Converter.RadiansToDegrees(difference);
}
@@ -394,10 +394,10 @@
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);
+ this.undoGroup.Add(undoHeight);
+ this.undoGroup.Add(undoLeft);
+ this.undoGroup.Add(undoTop);
+ this.undoGroup.Add(undoWidth);
}
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches