コード例 #1
0
        /// <summary>
        /// Reverts the previous command in the undo buffer, if available.
        /// </summary>
        /// <returns>True if the undo was executed.</returns>
        public bool Undo()
        {
            if (!this.CanUndo)
            {
                return(false);
            }

            var command = this.commands[this.PreviousCommandIndex];

            command.Undo();
            this.PreviousCommandIndex -= 1;
            this.NextCommandIndex     -= 1;

            var eventArgs = new NefsEditCommandEventArgs(NefsEditCommandEventKind.Undo, command);

            this.CommandExecuted?.Invoke(this, eventArgs);
            return(true);
        }
コード例 #2
0
        /// <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);
        }