//-------------------------------------------------------------------------
        #region ** event handlers

        // undo/redo column sizes
        void flex_ResizingColumn(object sender, CellRangeEventArgs e)
        {
            if (!(_pendingAction is ColumnResizeAction))
            {
                _pendingAction = new ColumnResizeAction(_flex);
            }
        }
Ejemplo n.º 2
0
 public void ExecuteAction(IUndoableAction action)
 {
     action.Execute();
     Push(_undoStack, action);
     _redoStack.Clear();
     EnforceLimit();
 }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 5
0
        /// <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);
            }
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
        /// <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();
        }
Ejemplo n.º 9
0
 public void ExecuteAction(IUndoableAction action)
 {
     action.Execute();
     Push(_undoStack, action);
     _redoStack.Clear();
     EnforceLimit();
 }
Ejemplo n.º 10
0
        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();
            }
        }
Ejemplo n.º 11
0
 protected void OnUndoEvent(IUndoableAction action)
 {
     if (UndoEvent != null)
     {
         UndoEvent(action);
     }
 }
Ejemplo n.º 12
0
        /// <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));
            }
        }
Ejemplo n.º 13
0
 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;
 }
Ejemplo n.º 15
0
 void flex_CellEditEnded(object sender, CellEditEventArgs e)
 {
     if (!e.Cancel && _pendingAction is EditAction && _pendingAction.SaveNewState())
     {
         _flex.UndoStack.AddAction(_pendingAction);
     }
     _pendingAction = null;
 }
Ejemplo n.º 16
0
 /// <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);
 }
Ejemplo n.º 17
0
 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;
 }
Ejemplo n.º 19
0
 public void UndoTo(IUndoableAction action)
 {
     while (Peek(UndoStack) != action)
     {
         var currentAction = Pop(UndoStack);
         currentAction.Undo();
         Push(RedoStack, currentAction);
     }
 }
Ejemplo n.º 20
0
 public void AddUndoAction(IUndoableAction action)
 {
     UndoList.Push(action);
     if (RedoList.Count > 0)
     {
         RedoList.Clear();
         OnRedoChanged(RedoChangedEventArgs.Empty);
     }
     OnUndoChanged(UndoChangedEventArgs.Empty);
 }
Ejemplo n.º 21
0
 public void Undo()
 {
     if (UndoList.Count > 0)
     {
         IUndoableAction act = UndoList.Pop();
         act.Undo(this);
         OnUndoChanged(UndoChangedEventArgs.Empty);
         RedoList.Push(act);
         OnRedoChanged(RedoChangedEventArgs.Empty);
     }
 }
Ejemplo n.º 22
0
 public void RedoTo(IUndoableAction action)
 {
     while (true)
     {
         var thisAction = Pop(_redoStack);
         thisAction.Execute();
         Push(_undoStack, thisAction);
         if (thisAction == action)
             return;
     }
 }
Ejemplo n.º 23
0
 public void UndoTo(IUndoableAction action)
 {
     while (true)
     {
         if (Peek(_undoStack) == action)
             return;
         var thisAction = Pop(_undoStack);
         thisAction.Undo();
         Push(_redoStack, thisAction);
     }
 }
Ejemplo n.º 24
0
 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);
     }
 }
Ejemplo n.º 25
0
        public void Push(IUndoableAction action)
        {
            CurrentIndex += 1;
            while (Actions.Count > CurrentIndex)
            {
                Actions.RemoveAt(CurrentIndex);
            }

            Actions.Add(action);

            if (Updated != null)
                Updated(this, new EventArgs());
        }
Ejemplo n.º 26
0
 public void RedoTo(IUndoableAction action)
 {
     while (true)
     {
         var currentAction = Pop(RedoStack);
         currentAction.Execute();
         Push(UndoStack, currentAction);
         if (currentAction == action)
         {
             return;
         }
     }
 }
Ejemplo n.º 27
0
        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);
            }
        }
Ejemplo n.º 28
0
 public void RedoTo(IUndoableAction action)
 {
     while (true)
     {
         var thisAction = Pop(_redoStack);
         thisAction.Execute();
         Push(_undoStack, thisAction);
         if (thisAction == action)
         {
             return;
         }
     }
 }
Ejemplo n.º 29
0
 public void UndoTo(IUndoableAction action)
 {
     while (true)
     {
         if (Peek(_undoStack) == action)
         {
             return;
         }
         var thisAction = Pop(_undoStack);
         thisAction.Undo();
         Push(_redoStack, thisAction);
     }
 }
Ejemplo n.º 30
0
        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);
            }
        }
Ejemplo n.º 31
0
        public void Push(IUndoableAction action)
        {
            CurrentIndex += 1;
            while (Actions.Count > CurrentIndex)
            {
                Actions.RemoveAt(CurrentIndex);
            }

            Actions.Add(action);

            if (Updated != null)
            {
                Updated(this, new EventArgs());
            }
        }
Ejemplo n.º 32
0
 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;
     }
 }
Ejemplo n.º 33
0
        /// <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);
        }
Ejemplo n.º 34
0
        /// <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);
        }
Ejemplo n.º 35
0
        public void RedoTo(IUndoableAction action)
        {
            OnBegin();

            try
            {
                while (true)
                {
                    var thisAction = Pop(_redoStack);
                    thisAction.Execute();
                    Push(_undoStack, thisAction);
                    if (thisAction == action)
                        return;
                }
            }
            finally
            {
                OnEnd();
            }
        }
Ejemplo n.º 36
0
        public void RedoTo(IUndoableAction action)
        {
            OnBegin();

            try
            {
                while (true)
                {
                    var thisAction = Pop(_redoStack);
                    thisAction.Execute();
                    Push(_undoStack, thisAction);
                    if (thisAction == action)
                    {
                        return;
                    }
                }
            }
            finally
            {
                OnEnd();
            }
        }
Ejemplo n.º 37
0
        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);
        }
Ejemplo n.º 38
0
        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);
            }
        }
Ejemplo n.º 39
0
 // undo/redo row sizes
 void flex_ResizingRow(object sender, CellRangeEventArgs e)
 {
     if (!(_pendingAction is RowResizeAction))
     {
         _pendingAction = new RowResizeAction(_flex, e);
     }
 }
Ejemplo n.º 40
0
 // undo/redo column sizes
 void flex_ResizingColumn(object sender, CellRangeEventArgs e)
 {
     if (!(_pendingAction is ColumnResizeAction))
     {
         _pendingAction = new ColumnResizeAction(_flex);
     }
 }
Ejemplo n.º 41
0
 // undo/redo edits
 void flex_PrepareCellForEdit(object sender, CellEditEventArgs e)
 {
     _pendingAction = new EditAction(_flex);
 }
Ejemplo n.º 42
0
 // record original sort values
 void flex_SortingColumn(object sender, CellRangeEventArgs e)
 {
     _pendingAction = new SortAction(_flex);
 }
Ejemplo n.º 43
0
 public HistoryItemViewModel(IUndoableAction action, HistoryItemType itemType)
 {
     _action = action;
     _itemType = itemType;
 }
Ejemplo n.º 44
0
 public void PushHistoryAction(IUndoableAction action)
 {
     History.Push(action);
 }
Ejemplo n.º 45
0
 private static void Push(BindableCollection<IUndoableAction> stack, IUndoableAction action)
 {
     stack.Add(action);
 }