Add undo/redo support for the DisableSound commands.
This commit is contained in:
parent
19957659d1
commit
8acc1333a3
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Filtration.ObjectModel.Commands.ItemFilterScript
|
||||
{
|
||||
public class AddBlockItemToBlocksCommand : IUndoableCommand
|
||||
{
|
||||
private readonly List<Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>> _input;
|
||||
|
||||
public AddBlockItemToBlocksCommand(List<Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>> input)
|
||||
{
|
||||
_input = input;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
foreach (var v in _input)
|
||||
{
|
||||
var blockItems = v.Item1;
|
||||
var item = v.Item2;
|
||||
|
||||
blockItems.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
foreach (var v in _input)
|
||||
{
|
||||
var blockItems = v.Item1;
|
||||
var item = v.Item2;
|
||||
blockItems.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void Redo() => Execute();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Filtration.ObjectModel.Commands.ItemFilterScript
|
||||
{
|
||||
public class RemoveBlockItemFromBlocksCommand : IUndoableCommand
|
||||
{
|
||||
private readonly List<Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>> _input;
|
||||
|
||||
public RemoveBlockItemFromBlocksCommand(List<Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>> input)
|
||||
{
|
||||
_input = input;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
foreach (var pair in _input)
|
||||
{
|
||||
var blockItems = pair.Item1;
|
||||
var blockItem = pair.Item2;
|
||||
|
||||
for (var i = 0; i < blockItems.Count; i++)
|
||||
{
|
||||
if (blockItems[i] == blockItem)
|
||||
{
|
||||
blockItems.RemoveAt(i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
foreach (var pair in _input)
|
||||
{
|
||||
var blockItems = pair.Item1;
|
||||
var blockItem = pair.Item2;
|
||||
blockItems.Add(blockItem);
|
||||
}
|
||||
}
|
||||
|
||||
public void Redo() => Execute();
|
||||
}
|
||||
}
|
@ -114,11 +114,13 @@
|
||||
<Compile Include="BlockItemTypes\WidthBlockItem.cs" />
|
||||
<Compile Include="Commands\CommandManager.cs" />
|
||||
<Compile Include="Commands\ICommand.cs" />
|
||||
<Compile Include="Commands\ItemFilterScript\AddBlockItemToBlocksCommand.cs" />
|
||||
<Compile Include="Commands\ItemFilterScript\MoveBlocksToIndexCommand.cs" />
|
||||
<Compile Include="Commands\ItemFilterScript\MoveBlocksToBottomCommand.cs" />
|
||||
<Compile Include="Commands\ItemFilterScript\AddCommentBlockCommand.cs" />
|
||||
<Compile Include="Commands\ItemFilterScript\MoveBlocksToTopCommand.cs" />
|
||||
<Compile Include="Commands\ItemFilterScript\PasteBlocksCommand.cs" />
|
||||
<Compile Include="Commands\ItemFilterScript\RemoveBlockItemFromBlocksCommand.cs" />
|
||||
<Compile Include="Commands\ItemFilterScript\RemoveBlocksCommand.cs" />
|
||||
<Compile Include="Commands\ItemFilterScript\SetScriptDescriptionCommand.cs" />
|
||||
<Compile Include="Commands\ItemFilterScript\AddBlockCommand.cs" />
|
||||
|
@ -1294,23 +1294,24 @@ namespace Filtration.ViewModels
|
||||
{
|
||||
ValidateSelectedBlocks();
|
||||
|
||||
var modified = false;
|
||||
var input = new List<Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>>();
|
||||
|
||||
foreach (var block in SelectedBlockViewModels.OfType<IItemFilterBlockViewModel>())
|
||||
{
|
||||
var blockItems= block.Block.BlockItems;
|
||||
var blockItems = block.Block.BlockItems;
|
||||
for (var i = 0; i < blockItems.Count; i++)
|
||||
{
|
||||
if (blockItems[i] is DisableDropSoundBlockItem)
|
||||
var blockItem = blockItems[i];
|
||||
if (blockItem is DisableDropSoundBlockItem)
|
||||
{
|
||||
blockItems.RemoveAt(i--);
|
||||
modified = true;
|
||||
input.Add(new Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>(blockItems, blockItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (modified)
|
||||
if (input.Count > 0)
|
||||
{
|
||||
_scriptCommandManager.ExecuteCommand(new RemoveBlockItemFromBlocksCommand(input));
|
||||
SetDirtyFlag();
|
||||
}
|
||||
}
|
||||
@ -1319,7 +1320,7 @@ namespace Filtration.ViewModels
|
||||
{
|
||||
ValidateSelectedBlocks();
|
||||
|
||||
var modified = false;
|
||||
var input = new List<Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>>();
|
||||
|
||||
foreach (var block in SelectedBlockViewModels.OfType<IItemFilterBlockViewModel>())
|
||||
{
|
||||
@ -1335,12 +1336,13 @@ namespace Filtration.ViewModels
|
||||
|
||||
if (!found) {
|
||||
var item = new DisableDropSoundBlockItem(true);
|
||||
blockItems.Add(item);
|
||||
modified = true;
|
||||
input.Add(new Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>(blockItems, item));
|
||||
}
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
if (input.Count > 0)
|
||||
{
|
||||
_scriptCommandManager.ExecuteCommand(new AddBlockItemToBlocksCommand(input));
|
||||
SetDirtyFlag();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user