diff --git a/README.md b/README.md index aec351f..e62cac9 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,97 @@ DefaultUnDo is a simple [Command pattern](https://en.wikipedia.org/wiki/Command_ - [Release note](./documentation/RELEASENOTE.md 'Release note') - [Api documentation](./documentation/api/DefaultUnDo.md 'Api documentation') - \ No newline at end of file + + +- [Requirement](#Requirement) +- [Overview](#Overview) + + +# Requirement +Compatible from .NETStandard 1.0. +For development, a C#8.0 compatible environment, net framework 4.8, net core 1.0 and netcore 3.0 are required to build and run all tests (it is possible to disable some target in the test project if needed). + + +# Overview +Easy to use, just instanciate a `UnDoManager` and get going. Numerous extension methods are available to ease the integration. +```csharp +IUnDoManager manager = new UnDoManager(); + +// do an action and record it in the manager, undoAction being the undo equivalent of the action +manager.Do(doAction, undoAction); + +if (manager.CanUndo) +{ + manager.Undo(); +} + +if (Manager.CanRedo) +{ + manager.Redo(); +} + +// clean any recorded action +manager.Clear(); +``` + +`ICollection`, `IList`, `IDictionary` and `ISet` can be coverterted to an undo instance so that any action performed on them will generate a `IUnDo` action on the manager. +```csharp +IUnDoManager manager = new UnDoManager(); + +// use myList as you would use your list normaly +IList myList = new List().AsUnDo(manager); + +// use myCollection as you would use your collection normaly +// note than the returned collection also implement INotifyCollectionChanged +ICollection myCollection = new ObservableCollection().AsUnDo(manager); + +// use myDictionary as you would use your dictionary normaly +Dictionary myDictionary = new Dictionary().AsUnDo(manager); + +// use mySet as you would use your set normaly +ISet mySet = new HashSet().AsUnDo(manager); +``` + +It is possible to declare a group scope for you operations so a single undo/redo will execute all the contained operations. +```csharp +IUnDoManager manager = new UnDoManager(); + +using (manager.BeginGroup()) +{ + manager.Do(action1, undo1); + manager.Do(action2, undo2); +} + +// both undo2 and undo1 will be called in this order +manager.Undo(); + +// both action1 and action2 will be called in this order +manager.Redo(); +``` + +If a group scope is declared inside an other group scope, all operations will be grouped in the same undo/redo operation. +```csharp +IUnDoManager manager = new UnDoManager(); + +using (manager.BeginGroup()) +{ + manager.Do(action1, undo1); + + using (manager.BeginGroup()) + { + manager.Do(action2, undo2); + } +} + +// both undo2 and undo1 will be called in this order +manager.Undo(); + +// both action1 and action2 will be called in this order +manager.Redo(); +``` + +`IUnDoManager.Undo` and `IUnDoManager.Redo` calls are not supported when inside a group operation. Also the actions recorded by the manager should not generate more operations themselves. + +To keep track of the modification, a `Version` property is available on the manager. + +Missing something? you can easily extend what you need by creating your own implementations of the `IUnDo` interface and extension methods to ease the usage. Feel free to open an issue or send a pull request. \ No newline at end of file