/// <summary> /// execute redo command. /// </summary> /// <param name="dataGridView">datagridview that trigger redo event.</param> public void RedoExecute(DataGridView dataGridView) { // execute command in the redo stack. RedoCommand newCommand = this.SpreadSheetRedo(); // update data grid view cell. if (newCommand.CommandType == CommandType.Text) { dataGridView.Rows[newCommand.Cell.RowIndex].Cells[newCommand.Cell.ColumnIndex].Value = this.spreadSheet[newCommand.Cell.RowIndex, newCommand.Cell.ColumnIndex].Text; this.undoStack.Pop(); } else if (newCommand.CommandType == CommandType.Color) { dataGridView.Rows[newCommand.Cell.RowIndex].Cells[newCommand.Cell.ColumnIndex].Style.BackColor = System.Drawing.Color.FromArgb(this.spreadSheet[newCommand.Cell.RowIndex, newCommand.Cell.ColumnIndex].Color); } }
/// <summary> /// Spreadsheet undo execute. /// </summary> public void SpreadSheetUndo() { ICommandInterface command = this.undoStack.Pop(); UndoCommand newCommand = command as UndoCommand; if (newCommand.CommandType == CommandType.Text) { ICommandInterface newRedoCommand = new RedoCommand(newCommand.CommandType, newCommand.Cell, newCommand.Cell.Text); this.redoStack.Push(newRedoCommand); } else if (newCommand.CommandType == CommandType.Color) { ICommandInterface newRedoCommand = new RedoCommand(newCommand.CommandType, newCommand.Cell, newCommand.Cell.Color.ToString()); this.redoStack.Push(newRedoCommand); } command.Action(); }
private RedoCommand SpreadSheetRedo() { ICommandInterface command = this.redoStack.Pop(); RedoCommand newCommand = command as RedoCommand; if (newCommand.CommandType == CommandType.Text) { ICommandInterface newUndoCommand = new UndoCommand(newCommand.CommandType, newCommand.Cell, newCommand.Cell.Text); this.UndoStack.Push(newUndoCommand); } else if (newCommand.CommandType == CommandType.Color) { ICommandInterface newUndoCommand = new UndoCommand(newCommand.CommandType, newCommand.Cell, newCommand.Cell.Color.ToString()); this.undoStack.Push(newUndoCommand); } command.Action(); return(newCommand); }