Пример #1
0
 private IDisposable Start(string commandCaption, bool visible)
 {
     AssertNoCommand();
     currentArea = this;
     currentCommand = new Command(commandCaption, this, visible);
     return currentCommand;
 }
Пример #2
0
        /// <summary>Commits current command and saves changes into history</summary>
        public void Commit()
        {
            AssertCurrentCommand();
            if (currentCommand.HasChanges)
            {
                currentCommand.Commit();

                // remove all redo records
                int count = history.Count - currentPosition - 1;
                history.RemoveRange(currentPosition + 1, count);

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

                currentCommand = null;
                OnCommandDone(CommandDoneType.Commit);
            }
            else
                currentCommand = null;
        }
Пример #3
0
 /// <summary>
 /// Rollback current command. It does not saves any changes done in current command.
 /// </summary>
 public void Cancel()
 {
     AssertCurrentCommand();
     currentCommand.Undo();
     currentCommand = null;
 }
Пример #4
0
 /// <summary>
 /// Clears all history. It does not affect current data but history only. 
 /// It is usefull after any data initialization if you want forbid user to undo this initialization.
 /// </summary>
 public void ClearHistory()
 {
     currentCommand = null;
     currentPosition = -1;
     history.Clear();
 }
Пример #5
0
 internal void Merge(Command mergedCommand)
 {
     if (merges == null)
         merges = new Dictionary<IUndoRedoMember, object>();
     foreach (IUndoRedoMember member in mergedCommand.changes.Keys)
         merges[member] = mergedCommand[member];
 }