📄 undostack.cs
字号:
// UndoStack.cs
// Copyright (c) 2000 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Diagnostics;
using System.Collections;
using SharpDevelop.Internal.Text;
namespace SharpDevelop.Internal.Undo {
/// <summary>
/// This class implements an undo stack
/// </summary>
public class UndoStack
{
Stack undostack = new Stack();
Stack redostack = new Stack();
public event EventHandler AfterUndo;
public event EventHandler AfterRedo;
/// <summary>
/// This property is EXCLUSIVELY for the UndoQueue class, don't USE it
/// </summary>
internal Stack _UndoStack {
get {
return undostack;
}
}
/// <summary>
/// You call this method to pool the last x operations from the undo stack
/// to make 1 operation from it.
/// </summary>
public void UndoLast(int x)
{
undostack.Push(new UndoQueue(this, x));
}
/// <summary>
/// Call this method to undo the last operation on the stack
/// </summary>
public void Undo()
{
if (undostack.Count > 0) {
UndoableOperation uedit = (UndoableOperation)undostack.Pop();
redostack.Push(uedit);
uedit.Undo();
if (AfterUndo != null)
AfterUndo(null, null);
}
}
/// <summary>
/// Call this method to redo the last undone operation
/// </summary>
public void Redo()
{
if (redostack.Count > 0) {
UndoableOperation uedit = (UndoableOperation)redostack.Pop();
undostack.Push(uedit);
uedit.Redo();
if (AfterRedo != null)
AfterRedo(null, null);
}
}
/// <summary>
/// Call this method to push an UndoableOperation on the undostack, the redostack
/// will be cleared, if you use this method.
/// </summary>
public void Push(UndoableOperation operation)
{
if (operation == null)
throw new ArgumentNullException("UndoStack.Push(UndoableOperation operation) : operation can't be null");
undostack.Push(operation);
ClearRedoStack();
}
/// <summary>
/// Call this method, if you want to clear the redo stack
/// </summary>
public void ClearRedoStack()
{
redostack.Clear();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -