| 0: | // UndoStack.cs | |
| 1: | // Copyright (c) 2000 Mike Krueger | |
| 2: | // | |
| 3: | // This program is free software; you can redistribute it and/or modify | |
| 4: | // it under the terms of the GNU General Public License as published by | |
| 5: | // the Free Software Foundation; either version 2 of the License, or | |
| 6: | // (at your option) any later version. | |
| 7: | // | |
| 8: | // This program is distributed in the hope that it will be useful, | |
| 9: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11: | // GNU General Public License for more details. | |
| 12: | // | |
| 13: | // You should have received a copy of the GNU General Public License | |
| 14: | // along with this program; if not, write to the Free Software | |
| 15: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 16: | ||
| 17: | using System; | |
| 18: | using System.Diagnostics; | |
| 19: | using System.Collections; | |
| 20: | using SharpDevelop.Internal.Text; | |
| 21: | ||
| 22: | namespace SharpDevelop.Internal.Undo { | |
| 23: | ||
| 24: | /// <summary> | |
| 25: | /// This class implements an undo stack | |
| 26: | /// </summary> | |
| 27: | public class UndoStack | |
| 28: | { | |
| 29: | Stack undostack = new Stack(); | |
| 30: | Stack redostack = new Stack(); | |
| 31: | ||
| 32: | public event EventHandler AfterUndo; | |
| 33: | public event EventHandler AfterRedo; | |
| 34: | ||
| 35: | /// <summary> | |
| 36: | /// This property is EXCLUSIVELY for the UndoQueue class, don't USE it | |
| 37: | /// </summary> | |
| 38: | internal Stack _UndoStack { | |
| 39: | get { | |
| 40: | return undostack; | |
| 41: | } | |
| 42: | } | |
| 43: | ||
| 44: | /// <summary> | |
| 45: | /// You call this method to pool the last x operations from the undo stack | |
| 46: | /// to make 1 operation from it. | |
| 47: | /// </summary> | |
| 48: | public void UndoLast(int x) | |
| 49: | { | |
| 50: | undostack.Push(new UndoQueue(this, x)); | |
| 51: | } | |
| 52: | ||
| 53: | /// <summary> | |
| 54: | /// Call this method to undo the last operation on the stack | |
| 55: | /// </summary> | |
| 56: | public void Undo() | |
| 57: | { | |
| 58: | if (undostack.Count > 0) { | |
| 59: | IUndoableOperation uedit = (IUndoableOperation)undostack.Pop(); | |
| 60: | redostack.Push(uedit); | |
| 61: | uedit.Undo(); | |
| 62: | if (AfterUndo != null) | |
| 63: | AfterUndo(null, null); | |
| 64: | } | |
| 65: | } | |
| 66: | ||
| 67: | /// <summary> | |
| 68: | /// Call this method to redo the last undone operation | |
| 69: | /// </summary> | |
| 70: | public void Redo() | |
| 71: | { | |
| 72: | if (redostack.Count > 0) { | |
| 73: | IUndoableOperation uedit = (IUndoableOperation)redostack.Pop(); | |
| 74: | undostack.Push(uedit); | |
| 75: | uedit.Redo(); | |
| 76: | if (AfterRedo != null) | |
| 77: | AfterRedo(null, null); | |
| 78: | } | |
| 79: | } | |
| 80: | ||
| 81: | /// <summary> | |
| 82: | /// Call this method to push an UndoableOperation on the undostack, the redostack | |
| 83: | /// will be cleared, if you use this method. | |
| 84: | /// </summary> | |
| 85: | public void Push(IUndoableOperation operation) | |
| 86: | { | |
| 87: | if (operation == null) | |
| 88: | throw new ArgumentNullException("UndoStack.Push(UndoableOperation operation) : operation can't be null"); | |
| 89: | ||
| 90: | undostack.Push(operation); | |
| 91: | ClearRedoStack(); | |
| 92: | } | |
| 93: | ||
| 94: | /// <summary> | |
| 95: | /// Call this method, if you want to clear the redo stack | |
| 96: | /// </summary> | |
| 97: | public void ClearRedoStack() | |
| 98: | { | |
| 99: | redostack.Clear(); | |
| 100: | } | |
| 101: | } | |
| 102: | } |
This page was automatically generated by SharpDevelop.