Refactor theme code to support different types
This commit is contained in:
@@ -108,6 +108,7 @@
|
||||
<Compile Include="Providers\ThemeProvider.cs" />
|
||||
<Compile Include="Services\ThemePersistenceService.cs" />
|
||||
<Compile Include="Services\ThemeService.cs" />
|
||||
<Compile Include="ViewModels\ColorThemeComponentViewModel.cs" />
|
||||
<Compile Include="ViewModels\IThemeViewModelFactory.cs" />
|
||||
<Compile Include="ViewModels\ThemeComponentViewModel.cs" />
|
||||
<Compile Include="ViewModels\ThemeEditorViewModel.cs" />
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using Filtration.ObjectModel;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
using Filtration.ObjectModel.ThemeEditor;
|
||||
using Filtration.ThemeEditor.Services;
|
||||
using Filtration.ThemeEditor.ViewModels;
|
||||
@@ -34,7 +35,14 @@ namespace Filtration.ThemeEditor.Providers
|
||||
var themeComponentCollection = script.ThemeComponents.Aggregate(new ThemeComponentCollection(),
|
||||
(c, component) =>
|
||||
{
|
||||
c.Add(new ThemeComponent(component.ComponentType, component.ComponentName, component.Color));
|
||||
switch(component.ComponentType)
|
||||
{
|
||||
case ThemeComponentType.BackgroundColor:
|
||||
case ThemeComponentType.BorderColor:
|
||||
case ThemeComponentType.TextColor:
|
||||
c.Add(new ColorThemeComponent(component.ComponentType, component.ComponentName, ((ColorThemeComponent)component).Color));
|
||||
break;
|
||||
}
|
||||
return c;
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Filtration.Common.Services;
|
||||
@@ -29,39 +30,19 @@ namespace Filtration.ThemeEditor.Services
|
||||
var mismatchedComponents = false;
|
||||
foreach (var component in theme.Components)
|
||||
{
|
||||
var componentMatched = false;
|
||||
Type targetType = null;
|
||||
var blocks = script.ItemFilterBlocks.OfType<ItemFilterBlock>();
|
||||
switch (component.ComponentType)
|
||||
{
|
||||
case ThemeComponentType.BackgroundColor:
|
||||
targetType = typeof (BackgroundColorBlockItem);
|
||||
mismatchedComponents = ApplyColorTheme(blocks, typeof(BackgroundColorBlockItem), component);
|
||||
break;
|
||||
case ThemeComponentType.TextColor:
|
||||
targetType = typeof (TextColorBlockItem);
|
||||
mismatchedComponents = ApplyColorTheme(blocks, typeof(TextColorBlockItem), component);
|
||||
break;
|
||||
case ThemeComponentType.BorderColor:
|
||||
targetType = typeof (BorderColorBlockItem);
|
||||
mismatchedComponents = ApplyColorTheme(blocks, typeof(BorderColorBlockItem), component);
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var block in script.ItemFilterBlocks.OfType<ItemFilterBlock>())
|
||||
{
|
||||
foreach (var blockItem in block.BlockItems.Where(i => i.GetType() == targetType))
|
||||
{
|
||||
var colorBlockItem = (ColorBlockItem) blockItem;
|
||||
if (colorBlockItem.ThemeComponent != null &&
|
||||
colorBlockItem.ThemeComponent.ComponentName == component.ComponentName)
|
||||
{
|
||||
colorBlockItem.Color = component.Color;
|
||||
componentMatched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!componentMatched)
|
||||
{
|
||||
mismatchedComponents = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (mismatchedComponents)
|
||||
@@ -71,5 +52,25 @@ namespace Filtration.ThemeEditor.Services
|
||||
MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ApplyColorTheme(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 = (ColorBlockItem)blockItem;
|
||||
if (colorBlockItem.ThemeComponent != null &&
|
||||
colorBlockItem.ThemeComponent.ComponentName == component.ComponentName)
|
||||
{
|
||||
colorBlockItem.Color = ((ColorThemeComponent)component).Color;
|
||||
componentMatched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !componentMatched;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Windows.Media;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
|
||||
namespace Filtration.ThemeEditor.ViewModels
|
||||
{
|
||||
public class ColorThemeComponentViewModel : ThemeComponentViewModel
|
||||
{
|
||||
public Color Color { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,11 @@ namespace Filtration.ThemeEditor.ViewModels
|
||||
{
|
||||
string ComponentName { get; set; }
|
||||
ThemeComponentType ComponentType { get; set; }
|
||||
Color Color { get; set; }
|
||||
}
|
||||
|
||||
public class ThemeComponentViewModel : IThemeComponentViewModel
|
||||
{
|
||||
public string ComponentName { get; set; }
|
||||
public ThemeComponentType ComponentType { get; set; }
|
||||
public Color Color { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,8 +194,15 @@ namespace Filtration.ThemeEditor.ViewModels
|
||||
|
||||
private void OnAddThemeComponentCommand(ThemeComponentType themeComponentType)
|
||||
{
|
||||
Components.Add(new ThemeComponent(themeComponentType, "Untitled Component",
|
||||
new Color {A = 255, R = 255, G = 255, B = 255}));
|
||||
switch (themeComponentType)
|
||||
{
|
||||
case ThemeComponentType.BackgroundColor:
|
||||
case ThemeComponentType.BorderColor:
|
||||
case ThemeComponentType.TextColor:
|
||||
Components.Add(new ColorThemeComponent(themeComponentType, "Untitled Component",
|
||||
new Color { A = 255, R = 255, G = 255, B = 255 }));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDeleteThemeComponentCommand(ThemeComponent themeComponent)
|
||||
|
||||
@@ -58,6 +58,13 @@
|
||||
</Style>
|
||||
</ContentControl.Style>
|
||||
</ContentControl>
|
||||
<xctk:ColorPicker Grid.Row="2" SelectedColor="{Binding Color}" />
|
||||
<ContentControl Grid.Row="2" Content="{Binding Mode=OneWay}">
|
||||
<ContentControl.Resources>
|
||||
<!-- Color Theme Template -->
|
||||
<DataTemplate DataType="{x:Type themeEditor:ColorThemeComponent}">
|
||||
<xctk:ColorPicker SelectedColor="{Binding Color}" />
|
||||
</DataTemplate>
|
||||
</ContentControl.Resources>
|
||||
</ContentControl>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
Reference in New Issue
Block a user