From fbd02702b05b779285d305e37fbfed897008f6c2 Mon Sep 17 00:00:00 2001 From: Glen M Date: Wed, 5 Dec 2018 07:31:47 -0500 Subject: [PATCH] Add enable/disable DropSound buttons. (#112) * Add enable/disable DropSound buttons. * Add undo/redo support for the DisableSound commands. --- .../AddBlockItemToBlocksCommand.cs | 42 +++++++++++++ .../RemoveBlockItemFromBlocksCommand.cs | 48 ++++++++++++++ .../Filtration.ObjectModel.csproj | 2 + .../ViewModels/ItemFilterScriptViewModel.cs | 63 +++++++++++++++++++ Filtration/ViewModels/MainWindowViewModel.cs | 36 ++++++++++- Filtration/Views/IconsDictionary.xaml | 2 + Filtration/Views/MainWindow.xaml | 13 ++-- 7 files changed, 199 insertions(+), 7 deletions(-) create mode 100644 Filtration.ObjectModel/Commands/ItemFilterScript/AddBlockItemToBlocksCommand.cs create mode 100644 Filtration.ObjectModel/Commands/ItemFilterScript/RemoveBlockItemFromBlocksCommand.cs diff --git a/Filtration.ObjectModel/Commands/ItemFilterScript/AddBlockItemToBlocksCommand.cs b/Filtration.ObjectModel/Commands/ItemFilterScript/AddBlockItemToBlocksCommand.cs new file mode 100644 index 0000000..1deb97e --- /dev/null +++ b/Filtration.ObjectModel/Commands/ItemFilterScript/AddBlockItemToBlocksCommand.cs @@ -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, IItemFilterBlockItem>> _input; + + public AddBlockItemToBlocksCommand(List, 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(); + } +} diff --git a/Filtration.ObjectModel/Commands/ItemFilterScript/RemoveBlockItemFromBlocksCommand.cs b/Filtration.ObjectModel/Commands/ItemFilterScript/RemoveBlockItemFromBlocksCommand.cs new file mode 100644 index 0000000..e48355a --- /dev/null +++ b/Filtration.ObjectModel/Commands/ItemFilterScript/RemoveBlockItemFromBlocksCommand.cs @@ -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, IItemFilterBlockItem>> _input; + + public RemoveBlockItemFromBlocksCommand(List, 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(); + } +} diff --git a/Filtration.ObjectModel/Filtration.ObjectModel.csproj b/Filtration.ObjectModel/Filtration.ObjectModel.csproj index cec09a1..06fe4d0 100644 --- a/Filtration.ObjectModel/Filtration.ObjectModel.csproj +++ b/Filtration.ObjectModel/Filtration.ObjectModel.csproj @@ -114,11 +114,13 @@ + + diff --git a/Filtration/ViewModels/ItemFilterScriptViewModel.cs b/Filtration/ViewModels/ItemFilterScriptViewModel.cs index 1d9e847..14d4cae 100644 --- a/Filtration/ViewModels/ItemFilterScriptViewModel.cs +++ b/Filtration/ViewModels/ItemFilterScriptViewModel.cs @@ -77,6 +77,8 @@ namespace Filtration.ViewModels RelayCommand 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, IItemFilterBlockItem>>(); + + foreach (var block in SelectedBlockViewModels.OfType()) + { + 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, IItemFilterBlockItem>(blockItems, blockItem)); + } + } + } + + if (input.Count > 0) + { + _scriptCommandManager.ExecuteCommand(new RemoveBlockItemFromBlocksCommand(input)); + SetDirtyFlag(); + } + } + + public void OnDisableDropSoundsCommand() + { + ValidateSelectedBlocks(); + + var input = new List, IItemFilterBlockItem>>(); + + foreach (var block in SelectedBlockViewModels.OfType()) + { + 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, IItemFilterBlockItem>(blockItems, item)); + } + } + + if (input.Count > 0) + { + _scriptCommandManager.ExecuteCommand(new AddBlockItemToBlocksCommand(input)); + SetDirtyFlag(); + } + } + private void OnBlockBecameDirty(object sender, EventArgs e) { SetDirtyFlag(); diff --git a/Filtration/ViewModels/MainWindowViewModel.cs b/Filtration/ViewModels/MainWindowViewModel.cs index 1aed815..2e44f5e 100644 --- a/Filtration/ViewModels/MainWindowViewModel.cs +++ b/Filtration/ViewModels/MainWindowViewModel.cs @@ -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 CloseAllDocumentsAsync() { Settings.Default.LastOpenScripts = string.Join("|", _avalonDockWorkspaceViewModel.OpenDocuments.OfType().Select(sc => sc.Script.FilePath)); var openDocuments = _avalonDockWorkspaceViewModel.OpenDocuments.OfType().ToList(); - + foreach (var document in openDocuments) { if (!_avalonDockWorkspaceViewModel.OpenDocuments.Contains(document)) diff --git a/Filtration/Views/IconsDictionary.xaml b/Filtration/Views/IconsDictionary.xaml index e3e426c..99b4398 100644 --- a/Filtration/Views/IconsDictionary.xaml +++ b/Filtration/Views/IconsDictionary.xaml @@ -35,4 +35,6 @@ + + \ No newline at end of file diff --git a/Filtration/Views/MainWindow.xaml b/Filtration/Views/MainWindow.xaml index 2b36d70..4203b58 100644 --- a/Filtration/Views/MainWindow.xaml +++ b/Filtration/Views/MainWindow.xaml @@ -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}" /> @@ -125,6 +125,10 @@ + + + + @@ -172,5 +176,4 @@ - - \ No newline at end of file +