/// <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); }