示例#1
0
    private void Did(IUndoRedo iur)
    {
        try
        {
            m_UndoStack.Push(iur);
            m_RedoStack.Clear();
        }
        catch (System.Exception ex)
        {
            DebugUtility.ShowExceptionMessageBox("添加撤销操作失败", ex);
        }
        DoSomething(this, new DoSomethingEventArgs(DoEventType.Did, iur.GetDoType()));

        // 暂时不处理 Stack超出上限
        //if (m_UndoStack.Count >= GlobalData.UNDO_MAX_COUNT)
        //{
        //	Stack<IUndoRedo> undoCopyStack = new Stack<IUndoRedo>();
        //	for(int undoIdx = 0; undoIdx < GlobalData.UNDO_SAVE_COUNT; undoIdx++)
        //	{
        //		undoCopyStack.Push(m_UndoStack.Pop());
        //	}

        //	m_UndoStack.Clear();
        //	while(undoCopyStack.Count > 0)
        //	{
        //		m_UndoStack.Push(undoCopyStack.Pop());
        //	}
        //}
    }
示例#2
0
        bool IMergableOperation.TryMergeWith(IUndoRedo other, bool isBulkOperation)
        {
            if (!isBulkOperation)
            {
                return(false);
            }

            var otherTLV = other as AddTopLevelViewOperation;

            if (otherTLV != null)
            {
                this.relatedAdds.Add(otherTLV);
                return(true);
            }

            var setRoot = other as SetRootOperation;

            if (setRoot != null)
            {
                _rootChange = setRoot;
                return(true);
            }

            return(false);
        }
示例#3
0
        bool IMergableOperation.TryMergeWith(IUndoRedo other, bool isBulkOperation)
        {
            if (!isBulkOperation)
            {
                return(false);
            }

            var otherLFA = other as ArrayFieldAddOperation;

            if (otherLFA != null)
            {
                if (_relatedAdds == null)
                {
                    _relatedAdds = new List <ArrayFieldAddOperation>(1);
                }

                _relatedAdds.Add(otherLFA);

                //There is no need for related adds to hold onto their references as they are not used
                otherLFA._arr    = null;
                otherLFA._setter = null;
                return(true);
            }

            return(false);
        }
示例#4
0
文件: UndoRedo.cs 项目: Xlyoid/Primal
 public void Add(IUndoRedo cmd)
 {
     if (_enableAdd)
     {
         _undoList.Add(cmd);
         _redoList.Clear();
     }
 }
示例#5
0
 public void Redo(DataGridView dataGridView, DataTable dataTable)
 {
     for (int thingIdx = 0; thingIdx < ThingsList.Count; thingIdx++)
     {
         IUndoRedo thing = ThingsList[thingIdx];
         thing.Redo(dataGridView, dataTable);
     }
 }
示例#6
0
 public void Undo(DataGridView dataGridView, DataTable dataTable)
 {
     for (int thingIdx = ThingsList.Count - 1; thingIdx >= 0; thingIdx--)
     {
         IUndoRedo thing = ThingsList[thingIdx];
         thing.Undo(dataGridView, dataTable);
     }
 }
        public DefaultCanvas()
        {
            //Console.WriteLine(colorPick);
            this.ObjectToDraw   = new List <IDrawingObject>();
            this.DoubleBuffered = true;
            this.Tool           = null;

            this.undoRedo = new DefaultUndoRedo(this);
        }
示例#8
0
 public UndoMemento(IUndoRedo sender, ActionType actionType, string description)
 {
     if (sender == null || description == null)
     {
         throw new ArgumentNullException();
     }
     m_Sender      = sender;
     m_ActionType  = actionType;
     m_Description = description;
 }
 public static void DoRedoActions(IUndoRedo context, IUndoMemento memento)
 {
     if (memento.Sender == context)
     {
         foreach (var redoAction in memento.RedoActions)
         {
             redoAction();
         }
     }
 }
示例#10
0
 public UndoMemento(IUndoRedo sender, ActionType actionType, string description)
 {
     if (sender == null || description == null)
     {
         throw new ArgumentNullException();
     }
     m_Sender = sender;
     m_ActionType = actionType;
     m_Description = description;
 }
示例#11
0
 public void Redo()
 {
     if (this.oUndoRedoHandler is IUndoRedo)
     {
         IUndoRedo iur = (IUndoRedo)this.oUndoRedoHandler;
         iur.Redo(this.o, this.ura, this.oData);
     }
     else
     {
         throw new InterfaceNotImplementedException("IUndoRedo in " + this.oUndoRedoHandler.GetType().ToString() + " not implemented!");
     }
 }
