Fix theming for plugins

This commit is contained in:
John Gross
2018-04-12 18:04:15 -07:00
parent 03fa0a73b6
commit 85e307f8db
13 changed files with 26 additions and 17 deletions

View File

@@ -1,6 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:local="clr-namespace:Torch.Server.Themes">
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! --> <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />

View File

@@ -1,6 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:local="clr-namespace:Torch.Server.Themes">
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! --> <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->

View File

@@ -1,6 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:local="clr-namespace:Torch.Server.Themes">
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>

View File

@@ -1,6 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:local="clr-namespace:Torch.Server.Themes">
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! --> <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->

View File

@@ -3,9 +3,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Torch.API; using Torch.API;
using Torch.API.Plugins; using Torch.API.Plugins;
using Torch.Server.Views;
namespace Torch.Server.ViewModels namespace Torch.Server.ViewModels
{ {
@@ -23,6 +25,15 @@ namespace Torch.Server.ViewModels
Control = p.GetControl(); Control = p.GetControl();
Name = $"{plugin.Name} ({plugin.Version})"; Name = $"{plugin.Name} ({plugin.Version})";
ThemeControl.UpdateDynamicControls += UpdateResourceDict;
UpdateResourceDict(ThemeControl.currentTheme);
}
public void UpdateResourceDict(ResourceDictionary dictionary)
{
this.Control.Resources.MergedDictionaries.Clear();
this.Control.Resources.MergedDictionaries.Add(dictionary);
} }
} }
} }

View File

@@ -29,7 +29,7 @@ namespace Torch.Server.Views.Blocks
{ {
InitializeComponent(); InitializeComponent();
ThemeControl.UpdateWeirdViews += UpdateResourceDict; ThemeControl.UpdateDynamicControls += UpdateResourceDict;
UpdateResourceDict(ThemeControl.currentTheme); UpdateResourceDict(ThemeControl.currentTheme);
} }

View File

@@ -27,7 +27,7 @@ namespace Torch.Server.Views.Blocks
InitializeComponent(); InitializeComponent();
DataContextChanged += OnDataContextChanged; DataContextChanged += OnDataContextChanged;
ThemeControl.UpdateWeirdViews += UpdateResourceDict; ThemeControl.UpdateDynamicControls += UpdateResourceDict;
UpdateResourceDict(ThemeControl.currentTheme); UpdateResourceDict(ThemeControl.currentTheme);
} }

View File

@@ -24,7 +24,7 @@ namespace Torch.Server.Views.Entities
{ {
InitializeComponent(); InitializeComponent();
ThemeControl.UpdateWeirdViews += UpdateResourceDict; ThemeControl.UpdateDynamicControls += UpdateResourceDict;
UpdateResourceDict(ThemeControl.currentTheme); UpdateResourceDict(ThemeControl.currentTheme);
} }

View File

@@ -18,7 +18,7 @@ namespace Torch.Server.Views.Entities
InitializeComponent(); InitializeComponent();
DataContextChanged += OnDataContextChanged; DataContextChanged += OnDataContextChanged;
ThemeControl.UpdateWeirdViews += UpdateResourceDict; ThemeControl.UpdateDynamicControls += UpdateResourceDict;
UpdateResourceDict(ThemeControl.currentTheme); UpdateResourceDict(ThemeControl.currentTheme);
} }

View File

@@ -12,7 +12,7 @@ namespace Torch.Server.Views.Entities
{ {
InitializeComponent(); InitializeComponent();
ThemeControl.UpdateWeirdViews += UpdateResourceDict; ThemeControl.UpdateDynamicControls += UpdateResourceDict;
UpdateResourceDict(ThemeControl.currentTheme); UpdateResourceDict(ThemeControl.currentTheme);
} }

View File

@@ -24,7 +24,7 @@ namespace Torch.Server.Views.Entities
{ {
InitializeComponent(); InitializeComponent();
ThemeControl.UpdateWeirdViews += UpdateResourceDict; ThemeControl.UpdateDynamicControls += UpdateResourceDict;
UpdateResourceDict(ThemeControl.currentTheme); UpdateResourceDict(ThemeControl.currentTheme);
} }

View File

@@ -26,7 +26,7 @@ namespace Torch.Server.Views.Entities
InitializeComponent(); InitializeComponent();
DataContextChanged += VoxelMapView_DataContextChanged; DataContextChanged += VoxelMapView_DataContextChanged;
ThemeControl.UpdateWeirdViews += UpdateResourceDict; ThemeControl.UpdateDynamicControls += UpdateResourceDict;
UpdateResourceDict(ThemeControl.currentTheme); UpdateResourceDict(ThemeControl.currentTheme);
} }

View File

@@ -11,6 +11,7 @@ using System.Windows.Data;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Threading; using System.Windows.Threading;
using Torch.API.Managers; using Torch.API.Managers;
using Torch.API.Plugins;
using Torch.Server.Annotations; using Torch.Server.Annotations;
using Torch.Server.Managers; using Torch.Server.Managers;
using Torch.Server.ViewModels; using Torch.Server.ViewModels;
@@ -25,7 +26,7 @@ namespace Torch.Server.Views
/// <summary> /// <summary>
/// Action other views can subscribe to to update their views if they dont inherit the style from the window for some reason. /// Action other views can subscribe to to update their views if they dont inherit the style from the window for some reason.
/// </summary> /// </summary>
public static Action<ResourceDictionary> UpdateWeirdViews; public static Action<ResourceDictionary> UpdateDynamicControls;
/// <summary> /// <summary>
/// Current theme other views can set their theme to when they first spawn /// Current theme other views can set their theme to when they first spawn
@@ -47,6 +48,7 @@ namespace Torch.Server.Views
} }
private Dictionary<string, ResourceDictionary> _themes = new Dictionary<string, ResourceDictionary>(); private Dictionary<string, ResourceDictionary> _themes = new Dictionary<string, ResourceDictionary>();
private HashSet<ITorchPlugin> plugins;
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
@@ -84,7 +86,7 @@ namespace Torch.Server.Views
uiSource.Resources.MergedDictionaries.Clear(); uiSource.Resources.MergedDictionaries.Clear();
var resource = new ResourceDictionary() { Source = uri }; var resource = new ResourceDictionary() { Source = uri };
uiSource.Resources.MergedDictionaries.Add(resource); uiSource.Resources.MergedDictionaries.Add(resource);
UpdateWeirdViews?.Invoke(resource); UpdateDynamicControls?.Invoke(resource);
currentTheme = resource; currentTheme = resource;
} }