//-------------------------------------------------------------------------------------------------- public void AddTopologyChange(TopologyAction topologyAction, IUndoableTopology container, Entity instance) { // We save every change, so we can rewind it later step by step var action = new TopologyUndoAction(container.Guid); if (action.Set(instance, container, topologyAction)) { _PendingActions.Add(action); } }
//-------------------------------------------------------------------------------------------------- public bool Set(Entity child, IUndoableTopology container, UndoHandler.TopologyAction action) { _ChildGuid = child.Guid; InstanceGuid = container.Guid; _ParentGuid = null; var parent = container.GetParent(child); if (parent != null) { _ParentGuid = parent.Guid; } _TopoAction = action; _StoredData = null; switch (action) { case UndoHandler.TopologyAction.Added: // Counter-Action: Remove. We need only the instance to get it removed later. return(true); case UndoHandler.TopologyAction.Removed: // Counter-Action: Add. We need the instance, the parent and its data to add it later. var data = Serializer.Serialize(child, new SerializationContext(SerializationScope.UndoRedo)); if (!data.IsNullOrEmpty()) { _StoredData = data; //Debug.WriteLine(_StoredData); return(true); } break; case UndoHandler.TopologyAction.Moved: // Counter-Action: Move back. We need instance and parent. return(true); } return(false); }
//-------------------------------------------------------------------------------------------------- public UndoHandler(IUndoableTopology document) { _Document = document; _UndoStack = new LimitedStack <UndoAction[]>(500); _RedoStack = new LimitedStack <UndoAction[]>(500); }