Esempio n. 1
0
        /// <summary>
        /// 将 SEUndoUnit 添加到撤消堆栈中。
        /// </summary>
        /// <param name="unit"></param>
        public void AddUndoUnit(SEUndoUnitAbstract unit)
        {
            if (this.Working)
            {
                return;
            }

            if (unit == null)
            {
                return;
            }

            //放入新的可撤销单元时,必须清除当前的重做堆栈,否则会在使用重做功能时会发生逻辑问题
            //看文件头上的注释
            if (EnableRedo)
            {
                _redoStack.Clear();
            }

            unit.UndoEngine = this;

            _undoStack.Push(unit);

            //触发添加单元后的事件
            if (this.OnAddUndoUnit != null)
            {
                OnAddUndoUnit(unit);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 重做
        /// 并指定是否引发OnRedo事件
        /// </summary>
        /// <param name="redoEvent"></param>
        public void Redo(bool redoEvent)
        {
            this.Working = true;

            SEUndoUnitAbstract unit = null;

            Debug.Assert(_redoStack.Count > 0, "_redoStack.Count <= 0");

            if (_redoStack.Count > 0)
            {
                try
                {
                    unit = _redoStack.Pop();
                    unit.Redo();
                    _undoStack.Push(unit);

                    Debug.WriteLine("Redo:" + unit.ToString());

                    //触发重做后的事件
                    if (redoEvent && this.OnRedo != null)
                    {
                        OnRedo(unit);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Assert(false, ex.Message);
                }
            }

            this.Working = false;
        }
Esempio n. 3
0
        private SEUndoUnitAbstract RedoUnit()
        {
            if (_redoStack.Count == 0)
            {
                return(null);
            }
            SEUndoUnitAbstract unit = _redoStack.Pop();

            unit.Redo();
            _undoStack.Push(unit);
            Debug.WriteLine("Redo:" + unit.ToString());
            return(unit);
        }
Esempio n. 4
0
 public void AddUndoUnit(SEUndoUnitAbstract unit)
 {
     if (unit == null)
     {
         return;
     }
     if (_redoStack.Count > 0)
     {
         _redoStack.Clear();
     }
     unit.UndoEngine = this.UndoEngine;
     _undoStack.Push(unit);
 }
Esempio n. 5
0
        /// <summary>
        /// 多步重做,并指定是否在每一步Redo中引发事件
        /// </summary>
        /// <param name="step"></param>
        /// <param name="redoEvent"></param>
        public void Redo(int step, bool redoEvent)
        {
            this.Working = true;

            if (step < 1)
            {
                return;
            }

            Dictionary <SEUndoUnitAbstract, Action <SEUndoUnitAbstract, SEUndoEngine.Type> > _actions
                = new Dictionary <SEUndoUnitAbstract, Action <SEUndoUnitAbstract, Type> >();

            for (int i = 0; i < step; i++)
            {
                Debug.Assert(_redoStack.Count > 0, "_redoStack.Count <= 0");

                SEUndoUnitAbstract unit = null;

                if (_redoStack.Count > 0)
                {
                    try
                    {
                        unit = _redoStack.Pop();
                        if (unit.MergeAction && unit.Action != null)
                        {
                            if ((from c in _actions where c.Key.GetType().Equals(unit.GetType()) select c).Count() == 0)
                            {
                                _actions.Add(unit, unit.Action);
                            }

                            unit.Redo(false);
                        }
                        else
                        {
                            unit.Redo(true);
                        }
                        _undoStack.Push(unit);

                        Debug.WriteLine("Redo:" + unit.ToString());

                        //触发重做后的事件
                        if (this.OnRedo != null && redoEvent)
                        {
                            OnRedo(unit);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.Assert(false, ex.Message);
                    }
                }
            }

            foreach (KeyValuePair <SEUndoUnitAbstract, Action <SEUndoUnitAbstract, SEUndoEngine.Type> > pair in _actions)
            {
                pair.Value(pair.Key, SEUndoEngine.Type.Redo);
            }

            if (OnStepRedo != null)
            {
                OnStepRedo(step);
            }

            this.Working = false;
        }
 public int Add(SEUndoUnitAbstract obj)
 {
     return(this.Add(new StepListItem(obj)));
 }
 public void Remove(SEUndoUnitAbstract value)
 {
     List.Remove(value);
 }
 public void Insert(int index, SEUndoUnitAbstract value)
 {
     List.Insert(index, value);
 }
 public int IndexOf(SEUndoUnitAbstract value)
 {
     return(List.IndexOf(value));
 }
 public bool Contains(SEUndoUnitAbstract value)
 {
     return(List.Contains(value));
 }
 public int Add(SEUndoUnitAbstract value)
 {
     return(List.Add(value));
 }
Esempio n. 12
0
 public StepListItem(SEUndoUnitAbstract obj)
 {
     this.UndoUnit = obj;
 }