2015-06-26 12:42:20 -04:00
|
|
|
|
using System.Collections.ObjectModel;
|
2015-07-05 17:43:17 -04:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2015-06-26 12:42:20 -04:00
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Filtration.ObjectModel;
|
|
|
|
|
using Filtration.ObjectModel.ThemeEditor;
|
|
|
|
|
using Filtration.ThemeEditor.Services;
|
|
|
|
|
using Filtration.ThemeEditor.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace Filtration.ThemeEditor.Providers
|
|
|
|
|
{
|
|
|
|
|
public interface IThemeProvider
|
|
|
|
|
{
|
2015-07-05 17:43:17 -04:00
|
|
|
|
IThemeEditorViewModel NewThemeForScript(ItemFilterScript script);
|
|
|
|
|
IThemeEditorViewModel MasterThemeForScript(ItemFilterScript script);
|
|
|
|
|
IThemeEditorViewModel LoadThemeFromFile(string filePath);
|
2015-06-26 16:54:20 -04:00
|
|
|
|
Theme LoadThemeModelFromFile(string filePath);
|
2015-07-05 17:43:17 -04:00
|
|
|
|
void SaveTheme(IThemeEditorViewModel themeEditorViewModel, string filePath);
|
2015-06-26 12:42:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class ThemeProvider : IThemeProvider
|
|
|
|
|
{
|
|
|
|
|
private readonly IThemeViewModelFactory _themeViewModelFactory;
|
|
|
|
|
private readonly IThemePersistenceService _themePersistenceService;
|
|
|
|
|
|
|
|
|
|
public ThemeProvider(IThemeViewModelFactory themeViewModelFactory, IThemePersistenceService themePersistenceService)
|
|
|
|
|
{
|
|
|
|
|
_themeViewModelFactory = themeViewModelFactory;
|
|
|
|
|
_themePersistenceService = themePersistenceService;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 17:43:17 -04:00
|
|
|
|
public IThemeEditorViewModel NewThemeForScript(ItemFilterScript script)
|
2015-06-26 12:42:20 -04:00
|
|
|
|
{
|
2015-07-05 17:43:17 -04:00
|
|
|
|
var themeComponentCollection = script.ThemeComponents.Aggregate(new ThemeComponentCollection(),
|
|
|
|
|
(c, component) =>
|
|
|
|
|
{
|
|
|
|
|
c.Add(new ThemeComponent(component.ComponentType, component.ComponentName, component.Color));
|
|
|
|
|
return c;
|
|
|
|
|
});
|
|
|
|
|
|
2015-06-26 12:42:20 -04:00
|
|
|
|
var themeViewModel = _themeViewModelFactory.Create();
|
2015-07-06 08:41:46 -04:00
|
|
|
|
themeViewModel.InitialiseForNewTheme(themeComponentCollection);
|
2015-06-26 12:42:20 -04:00
|
|
|
|
themeViewModel.FilePath = "Untitled.filtertheme";
|
|
|
|
|
|
|
|
|
|
return themeViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 17:43:17 -04:00
|
|
|
|
public IThemeEditorViewModel MasterThemeForScript(ItemFilterScript script)
|
|
|
|
|
{
|
|
|
|
|
var themeViewModel = _themeViewModelFactory.Create();
|
2015-07-06 08:41:46 -04:00
|
|
|
|
themeViewModel.InitialiseForMasterTheme(script);
|
2015-07-05 17:43:17 -04:00
|
|
|
|
themeViewModel.FilePath = "<Master Theme> " + Path.GetFileName(script.FilePath);
|
|
|
|
|
|
|
|
|
|
return themeViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IThemeEditorViewModel LoadThemeFromFile(string filePath)
|
2015-06-26 12:42:20 -04:00
|
|
|
|
{
|
|
|
|
|
var model = _themePersistenceService.LoadTheme(filePath);
|
2015-07-05 17:43:17 -04:00
|
|
|
|
var viewModel = Mapper.Map<IThemeEditorViewModel>(model);
|
2015-06-26 12:42:20 -04:00
|
|
|
|
viewModel.FilePath = filePath;
|
|
|
|
|
return viewModel;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-26 16:54:20 -04:00
|
|
|
|
public Theme LoadThemeModelFromFile(string filePath)
|
|
|
|
|
{
|
|
|
|
|
return _themePersistenceService.LoadTheme(filePath);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 17:43:17 -04:00
|
|
|
|
public void SaveTheme(IThemeEditorViewModel themeEditorViewModel, string filePath)
|
2015-06-26 12:42:20 -04:00
|
|
|
|
{
|
2015-07-05 17:43:17 -04:00
|
|
|
|
var theme = Mapper.Map<Theme>(themeEditorViewModel);
|
2015-06-26 12:42:20 -04:00
|
|
|
|
_themePersistenceService.SaveTheme(theme, filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|