[StyleCop] Wox.Plugin - last amount needed to fully integrate (#5853)

* StyleCop for Plugin

* getting release mode working
This commit is contained in:
Clint Rutkas
2020-08-11 13:41:41 -07:00
committed by GitHub
parent 2c49df4be3
commit f1bb533321
20 changed files with 197 additions and 235 deletions

View File

@@ -8,15 +8,4 @@ namespace Wox.Plugin
{ {
public SpecialKeyState SpecialKeyState { get; set; } public SpecialKeyState SpecialKeyState { get; set; }
} }
public class SpecialKeyState
{
public bool CtrlPressed { get; set; }
public bool ShiftPressed { get; set; }
public bool AltPressed { get; set; }
public bool WinPressed { get; set; }
}
} }

View File

@@ -22,7 +22,7 @@ namespace Wox.Plugin
public ModifierKeys AcceleratorModifiers { get; set; } public ModifierKeys AcceleratorModifiers { get; set; }
/// <summary> /// <summary>
/// return true to hide wox after select result /// Gets or sets return true to hide wox after select result
/// </summary> /// </summary>
public Func<ActionContext, bool> Action { get; set; } public Func<ActionContext, bool> Action { get; set; }

View File

@@ -1,27 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Windows;
using System.Windows.Input;
namespace Wox.Plugin
{
public delegate void WoxKeyDownEventHandler(WoxKeyDownEventArgs e);
public delegate void AfterWoxQueryEventHandler(WoxQueryEventArgs e);
public delegate void ResultItemDropEventHandler(Result result, IDataObject dropObject, DragEventArgs e);
public class WoxKeyDownEventArgs
{
public string Query { get; set; }
public KeyEventArgs keyEventArgs { get; set; }
}
public class WoxQueryEventArgs
{
public Query Query { get; set; }
}
}

View File

@@ -1,56 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
namespace Wox.Plugin
{
public interface IFeatures { }
public interface IContextMenu : IFeatures
{
List<ContextMenuResult> LoadContextMenus(Result selectedResult);
}
[Obsolete("If a plugin has a action keyword, then it is exclusive. This interface will be remove in v1.3.0")]
public interface IExclusiveQuery : IFeatures
{
[Obsolete("If a plugin has a action keyword, then it is exclusive. This method will be remove in v1.3.0")]
bool IsExclusiveQuery(Query query);
}
/// <summary>
/// Represent plugin query will be executed in UI thread directly. Don't do long-running operation in Query method if you implement this interface
/// <remarks>This will improve the performance of instant search like websearch or cmd plugin</remarks>
/// </summary>
[Obsolete("Wox is fast enough now, executed on ui thread is no longer needed")]
public interface IInstantQuery : IFeatures
{
bool IsInstantQuery(string query);
}
/// <summary>
/// Represent plugins that support internationalization
/// </summary>
public interface IPluginI18n : IFeatures
{
string GetTranslatedPluginTitle();
string GetTranslatedPluginDescription();
}
public interface IResultUpdated : IFeatures
{
event ResultUpdatedEventHandler ResultsUpdated;
}
public delegate void ResultUpdatedEventHandler(IResultUpdated sender, ResultUpdatedEventArgs e);
public class ResultUpdatedEventArgs : EventArgs
{
public List<Result> Results;
public Query Query;
}
}

View File

@@ -1,13 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
namespace Wox.Plugin.Features
{
[Obsolete("Delete Wox.Plugin.Features using directive, " +
"and use Wox.Plugin.Feature.IContextMenu instead, " +
"this method will be removed in v1.3.0")]
public interface IContextMenu { }
}

View File

@@ -1,13 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
namespace Wox.Plugin.Features
{
[Obsolete("Delete Wox.Plugin.Features using directive, " +
"and use Wox.Plugin.Feature.IInstantQuery instead, " +
"this method will be removed in v1.3.0")]
public interface IExclusiveQuery { }
}

View File

