コード例 #1
0
        private TaskResult Redo()
        {
            if (this.globallyRedoableTasks.Count < 1)
            {
                throw new InvalidOperationException("No task to redo.");
            }
            IUndoableTask undoableTask        = this.globallyRedoableTasks.Pop();
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)undoableTask);

            this.OnRedoing(e);
            if (e.Cancel)
            {
                this.globallyRedoableTasks.AddLast(undoableTask);
                return(TaskResult.Cancelled);
            }
            IInternalTask internalTask = (IInternalTask)undoableTask;

            this.globallyRepeatableTasks.AddLast(internalTask);
            this.globallyUndoableTasks.AddLast(undoableTask);
            TaskResult taskResult = internalTask.PerformTask(internalTask.Argument, TaskMode.Redo);

            this.TrimIfRequired((object)null);
            this.OnRedone(new TaskServiceEventArgs((ITask)undoableTask));
            return(taskResult);
        }
コード例 #2
0
        private TaskResult Repeat()
        {
            IInternalTask internalTask = this.globallyRepeatableTasks.Peek();

            if (!internalTask.Repeatable)
            {
                return(TaskResult.NoTask);
            }
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)internalTask);

            this.OnExecuting(e);
            if (e.Cancel)
            {
                return(TaskResult.Cancelled);
            }
            this.globallyRedoableTasks.Clear();
            this.globallyRepeatableTasks.AddLast(internalTask);
            IUndoableTask undoableTask = internalTask as IUndoableTask;

            if (undoableTask != null)
            {
                this.globallyUndoableTasks.AddLast(undoableTask);
            }
            else
            {
                this.globallyUndoableTasks.Clear();
                this.globallyRedoableTasks.Clear();
            }
            TaskResult taskResult = internalTask.PerformTask(internalTask.Argument, TaskMode.Repeat);

            this.OnExecuted(new TaskServiceEventArgs((ITask)internalTask));
            return(taskResult);
        }
コード例 #3
0
 private static void UndoSequentially(Dictionary <UndoableTaskBase <T>, T> taskDictionary)
 {
     foreach (KeyValuePair <UndoableTaskBase <T>, T> current in taskDictionary)
     {
         IUndoableTask key = current.Key;
         key.Undo();
     }
 }
コード例 #4
0
        public TaskResult Repeat(object ownerKey = null)
        {
            if (ownerKey == null)
            {
                return(this.Repeat());
            }
            TaskService.TaskCollection <IInternalTask> taskCollection1;
            if (!this.repeatableDictionary.TryGetValue(ownerKey, out taskCollection1))
            {
                throw new InvalidOperationException("No tasks to be redone for the specified owner key.");
            }
            IInternalTask internalTask = taskCollection1.Peek();

            if (!internalTask.Repeatable)
            {
                return(TaskResult.NoTask);
            }
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)internalTask)
            {
                OwnerKey = ownerKey
            };

            this.OnExecuting(e);
            if (e.Cancel)
            {
                return(TaskResult.Cancelled);
            }
            taskCollection1.AddLast(internalTask);
            TaskService.TaskCollection <IUndoableTask> taskCollection2;
            if (!this.undoableDictionary.TryGetValue(ownerKey, out taskCollection2))
            {
                taskCollection2 = new TaskService.TaskCollection <IUndoableTask>();
                this.undoableDictionary[ownerKey] = taskCollection2;
            }
            IUndoableTask undoableTask = internalTask as IUndoableTask;

            if (undoableTask != null)
            {
                taskCollection2.AddLast(undoableTask);
            }
            else
            {
                this.undoableDictionary[ownerKey] = (TaskService.TaskCollection <IUndoableTask>)null;
                this.redoableDictionary[ownerKey] = (TaskService.TaskCollection <IUndoableTask>)null;
            }
            TaskResult taskResult = internalTask.PerformTask(internalTask.Argument, TaskMode.Repeat);

            this.TrimIfRequired(ownerKey);
            this.OnExecuted(new TaskServiceEventArgs((ITask)internalTask));
            return(taskResult);
        }
