PowerToys/Wox.Core/UI/ResourceMerger.cs

48 lines
1.5 KiB
C#
Raw Normal View History

2015-01-02 23:07:49 +08:00
using System;
2015-02-07 20:17:49 +08:00
using System.Collections.Generic;
2015-01-02 23:07:49 +08:00
using System.Linq;
using System.Windows;
using Wox.Core.i18n;
2015-02-07 20:17:49 +08:00
using Wox.Core.Plugin;
2015-01-02 23:07:49 +08:00
using Wox.Core.Theme;
2015-01-06 18:28:23 +08:00
using Wox.Plugin;
2015-01-02 23:07:49 +08:00
namespace Wox.Core.UI
{
public class ResourceMerger
{
2015-02-07 20:17:49 +08:00
internal static void ApplyResources()
2015-01-06 18:28:23 +08:00
{
Application.Current.Resources.MergedDictionaries.Clear();
ApplyPluginLanguages();
2015-01-07 22:23:10 +08:00
ApplyThemeAndLanguageResources();
2015-01-06 18:28:23 +08:00
}
2015-02-07 20:17:49 +08:00
internal static void ApplyThemeAndLanguageResources()
2015-01-02 23:07:49 +08:00
{
2015-02-07 20:17:49 +08:00
var UIResources = AssemblyHelper.LoadInterfacesFromAppDomain<IUIResource>();
2015-01-02 23:07:49 +08:00
foreach (var uiResource in UIResources)
{
2015-02-07 20:17:49 +08:00
Application.Current.Resources.MergedDictionaries.Add(uiResource.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
{
2015-02-07 20:17:49 +08:00
var pluginI18ns = AssemblyHelper.LoadInterfacesFromAppDomain<IPluginI18n>();
2015-01-06 23:24:11 +08:00
foreach (var pluginI18n in pluginI18ns)
2015-01-06 18:28:23 +08:00
{
2015-02-07 20:17:49 +08:00
string languageFile = InternationalizationManager.Instance.GetLanguageFile(pluginI18n.GetLanguagesFolder());
2015-01-06 23:24:11 +08:00
if (!string.IsNullOrEmpty(languageFile))
2015-01-06 18:28:23 +08:00
{
2015-01-06 23:24:11 +08:00
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
{
Source = new Uri(languageFile, UriKind.Absolute)
});
}
2015-01-06 18:28:23 +08:00
}
}
2015-02-07 20:17:49 +08:00
2015-01-02 23:07:49 +08:00
}
2015-01-06 18:28:23 +08:00
}