Add alert sound theme support

This commit is contained in:
azakhi 2018-08-26 20:24:13 +03:00
parent bc5a005ee7
commit d92d34af05
22 changed files with 262 additions and 53 deletions

View File

@ -0,0 +1,87 @@
using System;
using System.Windows.Media;
using Filtration.ObjectModel.ThemeEditor;
namespace Filtration.ObjectModel.BlockItemBaseTypes
{
public abstract class StrIntBlockItem : BlockItemBase, IAudioVisualBlockItem, IBlockItemWithTheme
{
private string _value;
private int _secondValue;
private ThemeComponent _themeComponent;
protected StrIntBlockItem()
{
}
protected StrIntBlockItem(string value, int secondValue)
{
Value = value;
SecondValue = secondValue;
Value = value;
SecondValue = secondValue;
}
public override string OutputText => PrefixText + " " + Value + " " + SecondValue + (ThemeComponent != null ? " # " + ThemeComponent.ComponentName : string.Empty);
public override string SummaryText => string.Empty;
public override Color SummaryBackgroundColor => Colors.Transparent;
public override Color SummaryTextColor => Colors.Transparent;
public ThemeComponent ThemeComponent
{
get { return _themeComponent; }
set
{
if (_themeComponent == value) { return; }
if (_themeComponent != null)
{
_themeComponent.ThemeComponentUpdated -= OnThemeComponentUpdated;
_themeComponent.ThemeComponentDeleted -= OnThemeComponentDeleted;
}
if (value != null)
{
value.ThemeComponentUpdated += OnThemeComponentUpdated;
value.ThemeComponentDeleted += OnThemeComponentDeleted;
}
_themeComponent = value;
OnPropertyChanged();
}
}
public string Value
{
get { return _value; }
set
{
_value = value;
IsDirty = true;
OnPropertyChanged();
}
}
public int SecondValue
{
get { return _secondValue; }
set
{
_secondValue = value;
IsDirty = true;
OnPropertyChanged();
}
}
private void OnThemeComponentUpdated(object sender, EventArgs e)
{
Value = ((StrIntBlockItem)sender).Value;
SecondValue = ((StrIntBlockItem)sender).SecondValue;
}
private void OnThemeComponentDeleted(object sender, EventArgs e)
{
ThemeComponent = null;
}
}
}

View File

@ -1,50 +0,0 @@
using System.Windows.Media;
namespace Filtration.ObjectModel.BlockItemBaseTypes
{
public abstract class StrIntBlockItem : BlockItemBase, IAudioVisualBlockItem
{
private string _value;
private int _secondValue;
protected StrIntBlockItem()
{
}
protected StrIntBlockItem(string value, int secondValue)
{
Value = value;
SecondValue = secondValue;
Value = value;
SecondValue = secondValue;
}
public override string OutputText => PrefixText + " " + Value + " " + SecondValue;
public override string SummaryText => string.Empty;
public override Color SummaryBackgroundColor => Colors.Transparent;
public override Color SummaryTextColor => Colors.Transparent;
public string Value
{
get { return _value; }
set
{
_value = value;
IsDirty = true;
OnPropertyChanged();
}
}
public int SecondValue
{
get { return _secondValue; }
set
{
_secondValue = value;
IsDirty = true;
OnPropertyChanged();
}
}
}
}

View File

@ -11,6 +11,8 @@ namespace Filtration.ObjectModel.Enums
[Description("Border")]
BorderColor,
[Description("Font Size")]
FontSize
FontSize,
[Description("Alert Sound")]
AlertSound
}
}

View File

@ -55,7 +55,7 @@
<Compile Include="BlockItemBaseTypes\ColorBooleanBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\DualIntegerBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\StringBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\StringIntBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\StrIntBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\IntegerBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\NumericFilterPredicateBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\StringListBlockItem.cs" />
@ -131,6 +131,7 @@
<Compile Include="ReplaceColorsParameterSet.cs" />
<Compile Include="Socket.cs" />
<Compile Include="SocketGroup.cs" />
<Compile Include="ThemeEditor\StrIntThemeComponent.cs" />
<Compile Include="ThemeEditor\IntegerThemeComponent.cs" />
<Compile Include="ThemeEditor\Theme.cs" />
<Compile Include="ThemeEditor\ColorThemeComponent.cs" />

View File

