Implemented editable themes / master themes

This commit is contained in:
Ben
2015-07-05 22:43:17 +01:00
parent 511f503e88
commit bfa2341ab8
20 changed files with 354 additions and 89 deletions

View File

@@ -20,6 +20,7 @@
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.RadioButton.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Scrollbars.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.TextBox.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.ListView.xaml" />
<ResourceDictionary Source="Views/CrossButton.xaml" />
<ResourceDictionary Source="Views/IconsDictionary.xaml" />

View File

@@ -58,9 +58,9 @@ namespace Filtration
.ForMember(dest => dest.IsExpanded,
opts => opts.UseValue(false));
Mapper.CreateMap<Theme, IThemeViewModel>().ConstructUsingServiceLocator();
Mapper.CreateMap<Theme, IThemeEditorViewModel>().ConstructUsingServiceLocator();
Mapper.CreateMap<ThemeComponent, ThemeComponentViewModel>().ReverseMap();
Mapper.CreateMap<IThemeViewModel, Theme>();
Mapper.CreateMap<IThemeEditorViewModel, Theme>();
Mapper.AssertConfigurationIsValid();

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using Filtration.Common.ViewModels;
using Filtration.Interface;
using Filtration.ThemeEditor.ViewModels;
using Filtration.ViewModels.ToolPanes;
using GalaSoft.MvvmLight.Messaging;
@@ -14,6 +15,7 @@ namespace Filtration.ViewModels
IDocument ActiveDocument { get; set; }
ReadOnlyObservableCollection<IDocument> OpenDocuments { get; }
IItemFilterScriptViewModel ActiveScriptViewModel { get; }
IThemeEditorViewModel ActiveThemeViewModel { get; }
ISectionBrowserViewModel SectionBrowserViewModel { get; }
IBlockGroupBrowserViewModel BlockGroupBrowserViewModel { get; }
IBlockOutputPreviewViewModel BlockOutputPreviewViewModel { get; }
@@ -30,6 +32,7 @@ namespace Filtration.ViewModels
private IDocument _activeDocument;
private IItemFilterScriptViewModel _activeScriptViewModel;
private IThemeEditorViewModel _activeThemeViewModel;
private readonly ObservableCollection<IDocument> _openDocuments;
private readonly ReadOnlyObservableCollection<IDocument> _readOnlyOpenDocuments;
@@ -72,9 +75,14 @@ namespace Filtration.ViewModels
{
_activeScriptViewModel = (IItemFilterScriptViewModel) value;
}
else if (value.IsTheme)
{
_activeThemeViewModel = (IThemeEditorViewModel) value;
}
else
{
_activeScriptViewModel = null;
_activeThemeViewModel = null;
}
if (ActiveDocumentChanged != null)
@@ -91,6 +99,11 @@ namespace Filtration.ViewModels
get { return _activeScriptViewModel; }
}
public IThemeEditorViewModel ActiveThemeViewModel
{
get { return _activeThemeViewModel; }
}
public IBlockGroupBrowserViewModel BlockGroupBrowserViewModel
{
get { return _blockGroupBrowserViewModel; }
@@ -107,6 +120,7 @@ namespace Filtration.ViewModels
}
private List<IToolViewModel> _tools;
public IEnumerable<IToolViewModel> Tools
{
@@ -127,6 +141,10 @@ namespace Filtration.ViewModels
{
_activeScriptViewModel = (IItemFilterScriptViewModel) document;
}
else if (document.IsTheme)
{
_activeThemeViewModel = (IThemeEditorViewModel) document;
}
_openDocuments.Add(document);
ActiveDocument = document;

View File

@@ -10,6 +10,7 @@ using Filtration.Common.Services;
using Filtration.Common.ViewModels;
using Filtration.Interface;
using Filtration.Models;
using Filtration.ObjectModel.Enums;
using Filtration.ObjectModel.ThemeEditor;
using Filtration.Properties;
using Filtration.Repositories;
@@ -95,8 +96,18 @@ namespace Filtration.ViewModels
OpenAboutWindowCommand = new RelayCommand(OnOpenAboutWindowCommand);
ReplaceColorsCommand = new RelayCommand(OnReplaceColorsCommand, () => ActiveDocumentIsScript);
CreateThemeCommand = new RelayCommand(OnCreateThemeCommand, () => ActiveDocumentIsScript);
ApplyThemeToScriptCommand = new RelayCommand(OnApplyThemeToScriptCommand, () => ActiveDocumentIsScript);
EditMasterThemeCommand = new RelayCommand(OnEditMasterThemeCommand, () => ActiveDocumentIsScript);
AddTextColorThemeComponentCommand = new RelayCommand(OnAddTextColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddBackgroundColorThemeComponentCommand = new RelayCommand(OnAddBackgroundColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddBorderColorThemeComponentCommand = new RelayCommand(OnAddBorderColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
DeleteThemeComponentCommand = new RelayCommand(OnDeleteThemeComponentCommand,
() =>
ActiveDocumentIsTheme && ActiveDocumentIsTheme &&
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent != null);
ExpandAllBlocksCommand = new RelayCommand(OnExpandAllBlocksCommand, () => ActiveDocumentIsScript);
CollapseAllBlocksCommand = new RelayCommand(OnCollapseAllBlocksCommand, () => ActiveDocumentIsScript);
@@ -129,6 +140,7 @@ namespace Filtration.ViewModels
PasteCommand.RaiseCanExecuteChanged();
ReplaceColorsCommand.RaiseCanExecuteChanged();
ApplyThemeToScriptCommand.RaiseCanExecuteChanged();
EditMasterThemeCommand.RaiseCanExecuteChanged();
CreateThemeCommand.RaiseCanExecuteChanged();
RaisePropertyChanged("ShowAdvancedStatus");
break;
@@ -161,9 +173,16 @@ namespace Filtration.ViewModels
public RelayCommand CloseCommand { get; private set; }
public RelayCommand OpenAboutWindowCommand { get; private set; }
public RelayCommand ReplaceColorsCommand { get; private set; }
public RelayCommand EditMasterThemeCommand { get; private set; }
public RelayCommand CreateThemeCommand { get; private set; }
public RelayCommand ApplyThemeToScriptCommand { get; private set; }
public RelayCommand AddTextColorThemeComponentCommand { get; private set; }
public RelayCommand AddBackgroundColorThemeComponentCommand { get; private set; }
public RelayCommand AddBorderColorThemeComponentCommand { get; private set; }
public RelayCommand DeleteThemeComponentCommand { get; private set; }
public RelayCommand AddBlockCommand { get; private set; }
public RelayCommand AddSectionCommand { get; private set; }
public RelayCommand DeleteBlockCommand { get; private set; }
@@ -262,7 +281,12 @@ namespace Filtration.ViewModels
public bool ActiveDocumentIsTheme
{
get { { return AvalonDockWorkspaceViewModel.ActiveDocument is ThemeViewModel; } }
get { return AvalonDockWorkspaceViewModel.ActiveDocument is ThemeEditorViewModel; }
}
public bool ActiveThemeIsEditable
{
get { return AvalonDockWorkspaceViewModel.ActiveThemeViewModel.EditEnabled; }
}
private bool ActiveDocumentIsEditable()
@@ -283,16 +307,23 @@ namespace Filtration.ViewModels
var themeViewModel = _themeProvider.NewThemeForScript(AvalonDockWorkspaceViewModel.ActiveScriptViewModel.Script);
OpenTheme(themeViewModel);
}
private void OpenTheme(IThemeViewModel themeViewModel)
private void OnEditMasterThemeCommand()
{
if (AvalonDockWorkspaceViewModel.OpenDocuments.Contains(themeViewModel))
var themeViewModel =
_themeProvider.MasterThemeForScript(AvalonDockWorkspaceViewModel.ActiveScriptViewModel.Script);
OpenTheme(themeViewModel);
}
private void OpenTheme(IThemeEditorViewModel themeEditorViewModel)
{
if (AvalonDockWorkspaceViewModel.OpenDocuments.Contains(themeEditorViewModel))
{
AvalonDockWorkspaceViewModel.SwitchActiveDocument(themeViewModel);
AvalonDockWorkspaceViewModel.SwitchActiveDocument(themeEditorViewModel);
}
else
{
AvalonDockWorkspaceViewModel.AddDocument(themeViewModel);
AvalonDockWorkspaceViewModel.AddDocument(themeEditorViewModel);
}
}
@@ -341,7 +372,7 @@ namespace Filtration.ViewModels
return;
}
IThemeViewModel loadedViewModel;
IThemeEditorViewModel loadedViewModel;
try
{
@@ -536,5 +567,26 @@ namespace Filtration.ViewModels
{
_avalonDockWorkspaceViewModel.ActiveScriptViewModel.ClearFilterCommand.Execute(null);
}
private void OnAddTextColorThemeComponentCommand()
{
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.AddThemeComponentCommand.Execute(ThemeComponentType.TextColor);
}
private void OnAddBackgroundColorThemeComponentCommand()
{
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.AddThemeComponentCommand.Execute(ThemeComponentType.BackgroundColor);
}
private void OnAddBorderColorThemeComponentCommand()
{
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.AddThemeComponentCommand.Execute(ThemeComponentType.BorderColor);
}
private void OnDeleteThemeComponentCommand()
{
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.DeleteThemeComponentCommand.Execute(
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent);
}
}
}

View File

@@ -56,7 +56,7 @@
</viewsAvalonDock:PanesTemplateSelector.StartPageTemplate>
<viewsAvalonDock:PanesTemplateSelector.ThemeTemplate>
<DataTemplate>
<themeEditorViews:ThemeControl DataContext="{Binding}" />
<themeEditorViews:ThemeEditorView DataContext="{Binding}" />
</DataTemplate>
</viewsAvalonDock:PanesTemplateSelector.ThemeTemplate>
</viewsAvalonDock:PanesTemplateSelector>

View File

@@ -25,7 +25,7 @@ namespace Filtration.Views.AvalonDock
return ItemFilterScriptTemplate;
}
if (item is IThemeViewModel)
if (item is IThemeEditorViewModel)
{
return ThemeTemplate;
}

