コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        public void Redo()
        {
            if (CanRedo)
            {
                m_IsProcessing = true;

                try
                {
                    IUndoCommand command = m_Redo.Pop();

                    LogManager.Instance.WriteLine(LogVerbosity.Trace, "UndoRedo Redo({0}) : history list: {1} item(s)",
                                                  command.ToString(), m_Undo.Count);

                    command.Redo();
                    m_Undo.Push(command);

                    OnPropertyChanged("CanUndo");
                    OnPropertyChanged("CanRedo");

                    if (UndoRedoCommandExecuted != null)
                    {
                        UndoRedoCommandExecuted(null, EventArgs.Empty);
                    }
                }
                catch (System.Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    m_IsProcessing = false;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Function to assign a command to the undo stack.
        /// </summary>
        /// <param name="undoCommand">The command to add to the stack.</param>
        private void AssignUndoStack(IUndoCommand undoCommand)
        {
            // Trim to 256 entries from the top of the stack.
            while (_undoStack.Count >= 256)
            {
                _undoStack.RemoveAt(0);
            }

            if (_undoIndex < 0)
            {
                _undoStack.Clear();
                _undoIndex = -1;
            }
            else
            {
                int lastIndex = _undoStack.Count - 1;
                int diff      = lastIndex - _undoIndex;

                for (int i = 0; i < diff; ++i)
                {
                    _undoStack.RemoveAt(_undoStack.Count - 1);
                }
            }

            _undoIndex++;
            _undoStack.Add(undoCommand);
        }
コード例 #3
0
        /// <summary>Function to perform a redo operation.</summary>
        /// <returns>A task representing the currently executing redo operation.</returns>
        public Task Redo()
        {
            if ((_undoStack.Count == 0) || (_undoIndex >= _undoStack.Count - 1))
            {
                _undoIndex = _undoStack.Count - 1;
                return(Task.FromResult <object>(null));
            }

            try
            {
                IUndoCommand redo = _undoStack[++_undoIndex];

                if (redo == null)
                {
                    return(Task.FromResult <object>(null));
                }

                _cancelSource = new CancellationTokenSource();
                _log.Print($"Executing redo for '{redo.Description}' command.", LoggingLevel.Simple);
                Task task = redo.Redo(_cancelSource.Token);

                if (_cancelSource.Token.IsCancellationRequested)
                {
                    --_undoIndex;
                }

                return(task);
            }
            finally
            {
                _cancelSource?.Dispose();
                _cancelSource = null;
            }
        }
コード例 #4
0
        /// <summary>Function to perform an undo operation.</summary>
        /// <returns>A task representing the currently executing undo operation.</returns>
        public Task Undo()
        {
            if ((_undoStack.Count == 0) || (_undoIndex < 0))
            {
                _undoIndex = -1;
                return(Task.FromResult <object>(null));
            }

            try
            {
                IUndoCommand undo = _undoStack[_undoIndex--];

                if (undo == null)
                {
                    return(Task.FromResult <object>(null));
                }

                _cancelSource = new CancellationTokenSource();
                _log.Print($"Executing undo command for '{undo.Description}'.", LoggingLevel.Simple);
                Task task = undo.Undo(_cancelSource.Token);

                if (_cancelSource.Token.IsCancellationRequested)
                {
                    ++_undoIndex;
                }

                return(task);
            }
            finally
            {
                _cancelSource?.Dispose();
                _cancelSource = null;
            }
        }
コード例 #5
0
ファイル: UndoStack.cs プロジェクト: YakushinDS/YDSCodeSample
        public void PerformCommand(IUndoCommand command)
        {
            if (performingCommandSequence)
            {
                commandSequence.PerformCommand(command);
            }
            else
            {
                try
                {
                    command.Perform();

                    index++;

                    commands.Insert(index, command);

                    if (index < capacity && commands.Count > index + 1)
                    {
                        commands.RemoveRange(index + 1, commands.Count - (index + 1));
                    }

                    if (commands.Count > capacity)
                    {
                        commands.RemoveRange(0, commands.Count - capacity);
                    }

                    CommandPerformed?.Invoke(this, new EventArgs());
                }
                catch (Exception ex)
                {
                    HandleError(command, ex);
                }
            }
        }
コード例 #6
0
 protected void RaiseObjectChanged(IUndoCommand cmd)
 {
     if (ObjectChangedEvent != null)
     {
         ObjectChangedEvent(cmd);
     }
 }
コード例 #7
0
        /// <inheritdoc/>
        public void Execute(IUndoCommand command)
        {
            #region Sanity checks
            if (command == null) throw new ArgumentNullException(nameof(command));
            #endregion

            command.Execute();
        }
コード例 #8
0
        private string Serialize(IUndoCommand undoCommand)
        {
            var stream     = new MemoryStream();
            var serializer = new XmlSerializer(undoCommand.GetType());

            serializer.Serialize(stream, undoCommand);
            return(Convert.ToBase64String(stream.ToArray()));
        }
コード例 #9
0
        public IUndoCommand pop()
        {
            int          lastIndex   = this.commands.Count - 1;
            IUndoCommand lastElement = this.commands[lastIndex];

            this.commands.RemoveAt(lastIndex);
            return(lastElement);
        }
コード例 #10
0
        private void UndoStackPushCommand(IUndoCommand command)
        {
            if (null != command)
            {
                this.undoStack.Push(command);

                UndoStateChangedNotify();
            }
        }
コード例 #11
0
ファイル: UndoStack.cs プロジェクト: YakushinDS/YDSCodeSample
            public new void PerformCommand(IUndoCommand command)
            {
                if (index + 1 > capacity)
                {
                    overfillDetected = true;
                }

                base.PerformCommand(command);
            }
コード例 #12
0
 public void AddCommand(IUndoCommand cmd)
 {
     _undoList.Add(cmd);
     _redoList.Clear();
     if (UndoLimit > 0 && _undoList.Count > UndoLimit)
     {
         _undoList.RemoveAt(0);
     }
 }
コード例 #13
0
        public void AddCommand(IUndoCommand command)
        {
            redoStack.Clear();
            command.Do(view);
            documentModifiedState = view.IsModified;
            view.IsModified       = true;

            undoStack.Push(command);
            RaiseCanExecuteChanged();
        }
コード例 #14
0
ファイル: EntryInfo.cs プロジェクト: isaveu/common
 public EntryInfo(string name, string description, object target, Func <Undo.ICommandExecutor, Control> getEditorControl, Func <string> toXmlString, Func <string, IValueCommand> fromXmlString, IUndoCommand removeCommand)
 {
     Name             = name;
     Description      = description;
     Target           = target;
     GetEditorControl = getEditorControl;
     ToXmlString      = toXmlString;
     FromXmlString    = fromXmlString;
     RemoveCommand    = removeCommand;
 }
コード例 #15
0
        public void Execute(IUndoCommand cmd)
        {
            var r = cmd.Execute();

            if (r)
            {
                ++this.CommandCount;
                this.CommandStack.Push(cmd);
            }
        }
コード例 #16
0
ファイル: EntryInfo.cs プロジェクト: nano-byte/common
 public EntryInfo(string name, string description, object target, Func<Undo.ICommandExecutor, Control> getEditorControl, Func<string> toXmlString, Func<string, IValueCommand> fromXmlString, IUndoCommand removeCommand)
 {
     Name = name;
     Description = description;
     Target = target;
     GetEditorControl = getEditorControl;
     ToXmlString = toXmlString;
     FromXmlString = fromXmlString;
     RemoveCommand = removeCommand;
 }
コード例 #17
0
        /// <inheritdoc/>
        public void Execute(IUndoCommand command)
        {
            #region Sanity checks
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }
            #endregion

            command.Execute();
        }
コード例 #18
0
ファイル: UndoCommandService.cs プロジェクト: pashav15/pashav
 IEnumerable <IUndoObject> GetModifiedObjects(IUndoCommand command)
 {
     foreach (var obj in command.ModifiedObjects)
     {
         var uo = GetUndoObject(obj);
         if (uo != null)
         {
             yield return(uo);
         }
     }
 }
コード例 #19
0
 static IEnumerable <LoadedAssembly> GetLoadedAssemblies(IUndoCommand command)
 {
     foreach (var node in command.TreeNodes)
     {
         var asmNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(node);
         Debug.Assert(asmNode != null);
         if (asmNode != null)
         {
             yield return(asmNode.LoadedAssembly);
         }
     }
 }
コード例 #20
0
 private IUndoCommand UndoStatckPopCommand()
 {
     if (this.undoStack.Count > 0)
     {
         IUndoCommand command = (IUndoCommand)this.undoStack.Pop();
         UndoStateChangedNotify();
         return(command);
     }
     else
     {
         return(null);
     }
 }
コード例 #21
0
        public void Undo()
        {
            if (UndoCommands.Count == 0)
            {
                return;
            }

            IUndoCommand cmd = UndoCommands.Pop();

            cmd.Undo();
            RedoCommands.Push(cmd);
            undoCallback();
        }
コード例 #22
0
        public void Redo()
        {
            if (RedoCommands.Count == 0)
            {
                return;
            }

            IUndoCommand cmd = RedoCommands.Pop();

            cmd.Execute();
            UndoCommands.Push(cmd);
            redoCallback();
        }
コード例 #23
0
        public void Redo()
        {
            if (mRedoCommands.Count == 0)
            {
                return;
            }

            IUndoCommand cmd = mRedoCommands.Pop();

            cmd.Execute();

            mUndoCommands.Push(cmd);

            TextChangedEvent();
        }
コード例 #24
0
        public void ReverseUndo()
        {
            if (this.reverseStack.Count > 0)
            {
                IUndoCommand command = ReverseStackPopCommand();
                if (command == null)
                {
                    return;
                }

                command.Execute();

                UndoStackPushCommand(command);
            }
        }
コード例 #25
0
        public void Undo()
        {
            if (this.undoStack.Count > 0)
            {
                IUndoCommand command = UndoStatckPopCommand();
                if (command == null)
                {
                    return;
                }

                command.Undo();

                ReverseStackPushCommand(command);
            }
        }
コード例 #26
0
 /// <summary>
 /// Adds a command and executes it
 /// </summary>
 /// <param name="command"></param>
 public void Add(IUndoCommand command)
 {
     if (currentCommands == null)
     {
         using (BeginAdd())
             Add(command);
     }
     else
     {
         currentCommands.ModifiedAssemblies.AddRange(GetLoadedAssemblies(command));
         command.Execute();
         OnExecutedOneCommand(currentCommands);
         currentCommands.Commands.Add(command);
     }
 }
コード例 #27
0
ファイル: UndoCommandService.cs プロジェクト: pashav15/pashav
 public void Add(IUndoCommand command)
 {
     if (currentCommands == null)
     {
         using (BeginAdd())
             Add(command);
     }
     else
     {
         foreach (var o in GetModifiedObjects(command))
         {
             currentCommands.ModifiedObjects.Add(o);
         }
         command.Execute();
         OnExecutedOneCommand(currentCommands);
         currentCommands.Commands.Add(command);
     }
 }
コード例 #28
0
        public Guid RegisterUndoCommand(string userId, IUndoCommand undoCommand)
        {
            var serializedData = Serialize(undoCommand);
            var uniqueKey      = Guid.NewGuid();

            var undo = new Undo
            {
                UserId         = userId,
                UniqueKey      = uniqueKey,
                TypeKey        = _typeRegistry.GetTypeKeyFromSerializationAttribute(undoCommand.GetType()),
                SerializedData = serializedData,
                CreateDate     = DateTime.UtcNow
            };

            _undoRepository.Insert(undo);
            _unitOfWork.Save();

            return(uniqueKey);
        }
コード例 #29
0
        public void UndoCommand()
        {
            if (undoStack.Count == 0)
            {
                return;
            }
            IUndoCommand cmd = undoStack.Pop();

            try
            {
                cmd.Undo();
                view.IsModified = documentModifiedState;
            }
            finally
            {
                redoStack.Push(cmd);
                RaiseCanExecuteChanged();
            }
        }
コード例 #30
0
        public void RedoCommand()
        {
            if (redoStack.Count == 0)
            {
                return;
            }
            IUndoCommand cmd = redoStack.Pop();

            try
            {
                cmd.Redo();
                //if (!CanRedo()) (Env.Current.MainWindow as MainForm).redoButton.Enabled = false;
                documentModifiedState = view.IsModified;
                view.IsModified       = true;
            }
            finally
            {
                undoStack.Push(cmd);
                RaiseCanExecuteChanged();
                //(Env.Current.MainWindow as MainForm).undoButton.Enabled = true;
            }
        }
コード例 #31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command_"></param>
        /// <param name="arg_"></param>
        public void Add(IUndoCommand command_)
        {
            if (m_IsProcessing == true)
            {
                LogManager.Instance.WriteLine(LogVerbosity.Trace, "UndoRedo : can't add because processing");
                return;
            }

            m_Undo.Push(command_);
            m_Redo.Clear();

            LogManager.Instance.WriteLine(LogVerbosity.Trace, "UndoRedo Add({0}) : history list: {1} item(s)",
                                          command_.ToString(), m_Undo.Count);

            OnPropertyChanged("CanUndo");
            OnPropertyChanged("CanRedo");

            if (UndoRedoCommandListChanged != null)
            {
                UndoRedoCommandListChanged(null, EventArgs.Empty);
            }
        }
コード例 #32
0
ファイル: UndoRedoManager.cs プロジェクト: xcasadio/FlowGraph
        /// <summary>
        /// 
        /// </summary>
        /// <param name="command_"></param>
        /// <param name="arg_"></param>
        public void Add(IUndoCommand command_)
        {
            if (m_IsProcessing == true)
            {
                LogManager.Instance.WriteLine(LogVerbosity.Trace, "UndoRedo : can't add because processing");
                return;
            }

            m_Undo.Push(command_);
            m_Redo.Clear();

            LogManager.Instance.WriteLine(LogVerbosity.Trace, "UndoRedo Add({0}) : history list: {1} item(s)",
                command_.ToString(), m_Undo.Count);

            OnPropertyChanged("CanUndo");
            OnPropertyChanged("CanRedo");

            if (UndoRedoCommandListChanged != null)
            {
                UndoRedoCommandListChanged(null, EventArgs.Empty);
            }
        }
コード例 #33
0
ファイル: UndoStack.cs プロジェクト: YakushinDS/YDSCodeSample
        public void Redo()
        {
            if (index + 1 == commands.Count)
            {
                return;
            }

            IUndoCommand command = commands.ElementAt(index + 1);

            try
            {
                command.Perform();

                index++;

                CommandPerformed?.Invoke(this, new EventArgs());
            }
            catch (Exception ex)
            {
                HandleError(command, ex);
            }
        }
コード例 #34
0
 static IEnumerable<IUndoObject> GetModifiedObjects(IUndoCommand command)
 {
     foreach (var obj in command.ModifiedObjects) {
         var uo = GetUndoObject(obj);
         if (uo != null)
             yield return uo;
     }
 }
コード例 #35
0
 /// <summary>
 /// Adds a command and executes it
 /// </summary>
 /// <param name="command"></param>
 public void Add(IUndoCommand command)
 {
     if (currentCommands == null) {
         using (BeginAdd())
             Add(command);
     }
     else {
         currentCommands.ModifiedObjects.AddRange(GetModifiedObjects(command));
         command.Execute();
         OnExecutedOneCommand(currentCommands);
         currentCommands.Commands.Add(command);
     }
 }
コード例 #36
0
ファイル: UndoCommandManager.cs プロジェクト: lisong521/dnSpy
		/// <summary>
		/// Adds a command and executes it
		/// </summary>
		/// <param name="command"></param>
		public void Add(IUndoCommand command)
		{
			if (currentCommands == null) {
				using (BeginAdd())
					Add(command);
			}
			else {
				currentCommands.ModifiedAssemblies.AddRange(GetAssemblyTreeNodes(command));
				command.Execute();
				OnExecutedOneCommand(currentCommands);
				currentCommands.Commands.Add(command);
			}
		}
コード例 #37
0
ファイル: UndoCommandManager.cs プロジェクト: lisong521/dnSpy
		static IEnumerable<LoadedAssembly> GetAssemblyTreeNodes(IUndoCommand command)
		{
			foreach (var node in command.TreeNodes) {
				var asmNode = ILSpyTreeNode.GetNode<AssemblyTreeNode>(node);
				Debug.Assert(asmNode != null);
				if (asmNode != null)
					yield return asmNode.LoadedAssembly;
			}
		}