PowerToys/Wox.Core/UI/ResourceMerger.cs

54 lines
1.9 KiB
C#
Raw Normal View History

2015-01-02 23:07:49 +08:00
using System;
using System.IO;
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 directoryName)
2015-01-06 18:28:23 +08:00
{
directoryName = $"{Path.DirectorySeparatorChar}{directoryName}";
var dictionaries = Application.Current.Resources.MergedDictionaries;
foreach (var resource in dictionaries)
{
string currentDirectoryName = Path.GetDirectoryName(resource.Source.AbsolutePath);
if (currentDirectoryName == directoryName)
{
dictionaries.Remove(resource);
break;
}
}
}
public static void UpdateResource(Theme.Theme t)
{
RemoveResource(Theme.Theme.DirectoryName);
Application.Current.Resources.MergedDictionaries.Add(t.GetResourceDictionary());
}
public static void UpdateResources(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
internal static void UpdatePluginLanguages()
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
}