public override void Redo(ref MokkanList list) { // Delete from list all objects kept in cloneList int n = list.Count; for (int i = n - 1; i >= 0; i--) { bool toDelete = false; DrawObject objectToDelete = list[i]; foreach (DrawObject o in cloneList) { if (objectToDelete.ID == o.ID) { toDelete = true; break; } } if (toDelete) { list.RemoveAt(i); } } }
public override void Undo(ref MokkanList list) { // Add all objects from clone list to list - // opposite to DeleteAll foreach (DrawObject o in cloneList) { list.Add(o); } }
public override void Redo(ref MokkanList list) { list.UnselectAll(); foreach (DrawObject o in cloneObjects) { list.Add(o); } addedCount = cloneObjects.Count; }
public override void Undo(ref MokkanList list) { list.UnselectAll(); // Add all objects from cloneList to list. foreach (DrawObject o in cloneList) { list.Add(o); } }
List <DrawObject> cloneList; // contains selected items which are deleted // Create this command BEFORE applying Delete All function. public CommandDelete(MokkanList mokkanList) { cloneList = new List <DrawObject>(); // Make clone of the list selection. foreach (DrawObject o in mokkanList.Selection) { cloneList.Add(o.Clone()); } }
/// <summary> /// Clone this instance /// </summary> /// <returns></returns> public MokkanList Clone() { MokkanList ret = (MokkanList)this.MemberwiseClone(); MokkanObjectList list = new MokkanObjectList(); foreach (DrawObject o in MokkanObjectList) { list.Add(o.Clone()); } ret.MokkanObjectList = list; return(ret); }
// Fill list from selection private void FillList(MokkanList mokkanList, ref List <DrawObject> listToFill) { listToFill = new List <DrawObject>(); DrawObject changedObj; foreach (DrawObject o in mokkanList.Selection) { changedObj = o.Clone(); changedObj.Selected = false; listToFill.Add(changedObj); } }
// Create this command BEFORE applying Delete All function. public CommandDeleteAll(MokkanList mokkanList) { cloneList = new List <DrawObject>(); // Make clone of the whole list. // Add objects in reverse order because mokkanList.Add // insert every object to the beginning. int n = mokkanList.Count; for (int i = n - 1; i >= 0; i--) { cloneList.Add(mokkanList[i].Clone()); } }
// Replace objects in mokkanList with objects from list private void ReplaceObjects(MokkanList mokkanList, List <DrawObject> list) { for (int i = 0; i < mokkanList.Count; i++) { DrawObject replacement = null; foreach (DrawObject o in list) { if (o.ID == mokkanList[i].ID) { replacement = o; replacement.Selected = true; break; } } if (replacement != null) { mokkanList.Replace(i, replacement); } } }
public override void Redo(ref MokkanList list) { // Clear list - make DeleteAll again list.Clear(); }
public override void Redo(ref MokkanList list) { list = listAfter.Clone(); }
public UndoManager(MokkanList mokkanList) { this._mokkanList = mokkanList; ClearHistory(); }
public override void Undo(ref MokkanList list) { // Replace all objects in the list with objects from listBefore ReplaceObjects(list, listBefore); }
public override void Undo(ref MokkanList list) { list.DeleteLastAddedObjects(addedCount); }
// Create this command BEFORE operation. public CommandChangeState(MokkanList mokkanList) { // Keep objects state before operation. FillList(mokkanList, ref listBefore); }
// Call this function AFTER operation. public void NewState(MokkanList mokkanList) { // Keep objects state after operation. FillList(mokkanList, ref listAfter); }
// Create this command BEFORE operation. public CommandChange(MokkanList mokkanList) { // Keep objects state before operation. listBefore = mokkanList.Clone(); }
public override void Redo(ref MokkanList list) { // Replace all objects in the list with objects from listAfter ReplaceObjects(list, listAfter); }
// Call this function AFTER operation. public void NewState(MokkanList mokkanList) { // Keep objects state after operation. listAfter = mokkanList.Clone(); }
public override void Undo(ref MokkanList list) { list = listBefore.Clone(); }
// This command is used to make Redo operation. // It makes original command again. public abstract void Redo(ref MokkanList list);