Browse Source

Added tests for different combinations of Remove, Clear and Reset with multiple undo/redo operations on collections. Added ResetAction to make the tests pass.

pull/657/head
gumme 11 years ago
parent
commit
5b285348b0
  1. 60
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs
  2. 24
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelProperty.cs
  3. 54
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs

60
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs

@ -164,6 +164,11 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -164,6 +164,11 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
Execute(new RemoveAtAction(this, index, (XamlDesignItem)this[index]));
}
internal ITransactionItem CreateResetTransaction()
{
return new ResetAction(this);
}
void Execute(ITransactionItem item)
{
UndoService undoService = context.Services.GetService<UndoService>();
@ -279,5 +284,60 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -279,5 +284,60 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
return false;
}
}
sealed class ResetAction : ITransactionItem
{
readonly XamlModelCollectionElementsCollection collection;
readonly XamlDesignItem[] items;
public ResetAction(XamlModelCollectionElementsCollection collection)
{
this.collection = collection;
items = new XamlDesignItem[collection.Count];
for (int i = 0; i < collection.Count; i++) {
items[i] = (XamlDesignItem)collection[i];
}
}
#region ITransactionItem implementation
public void Do()
{
for (int i = items.Length - 1; i >= 0; i--) {
collection.RemoveInternal(i, items[i]);
}
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty);
}
public void Undo()
{
for (int i = 0; i < items.Length; i++) {
collection.InsertInternal(i, items[i]);
}
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty);
}
public bool MergeWith(ITransactionItem other)
{
return false;
}
#endregion
#region IUndoAction implementation
public ICollection<DesignItem> AffectedElements {
get {
return new DesignItem[] { collection.modelProperty.DesignItem };
}
}
public string Title {
get {
return "Reset collection";
}
}
#endregion
}
}
}

24
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelProperty.cs

@ -249,11 +249,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -249,11 +249,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
public sealed class PropertyChangeAction : ITransactionItem
{
XamlModelProperty property;
XamlPropertyValue oldValue;
readonly XamlModelProperty property;
readonly XamlPropertyValue oldValue;
XamlPropertyValue newValue;
bool oldIsSet;
readonly bool oldIsSet;
bool newIsSet;
readonly ITransactionItem collectionTransactionItem;
public PropertyChangeAction(XamlModelProperty property, XamlPropertyValue newValue, bool newIsSet)
{
@ -263,6 +264,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -263,6 +264,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
oldIsSet = property._property.IsSet;
oldValue = property._property.PropertyValue;
if (oldIsSet && oldValue == null && property.IsCollection) {
collectionTransactionItem = property._collectionElements.CreateResetTransaction();
}
}
public string Title {
@ -276,6 +281,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -276,6 +281,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
public void Do()
{
if (collectionTransactionItem != null) {
collectionTransactionItem.Do();
}
if (newIsSet)
property.SetValueInternal(newValue);
else
@ -284,8 +293,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -284,8 +293,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
public void Undo()
{
if (oldIsSet)
property.SetValueInternal(oldValue);
if (oldIsSet) {
if (collectionTransactionItem != null) {
collectionTransactionItem.Undo();
} else {
property.SetValueInternal(oldValue);
}
}
else
property.ResetInternal();
}

54
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs

@ -377,8 +377,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -377,8 +377,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
AssertLog("");
}
[Test]
public void UndoRedoRemoveClearResetInputBindings()
void UndoRedoInputBindingsRemoveClearResetInternal(bool remove, bool clear, bool reset)
{
const string originalXaml = "<TextBlock Text=\"My text\" />";
@ -420,9 +419,12 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -420,9 +419,12 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
DesignItem di = inputbinding.CollectionElements.First();
// Remove, Clear, Reset combination caused exception at first Undo after this group commit before the issue was fixed
inputbinding.CollectionElements.Remove(di);
inputbinding.CollectionElements.Clear();
inputbinding.Reset();
if (remove)
inputbinding.CollectionElements.Remove(di);
if (clear)
inputbinding.CollectionElements.Clear();
if (reset)
inputbinding.Reset();
di = component.RegisterComponentForDesigner(new System.Windows.Input.MouseBinding());
di.Properties["Gesture"].SetValue(System.Windows.Input.MouseAction.LeftDoubleClick);
@ -452,6 +454,48 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -452,6 +454,48 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
AssertLog("");
}
[Test]
public void UndoRedoInputBindingsRemoveClearReset()
{
UndoRedoInputBindingsRemoveClearResetInternal(true, true, true);
}
[Test]
public void UndoRedoInputBindingsRemove()
{
UndoRedoInputBindingsRemoveClearResetInternal(true, false, false);
}
[Test]
public void UndoRedoInputBindingsClear()
{
UndoRedoInputBindingsRemoveClearResetInternal(false, true, false);
}
[Test]
public void UndoRedoInputBindingsReset()
{
UndoRedoInputBindingsRemoveClearResetInternal(false, false, true);
}
[Test]
public void UndoRedoInputBindingsRemoveClear()
{
UndoRedoInputBindingsRemoveClearResetInternal(true, true, false);
}
[Test]
public void UndoRedoInputBindingsRemoveReset()
{
UndoRedoInputBindingsRemoveClearResetInternal(true, false, true);
}
[Test]
public void UndoRedoInputBindingsClearReset()
{
UndoRedoInputBindingsRemoveClearResetInternal(false, true, true);
}
[Test]
public void AddTextBoxToCanvas()
{

Loading…
Cancel
Save