@@ -1,13 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
namespace Wox.Plugin.Features
{
[Obsolete("Delete Wox.Plugin.Features using directive, " +
"and use Wox.Plugin.Feature.IInstantQuery instead, " +
"this method will be removed in v1.3.0")]
public interface IInstantQuery { }
}

View File

@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
namespace Wox.Plugin
{
public interface IFeatures
{
}
public interface IContextMenu : IFeatures
{
List<ContextMenuResult> LoadContextMenus(Result selectedResult);
}
/// <summary>
/// Represent plugins that support internationalization
/// </summary>
public interface IPluginI18n : IFeatures
{
string GetTranslatedPluginTitle();
string GetTranslatedPluginDescription();
}
public interface IResultUpdated : IFeatures
{
event ResultUpdatedEventHandler ResultsUpdated;
}
public delegate void ResultUpdatedEventHandler(IResultUpdated sender, ResultUpdatedEventArgs e);
}

View File

@@ -9,7 +9,7 @@ namespace Wox.Plugin
public PluginMetadata CurrentPluginMetadata { get; internal set; } public PluginMetadata CurrentPluginMetadata { get; internal set; }
/// <summary> /// <summary>
/// Public APIs for plugin invocation /// Gets or sets public APIs for plugin invocation
/// </summary> /// </summary>
public IPublicAPI API { get; set; } public IPublicAPI API { get; set; }
} }

View File