@ -0,0 +1,48 @@
using System;
using System.Windows.Media;
using Filtration.ObjectModel.Enums;
namespace Filtration.ObjectModel.ThemeEditor
{
[Serializable]
public class StrIntThemeComponent : ThemeComponent
{
private string _value;
private int _secondValue;
public StrIntThemeComponent(ThemeComponentType componentType, string componentName, string componentValue, int componentSecondValue)
{
if (componentName == null || componentValue == null)
{
throw new ArgumentException("Null parameters not allowed in StrIntThemeComponent constructor");
}
ComponentType = componentType;
Value = componentValue;
SecondValue = componentSecondValue;
ComponentName = componentName;
}
public string Value
{
get { return _value; }
set
{
_value = value;
OnPropertyChanged();
_themeComponentUpdatedEventHandler?.Invoke(this, EventArgs.Empty);
}
}
public int SecondValue
{
get { return _secondValue; }
set
{
_secondValue = value;
OnPropertyChanged();
_themeComponentUpdatedEventHandler?.Invoke(this, EventArgs.Empty);
}
}
}
}

View File

@ -39,5 +39,10 @@ namespace Filtration.ObjectModel.ThemeEditor
{
_components.Add(new IntegerThemeComponent(componentType, componentName, componentValue));
}
public void AddComponent(ThemeComponentType componentType, string componentName, string componentValue, int componentSecondValue)
{
_components.Add(new StrIntThemeComponent(componentType, componentName, componentValue, componentSecondValue));
}
}
}

View File

@ -35,6 +35,19 @@ namespace Filtration.ObjectModel.ThemeEditor
return component;
}
public ThemeComponent AddComponent(ThemeComponentType componentType, string componentName, string componentValue, int componentSecondValue)
{
if (ComponentExists(componentType, componentName))
{
return Items.FirstOrDefault(t => t.ComponentName == componentName && t.ComponentType == componentType);
}
var component = new StrIntThemeComponent(componentType, componentName, componentValue, componentSecondValue);
Items.Add(component);
return component;
}
private bool ComponentExists(ThemeComponentType componentType, string componentName)
{
var componentCount =

View File

@ -236,7 +236,7 @@ namespace Filtration.Parser.Services
RemoveExistingBlockItemsOfType<SoundBlockItem>(block);
RemoveExistingBlockItemsOfType<PositionalSoundBlockItem>(block);
var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s?(\d+)?");
var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s?(\d+)?\s*([#]?)(.*)");
if (match.Success)
{
@ -250,6 +250,12 @@ namespace Filtration.Parser.Services
else
{
secondValue = 79;
}
ThemeComponent themeComponent = null;
if(match.Groups[3].Value == "#" && !string.IsNullOrWhiteSpace(match.Groups[4].Value))
{
themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.AlertSound, match.Groups[4].Value.Trim(), firstValue, secondValue);
}
if (lineOption == "PlayAlertSound")
@ -259,6 +265,7 @@ namespace Filtration.Parser.Services
Value = firstValue,
SecondValue = secondValue
};
blockItemValue.ThemeComponent = themeComponent;
block.BlockItems.Add(blockItemValue);
}
else
@ -268,6 +275,7 @@ namespace Filtration.Parser.Services
Value = firstValue,
SecondValue = secondValue
};
blockItemValue.ThemeComponent = themeComponent;
block.BlockItems.Add(blockItemValue);
}
}

View File

@ -35,6 +35,10 @@ namespace Filtration.ThemeEditor.Converters
{
return "Font Size Theme Components";
}
case "Alert Sound":
{
return "Alert Sound Theme Components";
}
}
return type.GetAttributeDescription();

View File

@ -109,6 +109,7 @@
<Compile Include="Services\ThemePersistenceService.cs" />
<Compile Include="Services\ThemeService.cs" />
<Compile Include="ViewModels\ColorThemeComponentViewModel.cs" />
<Compile Include="ViewModels\StrIntThemeComponentViewModel.cs" />
<Compile Include="ViewModels\IntegerThemeComponentViewModel.cs" />
<Compile Include="ViewModels\IThemeViewModelFactory.cs" />
<Compile Include="ViewModels\ThemeComponentViewModel.cs" />

View File

@ -45,6 +45,9 @@ namespace Filtration.ThemeEditor.Providers
case ThemeComponentType.FontSize:
c.Add(new IntegerThemeComponent(component.ComponentType, component.ComponentName, ((IntegerThemeComponent)component).Value));
break;
case ThemeComponentType.AlertSound:
c.Add(new StrIntThemeComponent(component.ComponentType, component.ComponentName, ((StrIntThemeComponent)component).Value, ((StrIntThemeComponent)component).SecondValue));
break;
}
return c;
});

View File

@ -45,6 +45,10 @@ namespace Filtration.ThemeEditor.Services
case ThemeComponentType.FontSize:
mismatchedComponents = ApplyIntegerTheme(blocks, typeof(FontSizeBlockItem), component);
break;
case ThemeComponentType.AlertSound:
mismatchedComponents = ApplyStrIntTheme(blocks, typeof(SoundBlockItem), component);
mismatchedComponents = ApplyStrIntTheme(blocks, typeof(PositionalSoundBlockItem), component);
break;
}
}
@ -95,5 +99,26 @@ namespace Filtration.ThemeEditor.Services
return !componentMatched;
}
private bool ApplyStrIntTheme(IEnumerable<ItemFilterBlock> blocks, Type type, ThemeComponent component)
{
var componentMatched = false;
foreach (var block in blocks)
{
foreach (var blockItem in block.BlockItems.Where(i => i.GetType() == type))
{
var colorBlockItem = (StrIntBlockItem)blockItem;
if (colorBlockItem.ThemeComponent != null &&
colorBlockItem.ThemeComponent.ComponentName == component.ComponentName)
{
colorBlockItem.Value = ((StrIntThemeComponent)component).Value;
colorBlockItem.SecondValue = ((StrIntThemeComponent)component).SecondValue;
componentMatched = true;
}
}
}
return !componentMatched;
}
}
}

View File

@ -0,0 +1,8 @@
namespace Filtration.ThemeEditor.ViewModels
{
public class StrIntThemeComponentViewModel : ThemeComponentViewModel
{
public int Value { get; set; }
public int SecondValue { get; set; }
}
}

View File

@ -205,6 +205,9 @@ namespace Filtration.ThemeEditor.ViewModels
case ThemeComponentType.FontSize:
Components.Add(new IntegerThemeComponent(themeComponentType, "Untitled Component", 35));
break;
case ThemeComponentType.AlertSound:
Components.Add(new StrIntThemeComponent(themeComponentType, "Untitled Component", "1", 100));
break;
}
}

View File

@ -69,6 +69,18 @@
<DataTemplate DataType="{x:Type themeEditor:IntegerThemeComponent}">
<xctk:ShortUpDown Value="{Binding Value}" />
</DataTemplate>
<!-- String Integer Theme Template -->
<DataTemplate DataType="{x:Type themeEditor:StrIntThemeComponent}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="{Binding Value}" Height="25" Padding="2,-15,0,0" />
<xctk:ShortUpDown Grid.Column="1" Value="{Binding SecondValue}" HorizontalAlignment="Right"/>
</Grid>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
</Grid>

View File

@ -48,6 +48,7 @@ namespace Filtration
cfg.CreateMap<ThemeComponent, ThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<ColorThemeComponent, ColorThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<IntegerThemeComponent, IntegerThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<StrIntThemeComponent, StrIntThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<IThemeEditorViewModel, Theme>();
});

View File

@ -37,6 +37,10 @@ namespace Filtration.Converters
{
themeComponentType = ThemeComponentType.FontSize;
}
else if (blockItem.GetType() == typeof(SoundBlockItem) || blockItem.GetType() == typeof(PositionalSoundBlockItem))
{
themeComponentType = ThemeComponentType.AlertSound;
}
else
{
return null;

View File

@ -141,6 +141,14 @@
</Button>
<ComboBox ItemsSource="{Binding ElementName=BlockItemContentControl, Path=DataContext.SoundsAvailable}" SelectedValue="{Binding Value}" Style="{StaticResource MetroComboBox}" />
<xctk:ShortUpDown Value="{Binding Path=SecondValue}" Minimum="1" Maximum="300" HorizontalAlignment="Right" ToolTip="Volume"/>
<userControls:ThemeComponentSelectionControl ThemeComponent="{Binding ThemeComponent}" Margin="0,2,0,0">
<userControls:ThemeComponentSelectionControl.AvailableThemeComponents>
<MultiBinding Converter="{StaticResource AvailableThemeComponentsConverter}">
<Binding Path="DataContext.Script.ThemeComponents" RelativeSource="{RelativeSource AncestorType={x:Type views:ItemFilterScriptView}}"/>
<Binding Path="." />
</MultiBinding>
</userControls:ThemeComponentSelectionControl.AvailableThemeComponents>
</userControls:ThemeComponentSelectionControl>
</WrapPanel>
</DataTemplate>
@ -152,6 +160,14 @@
</Button>
<ComboBox ItemsSource="{Binding ElementName=BlockItemContentControl, Path=DataContext.SoundsAvailable}" SelectedValue="{Binding Value}" Style="{StaticResource MetroComboBox}" />
<xctk:ShortUpDown Value="{Binding Path=SecondValue}" Minimum="1" Maximum="300" HorizontalAlignment="Right" ToolTip="Volume"/>
<userControls:ThemeComponentSelectionControl ThemeComponent="{Binding ThemeComponent}" Margin="0,2,0,0">
<userControls:ThemeComponentSelectionControl.AvailableThemeComponents>
<MultiBinding Converter="{StaticResource AvailableThemeComponentsConverter}">
<Binding Path="DataContext.Script.ThemeComponents" RelativeSource="{RelativeSource AncestorType={x:Type views:ItemFilterScriptView}}"/>
<Binding Path="." />
</MultiBinding>
</userControls:ThemeComponentSelectionControl.AvailableThemeComponents>
</userControls:ThemeComponentSelectionControl>
</WrapPanel>
</DataTemplate>

View File

@ -112,6 +112,11 @@ namespace Filtration.UserControls
var integerBlockItem = BlockItem as IntegerBlockItem;
integerBlockItem.Value = ((IntegerThemeComponent)integerBlockItem.ThemeComponent).Value;
break;
case ThemeComponentType.AlertSound:
var strIntBlockItem = BlockItem as StrIntBlockItem;
strIntBlockItem.Value = ((StrIntThemeComponent)strIntBlockItem.ThemeComponent).Value;
strIntBlockItem.SecondValue = ((StrIntThemeComponent)strIntBlockItem.ThemeComponent).SecondValue;
break;
}
}

