{"id":23240497,"url":"https://github.com/themysteriousstranger90/undoredomanagerlib","last_synced_at":"2026-04-27T20:33:27.097Z","repository":{"id":268501533,"uuid":"893294539","full_name":"TheMysteriousStranger90/UndoRedoManagerLib","owner":"TheMysteriousStranger90","description":"UndoRedoManager is a .NET library for managing undo and redo operations. It provides a mechanism to track changes to objects and collections, allowing you to undo and redo those changes as needed. ","archived":false,"fork":false,"pushed_at":"2024-12-17T05:57:55.000Z","size":256,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-12T04:29:20.069Z","etag":null,"topics":["csharp","dotnetcore","nuget-package","undo-redo"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/BohdanHarabadzhyu.UndoRedoManagerLib/0.0.1","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheMysteriousStranger90.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-24T03:36:02.000Z","updated_at":"2024-12-17T05:51:24.000Z","dependencies_parsed_at":"2024-12-17T06:40:44.673Z","dependency_job_id":null,"html_url":"https://github.com/TheMysteriousStranger90/UndoRedoManagerLib","commit_stats":null,"previous_names":["themysteriousstranger90/undoredomanagerlib"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheMysteriousStranger90%2FUndoRedoManagerLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheMysteriousStranger90%2FUndoRedoManagerLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheMysteriousStranger90%2FUndoRedoManagerLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheMysteriousStranger90%2FUndoRedoManagerLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheMysteriousStranger90","download_url":"https://codeload.github.com/TheMysteriousStranger90/UndoRedoManagerLib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411236,"owners_count":20934650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnetcore","nuget-package","undo-redo"],"created_at":"2024-12-19T05:12:27.040Z","updated_at":"2026-04-27T20:33:27.056Z","avatar_url":"https://github.com/TheMysteriousStranger90.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UndoRedoManager\n![Image 1](Screenshots/Screen1.png)\n\nUndoRedoManager is a .NET library for managing undo and redo operations. It provides a mechanism to track changes to objects and collections, allowing you to undo and redo those changes as needed. This library is useful for applications that require support for undo/redo functionality.\n\n## Features\n\n- Track changes to objects and collections.\n- Support for transactions to group multiple changes.\n- Undo and redo operations.\n- Notifications for property changes.\n\n## Usage\n### Defining Commands\n\nCommands represent the changes you want to track. Each command should implement the IUndoRedoCommand interface. You can either define custom commands or use the built-in ChangePropertyCommand for simpler property changes. Example:\n\n```csharp\nusing UndoRedoManager;\n\npublic class ChangeNameCommand : IUndoRedoCommand\n{\n    private readonly MainTransactionChange\u003cstring\u003e _change;\n\n    public ChangeNameCommand(Person person, string newName)\n    {\n        _change = new MainTransactionChange\u003cstring\u003e(\n            value =\u003e person.Name = value,\n            person.Name,\n            newName);\n    }\n\n    public void Execute() =\u003e _change.RollForward();\n    public void Undo() =\u003e _change.Rollback();\n}\n\npublic class ChangeAgeCommand : IUndoRedoCommand\n{\n    private readonly MainTransactionChange\u003cint\u003e _change;\n\n    public ChangeAgeCommand(Person person, int newAge)\n    {\n        _change = new MainTransactionChange\u003cint\u003e(\n            value =\u003e person.Age = value,\n            person.Age,\n            newAge);\n    }\n\n    public void Execute() =\u003e _change.RollForward();\n    public void Undo() =\u003e _change.Rollback();\n}\n\npublic class ChangeAddressCommand : IUndoRedoCommand\n{\n    private readonly MainTransactionChange\u003cAddress\u003e _change;\n\n    public ChangeAddressCommand(Person person, Address newAddress)\n    {\n        _change = new MainTransactionChange\u003cAddress\u003e(\n            value =\u003e person.Address = value,\n            person.Address,\n            newAddress);\n    }\n\n    public void Execute() =\u003e _change.RollForward();\n    public void Undo() =\u003e _change.Rollback();\n}\n```\n\n### Using ChangePropertyCommand\nThe ChangePropertyCommand allows you to define property changes dynamically without needing a custom command. This simplifies development while maintaining flexibility. Example:\n\n```\n...\n            new ChangePropertyCommand\u003cAddress\u003e(\n                value =\u003e person.Address = value,\n                person.Address,\n                new Address(\"456 Elm St\", \"Shelbyville\"))\n```\n\nUsing the UndoRedoManager\nCreate an instance of UndoRedoManager and use it to execute commands. You can also group multiple commands into a transaction. Example:\n\n```csharp\nusing UndoRedoManagerConsoleExample;\nusing UndoRedoManagerConsoleExample.Models;\nusing UndoRedoManagerLib;\n\nclass Program\n{\n    static void Main(string[] args)\n    {\n        var context = new UndoRedoContext();\n        var manager = new UndoRedoManager(1000, enableGrouping: false); // Stack size and Disable grouping for this example\n\n        var address = new Address(\"123 Main St\", \"Springfield\");\n        var person = new Person(\"John Doe\", 30, address);\n\n        Console.WriteLine(\"Initial state:\");\n        Console.WriteLine(person);\n\n        context.Resume();\n        manager.BeginTransaction(context);\n        var commands = new List\u003cIUndoRedoCommand\u003e\n        {\n            new ChangeNameCommand(person, \"Jane Doe\"),\n            new ChangeAgeCommand(person, 25),\n\n            // Using ChangePropertyCommand to change the Address property of the Person object.\n            // 1. Create custom commands like ChangeNameCommand and ChangeAgeCommand for specific properties.\n            //    - These commands are tailored to specific use cases, often encapsulating additional logic or validation.\n            // 2. Use the generic ChangePropertyCommand when we simply need to change a property value without custom logic.\n            //    - This allows us to reuse a single command implementation for any property of any object.\n            //    - In this case, ChangePropertyCommand\u003cAddress\u003e is used to change the Address property of the Person object.\n            //    - The lambda expression `value =\u003e person.Address = value` specifies how the property should be updated.\n            //    - The old value (person.Address) and new value (new Address(\"456 Elm St\", \"Shelbyville\")) are provided for undo/redo functionality.\n            new ChangePropertyCommand\u003cAddress\u003e(\n                value =\u003e person.Address = value,\n                person.Address,\n                new Address(\"456 Elm St\", \"Shelbyville\"))\n        };\n        var transactionCommand = new TransactionCommand(commands);\n        manager.Execute(transactionCommand);\n        manager.CommitTransaction();\n\n        Console.WriteLine(\"\\nAfter changes:\");\n        Console.WriteLine(person);\n\n        context.Undo();\n        Console.WriteLine(\"\\nAfter undo:\");\n        Console.WriteLine(person);\n\n        context.Redo();\n        Console.WriteLine(\"\\nAfter redo:\");\n        Console.WriteLine(person);\n    }\n}\n```\n\n### Using Groups Of Similar Commands\nYou can group similar commands together to simplify the undo/redo process. This is useful when you have multiple commands that are related and should be undone/redone together. Example:\n\n```csharp\nclass Program\n{\n    static void Main(string[] args)\n    {\n        var context = new UndoRedoContext();\n        var manager = new UndoRedoManager(1000, enableGrouping: true); // Enable grouping\n    \n        var address = new Address(\"123 Main St\", \"Springfield\");\n        var person = new Person(\"John Doe\", 30, address);\n\n        Console.WriteLine(\"Initial state:\");\n        Console.WriteLine(person);\n\n        // First group: Name changes (will be grouped due to same type and timing)\n        manager.Execute(new ChangeNameCommand(person, \"Jane Doe\"));\n        Thread.Sleep(100); // Small delay, still within grouping window\n        manager.Execute(new ChangeNameCommand(person, \"Jane Smith\"));\n    \n        Console.WriteLine(\"\\nAfter name changes:\");\n        Console.WriteLine(person);\n\n        // Second group: Age changes\n        Thread.Sleep(600); // Delay longer than grouping window (500ms default)\n        manager.Execute(new ChangeAgeCommand(person, 25));\n        Thread.Sleep(100);\n        manager.Execute(new ChangeAgeCommand(person, 26));\n\n        Console.WriteLine(\"\\nAfter age changes:\");\n        Console.WriteLine(person);\n\n        // Third group: Address changes\n        Thread.Sleep(600);\n        manager.Execute(new ChangePropertyCommand\u003cAddress\u003e(\n            value =\u003e person.Address = value,\n            person.Address,\n            new Address(\"456 Elm St\", \"Shelbyville\")));\n\n        Console.WriteLine(\"\\nAfter all changes:\");\n        Console.WriteLine(person);\n\n        // Undo operations - each group will be undone as a single unit\n        manager.Undo(); // Undoes address change\n        Console.WriteLine(\"\\nAfter first undo (address):\");\n        Console.WriteLine(person);\n\n        manager.Undo(); // Undoes age changes group\n        Console.WriteLine(\"\\nAfter second undo (age):\");\n        Console.WriteLine(person);\n\n        manager.Undo(); // Undoes name changes group\n        Console.WriteLine(\"\\nAfter third undo (name):\");\n        Console.WriteLine(person);\n    }\n}\n```\n\n## Future Development\n\nThis project is still under development.\n\n## Contributing\n\nContributions are welcome. Please fork the repository and create a pull request with your changes.\n\n## Author\n\nBohdan Harabadzhyu\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthemysteriousstranger90%2Fundoredomanagerlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthemysteriousstranger90%2Fundoredomanagerlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthemysteriousstranger90%2Fundoredomanagerlib/lists"}