Add enable/disable DropSound buttons. (#112)

* Add enable/disable DropSound buttons.

* Add undo/redo support for the DisableSound commands.
This commit is contained in:
Glen M 2018-12-05 07:31:47 -05:00 committed by Ben Wallis
parent a20c988380
commit fbd02702b0
7 changed files with 199 additions and 7 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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" />

View File

@ -77,6 +77,8 @@ namespace Filtration.ViewModels
RelayCommand<bool> ToggleShowAdvancedCommand { get; }
RelayCommand ClearFilterCommand { get; }
RelayCommand ClearStylesCommand { get; }
RelayCommand EnableDropSoundsCommand { get; }
RelayCommand DisableDropSoundsCommand { get; }
void AddCommentBlock(IItemFilterBlockViewModelBase targetBlockViewModelBase);
void AddBlock(IItemFilterBlockViewModelBase targetBlockViewModelBase);
@ -180,6 +182,8 @@ namespace Filtration.ViewModels
CollapseAllBlocksCommand = new RelayCommand(OnCollapseAllBlocksCommand);
ExpandAllSectionsCommand = new RelayCommand(ExpandAllSections);
CollapseAllSectionsCommand = new RelayCommand(CollapseAllSections);
EnableDropSoundsCommand = new RelayCommand(OnEnableDropSoundsCommand, CanModifySelectedBlocks);
DisableDropSoundsCommand = new RelayCommand(OnDisableDropSoundsCommand, CanModifySelectedBlocks);
var icon = new BitmapImage();
icon.BeginInit();
@ -421,6 +425,8 @@ namespace Filtration.ViewModels
public RelayCommand CollapseAllBlocksCommand { get; }
public RelayCommand ExpandAllSectionsCommand { get; }
public RelayCommand CollapseAllSectionsCommand { get; }
public RelayCommand EnableDropSoundsCommand { get; }
public RelayCommand DisableDropSoundsCommand { get; }
public bool IsActiveDocument
{
@ -1284,6 +1290,63 @@ namespace Filtration.ViewModels
SetDirtyFlag();
}
public void OnEnableDropSoundsCommand()
{
ValidateSelectedBlocks();
var input = new List<Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>>();
foreach (var block in SelectedBlockViewModels.OfType<IItemFilterBlockViewModel>())
{
var blockItems = block.Block.BlockItems;
for (var i = 0; i < blockItems.Count; i++)
{
var blockItem = blockItems[i];
if (blockItem is DisableDropSoundBlockItem)
{
input.Add(new Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>(blockItems, blockItem));
}
}
}
if (input.Count > 0)
{
_scriptCommandManager.ExecuteCommand(new RemoveBlockItemFromBlocksCommand(input));
SetDirtyFlag();
}
}
public void OnDisableDropSoundsCommand()
{
ValidateSelectedBlocks();
var input = new List<Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>>();
foreach (var block in SelectedBlockViewModels.OfType<IItemFilterBlockViewModel>())
{
var blockItems = block.Block.BlockItems;
var found = false;
foreach (var item in blockItems)
{
if (item is DisableDropSoundBlockItem)
{
found = true;
}
}
if (!found) {
var item = new DisableDropSoundBlockItem(true);
input.Add(new Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>(blockItems, item));
}
}
if (input.Count > 0)
{
_scriptCommandManager.ExecuteCommand(new AddBlockItemToBlocksCommand(input));
SetDirtyFlag();
}
}
private void OnBlockBecameDirty(object sender, EventArgs e)
{
SetDirtyFlag();

View File

@ -129,6 +129,9 @@ namespace Filtration.ViewModels
ApplyThemeToScriptCommand = new RelayCommand(async () => await OnApplyThemeToScriptCommandAsync(), () => ActiveDocumentIsScript);
EditMasterThemeCommand = new RelayCommand(OnEditMasterThemeCommand, () => ActiveDocumentIsScript);
EnableDropSoundsCommand = new RelayCommand(OnEnableDropSoundsCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock && ActiveScriptCanModifySelectedBlocks);
DisableDropSoundsCommand = new RelayCommand(OnDisableDropSoundsCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock && ActiveScriptCanModifySelectedBlocks);
AddTextColorThemeComponentCommand = new RelayCommand(OnAddTextColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddBackgroundColorThemeComponentCommand = new RelayCommand(OnAddBackgroundColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddBorderColorThemeComponentCommand = new RelayCommand(OnAddBorderColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
@ -230,6 +233,9 @@ namespace Filtration.ViewModels
public RelayCommand CreateThemeCommand { get; }
public RelayCommand ApplyThemeToScriptCommand { get; }
public RelayCommand EnableDropSoundsCommand { get; }
public RelayCommand DisableDropSoundsCommand { get; }
public RelayCommand AddTextColorThemeComponentCommand { get; }
public RelayCommand AddBackgroundColorThemeComponentCommand { get; }
public RelayCommand AddBorderColorThemeComponentCommand { get; }
@ -402,7 +408,7 @@ namespace Filtration.ViewModels
OpenTheme(themeViewModel);
}
}
private void OpenTheme(IThemeEditorViewModel themeEditorViewModel)
{
if (AvalonDockWorkspaceViewModel.OpenDocuments.Contains(themeEditorViewModel))
@ -724,11 +730,37 @@ namespace Filtration.ViewModels
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent);
}
private void OnEnableDropSoundsCommand()
{
var result = _messageBoxService.Show("Confirm",
"Are you sure you wish to enable drop sounds on all selected blocks?",
MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.No)
{
return;
}
_avalonDockWorkspaceViewModel.ActiveScriptViewModel.EnableDropSoundsCommand.Execute(null);
}
private void OnDisableDropSoundsCommand()
{
var result = _messageBoxService.Show("Confirm",
"Are you sure you wish to disable drop sounds on all selected blocks?",
MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.No)
{
return;
}
_avalonDockWorkspaceViewModel.ActiveScriptViewModel.DisableDropSoundsCommand.Execute(null);
}
public async Task<bool> CloseAllDocumentsAsync()
{
Settings.Default.LastOpenScripts = string.Join("|", _avalonDockWorkspaceViewModel.OpenDocuments.OfType<IItemFilterScriptViewModel>().Select(sc => sc.Script.FilePath));
var openDocuments = _avalonDockWorkspaceViewModel.OpenDocuments.OfType<IEditableDocument>().ToList();
foreach (var document in openDocuments)
{
if (!_avalonDockWorkspaceViewModel.OpenDocuments.Contains(document))

View File

@ -35,4 +35,6 @@
<Image Source="/Filtration;component/Resources/Icons/ThemeComponentDelete.ico" x:Key="ThemeComponentDeleteIcon" x:Shared="False" />
<Image Source="/Filtration;component/Resources/Icons/standby_enabled_icon.png" x:Key="StandbyEnabledIcon" x:Shared="False" />
<Image Source="/Filtration;component/Resources/Icons/standby_disabled_icon.png" x:Key="StandbyDisabledIcon" x:Shared="False" />
<Image Source="/Filtration;component/Resources/Icons/standby_enabled_icon.png" x:Key="EnableDropSoundsIcon" x:Shared="False" />
<Image Source="/Filtration;component/Resources/Icons/standby_disabled_icon.png" x:Key="DisableDropSoundsIcon" x:Shared="False" />
</ResourceDictionary>

View File

@ -2,7 +2,7 @@
x:ClassModifier="internal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:fluent="clr-namespace:Fluent;assembly=Fluent"
xmlns:viewModels="clr-namespace:Filtration.ViewModels"
@ -64,12 +64,12 @@
Background="ForestGreen"
BorderBrush="ForestGreen"
x:Name="ScriptToolsGroup"
IsVisibleChanged="ScriptToolsGroup_OnIsVisibleChanged"
IsVisibleChanged="ScriptToolsGroup_OnIsVisibleChanged"
Visibility="{Binding ActiveDocumentIsScript, Converter={StaticResource BooleanVisibilityConverter}, Mode=OneWay}" />
<fluent:RibbonContextualTabGroup Header="Theme"
Background="DodgerBlue"
BorderBrush="DodgerBlue"
x:Name="ThemeToolsGroup"
x:Name="ThemeToolsGroup"
IsVisibleChanged="ThemeToolsGroup_OnIsVisibleChanged"
Visibility="{Binding ActiveDocumentIsTheme, Converter={StaticResource BooleanVisibilityConverter}, Mode=OneWay}" />
</fluent:Ribbon.ContextualGroups>
@ -125,6 +125,10 @@
<fluent:Button Header="Create Theme" Command="{Binding CreateThemeCommand}" Icon="{StaticResource ThemeIcon}" LargeIcon="{StaticResource ThemeIcon}" />
<fluent:Button Header="Replace Colours" Command="{Binding ReplaceColorsCommand}" Icon="{StaticResource ReplaceColorsIcon}" LargeIcon="{StaticResource ReplaceColorsIcon}" />
</fluent:RibbonGroupBox>
<fluent:RibbonGroupBox Header="Helpers">
<fluent:Button Header="Enable Drop Sounds" Command="{Binding EnableDropSoundsCommand}" SizeDefinition="Middle" Icon="{StaticResource EnableDropSoundsIcon}" LargeIcon="{StaticResource EnableDropSoundsIcon}" />
<fluent:Button Header="Disable Drop Sounds" Command="{Binding DisableDropSoundsCommand}" SizeDefinition="Middle" Icon="{StaticResource DisableDropSoundsIcon}" LargeIcon="{StaticResource DisableDropSoundsIcon}" />
</fluent:RibbonGroupBox>
</fluent:RibbonTabItem>
<fluent:RibbonTabItem x:Name="ThemeToolsTabItem" Header="Theme Tools" Group="{Binding ElementName=ThemeToolsGroup}" Visibility="{Binding ActiveDocumentIsTheme, Converter={StaticResource BooleanVisibilityConverter}, Mode=OneWay}">
<fluent:RibbonGroupBox Header="Add Components">
@ -172,5 +176,4 @@
</Grid>
</DockPanel>
</fluent:RibbonWindow>