|
/////////////////////////////////////////////////////////////////////////////
//
// (c) 2007 BinaryComponents Ltd. All Rights Reserved.
//
// http://www.binarycomponents.com/
//
/////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace BinaryComponents.WinFormsUtility.Commands
{
public abstract class UndoableAction
{
protected UndoableAction()
{
}
public abstract string UndoTitle
{
get;
}
public abstract string RedoTitle
{
get;
}
public abstract bool Undo( Control owner );
public abstract bool Redo( Control owner );
}
public class CompositeUndoableAction : UndoableAction
{
public CompositeUndoableAction( string undoTitle, string redoTitle )
{
if( undoTitle == null )
{
throw new ArgumentNullException( "undoTitle" );
}
if( redoTitle == null )
{
throw new ArgumentNullException( "redoTitle" );
}
_undoTitle = undoTitle;
_redoTitle = redoTitle;
}
public override string UndoTitle
{
get
{
return _undoTitle;
}
}
public override string RedoTitle
{
get
{
return _redoTitle;
}
}
public override bool Undo( Control owner )
{
bool success = false;
UndoableAction[] actions = _actions.ToArray();
Array.Reverse( actions );
foreach( UndoableAction action in actions )
{
success |= action.Undo( owner );
}
return success;
}
public override bool Redo( Control owner )
{
bool success = false;
foreach( UndoableAction action in _actions )
{
success |= action.Redo( owner );
}
return success;
}
public void AddAction( UndoableAction action )
{
if( action == null )
{
throw new ArgumentNullException( "action" );
}
_actions.Add( action );
}
private string _undoTitle, _redoTitle;
private List<UndoableAction> _actions = new List<UndoableAction>();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm currently working for a small start-up company, BinaryComponents Ltd, producing the FeedGhost RSS reader.
FeedGhost RSS Reader:
http://www.feedghost.com
Bespoke Software Development
http://www.binarycomponents.com