magicmanam.UndoRedo
1.1.1
Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package magicmanam.UndoRedo --version 1.1.1
NuGet\Install-Package magicmanam.UndoRedo -Version 1.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="magicmanam.UndoRedo" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add magicmanam.UndoRedo --version 1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: magicmanam.UndoRedo, 1.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install magicmanam.UndoRedo as a Cake Addin #addin nuget:?package=magicmanam.UndoRedo&version=1.1.1 // Install magicmanam.UndoRedo as a Cake Tool #tool nuget:?package=magicmanam.UndoRedo&version=1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
magicmanam.UndoRedo
magicmanam.UndoRedo
nuget package is easy and lightweight Undo/Redo operations implementation
In order to add it to your solution, run Install-Package magicmanam.UndoRedo
from your NuGet Package Manager console in Visual Studio.
Quick start
- Define class which will represent your application state at any time (for example AppState class)
- Implement interface <i>IStatefulComponent<AppState></i> to have possibility to retrieve current application state
- Initialize current undoable context for your application state:
UndoableContext<AppState>.Current = new UndoableContext<AppState>(statefulComponentInstance);
- Wrap any action which changes application state with the following code:
using (var action = UndoableContext<AppState>.Current.StartAction("Sample action name"))
{
statefulComponentInstance.ChangeState();
// action.Cancel(); - you can cancel your application state change and the previous state will be restored
}
- Now you can undo/redo any your action made in scope of current undoable context:
UndoableContext<AppState>.Current.Undo();
// statefulComponentInstance returns the previous state now
// or
UndoableContext<AppState>.Current.Redo();
// Rollbacks the previous Undo operation
- You can subscribe on any action in scope of the current undoable context including cancelled actions and Undo/Redo operations:
UndoableContext<AppState>.Current.UndoableAction += (object sender, UndoableActionEventArgs<AppState> e) =>
{
if (e.Action.IsCancelled)
{
// Action was cancelled
}
else
{
if (e.IsUndo)
{
// The latest action was undone
}
else if (e.IsRedo)
{
// The latest undo operation was restored
}
else
{
// e.Action.Name == "Sample action name"
// Ordinary action on application state was performed
}
}
};
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Fixes undoable action event arguments data