You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Design;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
namespace Host
{
public class UndoEngineExt : UndoEngine
{
//private string _Name_ = "UndoEngineExt";
private Stack<UndoEngine.UndoUnit> undoStack = new Stack<UndoEngine.UndoUnit>();
private Stack<UndoEngine.UndoUnit> redoStack = new Stack<UndoEngine.UndoUnit>();
public UndoEngineExt(IServiceProvider provider) : base(provider) { }
public bool EnableUndo
{
get { return undoStack.Count > 0; }
}
public bool EnableRedo
{
get { return redoStack.Count > 0; }
}
public void Undo()
{
if (undoStack.Count > 0)
{
try
{
UndoEngine.UndoUnit unit = undoStack.Pop();
unit.Undo();
redoStack.Push(unit);
//Log("::Undo - undo action performed: " + unit.Name);
}
catch
{
//Log("::Undo() - Exception " + ex.Message + " (line:" + new StackFrame(true).GetFileLineNumber() + ")");
}
}
else
{
//Log("::Undo - NO undo action to perform!");
}
}
public void Redo()
{
if (redoStack.Count > 0)
{
try
{
UndoEngine.UndoUnit unit = redoStack.Pop();
unit.Undo();
undoStack.Push(unit);
//Log("::Redo - redo action performed: " + unit.Name);
}
catch
{
//Log("::Redo() - Exception " + ex.Message + " (line:" + new StackFrame(true).GetFileLineNumber() + ")");
}
}
else
{
//Log("::Redo - NO redo action to perform!");
}
}
protected override void AddUndoUnit(UndoEngine.UndoUnit unit)
{
undoStack.Push(unit);
}
}//end_class
}//end_namespace