示例#12
0
        public void Undo()
        {
            if (!CanUndo())
            {
                return;
            }
            IUndoRedo action = undoStack.Pop();

            action.Undo();
            redoStack.Push(action);
            NotifyPropertyChanged("UndoDescription");
            NotifyPropertyChanged("RedoDescription");
            UndoOrRedoCalled?.Invoke(this, new EventArgs());
        }
示例#13
0
 public UndoMemento(IUndoRedo sender, ActionType actionType, string description,
                    IEnumerable <Action> undoActions,
                    IEnumerable <Action> redoActions)
 {
     if (sender == null || description == null || undoActions == null || redoActions == null)
     {
         throw new ArgumentNullException();
     }
     m_Sender      = sender;
     m_ActionType  = actionType;
     m_Description = description;
     m_UndoActions = new List <Action>(undoActions);
     m_RedoActions = new List <Action>(redoActions);
 }
示例#14
0
        /// <summary>
        /// Redo the last undone action, if any.
        /// </summary>
        public bool Redo()
        {
            if (_redoStack.Count == 0)
            {
                return(false);
            }

            IUndoRedo action = _redoStack.Pop();

            action.Redo();
            _undoStack.Push(action);

            return(true);
        }
示例#15
0
 public UndoMemento(IUndoRedo sender, ActionType actionType, string description,
     IEnumerable<Action> undoActions,
     IEnumerable<Action> redoActions)
 {
     if (sender == null || description == null || undoActions == null || redoActions == null)
     {
         throw new ArgumentNullException();
     }
     m_Sender = sender;
     m_ActionType = actionType;
     m_Description = description;
     m_UndoActions = new List<Action>(undoActions);
     m_RedoActions = new List<Action>(redoActions);
 }
示例#16
0
        public void Redo()
        {
            if (RedoList.Count > 0)
            {
                IUndoRedo item = RedoList.First();
                RedoList.RemoveFirst();

                LinkedList <IUndoRedo> cpyRedo = new LinkedList <IUndoRedo>(RedoList.ToList());
                item.Redo();

                RedoList = new LinkedList <IUndoRedo>(cpyRedo);
                RaisePropertyChanged("RedoDescription");
                RaisePropertyChanged("UndoDescription");
            }
        }
示例#17
0
        public void AddUndo(IUndoRedo undo)
        {
            if (Capacity == 0)
            {
                return;
            }

            if (redoStack.Count > 0)
            {
                redoStack.Clear();
            }

            undoStack.Push(undo);
            NotifyPropertyChanged("UndoDescription");
            NotifyPropertyChanged("RedoDescription");
        }
        bool IMergableOperation.TryMergeWith(IUndoRedo other, bool isBulkOperation)
        {
            var otherEFO = other as EditorFieldOperation <T>;

            if (otherEFO == null)
            {
                return(false);
            }

            if (object.ReferenceEquals(_owner, otherEFO._owner) && object.ReferenceEquals(_member, otherEFO._member))
            {
                _newValue = otherEFO._newValue;
                return(true);
            }

            return(false);
        }
示例#19
0
        bool IMergableOperation.TryMergeWith(IUndoRedo other, bool isBulkOperation)
        {
            var otherVCO = other as ViewValueChangeOperation;

            if (otherVCO == null)
            {
                return(false);
            }

            if (object.ReferenceEquals(this.view, otherVCO.view) && (_target == otherVCO._target))
            {
                _newValue = otherVCO._newValue;
                return(true);
            }

            return(false);
        }
        bool IMergableOperation.TryMergeWith(IUndoRedo other, bool isBulkOperation)
        {
            if (!isBulkOperation)
            {
                return(false);
            }

            var otherTLV = other as RemoveTopLevelViewOperation;

            if (otherTLV != null)
            {
                this.relatedRemovals.Add(otherTLV);
                return(true);
            }

            return(false);
        }
示例#21
0
        internal void Register(IUndoRedo op)
        {
            if (_current.HasValue)
            {
                bool prune = (_head != _current.Value);
                if (_savePoint > _current.Value)
                {
                    _validSavePoint = false;
                }

                _current = (_current + 1) % _array.Length;
                _head    = _current.Value;

                if (prune)
                {
                    if (_tail < _head)
                    {
                        Array.Clear(_array, 0, _tail);

                        var top = _head + 1;
                        if (top < _array.Length)
                        {
                            Array.Clear(_array, top, _array.Length - top);
                        }
                    }
                    else if (_tail > _head)
                    {
                        Array.Clear(_array, _head + 1, _tail - _head - 1);
                    }
                }
                else if (_tail == _head)
                {
                    _tail++;
                }
            }
            else
            {
                Clear();
                _current = _head = 0;
            }

            _array[_current.Value] = op;
        }
