//------------------------------------------------------------------------- #region ** event handlers // undo/redo column sizes void flex_ResizingColumn(object sender, CellRangeEventArgs e) { if (!(_pendingAction is ColumnResizeAction)) { _pendingAction = new ColumnResizeAction(_flex); } }
public void ExecuteAction(IUndoableAction action) { action.Execute(); Push(_undoStack, action); _redoStack.Clear(); EnforceLimit(); }
protected void OnRedoEvent(IUndoableAction action) { if (RedoEvent != null) { RedoEvent(action); } }
// undo/redo row sizes void flex_ResizingRow(object sender, CellRangeEventArgs e) { if (!(_pendingAction is RowResizeAction)) { _pendingAction = new RowResizeAction(_flex, e); } }
/// <summary> /// Adds the specified action state to the action lsit. /// </summary> public void AddAction(IUndoableAction action) { // Remove the oldest action is we have reached the max number of actions allowed. if (position == maxItems - 1) { actions.RemoveAt(0); position--; } // Remove any existing actions after our current position (as they will no longer // be valid in the undo sequence.) if (position < actions.Count - 1) { for (int x = actions.Count - 1; x > position; x--) { actions.RemoveAt(x); } } // Add the action to the list and update out position. actions.Add(action); position++; // Set our new clean point if this state is clean. if (action.CleanPoint) { SetCleanState(); } // Signal that a state change has occurred. if (StateChanged != null) { StateChanged(position != cleanPosition); } }
protected bool ExecuteActionInternal(IUndoableAction action, bool clearRedoStack) { OnBeforeStateChanged(); if (!action.Execute()) { return(false); } if (clearRedoStack) { redoStack.Clear(); } var undoGroup = action.GetUndoGroup(); // Should we group together this undo step with more of the same kind? if (undoGroup != 0) { if (currentGroup == null || currentGroup.CaughtGroup != undoGroup) { currentGroup = new UndoableActionGroup(undoGroup); AddToUndoStack(currentGroup); } currentGroup.Actions.Add(action); } else { AddToUndoStack(action); } OnAfterStateChanged(); return(true); }
/// <summary> /// Performs a redo /// </summary> /// <returns>False if there weren't any redos, true otherwise</returns> public bool Redo() { if (!this.AnyRedos) { return(false); } bool anyUndosChange = m_undoStack.Count == 0; bool anyRedosChange = m_redoStack.Count == 1; IUndoableAction action = m_redoStack[0]; m_redoStack.RemoveAt(0); action.Do(); m_undoStack.Insert(0, action); if (anyUndosChange) { this.RaisePropertiesChanged(nameof(AnyUndos)); } else if (anyRedosChange) { this.RaisePropertiesChanged(nameof(AnyRedos)); } return(true); }
/// <summary> /// Tells the context that an action has occurred. /// </summary> /// <param name="action">The action that was executed.</param> /// <param name="data">The data associated with the action.</param> public void ActionExecuted(IUndoableAction action, object data) { object possible = null; if (action is IUndoableProperty && (this.UndoStack.Count > 0 && this.UndoStack.First().Item1 == action.Name)) { if ((DateTime.Now - LastModified).TotalMilliseconds < (action as IUndoableProperty).BatchingTimeout) { possible = this.UndoStack.Pop().Item2; } else { this.LastModified = DateTime.Now; } } else { this.LastModified = DateTime.Now; } if (possible == null) { this.UndoStack.Push(new Tuple <string, object>(action.Name, data)); } else { this.UndoStack.Push(new Tuple <string, object>(action.Name, possible)); } this.RedoStack.Clear(); }
public void ExecuteAction(IUndoableAction action) { action.Execute(); Push(_undoStack, action); _redoStack.Clear(); EnforceLimit(); }
private void PaintCanvas_MouseDown(object sender, MouseEventArgs e) { if (CurrentAction is KeypressAction) { CurrentAction = null; } if (CurrentAction == null) { if (m_PaintMode == PaintModes.PaintBrush || m_PaintMode == PaintModes.Fill) { CurrentAction = new PaintAction(); } } SelectAppropriateCell(e.X, e.Y); if (m_PaintMode == PaintModes.PaintBrush || m_PaintMode == PaintModes.Fill) { PaintCellByMouseArgs(this.m_SelectedCellPosition, e); } else if (m_PaintMode == PaintModes.Bold) { BoldSelectedCell(); } else if (m_PaintMode == PaintModes.Underline) { UnderlineSelectedCell(); } else if (m_PaintMode == PaintModes.RemoveFormatting) { RemoveFormattingSelectedCell(); } }
protected void OnUndoEvent(IUndoableAction action) { if (UndoEvent != null) { UndoEvent(action); } }
/// <summary> /// Adds the action to the stack (does not execute) /// </summary> public void AddAction(IUndoableAction action) { if (action is UndoableGroupAction group) { switch (group.Children.Count) { // No children, don't save anything case 0: return; // One child, don't save the group case 1: action = group.Children.First(); break; } } bool anyUndosChange = !this.AnyUndos; bool anyRedosChange = this.AnyRedos; m_undoStack.Insert(0, action); m_redoStack.Clear(); if (anyUndosChange) { this.RaisePropertiesChanged(nameof(AnyUndos)); } else if (anyRedosChange) { this.RaisePropertiesChanged(nameof(AnyRedos)); } }
void flex_ResizedRow(object sender, CellRangeEventArgs e) { if (_pendingAction is RowResizeAction && _pendingAction.SaveNewState()) { _flex.UndoStack.AddAction(_pendingAction); } _pendingAction = null; }
void flex_CellEditEnded(object sender, CellEditEventArgs e) { if (!e.Cancel && _pendingAction is EditAction && _pendingAction.SaveNewState()) { _flex.UndoStack.AddAction(_pendingAction); } _pendingAction = null; }
void flex_CellEditEnded(object sender, CellEditEventArgs e) { if (!e.Cancel && _pendingAction is EditAction && _pendingAction.SaveNewState()) { _flex.UndoStack.AddAction(_pendingAction); } _pendingAction = null; }
/// <summary> /// Inserts an <see cref="IUndoableAction"/> at the top of the undo stack. /// </summary> internal void PushAction(IUndoableAction action) { if (_undoing || _rollbackPoints.Count == 0) { return; } _actionStack.Push(action); }
private void PaintCanvas_MouseUp(object sender, MouseEventArgs e) { if (CurrentAction is PaintAction) { AddUndoAction(CurrentAction); CurrentAction = null; } }
void flex_ResizedRow(object sender, CellRangeEventArgs e) { if (_pendingAction is RowResizeAction && _pendingAction.SaveNewState()) { _flex.UndoStack.AddAction(_pendingAction); } _pendingAction = null; }
public void UndoTo(IUndoableAction action) { while (Peek(UndoStack) != action) { var currentAction = Pop(UndoStack); currentAction.Undo(); Push(RedoStack, currentAction); } }
public void AddUndoAction(IUndoableAction action) { UndoList.Push(action); if (RedoList.Count > 0) { RedoList.Clear(); OnRedoChanged(RedoChangedEventArgs.Empty); } OnUndoChanged(UndoChangedEventArgs.Empty); }
public void Undo() { if (UndoList.Count > 0) { IUndoableAction act = UndoList.Pop(); act.Undo(this); OnUndoChanged(UndoChangedEventArgs.Empty); RedoList.Push(act); OnRedoChanged(RedoChangedEventArgs.Empty); } }
public void RedoTo(IUndoableAction action) { while (true) { var thisAction = Pop(_redoStack); thisAction.Execute(); Push(_undoStack, thisAction); if (thisAction == action) return; } }
public void UndoTo(IUndoableAction action) { while (true) { if (Peek(_undoStack) == action) return; var thisAction = Pop(_undoStack); thisAction.Undo(); Push(_redoStack, thisAction); } }
public void Redo() { if (RedoList.Count > 0) { IUndoableAction act = RedoList.Pop(); act.Redo(this); OnRedoChanged(RedoChangedEventArgs.Empty); //UndoList.Clear(); UndoList.Push(act); OnUndoChanged(UndoChangedEventArgs.Empty); } }
public void Push(IUndoableAction action) { CurrentIndex += 1; while (Actions.Count > CurrentIndex) { Actions.RemoveAt(CurrentIndex); } Actions.Add(action); if (Updated != null) Updated(this, new EventArgs()); }
public void RedoTo(IUndoableAction action) { while (true) { var currentAction = Pop(RedoStack); currentAction.Execute(); Push(UndoStack, currentAction); if (currentAction == action) { return; } } }
public void AddCharacterChangeToKeypressAction(int x, int y, char origchar, char newchar) { if (CurrentAction == null) { CurrentAction = new KeypressAction(); AddUndoAction(CurrentAction); } if (CurrentAction is KeypressAction) { ((KeypressAction)CurrentAction).AddCharacter(x, y, origchar, newchar); } }
public void RedoTo(IUndoableAction action) { while (true) { var thisAction = Pop(_redoStack); thisAction.Execute(); Push(_undoStack, thisAction); if (thisAction == action) { return; } } }
public void UndoTo(IUndoableAction action) { while (true) { if (Peek(_undoStack) == action) { return; } var thisAction = Pop(_undoStack); thisAction.Undo(); Push(_redoStack, thisAction); } }
private void AddToUndoStack(IUndoableAction action) { // Clear oldest actions if we're out of room if (undoStack.Count > 0 && undoStack.Count >= MaxUndoSteps) { undoStack.RemoveAt(0); } // Note: not certain that we got room, MaxUndoSteps may be zero if (undoStack.Count < MaxUndoSteps) { undoStack.Add(action); } }
public void Push(IUndoableAction action) { CurrentIndex += 1; while (Actions.Count > CurrentIndex) { Actions.RemoveAt(CurrentIndex); } Actions.Add(action); if (Updated != null) { Updated(this, new EventArgs()); } }
private void StartFillCell(Point point, byte origcolor, byte color, bool foreground) { if (CurrentAction is PaintAction) { //CurrentAction = new PaintAction(); ((PaintAction)CurrentAction).IsForeground = foreground; ((PaintAction)CurrentAction).NewPaintColor = color; ((PaintAction)CurrentAction).OldPaintColor = origcolor; } FillCell(point, origcolor, color, foreground); if (CurrentAction is PaintAction) { AddUndoAction(CurrentAction); CurrentAction = null; } }
/// <summary> /// Adds an action to the undo/redo stack. /// </summary> public void AddAction(IUndoableAction action) { // trim stack while (_stack.Count > 0 && _stack.Count > _ptr + 1) { _stack.RemoveAt(_stack.Count - 1); } while (_stack.Count >= MAX_STACK_SIZE) { _stack.RemoveAt(0); } // update pointer and add action to stack _ptr = _stack.Count; _stack.Add(action); // done OnStateChanged(EventArgs.Empty); }
/// <summary> /// Adds an action to the undo/redo stack. /// </summary> public void AddAction(IUndoableAction action) { // trim stack while (_stack.Count > 0 && _stack.Count > _ptr + 1) { _stack.RemoveAt(_stack.Count - 1); } while (_stack.Count >= MAX_STACK_SIZE) { _stack.RemoveAt(0); } // update pointer and add action to stack _ptr = _stack.Count; _stack.Add(action); // done OnStateChanged(EventArgs.Empty); }
public void RedoTo(IUndoableAction action) { OnBegin(); try { while (true) { var thisAction = Pop(_redoStack); thisAction.Execute(); Push(_undoStack, thisAction); if (thisAction == action) return; } } finally { OnEnd(); } }
public void RedoTo(IUndoableAction action) { OnBegin(); try { while (true) { var thisAction = Pop(_redoStack); thisAction.Execute(); Push(_undoStack, thisAction); if (thisAction == action) { return; } } } finally { OnEnd(); } }
public IAction Undo() { if (undoStack.Count() > 0) { IUndoableAction action = null; while (undoStack.Count > 0) { action = undoStack.Last(); Logger.Log(LOGKEY, "undo action: " + action.ToString()); // before event if (BeforePerformAction != null) { var arg = new ActionEventArgs(action, ActionBehavior.Undo); BeforePerformAction(this, new ActionEventArgs(action, ActionBehavior.Undo)); if (arg.Cancel) { break; } } undoStack.Remove(action); action.Undo(); redoStack.Push(action); // after event AfterPerformAction?.Invoke(this, new ActionEventArgs(action, ActionBehavior.Undo)); if (!(action is ISerialUndoAction)) { break; } } return(action); } return(null); }
public IAction Redo() { if (redoStack.Count > 0) { IUndoableAction action = null; while (redoStack.Count > 0) { action = redoStack.Pop(); Logger.Log(LOGKEY, "redo action: " + action.ToString()); if (BeforePerformAction != null) { var arg = new ActionEventArgs(action, ActionBehavior.Redo); BeforePerformAction(this, arg); if (arg.Cancel) { break; } } action.Redo(); undoStack.Add(action); AfterPerformAction?.Invoke(this, new ActionEventArgs(action, ActionBehavior.Redo)); if (!(action is ISerialUndoAction)) { break; } } return(action); } else { return(null); } }
// undo/redo row sizes void flex_ResizingRow(object sender, CellRangeEventArgs e) { if (!(_pendingAction is RowResizeAction)) { _pendingAction = new RowResizeAction(_flex, e); } }
// undo/redo column sizes void flex_ResizingColumn(object sender, CellRangeEventArgs e) { if (!(_pendingAction is ColumnResizeAction)) { _pendingAction = new ColumnResizeAction(_flex); } }
// undo/redo edits void flex_PrepareCellForEdit(object sender, CellEditEventArgs e) { _pendingAction = new EditAction(_flex); }
// record original sort values void flex_SortingColumn(object sender, CellRangeEventArgs e) { _pendingAction = new SortAction(_flex); }
public HistoryItemViewModel(IUndoableAction action, HistoryItemType itemType) { _action = action; _itemType = itemType; }
public void PushHistoryAction(IUndoableAction action) { History.Push(action); }
private static void Push(BindableCollection<IUndoableAction> stack, IUndoableAction action) { stack.Add(action); }