mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Refactoring directory path for UI resource
This commit is contained in:
15
Wox.Core/Resource/Resource.cs
Normal file
15
Wox.Core/Resource/Resource.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Windows;
|
||||||
|
using Wox.Infrastructure;
|
||||||
|
|
||||||
|
namespace Wox.Core.UI
|
||||||
|
{
|
||||||
|
public abstract class Resource
|
||||||
|
{
|
||||||
|
public string DirectoryName { get; protected set; }
|
||||||
|
|
||||||
|
protected string DirectoryPath => Path.Combine(WoxDirectroy.Executable, DirectoryName);
|
||||||
|
|
||||||
|
public abstract ResourceDictionary GetResourceDictionary();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,18 +25,12 @@ namespace Wox.Core.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateResource(Theme.Theme t)
|
public static void UpdateResource<T>(T t) where T : Resource
|
||||||
{
|
{
|
||||||
RemoveResource(Theme.Theme.DirectoryName);
|
RemoveResource(t.DirectoryName);
|
||||||
Application.Current.Resources.MergedDictionaries.Add(t.GetResourceDictionary());
|
Application.Current.Resources.MergedDictionaries.Add(t.GetResourceDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateResources(Internationalization i)
|
|
||||||
{
|
|
||||||
RemoveResource(Internationalization.DirectoryName);
|
|
||||||
Application.Current.Resources.MergedDictionaries.Add(i.GetResourceDictionary());
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void UpdatePluginLanguages()
|
internal static void UpdatePluginLanguages()
|
||||||
{
|
{
|
||||||
RemoveResource(PluginManager.DirectoryName);
|
RemoveResource(PluginManager.DirectoryName);
|
||||||
@@ -14,14 +14,14 @@ using Wox.Infrastructure.Logger;
|
|||||||
|
|
||||||
namespace Wox.Core.Theme
|
namespace Wox.Core.Theme
|
||||||
{
|
{
|
||||||
public class Theme : IUIResource
|
public class Theme : Resource
|
||||||
{
|
{
|
||||||
public const string DirectoryName = "Themes";
|
|
||||||
private static List<string> themeDirectories = new List<string>();
|
private static List<string> themeDirectories = new List<string>();
|
||||||
|
|
||||||
static Theme()
|
public Theme()
|
||||||
{
|
{
|
||||||
themeDirectories.Add(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), DirectoryName));
|
DirectoryName = "Themes";
|
||||||
|
themeDirectories.Add(DirectoryPath);
|
||||||
MakesureThemeDirectoriesExist();
|
MakesureThemeDirectoriesExist();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ namespace Wox.Core.Theme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceDictionary GetResourceDictionary()
|
public override ResourceDictionary GetResourceDictionary()
|
||||||
{
|
{
|
||||||
var dict = new ResourceDictionary
|
var dict = new ResourceDictionary
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
using System.Windows;
|
|
||||||
|
|
||||||
namespace Wox.Core.UI
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Object implement this interface will have the ability to has its own UI styles
|
|
||||||
/// </summary>
|
|
||||||
public interface IUIResource
|
|
||||||
{
|
|
||||||
ResourceDictionary GetResourceDictionary();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -66,13 +66,12 @@
|
|||||||
<Compile Include="Updater\WoxUpdateSource.cs" />
|
<Compile Include="Updater\WoxUpdateSource.cs" />
|
||||||
<Compile Include="UserSettings\HttpProxy.cs" />
|
<Compile Include="UserSettings\HttpProxy.cs" />
|
||||||
<Compile Include="i18n\AvailableLanguages.cs" />
|
<Compile Include="i18n\AvailableLanguages.cs" />
|
||||||
<Compile Include="i18n\IInternationalization.cs" />
|
|
||||||
<Compile Include="i18n\Internationalization.cs" />
|
<Compile Include="i18n\Internationalization.cs" />
|
||||||
<Compile Include="i18n\InternationalizationManager.cs" />
|
<Compile Include="i18n\InternationalizationManager.cs" />
|
||||||
<Compile Include="i18n\Language.cs" />
|
<Compile Include="i18n\Language.cs" />
|
||||||
<Compile Include="Theme\ThemeManager.cs" />
|
<Compile Include="Theme\ThemeManager.cs" />
|
||||||
<Compile Include="UI\IUIResource.cs" />
|
<Compile Include="Resource\Resource.cs" />
|
||||||
<Compile Include="UI\ResourceMerger.cs" />
|
<Compile Include="Resource\ResourceMerger.cs" />
|
||||||
<Compile Include="Plugin\PluginInstaller.cs" />
|
<Compile Include="Plugin\PluginInstaller.cs" />
|
||||||
<Compile Include="Plugin\JsonRPCPlugin.cs" />
|
<Compile Include="Plugin\JsonRPCPlugin.cs" />
|
||||||
<Compile Include="Plugin\JsonRPCPluginLoader.cs" />
|
<Compile Include="Plugin\JsonRPCPluginLoader.cs" />
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Wox.Core.i18n
|
|
||||||
{
|
|
||||||
interface IInternationalization
|
|
||||||
{
|
|
||||||
List<Language> LoadAvailableLanguages();
|
|
||||||
|
|
||||||
string GetTranslation(string key);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get language file for current user selected language
|
|
||||||
/// if couldn't find the current selected language file, it will first try to load en.xaml
|
|
||||||
/// if en.xaml couldn't find, return empty string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="folder"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
string GetLanguageFile(string folder);
|
|
||||||
|
|
||||||
void ChangeLanguage(Language language);
|
|
||||||
|
|
||||||
void ChangeLanguage(string languageCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Wox.Core.UI;
|
using Wox.Core.UI;
|
||||||
using Wox.Core.UserSettings;
|
using Wox.Core.UserSettings;
|
||||||
@@ -12,23 +11,21 @@ using Wox.Plugin;
|
|||||||
|
|
||||||
namespace Wox.Core.i18n
|
namespace Wox.Core.i18n
|
||||||
{
|
{
|
||||||
public class Internationalization : IInternationalization, IUIResource
|
public class Internationalization : Resource
|
||||||
{
|
{
|
||||||
public const string DirectoryName = "Languages";
|
public Internationalization()
|
||||||
private static readonly string DefaultDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), DirectoryName);
|
|
||||||
|
|
||||||
static Internationalization()
|
|
||||||
{
|
{
|
||||||
|
DirectoryName = "Languages";
|
||||||
MakesureThemeDirectoriesExist();
|
MakesureThemeDirectoriesExist();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MakesureThemeDirectoriesExist()
|
private void MakesureThemeDirectoriesExist()
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(DefaultDirectory))
|
if (!Directory.Exists(DirectoryPath))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(DefaultDirectory);
|
Directory.CreateDirectory(DirectoryPath);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -70,14 +67,16 @@ namespace Wox.Core.i18n
|
|||||||
|
|
||||||
UserSettingStorage.Instance.Language = language.LanguageCode;
|
UserSettingStorage.Instance.Language = language.LanguageCode;
|
||||||
UserSettingStorage.Instance.Save();
|
UserSettingStorage.Instance.Save();
|
||||||
ResourceMerger.UpdateResources(this);
|
ResourceMerger.UpdateResource(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceDictionary GetResourceDictionary()
|
|
||||||
|
|
||||||
|
public override ResourceDictionary GetResourceDictionary()
|
||||||
{
|
{
|
||||||
return new ResourceDictionary
|
return new ResourceDictionary
|
||||||
{
|
{
|
||||||
Source = new Uri(GetLanguageFile(DefaultDirectory), UriKind.Absolute)
|
Source = new Uri(GetLanguageFile(DirectoryPath), UriKind.Absolute)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +123,7 @@ namespace Wox.Core.i18n
|
|||||||
|
|
||||||
private string GetLanguagePath(Language language)
|
private string GetLanguagePath(Language language)
|
||||||
{
|
{
|
||||||
string path = Path.Combine(DefaultDirectory, language.LanguageCode + ".xaml");
|
string path = Path.Combine(DirectoryPath, language.LanguageCode + ".xaml");
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
return path;
|
return path;
|
||||||
@@ -156,4 +155,5 @@ namespace Wox.Core.i18n
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user