示例#22
0
    public void Redo()
    {
        if (CanRedo())
        {
            try
            {
                m_CsvForm.BeforeChangeCellValue();
                IUndoRedo iur = m_RedoStack.Pop();
                iur.Redo(m_CsvForm.GetDataGridView(), m_CsvForm.GetDataTable());
                m_UndoStack.Push(iur);
                DoSomething(this, new DoSomethingEventArgs(DoEventType.Redo, iur.GetDoType()));
                m_CsvForm.AfterChangeCellValue();

                MainForm.Instance.UpdateCellEdit();
            }
            catch (System.Exception ex)
            {
                DebugUtility.ShowExceptionMessageBox("重做失败", ex);
            }
        }
    }
示例#23
0
        bool IMergableOperation.TryMergeWith(IUndoRedo other, bool isBulkOperation)
        {
            if (!isBulkOperation)
            {
                return(false);
            }

            var otherLFA = other as ListFieldAddOperation;

            if (otherLFA != null)
            {
                if (_relatedAdds == null)
                {
                    _relatedAdds = new List <ListFieldAddOperation>(1);
                }

                _relatedAdds.Add(otherLFA);
                return(true);
            }

            return(false);
        }
示例#24
0
        /// <summary>
        ///   Register a new undo command along with an undo handler.
        ///   The undo handler is used to perform the actual undo or redo operation later when requested.
        /// </summary>
        /// <param name = "cmd">New command to add to the manager.</param>
        /// <param name = "undoHandler">Undo handler to perform the actual undo/redo operation.</param>
        private void AddUndoCommand(IUndoRedo cmd, IUndoRedoHandler undoHandler)
        {
            if (cmd == null)
            {
                throw new NullReferenceException("The cmd sent to AddUndoCommand should not be null.");
            }

            if (this._maxUndoLevel == 0)
            {
                return;
            }

            if (this._undoList.Count == this._maxUndoLevel)
            {
                this._undoList.RemoveAt(0);
            }

            // Insert the new undoable command into the undo list.
            this._undoList.Add(new UndoRedoInfo(cmd, undoHandler));

            // Clear the redo stack.
            this.ClearRedo();
        }
        internal void Do(IUndoRedo operation)
        {
            var viewBound = operation as IViewBoundOperation;

            if (viewBound != null)
            {
                viewBound.view = _ui.selectedView;
            }

            var last = (this.isBulkOperation ? _bulkOperation.lastOperation : _log.lastEntry) as IMergableOperation;

            if (last != null && last.TryMergeWith(operation, this.isBulkOperation))
            {
                return;
            }

            if (this.isBulkOperation)
            {
                _bulkOperation.lastOperation = operation;
            }

            _log.Register(operation);
            _functionalChangeCount++;
        }
示例#26
0
 /// <summary>
 ///   Register a new undo command. Use this method after your
 ///   application has performed an operation/command that is undoable.
 /// </summary>
 /// <param name = "cmd">New command to add to the manager.</param>
 public void AddUndoCommand(IUndoRedo cmd)
 {
     this.AddUndoCommand(cmd, null);
 }
示例#27
0
 public UndoRedoInfo(IUndoRedo undoable, IUndoRedoHandler doHandler)
 {
     this.UndoRedoObject  = undoable;
     this.UndoRedoHandler = doHandler;
 }
 //Used for adding the Undo/Redo command to the "undoStack", clears the "redoStack",
 // and executes the command
 public void AddAndExecute(IUndoRedo command) {
     undoStack.Push(command);
     redoStack.Clear();
     command.Execute();
     drawingIsSaved = false;
 }
 public void Dispose()
 {
     _parent.isBulkOperation = false;
     lastOperation           = null;
 }
示例#30
0
 public void Add(IUndoRedo cmd)
 {
     _undoList.Add(cmd);
     _redoList.Clear();
 }
示例#31
0
 public static void DoRedoActions(IUndoRedo context, IUndoMemento memento)
 {
     if (memento.Sender == context)
     {
         foreach (var redoAction in memento.RedoActions)
         {
             redoAction();
         }
     }
 }
 public override bool CanLogData(IUndoRedo source, object data)
 {
     return(base.CanLogData(source, data));
 }
示例#33
0
 // make it easier to add a single undo to a collection right away
 public UndoRedoCollection(UndoRedoType type, IUndoRedo ur)
 {
     Type = type;
     Add(ur);
 }
示例#34
0
 public void Add(IUndoRedo ur)
 {
     undoRedos.Add(ur);
 }