Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 300417b

Browse files
author
gumme
committed
Added tests for undo/redo operations on implicit and explicit lists.
Fixed bug where explicit collection was not handled correctly when resetting a XamlProperty.
1 parent 96f6ad6 commit 300417b

2 files changed

Lines changed: 87 additions & 1 deletion

File tree

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,84 @@ public void UndoRedoChangeGroupTest()
149149
AssertLog("");
150150
}
151151

152+
[Test]
153+
public void UndoRedoImplicitList()
154+
{
155+
UndoRedoListInternal(false);
156+
}
157+
158+
[Test]
159+
public void UndoRedoExplicitList()
160+
{
161+
UndoRedoListInternal(true);
162+
}
163+
164+
void UndoRedoListInternal(bool useExplicitList)
165+
{
166+
DesignItem button = CreateCanvasContext("<Button/>");
167+
UndoService s = button.Context.Services.GetService<UndoService>();
168+
IComponentService component = button.Context.Services.Component;
169+
string expectedXamlWithList;
170+
171+
Assert.IsFalse(s.CanUndo);
172+
Assert.IsFalse(s.CanRedo);
173+
174+
using (ChangeGroup g = button.OpenGroup("UndoRedoListInternal test")) {
175+
DesignItem containerItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer());
176+
177+
var otherListProp = containerItem.Properties["OtherList"];
178+
179+
if(useExplicitList) {
180+
otherListProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList());
181+
182+
expectedXamlWithList = @"<Button>
183+
<Button.Tag>
184+
<Controls0:ExampleClassContainer>
185+
<Controls0:ExampleClassContainer.OtherList>
186+
<Controls0:ExampleClassList>
187+
<Controls0:ExampleClass StringProp=""String value"" />
188+
</Controls0:ExampleClassList>
189+
</Controls0:ExampleClassContainer.OtherList>
190+
</Controls0:ExampleClassContainer>
191+
</Button.Tag>
192+
</Button>";
193+
}
194+
else {
195+
expectedXamlWithList = @"<Button>
196+
<Button.Tag>
197+
<Controls0:ExampleClassContainer>
198+
<Controls0:ExampleClassContainer.OtherList>
199+
<Controls0:ExampleClass StringProp=""String value"" />
200+
</Controls0:ExampleClassContainer.OtherList>
201+
</Controls0:ExampleClassContainer>
202+
</Button.Tag>
203+
</Button>";
204+
}
205+
206+
DesignItem exampleClassItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass());
207+
exampleClassItem.Properties["StringProp"].SetValue("String value");
208+
otherListProp.CollectionElements.Add(exampleClassItem);
209+
210+
button.Properties["Tag"].SetValue(containerItem);
211+
g.Commit();
212+
}
213+
214+
Assert.IsTrue(s.CanUndo);
215+
Assert.IsFalse(s.CanRedo);
216+
AssertCanvasDesignerOutput(expectedXamlWithList, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
217+
218+
s.Undo();
219+
Assert.IsFalse(s.CanUndo);
220+
Assert.IsTrue(s.CanRedo);
221+
AssertCanvasDesignerOutput("<Button>\n</Button>", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
222+
223+
s.Redo();
224+
Assert.IsTrue(s.CanUndo);
225+
Assert.IsFalse(s.CanRedo);
226+
AssertCanvasDesignerOutput(expectedXamlWithList, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
227+
228+
AssertLog("");
229+
}
152230

153231
[Test]
154232
public void AddTextBoxToCanvas()

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,21 @@ public void Reset()
254254

255255
void ResetInternal()
256256
{
257+
bool isExplicitCollection = false;
258+
257259
if (propertyValue != null) {
260+
isExplicitCollection = IsCollection;
261+
258262
propertyValue.RemoveNodeFromParent();
259263
propertyValue.ParentProperty = null;
260264
propertyValue = null;
261265
}
262266
if (_propertyElement != null) {
263-
_propertyElement.ParentNode.RemoveChild(_propertyElement);
267+
Debug.Assert(!isExplicitCollection || _propertyElement.ParentNode == null);
268+
269+
if (!isExplicitCollection) {
270+
_propertyElement.ParentNode.RemoveChild(_propertyElement);
271+
}
264272
_propertyElement = null;
265273
}
266274
}

0 commit comments

Comments
 (0)