コード例 #5
0
        public TaskResult Undo(object ownerKey = null)
        {
            if (ownerKey == null)
            {
                return(this.Undo());
            }
            TaskService.TaskCollection <IUndoableTask> taskCollection1;
            if (!this.undoableDictionary.TryGetValue(ownerKey, out taskCollection1))
            {
                throw new InvalidOperationException("No undoable tasks for the specified owner key.");
            }
            IUndoableTask undoableTask = taskCollection1.Pop();

            TaskService.TaskCollection <IInternalTask> taskCollection2;
            if (!this.repeatableDictionary.TryGetValue(ownerKey, out taskCollection2))
            {
                throw new InvalidOperationException("No repeatable tasks for the specified owner key.");
            }
            taskCollection2.RemoveLast();
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)undoableTask)
            {
                OwnerKey = ownerKey
            };

            this.OnUndoing(e);
            if (e.Cancel)
            {
                taskCollection1.AddLast(undoableTask);
                return(TaskResult.Cancelled);
            }
            TaskService.TaskCollection <IUndoableTask> taskCollection3;
            if (!this.redoableDictionary.TryGetValue(ownerKey, out taskCollection3))
            {
                taskCollection3 = new TaskService.TaskCollection <IUndoableTask>();
                this.redoableDictionary[ownerKey] = taskCollection3;
            }
            taskCollection3.AddLast(undoableTask);
            TaskResult taskResult = undoableTask.Undo();

            this.TrimIfRequired(ownerKey);
            this.OnUndone(new TaskServiceEventArgs((ITask)undoableTask));
            return(taskResult);
        }
コード例 #6
0
        public TaskResult Redo(object ownerKey = null)
        {
            if (ownerKey == null)
            {
                return(this.Redo());
            }
            TaskService.TaskCollection <IUndoableTask> taskCollection1;
            if (!this.redoableDictionary.TryGetValue(ownerKey, out taskCollection1))
            {
                throw new InvalidOperationException("No tasks to be redone for the specified owner key.");
            }
            IUndoableTask undoableTask        = taskCollection1.Pop();
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)undoableTask);

            this.OnRedoing(e);
            if (e.Cancel)
            {
                taskCollection1.AddLast(undoableTask);
                return(TaskResult.Cancelled);
            }
            IInternalTask internalTask = (IInternalTask)undoableTask;

            TaskService.TaskCollection <IInternalTask> taskCollection2;
            if (!this.repeatableDictionary.TryGetValue(ownerKey, out taskCollection2))
            {
                taskCollection2 = new TaskService.TaskCollection <IInternalTask>();
            }
            taskCollection2.AddLast(internalTask);
            TaskService.TaskCollection <IUndoableTask> taskCollection3;
            if (!this.undoableDictionary.TryGetValue(ownerKey, out taskCollection3))
            {
                taskCollection3 = new TaskService.TaskCollection <IUndoableTask>();
            }
            taskCollection3.AddLast(undoableTask);
            TaskResult taskResult = internalTask.PerformTask(internalTask.Argument, TaskMode.Redo);

            this.TrimIfRequired(ownerKey);
            this.OnRedone(new TaskServiceEventArgs((ITask)undoableTask));
            return(taskResult);
        }
コード例 #7
0
        private TaskResult Undo()
        {
            if (this.globallyRepeatableTasks.Count < 1)
            {
                throw new InvalidOperationException("No task to undo.");
            }
            IUndoableTask undoableTask        = this.globallyUndoableTasks.Pop();
            IInternalTask internalTask        = this.globallyRepeatableTasks.Pop();
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)undoableTask);

            this.OnUndoing(e);
            if (e.Cancel)
            {
                this.globallyUndoableTasks.AddLast(undoableTask);
                this.globallyRepeatableTasks.AddLast(internalTask);
                return(TaskResult.Cancelled);
            }
            this.globallyRedoableTasks.AddLast(undoableTask);
            TaskResult taskResult = undoableTask.Undo();

            this.OnUndone(new TaskServiceEventArgs((ITask)undoableTask));
            return(taskResult);
        }