/// <summary> /// Goes back to previous Transact call /// </summary> public void Undo() { if (_historyPos < 0) { return; } try { var undoDiff = GetHistoryItem(_historyPos); NodeDiff.ApplyDiff(Root, undoDiff); var redo = NodeDiff.ApplyDiffToSerializedNode(_treeMirror, undoDiff); SetHistoryItem(_historyPos, redo); _historyPos--; NotifyChanges("Undo"); } catch (Exception e) { Log.Info("Exception on Undo:" + e.Message + Environment.NewLine + e.StackTrace); _historyList.Clear(); _historyPos = -1; _reasonList = new List <string>(); _transactStarted = false; } }
/// <summary> /// Save a file from a specific location as XML content /// </summary> /// <param name = "fileName">Filename location</param> public bool LoadFromXml(string fileName) { try { var oldTree = _treeMirror; _treeMirror = XmlHelper.LoadFromXml(fileName); if (_treeMirror == null) { _treeMirror = oldTree; NaroMessage.Show("Invalid NaroXML file. NaroCAD cannot open this file"); return(false); } Transact(); var undo = new NodeDiff(null); var redo = new NodeDiff(null); var currentTreeMirror = ReflectTreeMirror(Root); NodeDiff.ComputeDiff(currentTreeMirror, _treeMirror, undo, redo); try { NodeDiff.ApplyDiff(Root, redo); } catch (Exception ex) { Log.Info(string.Format("Exception loading file: {0} with message: {1} with stack: {2}", fileName, ex.Message, ex.StackTrace)); NaroMessage.Show(string.Format("Cannot load file {0}", fileName)); var brokenTreeMirror = ReflectTreeMirror(Root); NodeDiff.ComputeDiff(brokenTreeMirror, currentTreeMirror, undo, redo); NodeDiff.ApplyDiff(Root, undo); } Commit("Loaded file: " + fileName); return(true); } catch (Exception e) { Revert(); Log.Info("Error on loading xml: " + e.Message + Environment.NewLine + "Stack: " + e.StackTrace); return(false); } }
/// <summary> /// Goes to next Transact call in a history list /// </summary> public void Redo() { if (_historyPos < -1 || _historyPos >= _historyList.Count - 1) { return; } var redoDiff = GetHistoryItem(_historyPos + 1); NodeDiff.ApplyDiff(Root, redoDiff); var redo = new NodeDiff(null); redo.ComputeMarkingDiff(_treeMirror, Root); var undo = NodeDiff.ApplyDiffToSerializedNode(_treeMirror, redoDiff); SetHistoryItem(_historyPos + 1, undo); _historyPos++; NotifyChanges("Redo"); }
public void ApplyOnNode(Node node) { NodeDiff.ApplyDiff(node, Diff); }