void Add(Command cmd) { if (pos < stack.Count) { stack.RemoveRange(pos, stack.Count - pos); } System.Diagnostics.Trace.WriteLine(cmd.Name); stack.Add(cmd); if (stack.Count > this.max) { stack.RemoveAt(0); } else { pos++; } }
public CommandEventArgs(Command cmd) { this.cmd = cmd; }
public Command Undo() { if (pos>0){ pos--; Command cmd = this.Current; if (cmd != null && !cmd.IsNoop){ Command saved = this.exec; try { this.exec = cmd; cmd.Undo(); } finally { this.exec = saved; } if (StateChanged != null) { StateChanged(this, EventArgs.Empty); } if (CommandUndone != null) { CommandUndone(this, new CommandEventArgs(cmd)); } } return cmd; } return null; }
public Command Redo() { if (pos < stack.Count){ Command cmd = this.Current; if (cmd != null && !cmd.IsNoop){ Command saved = this.exec; try { this.exec = cmd; cmd.Redo(); } finally { this.exec = saved; } if (StateChanged != null) { StateChanged(this, new CommandEventArgs(cmd)); } if (CommandRedone != null) { CommandRedone(this, new CommandEventArgs(cmd)); } } pos++; return cmd; } return null; }
public void Push(Command cmd) { if (cmd.IsNoop) return; // do nothing! if (this.compound != null) { this.compound.Add(cmd); } else { Add(cmd); } // Must do command after adding it to the command stack! Command saved = this.exec; try { this.exec = cmd; cmd.Do(); } finally { this.exec = saved; } if (StateChanged != null) { StateChanged(this, EventArgs.Empty); } if (CommandDone != null) { CommandDone(this, new CommandEventArgs(cmd)); } }
public void Insert(Command cmd) { commands.Insert(0, cmd); }
public void Add(Command cmd) { commands.Add(cmd); }