private IDisposable Start(string commandCaption, bool visible) { AssertNoCommand(); currentArea = this; currentCommand = new Command(commandCaption, this, visible); return currentCommand; }
/// <summary>Commits current command and saves changes into history</summary> public void Commit() { AssertCurrentCommand(); if (currentCommand.HasChanges) { currentCommand.Commit(); // remove all redo records int count = history.Count - currentPosition - 1; history.RemoveRange(currentPosition + 1, count); // add command to history if (currentCommand.Visible) { history.Add(currentCommand); currentPosition++; TruncateHistory(); } else { // merge with previous command if (currentPosition >= 0) history[currentPosition].Merge(currentCommand); } currentCommand = null; OnCommandDone(CommandDoneType.Commit); } else currentCommand = null; }
/// <summary> /// Rollback current command. It does not saves any changes done in current command. /// </summary> public void Cancel() { AssertCurrentCommand(); currentCommand.Undo(); currentCommand = null; }
/// <summary> /// Clears all history. It does not affect current data but history only. /// It is usefull after any data initialization if you want forbid user to undo this initialization. /// </summary> public void ClearHistory() { currentCommand = null; currentPosition = -1; history.Clear(); }
internal void Merge(Command mergedCommand) { if (merges == null) merges = new Dictionary<IUndoRedoMember, object>(); foreach (IUndoRedoMember member in mergedCommand.changes.Keys) merges[member] = mergedCommand[member]; }