@@ -36,7 +36,10 @@ namespace Wox.Plugin
public string PluginDirectory public string PluginDirectory
{ {
get { return _pluginDirectory; } get
{
return _pluginDirectory;
}
internal set internal set
{ {
@@ -61,7 +64,7 @@ namespace Wox.Plugin
public string FullIcoPath => IcoPath; public string FullIcoPath => IcoPath;
/// <summary> /// <summary>
/// Init time include both plugin load time and init time /// Gets or sets init time include both plugin load time and init time
/// </summary> /// </summary>
[JsonIgnore] [JsonIgnore]
public long InitTime { get; set; } public long InitTime { get; set; }

View File

@@ -10,8 +10,6 @@ namespace Wox.Plugin
public PluginMetadata Metadata { get; internal set; } public PluginMetadata Metadata { get; internal set; }
public override string ToString() public override string ToString()
{ {
return Metadata.Name; return Metadata.Name;
@@ -19,8 +17,7 @@ namespace Wox.Plugin
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
PluginPair r = obj as PluginPair; if (obj is PluginPair r)
if (r != null)
{ {
return string.Equals(r.Metadata.ID, Metadata.ID); return string.Equals(r.Metadata.ID, Metadata.ID);
} }

View File

@@ -10,9 +10,12 @@ namespace Wox.Plugin
{ {
public class Query public class Query
{ {
internal Query() { } internal Query()
{
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Query"/> class.
/// to allow unit tests for plug ins /// to allow unit tests for plug ins
/// </summary> /// </summary>
public Query(string rawQuery, string search, string[] terms, string actionKeyword = "") public Query(string rawQuery, string search, string[] terms, string actionKeyword = "")
@@ -24,13 +27,13 @@ namespace Wox.Plugin
} }
/// <summary> /// <summary>
/// Raw query, this includes action keyword if it has /// Gets raw query, this includes action keyword if it has
/// We didn't recommend use this property directly. You should always use Search property. /// We didn't recommend use this property directly. You should always use Search property.
/// </summary> /// </summary>
public string RawQuery { get; internal set; } public string RawQuery { get; internal set; }
/// <summary> /// <summary>
/// Search part of a query. /// Gets search part of a query.
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery. /// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
/// Since we allow user to switch a exclusive plugin to generic plugin, /// Since we allow user to switch a exclusive plugin to generic plugin,
/// so this property will always give you the "real" query part of the query /// so this property will always give you the "real" query part of the query
@@ -38,7 +41,7 @@ namespace Wox.Plugin
public string Search { get; internal set; } public string Search { get; internal set; }
/// <summary> /// <summary>
/// The raw query splited into a string array. /// Gets or sets the raw query splited into a string array.
/// </summary> /// </summary>
public string[] Terms { get; set; } public string[] Terms { get; set; }
@@ -46,6 +49,7 @@ namespace Wox.Plugin
/// Query can be splited into multiple terms by whitespace /// Query can be splited into multiple terms by whitespace
/// </summary> /// </summary>
public const string TermSeparator = " "; public const string TermSeparator = " ";
/// <summary> /// <summary>
/// User can set multiple action keywords separated by ';' /// User can set multiple action keywords separated by ';'
/// </summary> /// </summary>
@@ -59,12 +63,12 @@ namespace Wox.Plugin
public string ActionKeyword { get; set; } public string ActionKeyword { get; set; }
/// <summary> /// <summary>
/// Return first search split by space if it has /// Gets return first search split by space if it has
/// </summary> /// </summary>
public string FirstSearch => SplitSearch(0); public string FirstSearch => SplitSearch(0);
/// <summary> /// <summary>
/// strings from second search (including) to last search /// Gets strings from second search (including) to last search
/// </summary> /// </summary>
public string SecondToEndSearch public string SecondToEndSearch
{ {
@@ -76,12 +80,12 @@ namespace Wox.Plugin
} }
/// <summary> /// <summary>
/// Return second search split by space if it has /// Gets return second search split by space if it has
/// </summary> /// </summary>
public string SecondSearch => SplitSearch(1); public string SecondSearch => SplitSearch(1);
/// <summary> /// <summary>
/// Return third search split by space if it has /// Gets return third search split by space if it has
/// </summary> /// </summary>
public string ThirdSearch => SplitSearch(2); public string ThirdSearch => SplitSearch(2);

View File

@@ -19,7 +19,10 @@ namespace Wox.Plugin
public string Title public string Title
{ {
get { return _title; } get
{
return _title;
}
set set
{ {
@@ -50,13 +53,16 @@ namespace Wox.Plugin
} }
/// <summary> /// <summary>
/// The text that will get displayed in the Search text box, when this item is selected in the result list. /// Gets or sets the text that will get displayed in the Search text box, when this item is selected in the result list.
/// </summary> /// </summary>
public string QueryTextDisplay { get; set; } public string QueryTextDisplay { get; set; }
public string IcoPath public string IcoPath
{ {
get { return _icoPath; } get
{
return _icoPath;
}
set set
{ {
@@ -73,37 +79,39 @@ namespace Wox.Plugin
public delegate ImageSource IconDelegate(); public delegate ImageSource IconDelegate();
public IconDelegate Icon; public IconDelegate Icon { get; set; }
/// <summary> /// <summary>
/// return true to hide wox after select result /// Gets or sets return true to hide wox after select result
/// </summary> /// </summary>
public Func<ActionContext, bool> Action { get; set; } public Func<ActionContext, bool> Action { get; set; }
public int Score { get; set; } public int Score { get; set; }
/// <summary> /// <summary>
/// A list of indexes for the characters to be highlighted in Title /// Gets or sets a list of indexes for the characters to be highlighted in Title
/// </summary> /// </summary>
public IList<int> TitleHighlightData { get; set; } public IList<int> TitleHighlightData { get; set; }
/// <summary> /// <summary>
/// A list of indexes for the characters to be highlighted in SubTitle /// Gets or sets a list of indexes for the characters to be highlighted in SubTitle
/// </summary> /// </summary>
public IList<int> SubTitleHighlightData { get; set; } public IList<int> SubTitleHighlightData { get; set; }
/// <summary> /// <summary>
/// Only results that originQuery match with current query will be displayed in the panel /// Gets or sets only results that originQuery match with current query will be displayed in the panel
/// </summary> /// </summary>
internal Query OriginQuery { get; set; } internal Query OriginQuery { get; set; }
/// <summary> /// <summary>
/// Plugin directory /// Gets or sets plugin directory
/// </summary> /// </summary>
public string PluginDirectory public string PluginDirectory
{ {
get { return _pluginDirectory; } get
{
return _pluginDirectory;
}
set set
{ {
@@ -140,29 +148,17 @@ namespace Wox.Plugin
return Title + SubTitle; return Title + SubTitle;
} }
[Obsolete("Use IContextMenu instead")] public Result()
/// <summary>
/// Context menus associate with this result
/// </summary>
public List<Result> ContextMenu { get; set; }
[Obsolete("Use Object initializers instead")]
public Result(string Title, string IcoPath, string SubTitle = null)
{ {
this.Title = Title;
this.IcoPath = IcoPath;
this.SubTitle = SubTitle;
} }
public Result() { }
/// <summary> /// <summary>
/// Additional data associate with this result /// Gets or sets additional data associate with this result
/// </summary> /// </summary>
public object ContextData { get; set; } public object ContextData { get; set; }
/// <summary> /// <summary>
/// Plugin ID that generated this result /// Gets plugin ID that generated this result
/// </summary> /// </summary>
public string PluginID { get; internal set; } public string PluginID { get; internal set; }
} }

View File

@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
namespace Wox.Plugin
{
public class ResultUpdatedEventArgs : EventArgs
{
public List<Result> Results { get; set; }
public Query Query { get; set; }
}
}

View File

@@ -4,7 +4,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Windows;
namespace Wox.Plugin.SharedCommands namespace Wox.Plugin.SharedCommands
{ {
@@ -25,6 +24,7 @@ namespace Wox.Plugin.SharedCommands
try try
{ {
DirectoryInfo[] dirs = dir.GetDirectories(); DirectoryInfo[] dirs = dir.GetDirectories();
// If the destination directory doesn't exist, create it. // If the destination directory doesn't exist, create it.
if (!Directory.Exists(targetPath)) if (!Directory.Exists(targetPath))
{ {
@@ -51,11 +51,10 @@ namespace Wox.Plugin.SharedCommands
#if DEBUG #if DEBUG
throw e; throw e;
#else #else
MessageBox.Show(string.Format("Copying path {0} has failed, it will now be deleted for consistency", targetPath)); System.Windows.MessageBox.Show(string.Format("Copying path {0} has failed, it will now be deleted for consistency", targetPath));
RemoveFolder(targetPath); RemoveFolder(targetPath);
#endif #endif
} }
} }
public static bool VerifyBothFolderFilesEqual(this string fromPath, string toPath) public static bool VerifyBothFolderFilesEqual(this string fromPath, string toPath)
@@ -66,10 +65,14 @@ namespace Wox.Plugin.SharedCommands
var toDir = new DirectoryInfo(toPath); var toDir = new DirectoryInfo(toPath);
if (fromDir.GetFiles("*", SearchOption.AllDirectories).Length != toDir.GetFiles("*", SearchOption.AllDirectories).Length) if (fromDir.GetFiles("*", SearchOption.AllDirectories).Length != toDir.GetFiles("*", SearchOption.AllDirectories).Length)
{
return false; return false;
}
if (fromDir.GetDirectories("*", SearchOption.AllDirectories).Length != toDir.GetDirectories("*", SearchOption.AllDirectories).Length) if (fromDir.GetDirectories("*", SearchOption.AllDirectories).Length != toDir.GetDirectories("*", SearchOption.AllDirectories).Length)
{
return false; return false;
}
return true; return true;
} }
@@ -78,11 +81,10 @@ namespace Wox.Plugin.SharedCommands
#if DEBUG #if DEBUG
throw e; throw e;
#else #else
MessageBox.Show(string.Format("Unable to verify folders and files between {0} and {1}", fromPath, toPath)); System.Windows.MessageBox.Show(string.Format("Unable to verify folders and files between {0} and {1}", fromPath, toPath));
return false; return false;
#endif #endif
} }
} }
public static void RemoveFolder(this string path) public static void RemoveFolder(this string path)
@@ -90,14 +92,16 @@ namespace Wox.Plugin.SharedCommands
try try
{ {
if (Directory.Exists(path)) if (Directory.Exists(path))
{
Directory.Delete(path, true); Directory.Delete(path, true);
}
} }
catch (Exception e) catch (Exception e)
{ {
#if DEBUG #if DEBUG
throw e; throw e;
#else #else
MessageBox.Show(string.Format("Not able to delete folder {0}, please go to the location and manually delete it", path)); System.Windows.MessageBox.Show(string.Format("Not able to delete folder {0}, please go to the location and manually delete it", path));
#endif #endif
} }
} }

View File

@@ -15,7 +15,7 @@ namespace Wox.Plugin.SharedCommands
/// Opens search in a new browser. If no browser path is passed in then Chrome is used. /// Opens search in a new browser. If no browser path is passed in then Chrome is used.
/// Leave browser path blank to use Chrome. /// Leave browser path blank to use Chrome.
/// </summary> /// </summary>
public static void NewBrowserWindow(this string url, string browserPath) public static void NewBrowserWindow(this string url, string browserPath)
{ {
var browserExecutableName = browserPath? var browserExecutableName = browserPath?
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None) .Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
@@ -35,7 +35,7 @@ namespace Wox.Plugin.SharedCommands
var psi = new ProcessStartInfo var psi = new ProcessStartInfo
{ {
FileName = url, FileName = url,
UseShellExecute = true UseShellExecute = true,
}; };
Process.Start(psi); Process.Start(psi);
} }

View File

@@ -14,11 +14,14 @@ namespace Wox.Plugin.SharedCommands
{ {
public delegate bool EnumThreadDelegate(IntPtr hwnd, IntPtr lParam); public delegate bool EnumThreadDelegate(IntPtr hwnd, IntPtr lParam);
[DllImport("user32.dll")] static extern bool EnumThreadWindows(uint threadId, EnumThreadDelegate lpfn, IntPtr lParam); [DllImport("user32.dll")]
private static extern bool EnumThreadWindows(uint threadId, EnumThreadDelegate lpfn, IntPtr lParam);
[DllImport("user32.dll")] static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int nMaxCount); [DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")] static extern int GetWindowTextLength(IntPtr hwnd); [DllImport("user32.dll")]
private static extern int GetWindowTextLength(IntPtr hwnd);
private static bool containsSecurityWindow; private static bool containsSecurityWindow;
@@ -28,13 +31,16 @@ namespace Wox.Plugin.SharedCommands
var process = Process.Start(processStartInfo); var process = Process.Start(processStartInfo);
containsSecurityWindow = false; containsSecurityWindow = false;
while (!containsSecurityWindow) // wait for windows to bring up the "Windows Security" dialog
// wait for windows to bring up the "Windows Security" dialog
while (!containsSecurityWindow)
{ {
CheckSecurityWindow(); CheckSecurityWindow();
Thread.Sleep(25); Thread.Sleep(25);
} }
while (containsSecurityWindow) // while this process contains a "Windows Security" dialog, stay open // while this process contains a "Windows Security" dialog, stay open
while (containsSecurityWindow)
{ {
containsSecurityWindow = false; containsSecurityWindow = false;
CheckSecurityWindow(); CheckSecurityWindow();
@@ -48,13 +54,18 @@ namespace Wox.Plugin.SharedCommands
{ {
ProcessThreadCollection ptc = Process.GetCurrentProcess().Threads; ProcessThreadCollection ptc = Process.GetCurrentProcess().Threads;
for (int i = 0; i < ptc.Count; i++) for (int i = 0; i < ptc.Count; i++)
{
EnumThreadWindows((uint)ptc[i].Id, CheckSecurityThread, IntPtr.Zero); EnumThreadWindows((uint)ptc[i].Id, CheckSecurityThread, IntPtr.Zero);
}
} }
private static bool CheckSecurityThread(IntPtr hwnd, IntPtr lParam) private static bool CheckSecurityThread(IntPtr hwnd, IntPtr lParam)
{ {
if (GetWindowTitle(hwnd) == "Windows Security") if (GetWindowTitle(hwnd) == "Windows Security")
{
containsSecurityWindow = true; containsSecurityWindow = true;
}
return true; return true;
} }
@@ -72,7 +83,7 @@ namespace Wox.Plugin.SharedCommands
FileName = fileName, FileName = fileName,
WorkingDirectory = workingDirectory, WorkingDirectory = workingDirectory,
Arguments = arguments, Arguments = arguments,
Verb = verb Verb = verb,
}; };
return info; return info;

View File

@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Wox.Plugin
{
public class SpecialKeyState
{
public bool CtrlPressed { get; set; }
public bool ShiftPressed { get; set; }
public bool AltPressed { get; set; }
public bool WinPressed { get; set; }
}
}

View File

@@ -13,47 +13,54 @@ namespace Wox.Plugin
{ {
public class ThemeManager : IDisposable public class ThemeManager : IDisposable
{ {
private readonly Application _app;
private const string LightTheme = "Light.Accent1";
private const string DarkTheme = "Dark.Accent1";
private const string HighContrastOneTheme = "HighContrast.Accent2";
private const string HighContrastTwoTheme = "HighContrast.Accent3";
private const string HighContrastBlackTheme = "HighContrast.Accent4";
private const string HighContrastWhiteTheme = "HighContrast.Accent5";
private Theme currentTheme; private Theme currentTheme;
private readonly Application App;
private bool _disposed = false; private bool _disposed = false;
private readonly string LightTheme = "Light.Accent1";
private readonly string DarkTheme = "Dark.Accent1";
private readonly string HighContrastOneTheme = "HighContrast.Accent2";
private readonly string HighContrastTwoTheme = "HighContrast.Accent3";
private readonly string HighContrastBlackTheme = "HighContrast.Accent4";
private readonly string HighContrastWhiteTheme = "HighContrast.Accent5";
public event ThemeChangedHandler ThemeChanged; public event ThemeChangedHandler ThemeChanged;
public ThemeManager(Application app) public ThemeManager(Application app)
{ {
this.App = app; _app = app;
Uri HighContrastOneThemeUri = new Uri("pack://application:,,,/Themes/HighContrast1.xaml"); Uri highContrastOneThemeUri = new Uri("pack://application:,,,/Themes/HighContrast1.xaml");
Uri HighContrastTwoThemeUri = new Uri("pack://application:,,,/Themes/HighContrast2.xaml"); Uri highContrastTwoThemeUri = new Uri("pack://application:,,,/Themes/HighContrast2.xaml");
Uri HighContrastBlackThemeUri = new Uri("pack://application:,,,/Themes/HighContrastWhite.xaml"); Uri highContrastBlackThemeUri = new Uri("pack://application:,,,/Themes/HighContrastWhite.xaml");
Uri HighContrastWhiteThemeUri = new Uri("pack://application:,,,/Themes/HighContrastBlack.xaml"); Uri highContrastWhiteThemeUri = new Uri("pack://application:,,,/Themes/HighContrastBlack.xaml");
Uri LightThemeUri = new Uri("pack://application:,,,/Themes/Light.xaml"); Uri lightThemeUri = new Uri("pack://application:,,,/Themes/Light.xaml");
Uri DarkThemeUri = new Uri("pack://application:,,,/Themes/Dark.xaml"); Uri darkThemeUri = new Uri("pack://application:,,,/Themes/Dark.xaml");
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
new LibraryTheme(HighContrastOneThemeUri, new LibraryTheme(
MahAppsLibraryThemeProvider.DefaultInstance)); highContrastOneThemeUri,
MahAppsLibraryThemeProvider.DefaultInstance));
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
new LibraryTheme(HighContrastTwoThemeUri, new LibraryTheme(
MahAppsLibraryThemeProvider.DefaultInstance)); highContrastTwoThemeUri,
MahAppsLibraryThemeProvider.DefaultInstance));
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
new LibraryTheme(HighContrastBlackThemeUri, new LibraryTheme(
MahAppsLibraryThemeProvider.DefaultInstance)); highContrastBlackThemeUri,
MahAppsLibraryThemeProvider.DefaultInstance));
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
new LibraryTheme(HighContrastWhiteThemeUri, new LibraryTheme(
MahAppsLibraryThemeProvider.DefaultInstance)); highContrastWhiteThemeUri,
MahAppsLibraryThemeProvider.DefaultInstance));
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
new LibraryTheme(LightThemeUri, new LibraryTheme(
MahAppsLibraryThemeProvider.DefaultInstance)); lightThemeUri,
MahAppsLibraryThemeProvider.DefaultInstance));
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
new LibraryTheme(DarkThemeUri, new LibraryTheme(
MahAppsLibraryThemeProvider.DefaultInstance)); darkThemeUri,
MahAppsLibraryThemeProvider.DefaultInstance));
ResetTheme(); ResetTheme();
ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAppMode; ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAppMode;
@@ -76,20 +83,23 @@ namespace Wox.Plugin
private static Theme GetHighContrastBaseType() private static Theme GetHighContrastBaseType()
{ {
string RegistryKey = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes"; string registryKey = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes";
string theme = (string)Registry.GetValue(RegistryKey, "CurrentTheme", string.Empty); string theme = (string)Registry.GetValue(registryKey, "CurrentTheme", string.Empty);
theme = theme.Split('\\').Last().Split('.').First().ToString(); theme = theme.Split('\\').Last().Split('.').First().ToString();
if (theme == "hc1") switch (theme)
return Theme.HighContrastOne; {
else if (theme == "hc2") case "hc1":
return Theme.HighContrastTwo; return Theme.HighContrastOne;
else if (theme == "hcwhite") case "hc2":
return Theme.HighContrastWhite; return Theme.HighContrastTwo;
else if (theme == "hcblack") case "hcwhite":
return Theme.HighContrastBlack; return Theme.HighContrastWhite;
else case "hcblack":
return Theme.None; return Theme.HighContrastBlack;
default:
return Theme.None;
}
} }
private void ResetTheme() private void ResetTheme()
@@ -110,35 +120,38 @@ namespace Wox.Plugin
{ {
Theme oldTheme = currentTheme; Theme oldTheme = currentTheme;
if (theme == currentTheme) if (theme == currentTheme)
{
return; return;
}
if (theme == Theme.HighContrastOne) if (theme == Theme.HighContrastOne)
{ {
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.HighContrastOneTheme); ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastOneTheme);
currentTheme = Theme.HighContrastOne; currentTheme = Theme.HighContrastOne;
} }
else if (theme == Theme.HighContrastTwo) else if (theme == Theme.HighContrastTwo)
{ {
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.HighContrastTwoTheme); ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastTwoTheme);
currentTheme = Theme.HighContrastTwo; currentTheme = Theme.HighContrastTwo;
} }
else if (theme == Theme.HighContrastWhite) else if (theme == Theme.HighContrastWhite)
{ {
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.HighContrastWhiteTheme); ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastWhiteTheme);
currentTheme = Theme.HighContrastWhite; currentTheme = Theme.HighContrastWhite;
} }
else if (theme == Theme.HighContrastBlack) else if (theme == Theme.HighContrastBlack)
{ {
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.HighContrastBlackTheme); ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastBlackTheme);
currentTheme = Theme.HighContrastBlack; currentTheme = Theme.HighContrastBlack;
} }
else if (theme == Theme.Light) else if (theme == Theme.Light)
{ {
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.LightTheme); ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, LightTheme);
currentTheme = Theme.Light; currentTheme = Theme.Light;
} }
else if (theme == Theme.Dark) else if (theme == Theme.Dark)
{ {
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.DarkTheme); ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, DarkTheme);
currentTheme = Theme.Dark; currentTheme = Theme.Dark;
} }
else else

View File

@@ -68,7 +68,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\core\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj" /> <ProjectReference Include="..\..\..\core\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj" />
</ItemGroup> </ItemGroup>
<!--<ItemGroup> <ItemGroup>
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs"> <Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link> <Link>GlobalSuppressions.cs</Link>
</Compile> </Compile>
@@ -82,5 +82,5 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
</ItemGroup>--> </ItemGroup>
</Project> </Project>