Completed initial implementation of Theme Editor
This commit is contained in:
@@ -95,6 +95,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Providers\ThemeProvider.cs" />
|
||||
<Compile Include="Services\ThemePersistenceService.cs" />
|
||||
<Compile Include="Services\ThemeService.cs" />
|
||||
<Compile Include="ViewModels\IThemeViewModelFactory.cs" />
|
||||
<Compile Include="ViewModels\ThemeComponentViewModel.cs" />
|
||||
<Compile Include="ViewModels\ThemeViewModel.cs" />
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using AutoMapper;
|
||||
using Filtration.ObjectModel;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
using Filtration.ObjectModel.ThemeEditor;
|
||||
using Filtration.ThemeEditor.Services;
|
||||
using Filtration.ThemeEditor.ViewModels;
|
||||
@@ -12,6 +11,7 @@ namespace Filtration.ThemeEditor.Providers
|
||||
{
|
||||
IThemeViewModel NewThemeForScript(ItemFilterScript script);
|
||||
IThemeViewModel LoadThemeFromFile(string filePath);
|
||||
Theme LoadThemeModelFromFile(string filePath);
|
||||
void SaveTheme(IThemeViewModel themeViewModel, string filePath);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace Filtration.ThemeEditor.Providers
|
||||
public IThemeViewModel NewThemeForScript(ItemFilterScript script)
|
||||
{
|
||||
Mapper.CreateMap<ThemeComponent, ThemeComponentViewModel>();
|
||||
//Mapper.CreateMap<ThemeComponentType, ThemeComponentType>();
|
||||
|
||||
var themeComponentViewModels = Mapper.Map<ObservableCollection<ThemeComponentViewModel>>(script.ThemeComponents);
|
||||
var themeViewModel = _themeViewModelFactory.Create();
|
||||
@@ -43,7 +42,6 @@ namespace Filtration.ThemeEditor.Providers
|
||||
{
|
||||
Mapper.CreateMap<Theme, IThemeViewModel>().ConstructUsingServiceLocator();
|
||||
Mapper.CreateMap<ThemeComponent, ThemeComponentViewModel>();
|
||||
//Mapper.CreateMap<ThemeComponentType, ThemeComponentType>();
|
||||
|
||||
var model = _themePersistenceService.LoadTheme(filePath);
|
||||
var viewModel = Mapper.Map<IThemeViewModel>(model);
|
||||
@@ -51,11 +49,15 @@ namespace Filtration.ThemeEditor.Providers
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public Theme LoadThemeModelFromFile(string filePath)
|
||||
{
|
||||
return _themePersistenceService.LoadTheme(filePath);
|
||||
}
|
||||
|
||||
public void SaveTheme(IThemeViewModel themeViewModel, string filePath)
|
||||
{
|
||||
Mapper.CreateMap<IThemeViewModel, Theme>();
|
||||
Mapper.CreateMap<ThemeComponentViewModel, ThemeComponent>();
|
||||
//Mapper.CreateMap<ThemeComponentType, ThemeComponentType>();
|
||||
|
||||
var theme = Mapper.Map<Theme>(themeViewModel);
|
||||
_themePersistenceService.SaveTheme(theme, filePath);
|
||||
|
||||
67
Filtration.ThemeEditor/Services/ThemeService.cs
Normal file
67
Filtration.ThemeEditor/Services/ThemeService.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Filtration.ObjectModel;
|
||||
using Filtration.ObjectModel.BlockItemBaseTypes;
|
||||
using Filtration.ObjectModel.BlockItemTypes;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
using Filtration.ObjectModel.ThemeEditor;
|
||||
|
||||
namespace Filtration.ThemeEditor.Services
|
||||
{
|
||||
public interface IThemeService
|
||||
{
|
||||
void ApplyThemeToScript(Theme theme, ItemFilterScript script);
|
||||
}
|
||||
|
||||
public class ThemeService : IThemeService
|
||||
{
|
||||
public void ApplyThemeToScript(Theme theme, ItemFilterScript script)
|
||||
{
|
||||
var mismatchedComponents = false;
|
||||
foreach (var component in theme.Components)
|
||||
{
|
||||
var componentMatched = false;
|
||||
Type targetType = null;
|
||||
switch (component.ComponentType)
|
||||
{
|
||||
case ThemeComponentType.BackgroundColor:
|
||||
targetType = typeof (BackgroundColorBlockItem);
|
||||
break;
|
||||
case ThemeComponentType.TextColor:
|
||||
targetType = typeof (TextColorBlockItem);
|
||||
break;
|
||||
case ThemeComponentType.BorderColor:
|
||||
targetType = typeof (BorderColorBlockItem);
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var block in script.ItemFilterBlocks)
|
||||
{
|
||||
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)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Not all theme components had matches - are you sure this theme is designed for this script?",
|
||||
"Possible Theme Mismatch", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid>
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
|
||||
<ItemsControl ItemsSource="{Binding Components}">
|
||||
<ItemsControl ItemsSource="{Binding Components}" Margin="10">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel />
|
||||
@@ -18,7 +18,7 @@
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<views:ThemeComponentControl DataContext="{Binding}" Margin="10" />
|
||||
<views:ThemeComponentControl DataContext="{Binding}" Margin="10,5,10,5" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Filtration.ThemeEditor.WindsorInstallers
|
||||
Component.For<IThemePersistenceService>()
|
||||
.ImplementedBy<ThemePersistenceService>()
|
||||
.LifeStyle.Singleton);
|
||||
|
||||
container.Register(
|
||||
Component.For<IThemeService>()
|
||||
.ImplementedBy<ThemeService>()
|
||||
.LifeStyle.Singleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user