public override object GetUndoDiff() { XmlElement oldElem = UndoManager.GetObjectStatus(this); UndoWriter writer = new UndoWriter(oldElem.OwnerDocument, UndoManager); XmlElement newElem = Write(writer); ObjectDiff actionsDiff = GetDiffGenerator().GetDiff(this, oldElem); UndoManager.UpdateObjectStatus(this, newElem); return(actionsDiff); }
public override object ApplyUndoRedoDiff(object diff) { ObjectDiff actionsDiff = (ObjectDiff)diff; XmlElement status = UndoManager.GetObjectStatus(this); DiffGenerator differ = GetDiffGenerator(); differ.ApplyDiff(this, actionsDiff); actionsDiff = differ.GetDiff(this, status); UndoWriter writer = new UndoWriter(status.OwnerDocument, UndoManager); XmlElement newElem = Write(writer); UndoManager.UpdateObjectStatus(this, newElem); return(actionsDiff); }
public override object ApplyUndoRedoDiff (object diff) { ObjectDiff actionsDiff = (ObjectDiff) diff; XmlElement status = UndoManager.GetObjectStatus (this); DiffGenerator differ = GetDiffGenerator(); differ.ApplyDiff (this, actionsDiff); actionsDiff = differ.GetDiff (this, status); UndoWriter writer = new UndoWriter (status.OwnerDocument, UndoManager); XmlElement newElem = Write (writer); UndoManager.UpdateObjectStatus (this, newElem); return actionsDiff; }
public override object GetUndoDiff () { XmlElement oldElem = UndoManager.GetObjectStatus (this); UndoWriter writer = new UndoWriter (oldElem.OwnerDocument, UndoManager); XmlElement newElem = Write (writer); ObjectDiff actionsDiff = GetDiffGenerator().GetDiff (this, oldElem); UndoManager.UpdateObjectStatus (this, newElem); return actionsDiff; }
public override object ApplyUndoRedoDiff (object data) { ObjectDiff diff = ((ObjectDiff[]) data)[0]; ObjectDiff actionsDiff = ((ObjectDiff[]) data)[1]; ObjectDiff reverseDiff = null; ObjectDiff reverseActionsDiff = null; XmlElement status = UndoManager.GetObjectStatus (this); XmlElement oldStatus = (XmlElement) status.CloneNode (true); UndoReader reader = new UndoReader (Project, FileFormat.Native, UndoManager); // Only apply the actions diff if the widget has not been completely reloaded if (actionsDiff != null && !(diff != null && diff.ChildChanges != null)) { // Apply the patch LocalActionGroups.ApplyDiff (Project, actionsDiff); // Get the redo patch reverseActionsDiff = LocalActionGroups.GetDiff (Project, oldStatus); // Update the status of the action group list in the undo status tree. // It has to remove all action groups and then write them again foreach (XmlElement group in status.SelectNodes ("action-group")) status.RemoveChild (group); UndoWriter writer = new UndoWriter (status.OwnerDocument, UndoManager); foreach (ActionGroup actionGroup in LocalActionGroups) status.InsertBefore (actionGroup.Write (writer), status.FirstChild); } if (diff != null) { containerDiffGenerator.ApplyDiff (status, diff); reverseDiff = containerDiffGenerator.GetDiff (status, oldStatus); // Avoid reading the whole widget tree if only the properties have changed. if (diff.ChildChanges == null) { ReadProperties (reader, status); } else { // Console.WriteLine ("BEFORE PATCH: " + status.OuterXml); Read (reader, status); // Console.WriteLine ("\nAFTER PATCH:"); // UndoManager.Dump (); EmitContentsChanged (); } } if (reverseDiff != null || reverseActionsDiff != null) return new ObjectDiff[] { reverseDiff, reverseActionsDiff }; else return null; }
public override object GetUndoDiff () { XmlElement oldElem = UndoManager.GetObjectStatus (this); // Console.WriteLine ("UNDO status: "); // Console.WriteLine (oldElem.OuterXml); // Write the new status of the object. This is going to replace the old status in undoManager. // In the process, register new objects found. UndoWriter writer = new UndoWriter (oldElem.OwnerDocument, UndoManager); XmlElement newElem = Write (writer); // Console.WriteLine ("CURRENT status: "); // Console.WriteLine (newElem.OuterXml); // Get the changes since the last undo checkpoint ObjectDiff actionsDiff = null; ObjectDiff objectDiff = containerDiffGenerator.GetDiff (newElem, oldElem); // If there are child changes there is no need to look for changes in the // actions, since the whole widget will be read again if (IsTopLevel && (objectDiff == null || objectDiff.ChildChanges == null)) actionsDiff = LocalActionGroups.GetDiff (Project, oldElem); // The undo writer skips children which are already registered in the undo manager // to avoid writing information we already have. Now it's the moment to fill the gaps foreach (XmlElement newChild in newElem.SelectNodes ("child[widget/@unchanged_marker='yes']")) { string cid = newChild.GetAttribute ("undoId"); XmlElement oldChild = (XmlElement) oldElem.SelectSingleNode ("child[@undoId='" + cid + "']"); if (oldChild == null) throw new InvalidOperationException ("Child not found when filling widget info gaps."); XmlElement oldWidgetChild = oldChild ["widget"]; XmlElement newWidgetChild = newChild ["widget"]; oldChild.RemoveChild (oldWidgetChild); if (newWidgetChild != null) newChild.ReplaceChild (oldWidgetChild, newWidgetChild); } // Update the status tree UndoManager.UpdateObjectStatus (this, newElem); // UndoManager.Dump (); if (objectDiff != null || actionsDiff != null) return new ObjectDiff[] { objectDiff, actionsDiff }; else return null; }