Example #1
0
 public UndoManager()
 {
     this.mStack = sEmptyStack;
     this.mStackSize = 0;
     this.mStackSizeLimit = -1;
     this.mLastCmdIndex = -1;
     this.mCheckpoint = null;
 }
Example #2
0
 public UndoManager(int stackCapacity)
 {
     if (stackCapacity < 0)
     {
         throw new ArgumentOutOfRangeException("stackCapacity");
     }
     else if (stackCapacity == 0)
     {
         this.mStack = sEmptyStack;
     }
     else
     {
         this.mStack = new Command[stackCapacity];
     }
     this.mStackSize = 0;
     this.mStackSizeLimit = -1;
     this.mLastCmdIndex = -1;
     this.mCheckpoint = null;
 }
Example #3
0
 public virtual bool IsExtendable(Command possibleExtension)
 {
     return false;
 }
Example #4
0
 public virtual void Extend(Command possibleExtension)
 {
 }
Example #5
0
 public bool Submit(Command command)
 {
     if (command == null)
     {
         throw new ArgumentNullException("command");
     }
     if (!command.Execute())
     {
         command.Dispose();
         return false;
     }
     if (this.CommandExecuted != null)
     {
         this.CommandExecuted(this, command);
     }
     Command cmd;
     if (this.mLastCmdIndex < this.mStackSize - 1)
     {
         int index = this.mLastCmdIndex + 1;
         for (int i = index; i < this.mStackSize; i++)
         {
             this.mStack[i].Dispose();
         }
         Array.Clear(this.mStack, index, this.mStackSize - index);
         this.mStackSize = index;
     }
     if (this.mLastCmdIndex >= 0)
     {
         cmd = this.mStack[this.mLastCmdIndex];
         if (cmd.IsExtendable(command))
         {
             cmd.Extend(command);
             command.Dispose();
             return true;
         }
     }
     if (this.mStackSizeLimit >= 0 &&
         !command.GroupWithPreviousCommand)
     {
         int j, count = 0;
         for (j = 0; j < this.mStackSize; j++)
         {
             cmd = this.mStack[j];
             if (!cmd.GroupWithPreviousCommand)
             {
                 count++;
             }
         }
         int rCount = count - this.mStackSizeLimit + 1;
         if (rCount > 0)
         {
             count = 0;
             int last = 0;
             for (j = 0; j < this.mStackSize; j++)
             {
                 cmd = this.mStack[j];
                 if (!cmd.GroupWithPreviousCommand)
                 {
                     count++;
                 }
                 if (count <= rCount)
                 {
                     last++;
                     cmd.Dispose();
                 }
             }
             if (last > this.mStackSize)
             {
                 last = this.mStackSize;
             }
             if (last > 0)
             {
                 this.mStackSize -= last;
                 if (this.mStackSize > 0)
                 {
                     Array.Copy(this.mStack, last,
                         this.mStack, 0, this.mStackSize);
                 }
                 Array.Clear(this.mStack, this.mStackSize, last);
             }
         }
     }
     this.mLastCmdIndex = this.mStackSize;
     if (this.mStackSize == this.mStack.Length)
     {
         if (this.mStackSize == 0)
         {
             this.mStack = new Command[4];
         }
         else
         {
             Command[] stack = new Command[2 * this.mStackSize];
             Array.Copy(this.mStack, 0, stack, 0, this.mStackSize);
             this.mStack = stack;
         }
     }
     this.mStack[this.mStackSize++] = command;
     if (this.CommandAddedToHistory != null)
     {
         this.CommandAddedToHistory(this, command);
     }
     return true;
 }
Example #6
0
 public void SetCheckpoint()
 {
     if (this.mLastCmdIndex >= 0)
     {
         this.mCheckpoint = this.mStack[this.mLastCmdIndex];
     }
     else
     {
         this.mCheckpoint = null;
     }
 }
Example #7
0
 public void ClearCheckpoint()
 {
     this.mCheckpoint = null;
 }