Class CommandManager<T>
Executes IUndoCommands for editing a specific object and allows undo/redo operations.
Namespace: NanoByte.Common.Undo
Assembly: NanoByte.Common.dll
Syntax
public class CommandManager<T> : Object, ICommandManager<T>, ICommandExecutor where T : class
Type Parameters
Name | Description |
---|---|
T | The type of the object being edited. |
Constructors
CommandManager(T, String)
Creates a new command manager.
Declaration
public CommandManager(T target, string path = null)
Parameters
Type | Name | Description |
---|---|---|
T | target | The object being edited. |
String | path | The path of the file the |
Properties
Path
The path of the file the Target was loaded from. null
if none.
Declaration
public string Path { get; set; }
Property Value
Type | Description |
---|---|
String |
RedoEnabled
Indicates whether there currently are operations that can be Redo()ne.
Declaration
public bool RedoEnabled { get; }
Property Value
Type | Description |
---|---|
Boolean |
Target
The object being edited.
Declaration
public T Target { get; set; }
Property Value
Type | Description |
---|---|
T |
UndoEnabled
Indicates whether there currently are operations that can be Undo()ne.
Declaration
public bool UndoEnabled { get; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
This can also be used as an indicator for unsaved changes.
Methods
ClearUndo()
Clears the undo/redo stacks.
Declaration
protected void ClearUndo()
Execute(IUndoCommand)
Executes an IUndoCommand and stores it for later undo-operations.
Declaration
public void Execute(IUndoCommand command)
Parameters
Type | Name | Description |
---|---|---|
IUndoCommand | command | The command to be executed. |
Load(String)
Loads an object from an XML file.
Declaration
public static CommandManager<T> Load(string path)
Parameters
Type | Name | Description |
---|---|---|
String | path | The file to load from. |
Returns
Type | Description |
---|---|
CommandManager<T> | An ICommandManager<T> containing the loaded object. |
Exceptions
Type | Condition |
---|---|
IOException | A problem occurs while reading the file. |
UnauthorizedAccessException | Read access to the file is not permitted. |
InvalidDataException | A problem occurs while deserializing the XML data. |
Redo()
Redoes the last action undone by Undo().
Declaration
public void Redo()
Save(String)
Saves the Target to an XML file
Declaration
public virtual void Save(string path)
Parameters
Type | Name | Description |
---|---|---|
String | path | The file to save to. |
Exceptions
Type | Condition |
---|---|
IOException | A problem occurs while writing the file. |
UnauthorizedAccessException | Write access to the file is not permitted. |
Undo()
Undoes the last action performed by Execute(IUndoCommand).
Declaration
public void Undo()
Events
RedoEnabledChanged
Is raised when the value of RedoEnabled has changed.
Declaration
public event Action RedoEnabledChanged
Event Type
Type | Description |
---|---|
Action |
TargetUpdated
Is raised after Target has been updated.
Declaration
public event Action TargetUpdated
Event Type
Type | Description |
---|---|
Action |
UndoEnabledChanged
Is raised when the value of UndoEnabled has changed.
Declaration
public event Action UndoEnabledChanged
Event Type
Type | Description |
---|---|
Action |