diff --git a/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs b/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs index 17274f8..2a20555 100644 --- a/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs +++ b/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs @@ -6,6 +6,7 @@ using Filtration.ItemFilterPreview.Tests.Properties; using Filtration.ObjectModel; using Filtration.ObjectModel.BlockItemTypes; using Filtration.ObjectModel.Enums; +using Filtration.ObjectModel.Factories; using Filtration.Parser.Services; using Moq; using NUnit.Framework; @@ -71,7 +72,12 @@ namespace Filtration.ItemFilterPreview.Tests.Services //Arrange var testInputScriptFile = Resources.MuldiniFilterScript; var blockGroupHierarchyBuilder = new BlockGroupHierarchyBuilder(); - var scriptTranslator = new ItemFilterScriptTranslator(new ItemFilterBlockTranslator(blockGroupHierarchyBuilder), blockGroupHierarchyBuilder); + var mockItemFilterScriptFactory = new Mock(); + mockItemFilterScriptFactory + .Setup(i => i.Create()) + .Returns(new ItemFilterScript()); + + var scriptTranslator = new ItemFilterScriptTranslator(blockGroupHierarchyBuilder, new ItemFilterBlockTranslator(blockGroupHierarchyBuilder), mockItemFilterScriptFactory.Object); var script = scriptTranslator.TranslateStringToItemFilterScript(testInputScriptFile); var testInputItem = new Item @@ -101,7 +107,11 @@ namespace Filtration.ItemFilterPreview.Tests.Services //Arrange var testInputScriptFile = Resources.MuldiniFilterScript; var blockGroupHierarchyBuilder = new BlockGroupHierarchyBuilder(); - var scriptTranslator = new ItemFilterScriptTranslator(new ItemFilterBlockTranslator(blockGroupHierarchyBuilder), blockGroupHierarchyBuilder); + var mockItemFilterScriptFactory = new Mock(); + mockItemFilterScriptFactory + .Setup(i => i.Create()) + .Returns(new ItemFilterScript()); + var scriptTranslator = new ItemFilterScriptTranslator(blockGroupHierarchyBuilder, new ItemFilterBlockTranslator(blockGroupHierarchyBuilder), mockItemFilterScriptFactory.Object); var script = scriptTranslator.TranslateStringToItemFilterScript(testInputScriptFile); var testInputItems = new List diff --git a/Filtration.ObjectModel/Commands/CommandManager.cs b/Filtration.ObjectModel/Commands/CommandManager.cs new file mode 100644 index 0000000..e8dc6f7 --- /dev/null +++ b/Filtration.ObjectModel/Commands/CommandManager.cs @@ -0,0 +1,62 @@ +using System.Collections.Generic; + +namespace Filtration.ObjectModel.Commands +{ + public interface ICommandManager + { + void ExecuteCommand(ICommand command); + void Undo(int undoLevels = 1); + void Redo(int redoLevels = 1); + } + + public interface ICommandManagerInternal : ICommandManager + { + void SetScript(IItemFilterScriptInternal layout); + } + + internal class CommandManager : ICommandManagerInternal + { + private readonly Stack _undoCommandStack = new Stack(); + private readonly Stack _redoCommandStack = new Stack(); + private IItemFilterScriptInternal _itemFilterScript; + + public void SetScript(IItemFilterScriptInternal itemFilterScript) + { + _itemFilterScript = itemFilterScript; + } + + public void ExecuteCommand(ICommand command) + { + command.Execute(); + var undoableCommand = command as IUndoableCommand; + if (undoableCommand != null) + { + _undoCommandStack.Push(undoableCommand); + _redoCommandStack.Clear(); + } + _itemFilterScript.SetIsDirty(true); + } + + public void Undo(int undoLevels = 1) + { + for (var index = undoLevels; _undoCommandStack.Count > 0 && index > 0; --index) + { + var undoableCommand = _undoCommandStack.Pop(); + undoableCommand.Undo(); + _redoCommandStack.Push(undoableCommand); + } + _itemFilterScript.SetIsDirty(true); + } + + public void Redo(int redoLevels = 1) + { + for (int index = redoLevels; _redoCommandStack.Count > 0 && index > 0; --index) + { + var undoableCommand = _redoCommandStack.Pop(); + undoableCommand.Redo(); + _undoCommandStack.Push(undoableCommand); + } + _itemFilterScript.SetIsDirty(true); + } + } +} diff --git a/Filtration.ObjectModel/Commands/ICommand.cs b/Filtration.ObjectModel/Commands/ICommand.cs new file mode 100644 index 0000000..84cfe3c --- /dev/null +++ b/Filtration.ObjectModel/Commands/ICommand.cs @@ -0,0 +1,7 @@ +namespace Filtration.ObjectModel.Commands +{ + public interface ICommand + { + void Execute(); + } +} diff --git a/Filtration.ObjectModel/Commands/IUndoableCommand.cs b/Filtration.ObjectModel/Commands/IUndoableCommand.cs new file mode 100644 index 0000000..9a9eb76 --- /dev/null +++ b/Filtration.ObjectModel/Commands/IUndoableCommand.cs @@ -0,0 +1,8 @@ +namespace Filtration.ObjectModel.Commands +{ + internal interface IUndoableCommand : ICommand + { + void Undo(); + void Redo(); + } +} diff --git a/Filtration.ObjectModel/Factories/IItemFilterScriptFactory.cs b/Filtration.ObjectModel/Factories/IItemFilterScriptFactory.cs new file mode 100644 index 0000000..2a5c0b2 --- /dev/null +++ b/Filtration.ObjectModel/Factories/IItemFilterScriptFactory.cs @@ -0,0 +1,9 @@ +namespace Filtration.ObjectModel.Factories +{ + public interface IItemFilterScriptFactory + { + IItemFilterScript Create(); + + void Release(IItemFilterScript itemFilterScript); + } +} diff --git a/Filtration.ObjectModel/Filtration.ObjectModel.csproj b/Filtration.ObjectModel/Filtration.ObjectModel.csproj index 23e9171..17c34c7 100644 --- a/Filtration.ObjectModel/Filtration.ObjectModel.csproj +++ b/Filtration.ObjectModel/Filtration.ObjectModel.csproj @@ -31,6 +31,12 @@ 4 + + ..\packages\Castle.Core.3.3.0\lib\net45\Castle.Core.dll + + + ..\packages\Castle.Windsor.3.4.0\lib\net45\Castle.Windsor.dll + @@ -68,6 +74,9 @@ + + + @@ -77,6 +86,7 @@ + @@ -97,6 +107,12 @@ + + + + + + @@ -42,7 +42,6 @@ - diff --git a/Filtration/Views/StartPageView.xaml b/Filtration/Views/StartPageView.xaml index 150334c..8e3793c 100644 --- a/Filtration/Views/StartPageView.xaml +++ b/Filtration/Views/StartPageView.xaml @@ -8,7 +8,7 @@ Welcome to Filtration, to get started either - create a new script or open an existing script + create a new script or open an existing script