/// <summary> /// Automatically pushes given <see cref="IUndoRedoCommand"/> command on the Undo stack. /// </summary> public void Push(IUndoRedoCommand cmd) { // assertion #if DEBUG if (cmd == null) { throw new ArgumentNullException("cmd", "cmd parameter cannot be null."); } #endif if (cmd is EditCommand <IModel> ) { // check if rely on anything else (only Edit and Remove) for (int i = 0; i < _undoRedoStack.Count; i++) { IUndoRedoCommand c = _undoRedoStack[i]; if (cmd.GetType().GetGenericTypeDefinition() == typeof(AddCommand <>) || cmd.GetType().GetGenericTypeDefinition() == typeof(RemoveCommand <>)) { if (cmd.TargetObject == c.TargetObject) { (cmd as EditCommand <IModel>).RelyOn = c; } } // this would not work //if (cmd is AddCommand<IModel>) } } _undoRedoStack.Insert(_pointer++, cmd); _onUndoAction?.Invoke(); _onRedoAction?.Invoke(); }
/// <inheritdoc/> public void AddAndExecute(IUndoRedoCommand command, bool ignoreRedundant = true) { if (ignoreRedundant && command.IsRedundant) { return; } if (this.commands.Count == 0) { this.commands.Add(command); this.commandIndex = 0; } else { if (this.direction == Direction.Reverse) { this.commands[this.commandIndex] = command; this.RemoveCommandsAfterCurrentIndex(); } else { this.RemoveCommandsAfterCurrentIndex(); this.commands.Add(command); this.commandIndex = this.commands.Count - 1; } } command.Execute(); this.direction = Direction.Forward; }
public void AddAndExecute(IUndoRedoCommand command) { _undoStack.Push(command); _redoStack.Clear(); command.Execute(); UpdateCommandStatus(); }
/// <summary> /// Iterate over all commands and delete those no longer valid. /// Call it whenever data set was modified externally without undo/redo tracking. /// </summary> public void Refresh() { // edit command relies on add and remove so we have to first iterate over these for (int i = 0; i < _undoRedoStack.Count; i++) { IUndoRedoCommand cmd = _undoRedoStack[i]; if (cmd is AddCommand <IModel> || cmd is RemoveCommand <IModel> ) { if (!cmd.CheckExecutionContext()) { _undoRedoStack.RemoveAt(i--); _pointer--; } } } for (int i = 0; i < _undoRedoStack.Count; i++) { IUndoRedoCommand cmd = _undoRedoStack[i]; if (cmd is EditCommand <IModel> ) { if (!cmd.CheckExecutionContext()) { _undoRedoStack.RemoveAt(i--); _pointer--; } } } }
public bool Equals(IUndoRedoCommand other) { if (other == null) { return(false); } return(Id.Equals(other.Id)); }
public void Redo() { IUndoRedoCommand command = _redoStack.Pop(); _undoStack.Push(command); command.Execute(); UpdateCommandStatus(); }
/// <summary> /// Redoes an action /// </summary> public void Redo() { IUndoRedoCommand cmd = RedoList.Last(); cmd.Execute(); RedoList.Remove(cmd); UndoList.Add(cmd); }
public void AddAndDo(IUndoRedoCommand command) { undoBuffer.Push(command); redoBuffer.Clear(); Changed?.Invoke(this, null); command.Do(); }
public void Redo() { if (redoStack.Any()) { IUndoRedoCommand command = redoStack.Pop(); undoStack.Push(command); command.Execute(); } }
public void Undo() { if (undoStack.Any()) { IUndoRedoCommand command = undoStack.Pop(); redoStack.Push(command); command.UnExecute(); } }
public UndoRedoItem(string item, int level, IUndoRedoCommand Command) { Text = item; this.level = level; this.Command = Command; redo = new RelayCommand(_redoClicked); undo = new RelayCommand(_undoClicked); }
public void InsertInUndoRedo(IUndoRedoCommand command) { _undoCommands.Push(command); _redoCommands.Clear(); command.Execute(); EnableUndo = CanUndo(1); RaisePropertyChanged(nameof(EnableUndo)); RaisePropertyChanged(nameof(EnableRedo)); }
// Bruges til at tilføje commander. public void AddAndExecute(IUndoRedoCommand command) { undoStack.AddFirst(command); if (undoStack.Count == 50) { undoStack.RemoveLast(); } redoStack.Clear(); command.Execute(); }
/// <summary> /// Executes the action and pushes it to the appropriate stack /// </summary> public void Execute(IUndoRedoCommand command) { lock (_lockObject) { _executeInProgress = true; command.Execute(); Push(command); _executeInProgress = false; } }
public void Apply(IUndoRedoCommand command) { if (IsChangeTracking) { transaction.Add(command); } else { command.Execute(); } }
// Udfører redo hvis det kan lade sig gøre. public void Redo() { if (redoStack.Count() <= 0) { throw new InvalidOperationException(); } IUndoRedoCommand command = redoStack.Pop(); undoStack.Push(command); command.Execute(); }
public void Undo() { if (undoStack.Count() <= 0) { throw new InvalidOperationException(); } IUndoRedoCommand command = undoStack.Pop(); redoStack.Push(command); command.Undo(); }
public void AddAndExecute(IUndoRedoCommand command) { _undoStack.Push(command); _redoStack.Clear(); command.Execute(); UpdateCommandStatus(); foreach (var v in _undoStack) { Console.WriteLine(v.ToString()); } }
protected void UndoCommandExecute() { if (CurrentTabItem == null || !DicUndoCommands.Keys.Contains(CurrentTabItem)) { return; } if (DicUndoCommands[CurrentTabItem].Count > 0) { IUndoRedoCommand command = DicUndoCommands[CurrentTabItem].Pop(); command.Undo(); DicRedoCommands[CurrentTabItem].Push(command); } }
// Bruges til at tilføje commander. public void AddAndExecute(IUndoRedoCommand command) { if (undoList.Count > 10) { undoList.RemoveLast(); } undoList.AddFirst(command); redoList.Clear(); //Trace.Write("Command was pushed to undostack: " + command.ToString() + "\n"); undoStack.Push(command); redoStack.Clear(); command.Execute(); }
public void Undo(int undoCount = 1) { for (int i = 1; i <= undoCount; i++) { if (undoBuffer.Count != 0) { IUndoRedoCommand command = undoBuffer.Pop(); command.Undo(); redoBuffer.Push(command); } } Changed?.Invoke(this, null); }
/// <summary> /// Выполняет новую команду /// </summary> /// <param name="command">команда</param> public void ExecuteNewCommand(IUndoRedoCommand command) { if (command == null) { throw new ArgumentNullException(nameof(command)); } if (UndoedCommands.Any()) { UndoedCommands.Clear(); } Commands.Add(command); command.Execute(); }
// Udfører redo hvis det kan lade sig gøre. public void Redo() { if (redoStack.Count() <= 0) { throw new InvalidOperationException(); } IUndoRedoCommand command = redoStack.First(); undoStack.AddFirst(command); command.Execute(); if (redoStack.Any()) { redoStack.RemoveFirst(); } }
public void Undo() { IUndoRedoCommand cmd = _undoRedoStack[--_pointer]; if (cmd.CheckExecutionContext()) // if command is no longer valid dispose it { cmd.Undo(); } else { _undoRedoStack.RemoveAt(_pointer); } _onUndoAction?.Invoke(); _onRedoAction?.Invoke(); }
/// <summary> /// Отменяет предыдущую команду. /// </summary> public void Undo() { if (CanUndo) { IUndoRedoCommand command = (IUndoRedoCommand)_executedCommandList[_currentCommandIndex]; try { command.Unexecute(); _currentCommandIndex--; } catch (Exception ex) { throw;// new Exception(string.Format("Command {0} have not unexecuted", command.Name), ex); } } }
// CELLENDEDIT private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { // What cell did we edit? int row = e.RowIndex; int column = e.ColumnIndex; //Need add to the undo stack in this class. First declare an array of our command interface IUndoRedoCommand[] undos = new IUndoRedoCommand[1]; // variable for the cell's text string text; // Get that cell from our spreadsheet Cell editedCell = spreadsheet.GetCell(row, column + 1); // Get the value from the cell we are editing and apply it to text field if (dataGridView1.Rows[row].Cells[column].Value == null) { text = " "; } else { text = dataGridView1.Rows[row].Cells[column].Value.ToString(); } //add the text that will be replaced to the undo stack undos[0] = new RestoreText(editedCell, editedCell.Text); // set the text of the cell to the newly inputed text editedCell.Text = text; // This should also update the value of the cell //add the undo array to the undoRedo varaiable of the form along with a descriptive title of what it would be undoing if we called it. undoRedo.AddUndo(new UndoRedoCollection(undos, "Cell Text Change")); //set the grid cell to the value (evaluated) of the spreadsheet cell dataGridView1.Rows[row].Cells[column].Value = editedCell.Value; //Update the edit menu UpdateEditMenu(); }
public void Push(IUndoRedoCommand command) { if (!IsEnabled) { return; } if (_isSequenceActive) { _sequenceCommandBuffer.Add(command); } else { _redoStack.Clear(); if (_undoStack.Count >= _maxUndoStackSize) { _undoStack.RemoveFirst(); } _undoStack.AddLast(command); } }
/// <summary> /// Do処理 コマンドの実行 /// </summary> /// <param name="command">実行するコマンド</param> /// <returns> /// コマンドを実行したか /// false : アンドゥ用スタックがいっぱい /// </returns> public bool Invoke(IUndoRedoCommand command) { bool ret = true; // アンドゥスタックのサイズチェック if(m_undoStack.Count >= m_maxSize) { // 最初の要素を削除して追加 _PushAndPopFront(m_undoStack, command); ret = false; } else { // アンドゥ用スタックに実行したコマンドを積んでおく _Push(m_undoStack, command); } // コマンドの実行 command.Invoke(); // リドゥ用スタックのクリア m_redoStack.Clear(); return ret; }
/// <summary> /// Pushes the command to the appropriate stack /// </summary> public void Push(IUndoRedoCommand command) { lock (_lockObject) { _pushInProgress = true; if (!_undoInProgress && !_redoInProgress) { // Adding a new item to the stack, clear the redo stack first _redoCommandStack.Clear(); } // Now, add the item to the appropriate stack ... // ... which is the redo-stack when an undo is in progress if (_undoInProgress) { _redoCommandStack.Push(command); } else { // ... or just to the normal undo-stack otherwise _undoCommandStack.Push(command); } _pushInProgress = false; } }
// Used for adding the Undo/Redo command to the 'undoStack' and at the same time executing it. public void AddAndExecute(IUndoRedoCommand command) { undoStack.Push(command); redoStack.Clear(); command.Execute(); }
public void AddAndExecute(IUndoRedoCommand command) { undoRedoController.AddAndExecute(command); UpdateUIforUndoRedo(); }
public void Add(IUndoRedoCommand command) { undoStack.Push(command); redoStack.Clear(); }
public bool Compare(IUndoRedoCommand command) { return(false); }
public void AddCommand(IUndoRedoCommand command) { _commands.Add(command); }
public void InsertInUndoRedo(IUndoRedoCommand command) { _undoCommands.Push(command); _redoCommands.Clear(); command.Execute(); EnableUndo = CanUndo(1); RaisePropertyChanged(nameof(EnableUndo)); RaisePropertyChanged(nameof(EnableRedo)); Messenger.Default.Send(new UndoRedoEnabledMsg(true,false)); }
/// <summary> /// push_back, pop_front /// </summary> /// <param name="list"></param> /// <param name="command"></param> private static void _PushAndPopFront(List<IUndoRedoCommand> list, IUndoRedoCommand command) { // 最後にコマンドを追加 list.Add(command); // 最初のコマンドを削除 list.Remove(list.First()); }
public void AddAndExecute(IUndoRedoCommand command) { undoStack.Push(command); redoStack.Clear(); command.Execute(); }
public void addAndExecute(IUndoRedoCommand command) { redoStack.Clear(); undoStack.Push(command); command.execute(); }
/// <summary> /// push_back /// </summary> /// <param name="list"></param> /// <param name="command"></param> private static void _Push(List<IUndoRedoCommand> list, IUndoRedoCommand command) { // 最後にコマンドを追加 list.Add(command); }