/// <summary> /// This creates an empty command waiting to be filled with AddToLastCommand. Take in mind that if you add a new command this one would stop to work, /// since it won't be the last command anymore. /// </summary> /// <param name="name"></param> /// <returns></returns> public async Task <UndoRedoCollectionWithParametersCommand> NewEmptyCollectionCommandAsync(string name) { var command = new UndoRedoCollectionWithParametersCommand(Guid.NewGuid().ToString(), name, false); _UndoCommands.Push(command); _RedoCommands.Clear(); return(command); }
/// <summary> /// This creates an empty command waiting to be filled with AddToLastCommand. Take in mind that if you add a new command this one would stop to work, /// since it won't be the last command anymore. /// </summary> /// <param name="name"></param> /// <returns></returns> public UndoRedoCollectionWithParametersCommand NewEmptyCollectionCommand(string name) { var command = new UndoRedoCollectionWithParametersCommand(Guid.NewGuid().ToString(), name, true); _UndoCommands.Push(command); _RedoCommands.Clear(); return(command); }
public void AddToLastCommand(Func <object[], Task> undo, object[] undoParams, Func <object[], Task> redo, object[] redoParams) { switch (UndoRedoDropoutStack.LastCommandAdded.CommandType) { case UndoRedoCommandTypesEnum.NoParameters: throw new ArgumentException("Trying to add action with parameters to a command without parameters"); case UndoRedoCommandTypesEnum.WithParameters: var paramsCommand = UndoRedoDropoutStack.LastCommandAdded as UndoRedoWithParametersCommand; if (paramsCommand.AsyncUndoAction != null) { throw new ArgumentException("Trying to add async action to a command with sync actions"); } var undoDict = new Dictionary <Func <object[], Task>, object[]>(); if (undo != null) { if (undoParams == null) { throw new ArgumentNullException(); } undoDict.Add(paramsCommand.AsyncUndoAction, paramsCommand.UndoParameters); undoDict.Add(undo, undoParams); } var redoDict = new Dictionary <Func <object[], Task>, object[]>(); if (redo != null) { if (redoParams == null) { throw new ArgumentNullException(); } redoDict.Add(paramsCommand.AsyncRedoAction, paramsCommand.RedoParameters); redoDict.Add(redo, redoParams); } var newCommand = new UndoRedoCollectionWithParametersCommand(undoDict, redoDict, Guid.NewGuid().ToString(), paramsCommand.Name); if (!_UndoCommands.ExchangeLastCommand(newCommand)) { if (!_RedoCommands.ExchangeLastCommand(newCommand)) { throw new ArgumentException(); } } break; case UndoRedoCommandTypesEnum.CollWithParameters: var paramsCollCommand = UndoRedoDropoutStack.LastCommandAdded as UndoRedoCollectionWithParametersCommand; if (paramsCollCommand.AsyncUndoActions != null) { throw new ArgumentException("Trying to add async action to a command with sync actions"); } if (undo != null) { if (undoParams == null) { throw new ArgumentNullException(); } paramsCollCommand.AsyncUndoActions.Add(undo, undoParams); } if (redo != null) { if (redoParams == null) { throw new ArgumentNullException(); } paramsCollCommand.AsyncRedoActions.Add(redo, redoParams); } break; } }