There are a couple gotchas with this as well that need to be implemented
Parent parent = Parent.NewParent();
Child child = Child.NewChild();
parent.Add(child);
parent.BeginEdit();
parent.Remove(child);
//User decides they want to undo manually what they just did
parent.Add(child); // At this step, the editLevelAdded value of the child gets incremented from 0 to 1
parent.CancelEdit(); //Now on a cancel the child will be removed from the parent because the add edit level is set at 1
This can be fixed by keeping track of the editLevelAdded as you currently do in the UnDeleteChild() method when adding the child to a class where it is in the deleted list. Except another issue happens when you do something like this:
Parent parent = Parent.NewParent();
Child child = Child.NewChild();
parent.Add(child);
parent.BeginEdit();
parent.Remove(child);
//User decides they want to add it to a different parent
Parent parent2 = Parent.NewParent();
parent2.Add(child); // At this step, the editLevelAdded value of the child gets incremented from 0 to 1 because we have nothing in the deleted list to compare it to
//This updates the value in the deleted list of the parent
parent.CancelEdit(); //So now on a cancel the child will be removed from the parent because the edit level is set at 1
I believe the best way to fix this is always add a clone of the object to the deleted list, so the editLevel added value will always be stay the same, even if the object is added to a different collection
Parent parent = Parent.NewParent();
Child child = Child.NewChild();
parent.Add(child);
parent.BeginEdit();
parent.Remove(child); // Clone the object and set the clone to the deleted list in the RemoveItem() method
//User decides they want to add it to a different parent
Parent parent2 = Parent.NewParent();
parent2.Add(child); // At this step, the editLevelAdded value of the child gets incremented from 0 to 1 because we have nothing in the deleted list to compare it to
//This updates the value in the deleted list of the parent
parent.CancelEdit(); //So now on a cancel the child will be removed from parent2 because the edit level is set at 1, but the clone of parent is uneffected, and it is added back to the list. If the object is removed form parent 2 and added back to parent, the Add method will need to updated the editLevelAdded value of the item, to whatever the clone has.
Are there any other issues you can think of with this solution?