PowerToys/Wox.Core/UI/ResourceMerger.cs

53 lines
1.9 KiB
C#
Raw Normal View History

2015-01-02 23:07:49 +08:00
using System;
using System.Linq;
2015-01-02 23:07:49 +08:00
using System.Windows;
using Wox.Core.i18n;
using Wox.Core.Plugin;
2015-01-06 18:28:23 +08:00
using Wox.Plugin;
2015-01-02 23:07:49 +08:00
namespace Wox.Core.UI
{
public static class ResourceMerger
2015-01-02 23:07:49 +08:00
{
private static void RemoveResource(string resourceDirectoryName)
2015-01-06 18:28:23 +08:00
{
var mergedDictionaries = Application.Current.Resources.MergedDictionaries;
foreach (var resource in mergedDictionaries)
{
int directoryPosition = resource.Source.Segments.Length - 2;
string currentDirectoryName = resource.Source.Segments[directoryPosition];
if (currentDirectoryName == resourceDirectoryName)
{
mergedDictionaries.Remove(resource);
break;
}
}
}
public static void ApplyThemeResource(Theme.Theme t)
{
RemoveResource(Theme.Theme.DirectoryName);
Application.Current.Resources.MergedDictionaries.Add(t.GetResourceDictionary());
}
public static void ApplyLanguageResources(Internationalization i)
{
RemoveResource(Internationalization.DirectoryName);
Application.Current.Resources.MergedDictionaries.Add(i.GetResourceDictionary());
2015-01-02 23:07:49 +08:00
}
2015-01-06 18:28:23 +08:00
2015-02-07 20:17:49 +08:00
internal static void ApplyPluginLanguages()
2015-01-06 18:28:23 +08:00
{
RemoveResource(PluginManager.DirectoryName);
foreach (var languageFile in PluginManager.GetPluginsForInterface<IPluginI18n>().
2015-11-03 02:52:34 +08:00
Select(plugin => InternationalizationManager.Instance.GetLanguageFile(((IPluginI18n)plugin.Plugin).GetLanguagesFolder())).
2015-11-03 06:15:06 +08:00
Where(file => !string.IsNullOrEmpty(file)))
2015-01-06 18:28:23 +08:00
{
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
2015-01-06 18:28:23 +08:00
{
Source = new Uri(languageFile, UriKind.Absolute)
});
2015-01-06 18:28:23 +08:00
}
}
2015-01-02 23:07:49 +08:00
}
2015-01-06 18:28:23 +08:00
}