mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Refactoring.
This commit is contained in:
@@ -1,18 +1,17 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Forms;
|
||||||
using ICSharpCode.SharpZipLib.Zip;
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Wox.Core.Plugin;
|
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace Wox.Helper
|
namespace Wox.Core.Plugin
|
||||||
{
|
{
|
||||||
public class PluginInstaller
|
internal class PluginInstaller
|
||||||
{
|
{
|
||||||
public static void Install(string path)
|
internal static void Install(string path)
|
||||||
{
|
{
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
@@ -37,11 +36,7 @@ namespace Wox.Helper
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string pluginFolerPath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Plugins");
|
string pluginFolerPath = PluginManager.DefaultPluginDirectory;
|
||||||
if (!Directory.Exists(pluginFolerPath))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(pluginFolerPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
string newPluginName = plugin.Name
|
string newPluginName = plugin.Name
|
||||||
.Replace("/", "_")
|
.Replace("/", "_")
|
||||||
@@ -66,9 +61,9 @@ namespace Wox.Helper
|
|||||||
plugin.Name, existingPlugin.Metadata.Version, plugin.Version, plugin.Author);
|
plugin.Name, existingPlugin.Metadata.Version, plugin.Version, plugin.Author);
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageBoxResult result = MessageBox.Show(content, "Install plugin",
|
DialogResult result = MessageBox.Show(content, "Install plugin", MessageBoxButtons.YesNo,
|
||||||
MessageBoxButton.YesNo, MessageBoxImage.Question);
|
MessageBoxIcon.Question);
|
||||||
if (result == MessageBoxResult.Yes)
|
if (result == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory))
|
if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory))
|
||||||
{
|
{
|
||||||
@@ -88,7 +83,7 @@ namespace Wox.Helper
|
|||||||
// Plugins.Init();
|
// Plugins.Init();
|
||||||
//}
|
//}
|
||||||
if (MessageBox.Show("You have installed plugin " + plugin.Name + " successfully.\r\n Restart Wox to take effect?", "Install plugin",
|
if (MessageBox.Show("You have installed plugin " + plugin.Name + " successfully.\r\n Restart Wox to take effect?", "Install plugin",
|
||||||
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
ProcessStartInfo Info = new ProcessStartInfo();
|
ProcessStartInfo Info = new ProcessStartInfo();
|
||||||
Info.Arguments = "/C ping 127.0.0.1 -n 1 && \"" +
|
Info.Arguments = "/C ping 127.0.0.1 -n 1 && \"" +
|
||||||
@@ -97,7 +92,7 @@ namespace Wox.Helper
|
|||||||
Info.CreateNoWindow = true;
|
Info.CreateNoWindow = true;
|
||||||
Info.FileName = "cmd.exe";
|
Info.FileName = "cmd.exe";
|
||||||
Process.Start(Info);
|
Process.Start(Info);
|
||||||
App.Window.CloseApp();
|
PluginManager.API.CloseApp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,17 +24,31 @@ namespace Wox.Core.Plugin
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static List<string> pluginDirectories = new List<string>();
|
private static List<string> pluginDirectories = new List<string>();
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default plugin directory
|
||||||
|
/// new plugin will be installed to this directory
|
||||||
|
/// </summary>
|
||||||
|
public static string DefaultPluginDirectory
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
|
||||||
|
if (userProfilePath != null)
|
||||||
|
{
|
||||||
|
return Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Plugins");
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static PluginManager()
|
static PluginManager()
|
||||||
{
|
{
|
||||||
|
pluginDirectories.Add(DefaultPluginDirectory);
|
||||||
pluginDirectories.Add(
|
pluginDirectories.Add(
|
||||||
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins"));
|
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins"));
|
||||||
|
|
||||||
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
|
|
||||||
if (userProfilePath != null)
|
|
||||||
{
|
|
||||||
pluginDirectories.Add(Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Plugins"));
|
|
||||||
}
|
|
||||||
|
|
||||||
MakesurePluginDirectoriesExist();
|
MakesurePluginDirectoriesExist();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +87,11 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void InstallPlugin(string path)
|
||||||
|
{
|
||||||
|
PluginInstaller.Install(path);
|
||||||
|
}
|
||||||
|
|
||||||
public static void Query(Query query)
|
public static void Query(Query query)
|
||||||
{
|
{
|
||||||
QueryDispatcher.QueryDispatcher.Dispatch(query);
|
QueryDispatcher.QueryDispatcher.Dispatch(query);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Wox.Core.Plugin.QueryDispatcher
|
|||||||
//websearch mode
|
//websearch mode
|
||||||
queryPlugins = new List<PluginPair>()
|
queryPlugins = new List<PluginPair>()
|
||||||
{
|
{
|
||||||
allSytemPlugins.First(o => ((ISystemPlugin)o.Plugin).ID == "565B73353DBF4806919830B9202EE3BF")
|
allSytemPlugins.First(o => o.Metadata.ID == "565B73353DBF4806919830B9202EE3BF")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||||
@@ -45,6 +49,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Plugin\PluginInstaller.cs" />
|
||||||
<Compile Include="Plugin\QueryDispatcher\IQueryDispatcher.cs" />
|
<Compile Include="Plugin\QueryDispatcher\IQueryDispatcher.cs" />
|
||||||
<Compile Include="Plugin\QueryDispatcher\QueryDispatcher.cs" />
|
<Compile Include="Plugin\QueryDispatcher\QueryDispatcher.cs" />
|
||||||
<Compile Include="Plugin\QueryDispatcher\UserPluginQueryDispatcher.cs" />
|
<Compile Include="Plugin\QueryDispatcher\UserPluginQueryDispatcher.cs" />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="Newtonsoft.Json" version="6.0.7" targetFramework="net35" />
|
<package id="Newtonsoft.Json" version="6.0.7" targetFramework="net35" />
|
||||||
|
<package id="SharpZipLib" version="0.86.0" targetFramework="net35" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -174,7 +174,15 @@ namespace Wox.Infrastructure.Storage.UserSettings
|
|||||||
if (string.IsNullOrEmpty(storage.ProgramSuffixes))
|
if (string.IsNullOrEmpty(storage.ProgramSuffixes))
|
||||||
{
|
{
|
||||||
storage.ProgramSuffixes = "lnk;exe;appref-ms;bat";
|
storage.ProgramSuffixes = "lnk;exe;appref-ms;bat";
|
||||||
}
|
}
|
||||||
|
if (storage.QueryBoxFont == null)
|
||||||
|
{
|
||||||
|
storage.QueryBoxFont = FontFamily.GenericSansSerif.Name;
|
||||||
|
}
|
||||||
|
if (storage.ResultItemFont == null)
|
||||||
|
{
|
||||||
|
storage.ResultItemFont = FontFamily.GenericSansSerif.Name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,4 +10,4 @@ namespace Wox.Plugin
|
|||||||
System,
|
System,
|
||||||
User
|
User
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using Wox.Core.Plugin;
|
||||||
using Wox.Helper;
|
using Wox.Helper;
|
||||||
|
|
||||||
namespace Wox.CommandArgs
|
namespace Wox.CommandArgs
|
||||||
@@ -25,7 +26,7 @@ namespace Wox.CommandArgs
|
|||||||
MessageBox.Show("Plugin " + path + " didn't exist");
|
MessageBox.Show("Plugin " + path + " didn't exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PluginInstaller.Install(path);
|
PluginManager.InstallPlugin(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Threading;
|
|
||||||
|
|
||||||
namespace Wox.Converters
|
|
||||||
{
|
|
||||||
public class AsyncTask : INotifyPropertyChanged
|
|
||||||
{
|
|
||||||
public AsyncTask(Func<object> valueFunc)
|
|
||||||
{
|
|
||||||
LoadValue(valueFunc);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadValue(Func<object> valueFunc)
|
|
||||||
{
|
|
||||||
var frame = new DispatcherFrame();
|
|
||||||
ThreadPool.QueueUserWorkItem(delegate
|
|
||||||
{
|
|
||||||
|
|
||||||
object returnValue =
|
|
||||||
AsyncValue = valueFunc();
|
|
||||||
if (PropertyChanged != null)
|
|
||||||
PropertyChanged(this, new PropertyChangedEventArgs("AsyncValue"));
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
|
||||||
|
|
||||||
public object AsyncValue
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,7 +13,6 @@ namespace Wox.ImageLoader
|
|||||||
public class ImageLoader
|
public class ImageLoader
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<string, ImageSource> imageCache = new Dictionary<string, ImageSource>();
|
private static readonly Dictionary<string, ImageSource> imageCache = new Dictionary<string, ImageSource>();
|
||||||
private static object locker = new object();
|
|
||||||
|
|
||||||
private static readonly List<string> imageExts = new List<string>
|
private static readonly List<string> imageExts = new List<string>
|
||||||
{
|
{
|
||||||
@@ -54,23 +53,20 @@ namespace Wox.ImageLoader
|
|||||||
{
|
{
|
||||||
//ImageCacheStroage.Instance.TopUsedImages can be changed during foreach, so we need to make a copy
|
//ImageCacheStroage.Instance.TopUsedImages can be changed during foreach, so we need to make a copy
|
||||||
var imageList = new Dictionary<string, int>(ImageCacheStroage.Instance.TopUsedImages);
|
var imageList = new Dictionary<string, int>(ImageCacheStroage.Instance.TopUsedImages);
|
||||||
using (new Timeit(string.Format("Preload {0} images",imageList.Count)))
|
using (new Timeit(string.Format("Preload {0} images", imageList.Count)))
|
||||||
{
|
{
|
||||||
foreach (var image in imageList)
|
foreach (var image in imageList)
|
||||||
{
|
{
|
||||||
ImageSource img = Load(image.Key, false);
|
if (!imageCache.ContainsKey(image.Key))
|
||||||
if (img != null)
|
|
||||||
{
|
{
|
||||||
img.Freeze(); //to make it copy to UI thread
|
ImageSource img = Load(image.Key, false);
|
||||||
if (!imageCache.ContainsKey(image.Key))
|
if (img != null)
|
||||||
{
|
{
|
||||||
lock (locker)
|
img.Freeze(); //to make it copy to UI thread
|
||||||
|
if (!imageCache.ContainsKey(image.Key))
|
||||||
{
|
{
|
||||||
if (!imageCache.ContainsKey(image.Key))
|
KeyValuePair<string, int> copyedImg = image;
|
||||||
{
|
App.Window.Dispatcher.Invoke(new Action(() => imageCache.Add(copyedImg.Key, img)));
|
||||||
KeyValuePair<string, int> copyedImg = image;
|
|
||||||
App.Window.Dispatcher.Invoke(new Action(() => imageCache.Add(copyedImg.Key, img)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +74,7 @@ namespace Wox.ImageLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImageSource Load(string path,bool addToCache = true)
|
public static ImageSource Load(string path, bool addToCache = true)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(path)) return null;
|
if (string.IsNullOrEmpty(path)) return null;
|
||||||
if (addToCache)
|
if (addToCache)
|
||||||
@@ -112,13 +108,7 @@ namespace Wox.ImageLoader
|
|||||||
{
|
{
|
||||||
if (!imageCache.ContainsKey(path))
|
if (!imageCache.ContainsKey(path))
|
||||||
{
|
{
|
||||||
lock (locker)
|
imageCache.Add(path, img);
|
||||||
{
|
|
||||||
if (!imageCache.ContainsKey(path))
|
|
||||||
{
|
|
||||||
imageCache.Add(path, img);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ namespace Wox
|
|||||||
|
|
||||||
public void InstallPlugin(string path)
|
public void InstallPlugin(string path)
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(() => PluginInstaller.Install(path)));
|
Dispatcher.Invoke(new Action(() => PluginManager.InstallPlugin(path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReloadPlugins()
|
public void ReloadPlugins()
|
||||||
@@ -172,14 +172,8 @@ namespace Wox
|
|||||||
pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent;
|
pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent;
|
||||||
|
|
||||||
ThreadPool.SetMaxThreads(30, 10);
|
ThreadPool.SetMaxThreads(30, 10);
|
||||||
try
|
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
|
||||||
{
|
|
||||||
SetTheme(UserSettingStorage.Instance.Theme);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
SetTheme(UserSettingStorage.Instance.Theme = "Dark");
|
|
||||||
}
|
|
||||||
|
|
||||||
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
|
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
|
||||||
SetCustomPluginHotkey();
|
SetCustomPluginHotkey();
|
||||||
@@ -676,44 +670,6 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTheme(string themeName)
|
|
||||||
{
|
|
||||||
var dict = new ResourceDictionary
|
|
||||||
{
|
|
||||||
Source = new Uri(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes\\" + themeName + ".xaml"), UriKind.Absolute)
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Style queryBoxStyle = dict["QueryBoxStyle"] as Style;
|
|
||||||
if (queryBoxStyle != null)
|
|
||||||
{
|
|
||||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont)));
|
|
||||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle)));
|
|
||||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight)));
|
|
||||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStretch)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Style resultItemStyle = dict["ItemTitleStyle"] as Style;
|
|
||||||
Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style;
|
|
||||||
Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style;
|
|
||||||
Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style;
|
|
||||||
if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null)
|
|
||||||
{
|
|
||||||
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont));
|
|
||||||
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle));
|
|
||||||
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight));
|
|
||||||
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStretch));
|
|
||||||
|
|
||||||
Setter[] setters = new Setter[] { fontFamily, fontStyle, fontWeight, fontStretch };
|
|
||||||
Array.ForEach(new Style[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Application.Current.Resources.MergedDictionaries.Clear();
|
|
||||||
Application.Current.Resources.MergedDictionaries.Add(dict);
|
|
||||||
|
|
||||||
this.Opacity = this.AllowsTransparency ? UserSettingStorage.Instance.Opacity : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ShellRun(string cmd, bool runAsAdministrator = false)
|
public bool ShellRun(string cmd, bool runAsAdministrator = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -739,7 +695,7 @@ namespace Wox
|
|||||||
string[] files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop);
|
string[] files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop);
|
||||||
if (files[0].ToLower().EndsWith(".wox"))
|
if (files[0].ToLower().EndsWith(".wox"))
|
||||||
{
|
{
|
||||||
PluginInstaller.Install(files[0]);
|
PluginManager.InstallPlugin(files[0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -172,8 +172,7 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
|
|
||||||
//PreviewPanel
|
//PreviewPanel
|
||||||
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
|
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Plugin
|
#region Plugin
|
||||||
@@ -366,7 +365,7 @@ namespace Wox
|
|||||||
private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
string themeName = themeComboBox.SelectedItem.ToString();
|
string themeName = themeComboBox.SelectedItem.ToString();
|
||||||
MainWindow.SetTheme(themeName);
|
ThemeManager.ChangeTheme(themeName);
|
||||||
UserSettingStorage.Instance.Theme = themeName;
|
UserSettingStorage.Instance.Theme = themeName;
|
||||||
UserSettingStorage.Instance.Save();
|
UserSettingStorage.Instance.Save();
|
||||||
}
|
}
|
||||||
@@ -379,7 +378,7 @@ namespace Wox
|
|||||||
this.cbQueryBoxFontFaces.SelectedItem = ((FontFamily)cbQueryBoxFont.SelectedItem).ChooseRegularFamilyTypeface();
|
this.cbQueryBoxFontFaces.SelectedItem = ((FontFamily)cbQueryBoxFont.SelectedItem).ChooseRegularFamilyTypeface();
|
||||||
|
|
||||||
UserSettingStorage.Instance.Save();
|
UserSettingStorage.Instance.Save();
|
||||||
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
|
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CbQueryBoxFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void CbQueryBoxFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
@@ -399,7 +398,7 @@ namespace Wox
|
|||||||
UserSettingStorage.Instance.QueryBoxFontWeight = typeface.Weight.ToString();
|
UserSettingStorage.Instance.QueryBoxFontWeight = typeface.Weight.ToString();
|
||||||
UserSettingStorage.Instance.QueryBoxFontStyle = typeface.Style.ToString();
|
UserSettingStorage.Instance.QueryBoxFontStyle = typeface.Style.ToString();
|
||||||
UserSettingStorage.Instance.Save();
|
UserSettingStorage.Instance.Save();
|
||||||
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
|
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,7 +410,7 @@ namespace Wox
|
|||||||
this.cbResultItemFontFaces.SelectedItem = ((FontFamily)cbResultItemFont.SelectedItem).ChooseRegularFamilyTypeface();
|
this.cbResultItemFontFaces.SelectedItem = ((FontFamily)cbResultItemFont.SelectedItem).ChooseRegularFamilyTypeface();
|
||||||
|
|
||||||
UserSettingStorage.Instance.Save();
|
UserSettingStorage.Instance.Save();
|
||||||
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
|
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CbResultItemFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void CbResultItemFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
@@ -422,8 +421,6 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
if (cbResultItemFontFaces.Items.Count > 0)
|
if (cbResultItemFontFaces.Items.Count > 0)
|
||||||
cbResultItemFontFaces.SelectedIndex = 0;
|
cbResultItemFontFaces.SelectedIndex = 0;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -431,7 +428,7 @@ namespace Wox
|
|||||||
UserSettingStorage.Instance.ResultItemFontWeight = typeface.Weight.ToString();
|
UserSettingStorage.Instance.ResultItemFontWeight = typeface.Weight.ToString();
|
||||||
UserSettingStorage.Instance.ResultItemFontStyle = typeface.Style.ToString();
|
UserSettingStorage.Instance.ResultItemFontStyle = typeface.Style.ToString();
|
||||||
UserSettingStorage.Instance.Save();
|
UserSettingStorage.Instance.Save();
|
||||||
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
|
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,7 +442,7 @@ namespace Wox
|
|||||||
else
|
else
|
||||||
PreviewMainPanel.Opacity = 1;
|
PreviewMainPanel.Opacity = 1;
|
||||||
|
|
||||||
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
|
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
104
Wox/ThemeManager.cs
Normal file
104
Wox/ThemeManager.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using Wox.Helper;
|
||||||
|
using Wox.Infrastructure.Storage.UserSettings;
|
||||||
|
|
||||||
|
namespace Wox
|
||||||
|
{
|
||||||
|
internal class ThemeManager
|
||||||
|
{
|
||||||
|
private static List<string> themeDirectories = new List<string>();
|
||||||
|
|
||||||
|
static ThemeManager()
|
||||||
|
{
|
||||||
|
themeDirectories.Add(
|
||||||
|
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Themes"));
|
||||||
|
|
||||||
|
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
|
||||||
|
if (userProfilePath != null)
|
||||||
|
{
|
||||||
|
themeDirectories.Add(Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Themes"));
|
||||||
|
}
|
||||||
|
|
||||||
|
MakesureThemeDirectoriesExist();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void MakesureThemeDirectoriesExist()
|
||||||
|
{
|
||||||
|
foreach (string pluginDirectory in themeDirectories)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(pluginDirectory))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(pluginDirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ChangeTheme(string themeName)
|
||||||
|
{
|
||||||
|
string themePath = GetThemePath(themeName);
|
||||||
|
if (string.IsNullOrEmpty(themePath))
|
||||||
|
{
|
||||||
|
themePath = GetThemePath("Dark");
|
||||||
|
if (string.IsNullOrEmpty(themePath))
|
||||||
|
{
|
||||||
|
throw new Exception("Change theme failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var dict = new ResourceDictionary
|
||||||
|
{
|
||||||
|
Source = new Uri(themePath, UriKind.Absolute)
|
||||||
|
};
|
||||||
|
|
||||||
|
Style queryBoxStyle = dict["QueryBoxStyle"] as Style;
|
||||||
|
if (queryBoxStyle != null)
|
||||||
|
{
|
||||||
|
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont)));
|
||||||
|
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle)));
|
||||||
|
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight)));
|
||||||
|
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStretch)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Style resultItemStyle = dict["ItemTitleStyle"] as Style;
|
||||||
|
Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style;
|
||||||
|
Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style;
|
||||||
|
Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style;
|
||||||
|
if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null)
|
||||||
|
{
|
||||||
|
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont));
|
||||||
|
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle));
|
||||||
|
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight));
|
||||||
|
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStretch));
|
||||||
|
|
||||||
|
Setter[] setters = new Setter[] { fontFamily, fontStyle, fontWeight, fontStretch };
|
||||||
|
Array.ForEach(new Style[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Application.Current.Resources.MergedDictionaries.Clear();
|
||||||
|
Application.Current.Resources.MergedDictionaries.Add(dict);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetThemePath(string themeName)
|
||||||
|
{
|
||||||
|
foreach (string themeDirectory in themeDirectories)
|
||||||
|
{
|
||||||
|
string path = Path.Combine(themeDirectory, themeName + ".xaml");
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -106,6 +106,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ImageLoader\ImageCacheStroage.cs" />
|
<Compile Include="ImageLoader\ImageCacheStroage.cs" />
|
||||||
<Compile Include="Storage\UserSelectedRecordStorage.cs" />
|
<Compile Include="Storage\UserSelectedRecordStorage.cs" />
|
||||||
|
<Compile Include="ThemeManager.cs" />
|
||||||
<Compile Include="Update\NewVersionWindow.xaml.cs">
|
<Compile Include="Update\NewVersionWindow.xaml.cs">
|
||||||
<DependentUpon>NewVersionWindow.xaml</DependentUpon>
|
<DependentUpon>NewVersionWindow.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -125,7 +126,6 @@
|
|||||||
<Compile Include="CommandArgs\PluginDebuggerCommandArg.cs" />
|
<Compile Include="CommandArgs\PluginDebuggerCommandArg.cs" />
|
||||||
<Compile Include="CommandArgs\QueryCommandArg.cs" />
|
<Compile Include="CommandArgs\QueryCommandArg.cs" />
|
||||||
<Compile Include="CommandArgs\ReloadPluginCommandArg.cs" />
|
<Compile Include="CommandArgs\ReloadPluginCommandArg.cs" />
|
||||||
<Compile Include="Converters\AsyncConverter.cs" />
|
|
||||||
<Compile Include="Converters\ConvertorBase.cs" />
|
<Compile Include="Converters\ConvertorBase.cs" />
|
||||||
<Compile Include="Helper\DataWebRequestFactory.cs" />
|
<Compile Include="Helper\DataWebRequestFactory.cs" />
|
||||||
<Compile Include="Helper\ErrorReporting\ErrorReporting.cs" />
|
<Compile Include="Helper\ErrorReporting\ErrorReporting.cs" />
|
||||||
@@ -145,7 +145,6 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Helper\DispatcherExtensions.cs" />
|
<Compile Include="Helper\DispatcherExtensions.cs" />
|
||||||
<Compile Include="Helper\DWMDropShadow.cs" />
|
<Compile Include="Helper\DWMDropShadow.cs" />
|
||||||
<Compile Include="Helper\PluginInstaller.cs" />
|
|
||||||
<Compile Include="HotkeyControl.xaml.cs">
|
<Compile Include="HotkeyControl.xaml.cs">
|
||||||
<DependentUpon>HotkeyControl.xaml</DependentUpon>
|
<DependentUpon>HotkeyControl.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -202,11 +201,6 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
<None Include="Themes\Dark.xaml">
|
|
||||||
<Generator>MSBuild:Compile</Generator>
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Include="Themes\Light.xaml">
|
<None Include="Themes\Light.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
@@ -227,6 +221,10 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<Page Include="Themes\Dark.xaml">
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</Page>
|
||||||
<Page Include="Update\NewVersionWindow.xaml">
|
<Page Include="Update\NewVersionWindow.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
|||||||
Reference in New Issue
Block a user