/// <summary> /// Executes a command and adds it to the undo buffer. /// </summary> /// <param name="command">The command to execute.</param> public void Execute(INefsEditCommand command) { command.Do(); // Clear any redo commands (can only undo after executing a new command) if (this.NextCommandIndex < this.commands.Count) { this.commands.RemoveRange(this.NextCommandIndex, this.commands.Count - this.NextCommandIndex); } // Add command this.commands.Add(command); // Update command index this.PreviousCommandIndex = this.NextCommandIndex; this.NextCommandIndex = this.commands.Count; // Notifiy command executed var eventArgs = new NefsEditCommandEventArgs(NefsEditCommandEventKind.New, command); this.CommandExecuted?.Invoke(this, eventArgs); }
/// <inheritdoc/> public void Execute(INefsEditCommand command) { this.UndoBuffer.Execute(command); }
/// <summary> /// Initializes a new instance of the <see cref="NefsEditCommandEventArgs"/> class. /// </summary> /// <param name="kind">The kind of event that was executed.</param> /// <param name="command">The command that was executed.</param> public NefsEditCommandEventArgs(NefsEditCommandEventKind kind, INefsEditCommand command) { this.Kind = kind; this.Command = command ?? throw new ArgumentNullException(nameof(command)); }