View File

@ -55,9 +55,14 @@
<DataTemplate DataType="{x:Type themeEditor:ColorThemeComponent}">
<Border Background="{Binding Color, Converter={StaticResource ColorToSolidColorBrushConverter}}" />
</DataTemplate>
<DataTemplate DataType="{x:Type themeEditor:IntegerThemeComponent}">
<TextBlock Text="{Binding Value}" FontWeight="Bold" />
</DataTemplate>
<DataTemplate DataType="{x:Type themeEditor:StrIntThemeComponent}">
<!--TODO: How to show theese?-->
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
</Grid>

View File

@ -115,6 +115,7 @@ namespace Filtration.ViewModels
AddBackgroundColorThemeComponentCommand = new RelayCommand(OnAddBackgroundColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddBorderColorThemeComponentCommand = new RelayCommand(OnAddBorderColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddFontSizeThemeComponentCommand = new RelayCommand(OnAddFontSizeThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddAlertSoundThemeComponentCommand = new RelayCommand(OnAddAlertSoundThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
DeleteThemeComponentCommand = new RelayCommand(OnDeleteThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable && _avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent != null);
ExpandAllBlocksCommand = new RelayCommand(OnExpandAllBlocksCommand, () => ActiveDocumentIsScript);
@ -215,6 +216,7 @@ namespace Filtration.ViewModels
public RelayCommand AddBackgroundColorThemeComponentCommand { get; }
public RelayCommand AddBorderColorThemeComponentCommand { get; }
public RelayCommand AddFontSizeThemeComponentCommand { get; }
public RelayCommand AddAlertSoundThemeComponentCommand { get; }
public RelayCommand DeleteThemeComponentCommand { get; }
public RelayCommand AddBlockCommand { get; }
@ -684,6 +686,11 @@ namespace Filtration.ViewModels
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.AddThemeComponentCommand.Execute(ThemeComponentType.FontSize);
}
private void OnAddAlertSoundThemeComponentCommand()
{
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.AddThemeComponentCommand.Execute(ThemeComponentType.AlertSound);
}
private void OnDeleteThemeComponentCommand()
{
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.DeleteThemeComponentCommand.Execute(

View File

@ -130,6 +130,7 @@
<fluent:Button SizeDefinition="Middle" Header="Add Background Color" Icon="{StaticResource AddIcon}" Command="{Binding AddBackgroundColorThemeComponentCommand}" />
<fluent:Button SizeDefinition="Middle" Header="Add Border Color" Icon="{StaticResource AddIcon}" Command="{Binding AddBorderColorThemeComponentCommand}" />
<fluent:Button SizeDefinition="Middle" Header="Add Font Size" Icon="{StaticResource AddIcon}" Command="{Binding AddFontSizeThemeComponentCommand}" />
<fluent:Button SizeDefinition="Middle" Header="Add Alert Sound" Icon="{StaticResource AddIcon}" Command="{Binding AddAlertSoundThemeComponentCommand}" />
</fluent:RibbonGroupBox>
<fluent:RibbonGroupBox Header="Delete">
<fluent:Button Header="Delete Theme Component" Icon="{StaticResource ThemeComponentDeleteIcon}" LargeIcon="{StaticResource ThemeComponentDeleteIcon}" Command="{Binding DeleteThemeComponentCommand}" />