Exemple #1
0
        /// <summary>
        /// Redoes one task on this UndoSystem
        /// </summary>
        public void Redo()
        {
            if (_currentTask == _undoTasks.Count)
            {
                return;
            }

            // Get the task to undo
            IUndoTask task = _undoTasks[_currentTask];

            // Fire the WillPerformRedo event handler
            WillPerformRedo?.Invoke(this, new UndoEventArgs(task));

            // Finish any currently opened group undos
            if (InGroupUndo)
            {
                FinishGroupUndo(_currentGroupUndoTask.DiscardOnOperation);
            }

            _currentTask++;
            task.Redo();

            // Fire the UndoPerformed event handler
            RedoPerformed?.Invoke(this, new UndoEventArgs(task));
        }
Exemple #2
0
        public async Task Undo()
        {
            if (this.UndoStack.Count() > 0)
            {
                IUndoTask undoTask = this.UndoStack.Pop();
                this.RedoStack.Push(undoTask);
                await undoTask.UndoAction.Invoke();

                this.OnTaskAdded();
            }
        }
Exemple #3
0
        /// <summary>
        /// Removes and returns the next redo task from this UndoSystem's undo list.
        /// The undo task is not performed, and is not disposed before being returned.
        /// If no redo task is available, null is returned
        /// </summary>
        /// <returns>The next available redo operation if available, null otherwise</returns>
        public IUndoTask PopRedo()
        {
            if (!CanRedo)
            {
                return(null);
            }

            IUndoTask task = NextRedo;

            _undoTasks.Remove(task);

            return(task);
        }
Exemple #4
0
        /// <summary>
        /// Performs the bucket fill operation
        /// </summary>
        /// <param name="color">The color of the fill operation</param>
        /// <param name="point">The point to start the fill operation at</param>
        public void PerformBucketOperaiton(Color color, Point point)
        {
            IUndoTask undoTask = PerformBucketOperaiton(pictureBox.Bitmap, color, point, compositingMode, true);

            if (undoTask != null)
            {
                pictureBox.OwningPanel.UndoSystem.RegisterUndo(undoTask);

                // Finish the operation by updating the picture box
                pictureBox.Invalidate();
                pictureBox.MarkModified();
            }
        }
Exemple #5
0
        /// <summary>
        /// Removes and returns the next undo task from this UndoSystem's undo list.
        /// The undo task is not performed, and is not disposed before being returned.
        /// If no undo task is available, null is returned
        /// </summary>
        /// <returns>The next available undo operation if available, null otherwise</returns>
        public IUndoTask PopUndo()
        {
            if (!CanUndo)
            {
                return(null);
            }

            IUndoTask task = NextUndo;

            _undoTasks.Remove(task);
            _currentTask--;

            return(task);
        }
Exemple #6
0
        /// <summary>
        /// Registers the given UndoTask on this UndoSystem
        /// </summary>
        /// <param name="task">The task to undo</param>
        /// <exception cref="ArgumentNullException">The undo task provided is null</exception>
        public void RegisterUndo(IUndoTask task)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task), @"The task cannot be null");
            }

            // Grouped undos: record them inside the group undo
            if (InGroupUndo)
            {
                _currentGroupUndoTask.AddTask(task);
                return;
            }

            // Redo task clearing
            ClearRedos();

            // Task capping
            if (_undoTasks.Count >= _maxTaskCount)
            {
                while (_undoTasks.Count >= _maxTaskCount)
                {
                    _undoTasks[0].Clear();

                    _undoTasks.RemoveAt(0);
                }
            }
            else
            {
                _currentTask++;
            }

            _undoTasks.Add(task);

            UndoRegistered?.Invoke(this, new UndoEventArgs(task));
        }
Exemple #7
0
 /// <summary>
 /// Creates a new instance of the UndoEventArgs
 /// </summary>
 /// <param name="task">The task associated with this event</param>
 public UndoEventArgs(IUndoTask task)
 {
     Task = task;
 }
Exemple #8
0
 /// <summary>
 /// Adds a new task on this GroupUndoTask
 /// </summary>
 /// <param name="task">The task to add to this GroupUndoTask</param>
 public void AddTask(IUndoTask task)
 {
     _undoList.Add(task);
 }
Exemple #9
0
 public Task AddUndoTask(IUndoTask undoTask)
 {
     this.UndoStack.Push(undoTask);
     this.OnTaskAdded();
     return(Task.FromResult(0));
 }