private void ClearCommands() { while ((_currentCommand = commandsStack.Pop()) != null) { _currentCommand.Finished = true; } commandsStack.Push(null); }
private Command PopCommand() { if (_currentCommand != null) { Command command = commandsStack.Pop(); _currentCommand = commandsStack.Peek(); return command; } else { Debug.Fail("Commands stack is empty"); return null; } }
internal void Merge(Command mergedCommand) { foreach (IUndoRedoMember member in mergedCommand.changes.Keys) { if (changes.ContainsKey(member)) { changes[member].NewObject = mergedCommand.changes[member].NewObject; } else { changes[member] = mergedCommand.changes[member]; } } }
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> /// 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(); }
/// <summary> /// Rollback current command. It does not saves any changes done in current command. /// </summary> public void Cancel() { AssertCurrentCommand(); currentCommand.Undo(); currentCommand = null; }
private IDisposable Start(string commandCaption, bool visible) { _currentArea = this; Command command = new Command(commandCaption, this, visible); PushCommand(command); return command; }
private void PushCommand(Command command) { _commandsStack.Push(command); _currentCommand = command; }
private Command PopCommand() { if (_currentCommand == null) { throw new Exception("Commands stack is empty"); } Command command = _commandsStack.Pop(); _currentCommand = _commandsStack.Peek(); return command; }
void OnCommandDone(Command command, CommandDoneType type) { command.NotifyOnChanges(type); if (CommandDone != null) CommandDone(null, new CommandDoneEventArgs(type)); }
private IDisposable Start(bool visible) { currentArea = this; Command command = new Command(this, visible); PushCommand(command); return command; }
internal void Merge(Command mergedCommand) { if (merges == null) merges = new Dictionary<IUndoRedoMember, object>(); foreach (IUndoRedoMember member in mergedCommand.changes.Keys) merges[member] = mergedCommand[member]; }