View File

@@ -58,6 +58,11 @@
BorderBrush="ForestGreen"
x:Name="ScriptToolsGroup"
Visibility="{Binding ActiveDocumentIsScript, Converter={StaticResource BooleanVisibilityConverterCopy}, Mode=OneWay}" />
<fluent:RibbonContextualTabGroup Header="Theme Tools"
Background="DodgerBlue"
BorderBrush="DodgerBlue"
x:Name="ThemeToolsGroup"
Visibility="{Binding ActiveDocumentIsTheme, Converter={StaticResource BooleanVisibilityConverterCopy}, Mode=OneWay}" />
</fluent:Ribbon.ContextualGroups>
<fluent:RibbonTabItem Header="Script Tools" Group="{Binding ElementName=ScriptToolsGroup}">
<fluent:RibbonGroupBox Header="Clipboard">
@@ -86,11 +91,22 @@
<fluent:Button Header="Clear All Filters" Command="{Binding ClearFiltersCommand}" SizeDefinition="Middle" Icon="{StaticResource ClearFilterIcon}" />
</fluent:RibbonGroupBox>
<fluent:RibbonGroupBox Header="Themes">
<fluent:Button Header="Edit Master Theme" Command="{Binding EditMasterThemeCommand}" Icon="{StaticResource ThemeIcon}" LargeIcon="{StaticResource ThemeIcon}" />
<fluent:Button Header="Apply Theme" Command="{Binding ApplyThemeToScriptCommand}" Icon="{StaticResource ThemeIcon}" LargeIcon="{StaticResource ThemeIcon}" />
<fluent:Button Header="Create Theme" Command="{Binding CreateThemeCommand}" Icon="{StaticResource ThemeIcon}" LargeIcon="{StaticResource ThemeIcon}" />
<fluent:Button Header="Replace Colours" Command="{Binding ReplaceColorsCommand}" Icon="{StaticResource ReplaceColorsIcon}" LargeIcon="{StaticResource ReplaceColorsIcon}" />
</fluent:RibbonGroupBox>
</fluent:RibbonTabItem>
<fluent:RibbonTabItem Header="Theme Tools" Group="{Binding ElementName=ThemeToolsGroup}">
<fluent:RibbonGroupBox Header="Add Components">
<fluent:Button SizeDefinition="Middle" Header="Add Text Color" Command="{Binding AddTextColorThemeComponentCommand}" />
<fluent:Button SizeDefinition="Middle" Header="Add Background Color" Command="{Binding AddBackgroundColorThemeComponentCommand}" />
<fluent:Button SizeDefinition="Middle" Header="Add Border Color" Command="{Binding AddBorderColorThemeComponentCommand}" />
</fluent:RibbonGroupBox>
<fluent:RibbonGroupBox Header="Delete">
<fluent:Button Header="Delete Theme Component" Command="{Binding DeleteThemeComponentCommand}" />
</fluent:RibbonGroupBox>
</fluent:RibbonTabItem>
<fluent:RibbonTabItem Header="View">
<fluent:RibbonGroupBox Header="Tools">
<fluent:ToggleButton Header="Section Browser" Width="150" SizeDefinition="Middle" Icon="{StaticResource AddSectionIcon}" IsChecked="{Binding AvalonDockWorkspaceViewModel.SectionBrowserViewModel.IsVisible}" />
@@ -104,3 +120,4 @@
</Grid>
</DockPanel>
</fluent:RibbonWindow>