Beispiel #1
0
        /// <summary>Commits current command and saves changes into history</summary>
        public void Commit(string caption)
        {
            AssertCurrentCommand();
            log.Add("    [Commit]");

            Command commitedCommand = PopCommand();

            if (commitedCommand.HasChanges)
            {
                commitedCommand.Commit(caption);

                if (IsAnyParentCommand())
                {                       // this is nested command - merge with parent
                    CurrentCommand.Merge(commitedCommand);
                }
                else
                {                       // put command into the history
                                        // remove all redo records
                    int count = history.Count - currentPosition - 1;
                    history.RemoveRange(currentPosition + 1, count);

                    // add command to history
                    if (commitedCommand.Visible)
                    {
                        history.Add(commitedCommand);
                        currentPosition++;
                        TruncateHistory();
                    }
                    else
                    {
                        // merge with previous command
                        if (currentPosition >= 0)
                        {
                            history[currentPosition].Merge(commitedCommand);
                        }
                    }

                    OnCommandDone(commitedCommand, CommandDoneType.Commit);
                }
            }
        }