Table of Contents

Class UndoRedoManager

Namespace
ExControls.Providers
Assembly
ExControls.dll

Provides undo-redo capability.

[ToolboxBitmap(typeof(ToolboxIcons), "Toolbox.UndoRedoManager.ico")]
public class UndoRedoManager : Component, IComponent, IDisposable
Inheritance
UndoRedoManager
Implements
Inherited Members

Constructors

UndoRedoManager()

Initializes a new instance of the UndoRedoManager class with an empty history; commands are added only after ManagerEnabled is turned on.

public UndoRedoManager()

Properties

CanRedo

Check if there is something to redo. Use this method to decide whether your application's "Redo" menu item should be enabled or disabled.

[Browsable(false)]
public bool CanRedo { get; }

Property Value

bool

CanUndo

Check if there is something to undo. Use this method to decide whether your application's "Undo" menu item should be enabled or disabled.

[Browsable(false)]
public bool CanUndo { get; }

Property Value

bool

ManagerEnabled

Enables or disables manager to add commands to stacks. Default is false.

public bool ManagerEnabled { get; set; }

Property Value

bool

NextRedoCommand

Get the next redo command. This is like a "Peek" method. It does not remove the command from the redo stack.

[Browsable(false)]
public IUndoRedoCommand NextRedoCommand { get; }

Property Value

IUndoRedoCommand

NextUndoCommand

Get the next (or newest) undo command. This is like a "Peek" method. It does not remove the command from the undo list.

[Browsable(false)]
public IUndoRedoCommand NextUndoCommand { get; }

Property Value

IUndoRedoCommand

SavedStateCommand

Represents last saved undo command in history.

protected IUndoRedoCommand? SavedStateCommand { get; set; }

Property Value

IUndoRedoCommand

Methods

AddCommand(IUndoRedoCommand)

Register a new undo command. Use this method after your application has performed an operation/command that is undoable.

public void AddCommand(IUndoRedoCommand cmd)

Parameters

cmd IUndoRedoCommand

command to add to the history

AddCommand(IUndoRedoCommand, IUndoHandler)

Register a new undo command along with an undo handler. The undo handler is used to perform the actual undo or redo operation later when requested.

public void AddCommand(IUndoRedoCommand cmd, IUndoHandler handler)

Parameters

cmd IUndoRedoCommand

command to add to the history

handler IUndoHandler

handler that performs the undo and redo of the command

Clear()

Clear the internal undo/redo data structures. Use this method when your application performs an operation that cannot be undone. For example, when the user "saves" or "commits" all the changes in the application, or when a form is closed.

public void Clear()

GetRedoHistory()

Gets current history of redo commands.

public IEnumerable<IUndoRedoCommand> GetRedoHistory()

Returns

IEnumerable<IUndoRedoCommand>

The commands that can be redone, the next one to redo first.

GetRedoText()

Get the text value of the next redo command. Use this method to update the Text property of your "Redo" menu item if desired. For example, the text value for a command might be "Draw Line". This allows you to change your menu item text to "Redo Draw Line".

public string GetRedoText()

Returns

string

GetUndoHistory()

Gets current history of undo commands.

public IEnumerable<IUndoRedoCommand> GetUndoHistory()

Returns

IEnumerable<IUndoRedoCommand>

The commands that can be undone, the newest first.

GetUndoText()

Get the text value of the next undo command. Use this method to update the Text property of your "Undo" menu item if desired. For example, the text value for a command might be "Draw Circle". This allows you to change your menu item Text property to "Undo Draw Circle".

public string GetUndoText()

Returns

string

IsInSavedState()

Returns whether the manager is in saved state.

public bool IsInSavedState()

Returns

bool

true if the newest undo command is the same as when SetSavedState() was called (both may be none); otherwise, false.

OnCommandAdded(UndoRedoAddedCommandEventArgs)

Raises the CommandAdded event.

protected virtual void OnCommandAdded(UndoRedoAddedCommandEventArgs e)

Parameters

e UndoRedoAddedCommandEventArgs

The event data.

OnUndoRedoStateChanged(UndoRedoStateEventArgs)

Raises the UndoRedoStateChanged event.

protected virtual void OnUndoRedoStateChanged(UndoRedoStateEventArgs e)

Parameters

e UndoRedoStateEventArgs

The event data.

Redo()

Perform the redo operation. If an undo handler was specified, it will be used to perform the actual operation. Otherwise, the command instance is asked to perform the redo.

public void Redo()

Redo(IUndoRedoCommand)

Perform the redo operation. If an undo handler was specified, it will be used to perform the actual operation. Otherwise, the command instance is asked to perform the redo.

public void Redo(IUndoRedoCommand finalCmd)

Parameters

finalCmd IUndoRedoCommand

command in the redo history up to which the commands are redone, including it

SetSavedState()

Sets current state as saved.

public void SetSavedState()

Undo()

Perform the undo operation. If an undo handler was specified, it will be used to perform the actual operation. Otherwise, the command instance is asked to perform the undo.

public void Undo()

Undo(IUndoRedoCommand)

Perform the undo operation. If an undo handler was specified, it will be used to perform the actual operation. Otherwise, the command instance is asked to perform the undo.

public void Undo(IUndoRedoCommand finalCmd)

Parameters

finalCmd IUndoRedoCommand

command in the undo history up to which the commands are undone, including it

Events

CommandAdded

Occurs when a new command was added to the undo history.

public event EventHandler<UndoRedoAddedCommandEventArgs>? CommandAdded

Event Type

EventHandler<UndoRedoAddedCommandEventArgs>

UndoRedoStateChanged

Occurs when a command was undone or redone, or when the history was cleared.

public event EventHandler<UndoRedoStateEventArgs>? UndoRedoStateChanged

Event Type

EventHandler<UndoRedoStateEventArgs>