mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
Don't remove /Theme/Dark.xaml
This commit is contained in:
@@ -16,14 +16,30 @@ namespace Wox.Core.Resource
|
|||||||
public class Theme
|
public class Theme
|
||||||
{
|
{
|
||||||
private readonly List<string> _themeDirectories = new List<string>();
|
private readonly List<string> _themeDirectories = new List<string>();
|
||||||
|
private ResourceDictionary _oldResource;
|
||||||
|
private string _oldTheme;
|
||||||
public Settings Settings { get; set; }
|
public Settings Settings { get; set; }
|
||||||
private string DirectoryPath => Path.Combine(Constant.ProgramDirectory, DirectoryName);
|
private const string Folder = "Themes";
|
||||||
private const string DirectoryName = "Themes";
|
private const string Extension = ".xaml";
|
||||||
|
private string DirectoryPath => Path.Combine(Constant.ProgramDirectory, Folder);
|
||||||
|
|
||||||
public Theme()
|
public Theme()
|
||||||
{
|
{
|
||||||
_themeDirectories.Add(DirectoryPath);
|
_themeDirectories.Add(DirectoryPath);
|
||||||
MakesureThemeDirectoriesExist();
|
MakesureThemeDirectoriesExist();
|
||||||
|
|
||||||
|
var dicts = Application.Current.Resources.MergedDictionaries;
|
||||||
|
_oldResource = dicts.First(d =>
|
||||||
|
{
|
||||||
|
var p = d.Source.AbsolutePath;
|
||||||
|
var dir = Path.GetDirectoryName(p).NonNull();
|
||||||
|
var info = new DirectoryInfo(dir);
|
||||||
|
var f = info.Name;
|
||||||
|
var e = Path.GetExtension(p);
|
||||||
|
var found = f == Folder && e == Extension;
|
||||||
|
return found;
|
||||||
|
});
|
||||||
|
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MakesureThemeDirectoriesExist()
|
private void MakesureThemeDirectoriesExist()
|
||||||
@@ -75,12 +91,16 @@ namespace Wox.Core.Resource
|
|||||||
Settings.Theme = theme;
|
Settings.Theme = theme;
|
||||||
|
|
||||||
var dicts = Application.Current.Resources.MergedDictionaries;
|
var dicts = Application.Current.Resources.MergedDictionaries;
|
||||||
// OnStartup, there is nothing to remove
|
Log.Debug($"|TEST1|{dicts.Select(d => d.Source.AbsolutePath).Formatted()}");
|
||||||
var oldResource = dicts.FirstOrDefault(d => d.Source.AbsolutePath == path) ?? new ResourceDictionary();
|
if (_oldTheme != theme)
|
||||||
dicts.Remove(oldResource);
|
{
|
||||||
var newResource = GetResourceDictionary();
|
dicts.Remove(_oldResource);
|
||||||
dicts.Add(newResource);
|
var newResource = GetResourceDictionary();
|
||||||
|
dicts.Add(newResource);
|
||||||
|
_oldResource = newResource;
|
||||||
|
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
|
||||||
|
}
|
||||||
|
Log.Debug($"|TEST2|{dicts.Select(d => d.Source.AbsolutePath).Formatted()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +145,7 @@ namespace Wox.Core.Resource
|
|||||||
{
|
{
|
||||||
themes.AddRange(
|
themes.AddRange(
|
||||||
Directory.GetFiles(themeDirectory)
|
Directory.GetFiles(themeDirectory)
|
||||||
.Where(filePath => filePath.EndsWith(".xaml") && !filePath.EndsWith("Base.xaml"))
|
.Where(filePath => filePath.EndsWith(Extension) && !filePath.EndsWith("Base.xaml"))
|
||||||
.ToList());
|
.ToList());
|
||||||
}
|
}
|
||||||
return themes.OrderBy(o => o).ToList();
|
return themes.OrderBy(o => o).ToList();
|
||||||
@@ -135,7 +155,7 @@ namespace Wox.Core.Resource
|
|||||||
{
|
{
|
||||||
foreach (string themeDirectory in _themeDirectories)
|
foreach (string themeDirectory in _themeDirectories)
|
||||||
{
|
{
|
||||||
string path = Path.Combine(themeDirectory, themeName + ".xaml");
|
string path = Path.Combine(themeDirectory, themeName + Extension);
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
return path;
|
return path;
|
||||||
|
|||||||
Reference in New Issue
Block a user