2015-01-02 23:07:49 +08:00
|
|
|
|
using System;
|
2015-11-02 02:49:38 +00:00
|
|
|
|
using System.Linq;
|
2015-01-02 23:07:49 +08:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using Wox.Core.i18n;
|
2015-11-02 02:49:38 +00:00
|
|
|
|
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
|
|
|
|
|
|
{
|
2015-11-02 02:49:38 +00:00
|
|
|
|
public static class ResourceMerger
|
2015-01-02 23:07:49 +08:00
|
|
|
|
{
|
2015-11-02 02:49:38 +00:00
|
|
|
|
private static void RemoveResource(string resourceDirectoryName)
|
2015-01-06 18:28:23 +08:00
|
|
|
|
{
|
2015-11-02 02:49:38 +00: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()
|
|
|
|
|
|
{
|
|
|
|
|
|
RemoveResource(Theme.Theme.DirectoryName);
|
|
|
|
|
|
ApplyUIResources();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void ApplyLanguageResources()
|
|
|
|
|
|
{
|
|
|
|
|
|
RemoveResource(Internationalization.DirectoryName);
|
|
|
|
|
|
ApplyUIResources();
|
2015-01-06 18:28:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-11-02 02:49:38 +00:00
|
|
|
|
private static void ApplyUIResources()
|
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-11-02 02:49:38 +00:00
|
|
|
|
RemoveResource(PluginManager.DirectoryName);
|
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
|
|
|
|
}
|