예제 #1
0
        public void OnEdit()
        {
            if (!picture.shapes.Any(shape => shape is CompoundShape))
            {
                ToUndoStack.Push(new List <IShape>(picture.shapes.Select(shape => shape.Clone()).ToList()));
            }
            else
            {
                var cloneList = new List <IShape>();
                foreach (var shape in picture.shapes)
                {
                    if (shape is CompoundShape compoundShape)
                    {
                        cloneList.Add(GetAllCompoundShapeClones(compoundShape));
                    }
                    else
                    {
                        cloneList.Add(shape.Clone());
                    }
                }

                ToUndoStack.Push(cloneList);
            }

            ToRedoStack = new Stack <List <IShape> >();
        }
예제 #2
0
        public List <IShape> OnRedo()
        {
            if (ToRedoStack.Count != 0 && ToRedoStack.Any())
            {
                var copy = ToRedoStack.Peek().Select(shape =>
                                                     shape is CompoundShape compoundShape ? GetAllCompoundShapeClones(compoundShape) : shape.Clone()
                                                     ).ToList();

                ToUndoStack.Push(ToRedoStack.Pop());

                return(copy);
            }

            return(null);
        }
예제 #3
0
        public List <IShape> OnUndo()
        {
            if (!IsStackEmpty())
            {
                ToRedoStack.Push(ToUndoStack.Pop());

                var copy = ToUndoStack.Peek().Select(shape =>
                                                     shape is CompoundShape compoundShape ? GetAllCompoundShapeClones(compoundShape) : shape.Clone()
                                                     ).ToList();

                return(copy);
            }

            return(null);
        }
예제 #4
0
 private bool IsStackEmpty()
 {
     return(ToUndoStack.Count == 1 && ToUndoStack.Peek().Count == 0);
 }