Class CommandManager<T>
Executes IUndoCommands for editing a specific object and allows undo/redo operations.
public class CommandManager<T> : ICommandManager<T>, ICommandExecutor where T : class
Type Parameters
T
The type of the object being edited.
- Inheritance
-
CommandManager<T>
- Implements
- Extension Methods
Constructors
CommandManager(T, string?)
Executes IUndoCommands for editing a specific object and allows undo/redo operations.
public CommandManager(T target, string? path = null)
Parameters
target
TThe object being edited.
path
stringThe path of the file the
target
was loaded from.null
if none.
Properties
Path
The path of the file the Target was loaded from. null
if none.
public string? Path { get; set; }
Property Value
RedoEnabled
Indicates whether there currently are operations that can be Redo()ne.
public bool RedoEnabled { get; }
Property Value
Target
The object being edited.
public T? Target { get; set; }
Property Value
- T
UndoEnabled
Indicates whether there currently are operations that can be Undo()ne.
public bool UndoEnabled { get; }
Property Value
Remarks
This can also be used as an indicator for unsaved changes.
Methods
ClearUndo()
Clears the undo/redo stacks.
protected void ClearUndo()
Execute(IUndoCommand)
Executes an IUndoCommand and stores it for later undo-operations.
public void Execute(IUndoCommand command)
Parameters
command
IUndoCommandThe command to be executed.
Load(string)
Loads an object from an XML file.
public static CommandManager<T> Load(string path)
Parameters
path
stringThe file to load from.
Returns
- CommandManager<T>
An ICommandManager<T> containing the loaded object.
Exceptions
- 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().
public void Redo()
Save(string)
Saves the Target to an XML file
public virtual void Save(string path)
Parameters
path
stringThe file to save to.
Exceptions
- 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).
public void Undo()
Events
RedoEnabledChanged
Is raised when the value of RedoEnabled has changed.
public event Action? RedoEnabledChanged
Event Type
TargetUpdated
Is raised after Target has been updated.
public event Action? TargetUpdated
Event Type
UndoEnabledChanged
Is raised when the value of UndoEnabled has changed.
public event Action? UndoEnabledChanged