/// <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; } } }
/// <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); }
/// <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; } }
/// <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; } }
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); } } }
protected void RaiseObjectChanged(IUndoCommand cmd) { if (ObjectChangedEvent != null) { ObjectChangedEvent(cmd); } }
/// <inheritdoc/> public void Execute(IUndoCommand command) { #region Sanity checks if (command == null) throw new ArgumentNullException(nameof(command)); #endregion command.Execute(); }
private string Serialize(IUndoCommand undoCommand) { var stream = new MemoryStream(); var serializer = new XmlSerializer(undoCommand.GetType()); serializer.Serialize(stream, undoCommand); return(Convert.ToBase64String(stream.ToArray())); }
public IUndoCommand pop() { int lastIndex = this.commands.Count - 1; IUndoCommand lastElement = this.commands[lastIndex]; this.commands.RemoveAt(lastIndex); return(lastElement); }
private void UndoStackPushCommand(IUndoCommand command) { if (null != command) { this.undoStack.Push(command); UndoStateChangedNotify(); } }
public new void PerformCommand(IUndoCommand command) { if (index + 1 > capacity) { overfillDetected = true; } base.PerformCommand(command); }
public void AddCommand(IUndoCommand cmd) { _undoList.Add(cmd); _redoList.Clear(); if (UndoLimit > 0 && _undoList.Count > UndoLimit) { _undoList.RemoveAt(0); } }
public void AddCommand(IUndoCommand command) { redoStack.Clear(); command.Do(view); documentModifiedState = view.IsModified; view.IsModified = true; undoStack.Push(command); RaiseCanExecuteChanged(); }
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; }
public void Execute(IUndoCommand cmd) { var r = cmd.Execute(); if (r) { ++this.CommandCount; this.CommandStack.Push(cmd); } }
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; }
/// <inheritdoc/> public void Execute(IUndoCommand command) { #region Sanity checks if (command == null) { throw new ArgumentNullException(nameof(command)); } #endregion command.Execute(); }
IEnumerable <IUndoObject> GetModifiedObjects(IUndoCommand command) { foreach (var obj in command.ModifiedObjects) { var uo = GetUndoObject(obj); if (uo != null) { yield return(uo); } } }
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); } } }
private IUndoCommand UndoStatckPopCommand() { if (this.undoStack.Count > 0) { IUndoCommand command = (IUndoCommand)this.undoStack.Pop(); UndoStateChangedNotify(); return(command); } else { return(null); } }
public void Undo() { if (UndoCommands.Count == 0) { return; } IUndoCommand cmd = UndoCommands.Pop(); cmd.Undo(); RedoCommands.Push(cmd); undoCallback(); }
public void Redo() { if (RedoCommands.Count == 0) { return; } IUndoCommand cmd = RedoCommands.Pop(); cmd.Execute(); UndoCommands.Push(cmd); redoCallback(); }
public void Redo() { if (mRedoCommands.Count == 0) { return; } IUndoCommand cmd = mRedoCommands.Pop(); cmd.Execute(); mUndoCommands.Push(cmd); TextChangedEvent(); }
public void ReverseUndo() { if (this.reverseStack.Count > 0) { IUndoCommand command = ReverseStackPopCommand(); if (command == null) { return; } command.Execute(); UndoStackPushCommand(command); } }
public void Undo() { if (this.undoStack.Count > 0) { IUndoCommand command = UndoStatckPopCommand(); if (command == null) { return; } command.Undo(); ReverseStackPushCommand(command); } }
/// <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); } }
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); } }
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); }
public void UndoCommand() { if (undoStack.Count == 0) { return; } IUndoCommand cmd = undoStack.Pop(); try { cmd.Undo(); view.IsModified = documentModifiedState; } finally { redoStack.Push(cmd); RaiseCanExecuteChanged(); } }
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; } }
/// <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); } }
/// <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); } }
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); } }
static IEnumerable<IUndoObject> GetModifiedObjects(IUndoCommand command) { foreach (var obj in command.ModifiedObjects) { var uo = GetUndoObject(obj); if (uo != null) yield return uo; } }
/// <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); } }
/// <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); } }
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; } }