From 146e7866a63b10634b577a39c034017c7a1ba364 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Sat, 24 Oct 2020 00:05:07 +0200 Subject: [PATCH] [PT Run] Option for override theme (#7355) * option for override PT Run theme * fix startup theme detection and moved strings in resources * xaml fixed * fix title spacing * launcher theme fix moved theme enum removed settings direct access * missing files * theme manager dispose removed Co-authored-by: Clint Rutkas --- src/common/ManagedCommon/Theme.cs | 17 ++++ ...osoft.PowerToys.Settings.UI.Library.csproj | 1 + .../PowerLauncherProperties.cs | 5 ++ .../ViewModels/PowerLauncherViewModel.cs | 75 +++++++++++++++++ .../Strings/en-us/Resources.resw | 12 +++ .../Views/PowerLauncherPage.xaml | 15 ++++ .../Microsoft.Plugin.Calculator/Main.cs | 1 + .../Plugins/Microsoft.Plugin.Folder/Main.cs | 1 + .../Sources/QueryInternalDirectory.cs | 1 + .../Plugins/Microsoft.Plugin.Indexer/Main.cs | 1 + .../Plugins/Microsoft.Plugin.Program/Main.cs | 1 + .../Programs/UWPApplication.cs | 1 + .../Plugins/Microsoft.Plugin.Shell/Main.cs | 1 + .../Plugins/Microsoft.Plugin.Uri/Main.cs | 1 + .../Microsoft.Plugin.WindowWalker/Main.cs | 1 + .../launcher/PowerLauncher/App.xaml.cs | 2 +- .../PowerLauncher/PublicAPIInstance.cs | 1 + .../launcher/PowerLauncher/SettingsWatcher.cs | 11 ++- .../Wox.Infrastructure/Image/ImageLoader.cs | 1 + .../UserSettings/Settings.cs | 3 +- src/modules/launcher/Wox.Plugin/IPublicAPI.cs | 2 +- .../launcher/Wox.Plugin/ThemeManager.cs | 82 +++++++++---------- .../launcher/Wox.Plugin/Wox.Plugin.csproj | 1 + 23 files changed, 189 insertions(+), 48 deletions(-) create mode 100644 src/common/ManagedCommon/Theme.cs diff --git a/src/common/ManagedCommon/Theme.cs b/src/common/ManagedCommon/Theme.cs new file mode 100644 index 0000000000..4e0cda2f3b --- /dev/null +++ b/src/common/ManagedCommon/Theme.cs @@ -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 ManagedCommon +{ + public enum Theme + { + System, + Light, + Dark, + HighContrastOne, + HighContrastTwo, + HighContrastBlack, + HighContrastWhite, + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Library/Microsoft.PowerToys.Settings.UI.Library.csproj b/src/core/Microsoft.PowerToys.Settings.UI.Library/Microsoft.PowerToys.Settings.UI.Library.csproj index 4deb2dea1e..4c94051072 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Library/Microsoft.PowerToys.Settings.UI.Library.csproj +++ b/src/core/Microsoft.PowerToys.Settings.UI.Library/Microsoft.PowerToys.Settings.UI.Library.csproj @@ -51,6 +51,7 @@ + diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Library/PowerLauncherProperties.cs b/src/core/Microsoft.PowerToys.Settings.UI.Library/PowerLauncherProperties.cs index dc96ff0c1a..4bc5a774e1 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Library/PowerLauncherProperties.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Library/PowerLauncherProperties.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Text.Json.Serialization; +using ManagedCommon; namespace Microsoft.PowerToys.Settings.UI.Library { @@ -44,6 +45,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library [JsonPropertyName("clear_input_on_launch")] public bool ClearInputOnLaunch { get; set; } + [JsonPropertyName("theme")] + public Theme Theme { get; set; } + public PowerLauncherProperties() { OpenPowerLauncher = new HotkeySettings(false, false, true, false, 32); @@ -56,6 +60,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library DisableDriveDetectionWarning = false; ClearInputOnLaunch = false; MaximumNumberOfResults = 4; + Theme = Theme.System; } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/PowerLauncherViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/PowerLauncherViewModel.cs index 89fe413ff4..6670f185fd 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/PowerLauncherViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Library/ViewModels/PowerLauncherViewModel.cs @@ -6,6 +6,7 @@ using System; using System.Globalization; using System.Runtime.CompilerServices; using System.Text.Json; +using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; @@ -13,6 +14,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels { public class PowerLauncherViewModel : Observable { + private bool _isDarkThemeRadioButtonChecked; + private bool _isLightThemeRadioButtonChecked; + private bool _isSystemThemeRadioButtonChecked; + private GeneralSettings GeneralSettingsConfig { get; set; } private readonly ISettingsUtils _settingsUtils; @@ -63,6 +68,19 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels settings.Properties.MaximumNumberOfResults = 4; callback(settings); } + + switch (settings.Properties.Theme) + { + case Theme.Light: + _isLightThemeRadioButtonChecked = true; + break; + case Theme.Dark: + _isDarkThemeRadioButtonChecked = true; + break; + case Theme.System: + _isSystemThemeRadioButtonChecked = true; + break; + } } public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback) @@ -149,6 +167,63 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels } } + public bool IsDarkThemeRadioButtonChecked + { + get + { + return _isDarkThemeRadioButtonChecked; + } + + set + { + if (value == true) + { + settings.Properties.Theme = Theme.Dark; + _isDarkThemeRadioButtonChecked = value; + + UpdateSettings(); + } + } + } + + public bool IsLightThemeRadioButtonChecked + { + get + { + return _isLightThemeRadioButtonChecked; + } + + set + { + if (value == true) + { + settings.Properties.Theme = Theme.Light; + _isDarkThemeRadioButtonChecked = value; + + UpdateSettings(); + } + } + } + + public bool IsSystemThemeRadioButtonChecked + { + get + { + return _isSystemThemeRadioButtonChecked; + } + + set + { + if (value == true) + { + settings.Properties.Theme = Theme.System; + _isDarkThemeRadioButtonChecked = value; + + UpdateSettings(); + } + } + } + public HotkeySettings OpenPowerLauncher { get diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw b/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw index 774adf76d0..4950b64dc0 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw +++ b/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw @@ -302,6 +302,9 @@ Clear the previous query on launch + + Choose color + To: Keyboard Manager mapping keys view right header @@ -774,4 +777,13 @@ Example: %1 (%2) + + Dark + + + System default + + + Light + \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerLauncherPage.xaml b/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerLauncherPage.xaml index 95331f4e55..4e2df36ca7 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerLauncherPage.xaml +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerLauncherPage.xaml @@ -143,7 +143,22 @@ IsChecked="{x:Bind Mode=TwoWay, Path=ViewModel.DisableDriveDetectionWarning}" IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.EnablePowerLauncher}" /> + + + + + + + + /// Get all loaded plugins /// - /// List GetAllPlugins(); } } diff --git a/src/modules/launcher/Wox.Plugin/ThemeManager.cs b/src/modules/launcher/Wox.Plugin/ThemeManager.cs index 5b73bbeb88..ee45ae06d9 100644 --- a/src/modules/launcher/Wox.Plugin/ThemeManager.cs +++ b/src/modules/launcher/Wox.Plugin/ThemeManager.cs @@ -3,11 +3,10 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics; using System.Linq; using System.Windows; -using ControlzEx.Theming; using MahApps.Metro.Theming; +using ManagedCommon; using Microsoft.Win32; namespace Wox.Plugin @@ -39,32 +38,32 @@ namespace Wox.Plugin Uri darkThemeUri = new Uri("pack://application:,,,/Themes/Dark.xaml"); ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( + new ControlzEx.Theming.LibraryTheme( highContrastOneThemeUri, MahAppsLibraryThemeProvider.DefaultInstance)); ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( + new ControlzEx.Theming.LibraryTheme( highContrastTwoThemeUri, MahAppsLibraryThemeProvider.DefaultInstance)); ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( + new ControlzEx.Theming.LibraryTheme( highContrastBlackThemeUri, MahAppsLibraryThemeProvider.DefaultInstance)); ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( + new ControlzEx.Theming.LibraryTheme( highContrastWhiteThemeUri, MahAppsLibraryThemeProvider.DefaultInstance)); ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( + new ControlzEx.Theming.LibraryTheme( lightThemeUri, MahAppsLibraryThemeProvider.DefaultInstance)); ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( + new ControlzEx.Theming.LibraryTheme( darkThemeUri, MahAppsLibraryThemeProvider.DefaultInstance)); ResetTheme(); - ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncAll; + ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ControlzEx.Theming.ThemeSyncMode.SyncAll; ControlzEx.Theming.ThemeManager.Current.ThemeChanged += Current_ThemeChanged; } @@ -90,67 +89,73 @@ namespace Wox.Plugin case "hcblack": return Theme.HighContrastBlack; default: - return Theme.None; + return Theme.HighContrastOne; } } private void ResetTheme() { - if (WindowsThemeHelper.IsHighContrastEnabled()) - { - Theme highContrastBaseType = GetHighContrastBaseType(); - ChangeTheme(highContrastBaseType); - } - else - { - string baseColor = WindowsThemeHelper.GetWindowsBaseColor(); - ChangeTheme((Theme)Enum.Parse(typeof(Theme), baseColor)); - } + ChangeTheme(currentTheme, false); } - private void ChangeTheme(Theme theme) + public void ChangeTheme(Theme theme, bool forceSystem) { Theme oldTheme = currentTheme; - if (theme == Theme.HighContrastOne) + if (theme == Theme.System) + { + currentTheme = Theme.System; + if (ControlzEx.Theming.WindowsThemeHelper.IsHighContrastEnabled()) + { + Theme highContrastBaseType = GetHighContrastBaseType(); + ChangeTheme(highContrastBaseType, true); + } + else + { + string baseColor = ControlzEx.Theming.WindowsThemeHelper.GetWindowsBaseColor(); + ChangeTheme((Theme)Enum.Parse(typeof(Theme), baseColor), true); + } + } + else if (theme == Theme.HighContrastOne) { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastOneTheme); currentTheme = Theme.HighContrastOne; + ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastOneTheme); } else if (theme == Theme.HighContrastTwo) { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastTwoTheme); currentTheme = Theme.HighContrastTwo; + ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastTwoTheme); } else if (theme == Theme.HighContrastWhite) { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastWhiteTheme); currentTheme = Theme.HighContrastWhite; + ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastWhiteTheme); } else if (theme == Theme.HighContrastBlack) { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastBlackTheme); currentTheme = Theme.HighContrastBlack; + ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastBlackTheme); } else if (theme == Theme.Light) { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, LightTheme); currentTheme = Theme.Light; + ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, LightTheme); } else if (theme == Theme.Dark) { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, DarkTheme); currentTheme = Theme.Dark; - } - else - { - currentTheme = Theme.None; + ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, DarkTheme); } ThemeChanged?.Invoke(oldTheme, currentTheme); + + if (forceSystem) + { + currentTheme = Theme.System; + } } - private void Current_ThemeChanged(object sender, ThemeChangedEventArgs e) + private void Current_ThemeChanged(object sender, ControlzEx.Theming.ThemeChangedEventArgs e) { ResetTheme(); } @@ -175,15 +180,4 @@ namespace Wox.Plugin } public delegate void ThemeChangedHandler(Theme oldTheme, Theme newTheme); - - public enum Theme - { - None, - Light, - Dark, - HighContrastOne, - HighContrastTwo, - HighContrastBlack, - HighContrastWhite, - } } diff --git a/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj b/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj index cb80fc6db9..94c616503c 100644 --- a/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj +++ b/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj @@ -78,6 +78,7 @@ +