Exemple #1
0
        private void SetStart()
        {
            redoStack.Clear();

            UndoBatch b = UndoHead;

            if (b == null)
            {
                b = new UndoBatch();
                undoStack.Push(b);
            }
            if (b.IsEmpty && context != null)
            {
                b.Start = context.ContextInfo;
            }
        }
Exemple #2
0
        public object Undo(object info)
        {
            if (!CanUndo)
            {
                throw new InvalidOperationException("Cannot undo");
            }

            if (UndoHead != null && UndoHead.IsEmpty)
            {
                // ignore an empty batch
                undoStack.Pop();
            }

            Debug.Assert(UndoHead != null && !UndoHead.IsEmpty, "Invalid undo state");

            UndoBatch batch = (UndoBatch)undoStack.Pop();

            if (batch.End == null)
            {
                batch.End = info;
            }

            disabled = true;
            try
            {
                batch.Undo();
            }
            finally
            {
                disabled = false;
            }

            redoStack.Push(batch);

            if (undoStack.Count == 0 || !UndoHead.IsEmpty)
            {
                // undo stack is empty or there is a non-empty batch on the undo
                // stack - we want to separate any future changes from that batch
                UndoBatch n = new UndoBatch();
                // TODO: M: not sure about this next line
                //			consider edit, undo, move, edit, undo
                n.Start = batch.Start;
                undoStack.Push(n);
            }

            return(batch.Start);
        }
Exemple #3
0
        public void Mark(object info)
        {
//			Console.WriteLine("UndoManager: Mark({0})", info);

            UndoBatch batch = UndoHead;

            if (batch != null)
            {
                if (batch.IsEmpty)
                {
                    return;
                }

                if (batch.End == null)
                {
                    batch.End = info;
                }
            }

            batch = new UndoBatch();
            undoStack.Push(batch);
        }
Exemple #4
0
        public object Redo()
        {
            if (!CanRedo)
            {
                throw new InvalidOperationException("Cannot redo");
            }

            UndoBatch batch = (UndoBatch)redoStack.Pop();

            disabled = true;
            try
            {
                batch.Redo();
                undoStack.Push(batch);
                UndoBatch n = new UndoBatch();
                n.Start = batch.End;
                undoStack.Push(n);
            }
            finally
            {
                disabled = false;
            }
            return(batch.End);
        }