From 3fc738b53a726ef42131791ef46a6de234557bbb Mon Sep 17 00:00:00 2001 From: Lavius Motileng <58791731+laviusmotileng-ms@users.noreply.github.com> Date: Fri, 17 Apr 2020 15:25:08 -0700 Subject: [PATCH] Added Tests and Refactored code (#2129) * Added Tests and Refactored code * removed un-used file * delete test files when test completes * removed extra build configs * added clean-up method * removed unused variable * re-added removed attributtion * added error handling and move strings to string resource * added error handling to file explorer view model * moved varible assignment to if statement block * removed savin of settings file from the UI * re-added open source notice * added missing controls for powerrename and fancy zones * removed dead coded * remove un-used configuration * added error handling for file saving and updated powerreanme constructor * removed added configurations * added settings state --- PowerToys.sln | 20 +- .../Microsoft.PowerToys.Settings.Test.csproj | 18 -- .../UnitTest1.cs | 13 -- .../FZConfigProperties.cs | 8 + .../PowerRenameLocalProperties.cs | 53 +++++ .../PowerRenameProperties.cs | 20 +- .../PowerRenameSettings.cs | 15 +- .../SettingsUtils.cs | 36 +-- .../Microsoft.PowerToys.Settings.UI.csproj | 1 + .../Strings/en-us/Resources.resw | 100 ++++++++- .../ViewModels/FancyZonesViewModel.cs | 96 +++++++- .../ViewModels/GeneralViewModel.cs | 211 ++++++++++++++++++ .../ViewModels/PowerPreviewViewModel.cs | 86 +++++++ .../ViewModels/PowerRenameViewModel.cs | 174 ++++++++++++++- .../Views/FancyZonesPage.xaml | 63 +++++- .../Views/GeneralPage.xaml | 126 +++++------ .../Views/GeneralPage.xaml.cs | 124 +--------- .../Views/PowerPreviewPage.xaml | 50 ++--- .../Views/PowerPreviewPage.xaml.cs | 64 +----- .../Views/PowerRenamePage.xaml | 83 +++---- .../Views/PowerRenamePage.xaml.cs | 122 +--------- .../Assets/LockScreenLogo.scale-200.png | Bin 0 -> 1430 bytes .../Assets/SplashScreen.scale-200.png | Bin 0 -> 7700 bytes .../Assets/Square150x150Logo.scale-200.png | Bin 0 -> 2937 bytes .../Assets/Square44x44Logo.scale-200.png | Bin 0 -> 1647 bytes ...x44Logo.targetsize-24_altform-unplated.png | Bin 0 -> 1255 bytes .../Assets/StoreLogo.png | Bin 0 -> 1451 bytes .../Assets/Wide310x150Logo.scale-200.png | Bin 0 -> 3204 bytes ...crosoft.PowerToys.Settings.UnitTest.csproj | 184 +++++++++++++++ .../ModelsTests/BasePTModuleSettingsTest.cs | 48 ++++ .../ModelsTests/BasePTSettingsTest.cs | 13 ++ .../ModelsTests/SettingsUtilsTests.cs | 119 ++++++++++ .../Package.appxmanifest | 46 ++++ .../Properties/AssemblyInfo.cs | 18 ++ .../UnitTestApp.xaml | 7 + .../UnitTestApp.xaml.cs | 102 +++++++++ .../GeneralSettingsViewModelTest.cs | 22 ++ 37 files changed, 1538 insertions(+), 504 deletions(-) delete mode 100644 src/core/Microsoft.PowerToys.Settings.Test/Microsoft.PowerToys.Settings.Test.csproj delete mode 100644 src/core/Microsoft.PowerToys.Settings.Test/UnitTest1.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameLocalProperties.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/Assets/LockScreenLogo.scale-200.png create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/Assets/SplashScreen.scale-200.png create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/Assets/Square150x150Logo.scale-200.png create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/Assets/Square44x44Logo.scale-200.png create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/Assets/Square44x44Logo.targetsize-24_altform-unplated.png create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/Assets/StoreLogo.png create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/Assets/Wide310x150Logo.scale-200.png create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/Microsoft.PowerToys.Settings.UnitTest.csproj create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/BasePTModuleSettingsTest.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/BasePTSettingsTest.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/SettingsUtilsTests.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/Package.appxmanifest create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/Properties/AssemblyInfo.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/UnitTestApp.xaml create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/UnitTestApp.xaml.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/GeneralSettingsViewModelTest.cs diff --git a/PowerToys.sln b/PowerToys.sln index 322e2eeb38..0fe9d331db 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -188,8 +188,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "powerpreviewTest", "src\mod EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "core", "core", "{C3081D9A-1586-441A-B5F4-ED815B3719C1}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.Test", "src\core\Microsoft.PowerToys.Settings.Test\Microsoft.PowerToys.Settings.Test.csproj", "{6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.UI.Runner", "src\core\Microsoft.PowerToys.Settings.UI.Runner\Microsoft.PowerToys.Settings.UI.Runner.csproj", "{E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}" ProjectSection(ProjectDependencies) = postProject {F88B6FD1-14BD-48DB-85C2-6C51B8045121} = {F88B6FD1-14BD-48DB-85C2-6C51B8045121} @@ -209,6 +207,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.UI.Lib", "src\core\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj", "{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerToys.Settings.UnitTest", "src\core\Microsoft.PowerToys.Settings.UnitTest\Microsoft.PowerToys.Settings.UnitTest.csproj", "{A80355C2-780D-4245-BD80-25B8DE698EE3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -367,10 +367,6 @@ Global {47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Debug|x64.Build.0 = Debug|x64 {47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Release|x64.ActiveCfg = Release|x64 {47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Release|x64.Build.0 = Release|x64 - {6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}.Debug|x64.ActiveCfg = Debug|x64 - {6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}.Debug|x64.Build.0 = Debug|x64 - {6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}.Release|x64.ActiveCfg = Release|x64 - {6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}.Release|x64.Build.0 = Release|x64 {E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}.Debug|x64.ActiveCfg = Debug|x64 {E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}.Debug|x64.Build.0 = Debug|x64 {E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}.Release|x64.ActiveCfg = Release|x64 @@ -389,8 +385,14 @@ Global {C073B057-B157-40F0-8678-1DCD119D841C}.Release|x64.ActiveCfg = Release|x64 {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.ActiveCfg = Debug|x64 {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.Build.0 = Debug|x64 - {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.ActiveCfg = Release|Any CPU - {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.Build.0 = Release|Any CPU + {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.ActiveCfg = Release|x64 + {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.Build.0 = Release|x64 + {A80355C2-780D-4245-BD80-25B8DE698EE3}.Debug|x64.ActiveCfg = Debug|x64 + {A80355C2-780D-4245-BD80-25B8DE698EE3}.Debug|x64.Build.0 = Debug|x64 + {A80355C2-780D-4245-BD80-25B8DE698EE3}.Debug|x64.Deploy.0 = Debug|x64 + {A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x64.ActiveCfg = Release|x64 + {A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x64.Build.0 = Release|x64 + {A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x64.Deploy.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -438,12 +440,12 @@ Global {748417CA-F17E-487F-9411-CAFB6D3F4877} = {2F305555-C296-497E-AC20-5FA1B237996A} {217DF501-135C-4E38-BFC8-99D4821032EA} = {2F305555-C296-497E-AC20-5FA1B237996A} {47310AB4-9034-4BD1-8D8B-E88AD21A171B} = {2F305555-C296-497E-AC20-5FA1B237996A} - {6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} {E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} {F88B6FD1-14BD-48DB-85C2-6C51B8045121} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} {A7D5099E-F0FD-4BF3-8522-5A682759F915} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} {C073B057-B157-40F0-8678-1DCD119D841C} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} + {A80355C2-780D-4245-BD80-25B8DE698EE3} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/core/Microsoft.PowerToys.Settings.Test/Microsoft.PowerToys.Settings.Test.csproj b/src/core/Microsoft.PowerToys.Settings.Test/Microsoft.PowerToys.Settings.Test.csproj deleted file mode 100644 index dd59020c85..0000000000 --- a/src/core/Microsoft.PowerToys.Settings.Test/Microsoft.PowerToys.Settings.Test.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - netcoreapp3.1 - - false - - x64 - - - - - - - - - - diff --git a/src/core/Microsoft.PowerToys.Settings.Test/UnitTest1.cs b/src/core/Microsoft.PowerToys.Settings.Test/UnitTest1.cs deleted file mode 100644 index 90cb7f0276..0000000000 --- a/src/core/Microsoft.PowerToys.Settings.Test/UnitTest1.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Microsoft.PowerToys.Settings.Test -{ - [TestClass] - public class UnitTest1 - { - [TestMethod] - public void TestMethod1() - { - } - } -} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/FZConfigProperties.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/FZConfigProperties.cs index 202a45f612..146a5b2ac3 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/FZConfigProperties.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/FZConfigProperties.cs @@ -22,6 +22,8 @@ namespace Microsoft.PowerToys.Settings.UI.Lib this.FancyzonesHighlightOpacity = new IntProperty(); this.FancyzonesEditorHotkey = new KeyBoardKeysProperty(); this.FancyzonesExcludedApps = new StringProperty(); + this.FancyzonesInActiveColor = new StringProperty(); + this.FancyzonesBorderColor = new StringProperty(); } [JsonPropertyName("fancyzones_shiftDrag")] @@ -62,5 +64,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib [JsonPropertyName("fancyzones_excluded_apps")] public StringProperty FancyzonesExcludedApps { get; set; } + + [JsonPropertyName("fancyzones_zoneBorderColor")] + public StringProperty FancyzonesBorderColor { get; set; } + + [JsonPropertyName("fancyzones_zoneColor")] + public StringProperty FancyzonesInActiveColor { get; set; } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameLocalProperties.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameLocalProperties.cs new file mode 100644 index 0000000000..4b38605576 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameLocalProperties.cs @@ -0,0 +1,53 @@ +// 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.Text.Json; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + + public class PowerRenameLocalProperties + { + public PowerRenameLocalProperties() + { + PersistState = false; + MRUEnabled = false; + MaxMRUSize = 0; + ShowIcon = false; + ExtendedContextMenuOnly = false; + } + + private int _maxSize; + + public bool PersistState { get; set; } + + public bool MRUEnabled { get; set; } + + public int MaxMRUSize + { + get + { + return _maxSize; + } + + set + { + if (value < 0) + { + _maxSize = 0; + } + } + } + + public bool ShowIcon { get; set; } + + public bool ExtendedContextMenuOnly { get; set; } + + public string ToJsonString() + { + return JsonSerializer.Serialize(this); + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameProperties.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameProperties.cs index 3f502b02d1..99bc3bd1f8 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameProperties.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameProperties.cs @@ -10,26 +10,26 @@ namespace Microsoft.PowerToys.Settings.UI.Lib { public PowerRenameProperties() { - PersistInput = new BoolProperty(); - MruEnabled = new BoolProperty(); - MaxMruSize = new IntProperty(); - ShowIconInMenu = new BoolProperty(); - ShowExtendedMenu = new BoolProperty(); + PersistState = new BoolProperty(); + MRUEnabled = new BoolProperty(); + MaxMRUSize = new IntProperty(); + ShowIcon = new BoolProperty(); + ExtendedContextMenuOnly = new BoolProperty(); } [JsonPropertyName("bool_persist_input")] - public BoolProperty PersistInput { get; set; } + public BoolProperty PersistState { get; set; } [JsonPropertyName("bool_mru_enabled")] - public BoolProperty MruEnabled { get; set; } + public BoolProperty MRUEnabled { get; set; } [JsonPropertyName("int_max_mru_size")] - public IntProperty MaxMruSize { get; set; } + public IntProperty MaxMRUSize { get; set; } [JsonPropertyName("bool_show_icon_on_menu")] - public BoolProperty ShowIconInMenu { get; set; } + public BoolProperty ShowIcon { get; set; } [JsonPropertyName("bool_show_extended_menu")] - public BoolProperty ShowExtendedMenu { get; set; } + public BoolProperty ExtendedContextMenuOnly { get; set; } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameSettings.cs index ca18535027..cfeecf40c6 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameSettings.cs @@ -15,7 +15,20 @@ namespace Microsoft.PowerToys.Settings.UI.Lib { properties = new PowerRenameProperties(); version = "1"; - name = "_unset_"; + name = "PowerRename"; + } + + public PowerRenameSettings(PowerRenameLocalProperties localProperties) + { + properties = new PowerRenameProperties(); + properties.PersistState.Value = localProperties.PersistState; + properties.MRUEnabled.Value = localProperties.MRUEnabled; + properties.MaxMRUSize.Value = localProperties.MaxMRUSize; + properties.ShowIcon.Value = localProperties.ShowIcon; + properties.ExtendedContextMenuOnly.Value = localProperties.ExtendedContextMenuOnly; + + version = "1"; + name = "PowerRename"; } public PowerRenameSettings(string ptName) diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs index 2ed273cae5..5a60a913ff 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs @@ -10,6 +10,8 @@ namespace Microsoft.PowerToys.Settings.UI.Lib { public static class SettingsUtils { + private const string DefaultFileName = "settings.json"; + public static bool SettingsFolderExists(string powertoy) { return Directory.Exists(Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}")); @@ -24,50 +26,56 @@ namespace Microsoft.PowerToys.Settings.UI.Lib /// Get path to the json settings file. /// /// string path. - public static string GetSettingsPath(string powertoy) + public static string GetSettingsPath(string powertoy, string fileName = DefaultFileName) { if (string.IsNullOrWhiteSpace(powertoy)) { return Path.Combine( LocalApplicationDataFolder(), - $"Microsoft\\PowerToys\\settings.json"); + $"Microsoft\\PowerToys\\{fileName}"); } return Path.Combine( LocalApplicationDataFolder(), - $"Microsoft\\PowerToys\\{powertoy}\\settings.json"); + $"Microsoft\\PowerToys\\{powertoy}\\{fileName}"); } - public static bool SettingsExists(string powertoy) + public static bool SettingsExists(string powertoy, string fileName = DefaultFileName) { - return File.Exists(GetSettingsPath(powertoy)); + return File.Exists(GetSettingsPath(powertoy, fileName)); } /// /// Get a Deserialized object of the json settings string. /// /// Deserialized json settings object. - public static T GetSettings(string powertoy) + public static T GetSettings(string powertoy, string fileName = DefaultFileName) { - var jsonSettingsString = File.ReadAllText(GetSettingsPath(powertoy)); + var jsonSettingsString = File.ReadAllText(GetSettingsPath(powertoy, fileName)); return JsonSerializer.Deserialize(jsonSettingsString); } // Save settings to a json file. - public static void SaveSettings(string jsonSettings, string powertoy) + public static void SaveSettings(string jsonSettings, string powertoy, string fileName = DefaultFileName) { - if (jsonSettings != null) + try { - if (!SettingsFolderExists(powertoy)) + if (jsonSettings != null) { - CreateSettingsFolder(powertoy); - } + if (!SettingsFolderExists(powertoy)) + { + CreateSettingsFolder(powertoy); + } - File.WriteAllText(GetSettingsPath(powertoy), jsonSettings); + File.WriteAllText(GetSettingsPath(powertoy, fileName), jsonSettings); + } + } + catch + { } } - private static string LocalApplicationDataFolder() + public static string LocalApplicationDataFolder() { return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj b/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj index f9952423e5..3bdd7f46a3 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj +++ b/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj @@ -72,6 +72,7 @@ + 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 87d0ed056f..0b49b12b8d 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 @@ -134,7 +134,7 @@ Navigation view item name for General - PowerLauncher + PowerLauncher [Not Functional] Navigation view item name for PowerLauncher @@ -142,7 +142,7 @@ Navigation view item name for PowerRename - Shortcut Guide + Shortcut Guide [Not Functional] Navigation view item name for Shortcut Guide @@ -154,7 +154,7 @@ Navigation view item name for FancyZones - Image Resizer + Image Resizer [Not Functional] Navigation view item name for Image Resizer @@ -290,8 +290,8 @@ Override Windows Snap hotkeys (Win + arrow) to move windows between zones - - Save Color Choice + + Save Zone Highlight Color Choice Hold Shift key or any non-primary mouse button to enable zones while dragging @@ -320,4 +320,94 @@ Module overview + + Attribution + + + About PowerToys + + + Check for updates + + + Privacy statement + + + Dark + + + System default + + + Light + + + Report a bug + + + Request a feature + + + Restart as admin + + + Run at startup + + + Miscellaneous + + + A Windows Shell Extension for more advanced bulk renaming using search and replace or regular expressions. + + + Shell integration + + + Enable PowerRename + + + Theme + + + Show on default context menu + + + Only show on extended context menu (Shift + Right-click) + + + Maximum numbers of items to show in recently used list + + + Restore search, replace and flags values on launch from previous run + + + Markdown Preview Handler + + + Svg Preview Handler + + + These settings allow you to manage your Windows File Explorer custom preview handlers. + + + Miscellaneous + + + Open-source notice + + + Enable Auto Complete + + + Zone border color (Default #FFFFFF) + + + Zone inactive color (Default #F5FCFF) + + + Save Zone Border Color Choice + + + Save Zone Inactive Color Choice + \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/FancyZonesViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/FancyZonesViewModel.cs index 031b14f3c9..546deb025a 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/FancyZonesViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/FancyZonesViewModel.cs @@ -20,11 +20,27 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels public ButtonClickCommand LaunchEditorEventHandler { get; set; } - public ICommand SaveColorChoiceEventHandler + public ICommand SaveZoneHighlightColorEventHandler { get { - return new RelayCommand(SaveColorChoice); + return new RelayCommand(SaveZoneHighlightColor); + } + } + + public ICommand SaveBorderColorEventHandler + { + get + { + return new RelayCommand(SaveZoneBorderColor); + } + } + + public ICommand SaveInActiveColorEventHandler + { + get + { + return new RelayCommand(SaveZoneInActiveColor); } } @@ -32,9 +48,17 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels public FancyZonesViewModel() { - Settings = SettingsUtils.GetSettings(ModuleName); + try + { + Settings = SettingsUtils.GetSettings(ModuleName); + } + catch + { + Settings = new FancyZonesSettings(); + SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); + } + this.LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor); - // this.SaveColorChoiceEventHandler = new ButtonClickCommand(SaveColorChoice); this._shiftDrag = Settings.Properties.FancyzonesShiftDrag.Value; this._overrideSnapHotkeys = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value; @@ -49,8 +73,20 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels this._highlightOpacity = Settings.Properties.FancyzonesHighlightOpacity.Value; this._excludedApps = Settings.Properties.FancyzonesExcludedApps.Value; this._editorHotkey = Settings.Properties.FancyzonesEditorHotkey.Value; + this._zoneBorderColor = Settings.Properties.FancyzonesBorderColor.Value; + this._zoneInActiveColor = Settings.Properties.FancyzonesInActiveColor.Value; + + GeneralSettings generalSettings; + try + { + generalSettings = SettingsUtils.GetSettings(string.Empty); + } + catch + { + generalSettings = new GeneralSettings(); + SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty); + } - GeneralSettings generalSettings = SettingsUtils.GetSettings(string.Empty); this._isEnabled = generalSettings.Enabled.FancyZones; } @@ -68,6 +104,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels private int _highlightOpacity; private string _excludedApps; private HotkeySettings _editorHotkey; + private string _zoneBorderColor; + private string _zoneInActiveColor; public bool IsEnabled { @@ -271,6 +309,42 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels } } + public string ZoneBorderColor + { + get + { + return _zoneBorderColor; + } + + set + { + if (value != _zoneBorderColor) + { + _zoneBorderColor = value; + Settings.Properties.FancyzonesBorderColor.Value = value; + RaisePropertyChanged(); + } + } + } + + public string ZoneInActiveColor + { + get + { + return _zoneInActiveColor; + } + + set + { + if (value != _zoneInActiveColor) + { + _zoneInActiveColor = value; + Settings.Properties.FancyzonesInActiveColor.Value = value; + RaisePropertyChanged(); + } + } + } + public int HighlightOpacity { get @@ -351,11 +425,21 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels ShellPage.DefaultSndMSGCallback("{\"action\":{\"FancyZones\":{\"action_name\":\"ToggledFZEditor\", \"value\":\"\"}}}"); } - private void SaveColorChoice(Color color) + private void SaveZoneHighlightColor(Color color) { ZoneHighlightColor = color.ToString(); } + private void SaveZoneBorderColor(Color color) + { + ZoneBorderColor = color.ToString(); + } + + private void SaveZoneInActiveColor(Color color) + { + ZoneInActiveColor = color.ToString(); + } + public void RaisePropertyChanged([CallerMemberName] string propertyName = null) { OnPropertyChanged(propertyName); diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/GeneralViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/GeneralViewModel.cs index 9a9dff010a..5ab16a997b 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/GeneralViewModel.cs @@ -2,14 +2,225 @@ // 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.Diagnostics; +using System.Runtime.CompilerServices; +using System.Text.Json; using Microsoft.PowerToys.Settings.UI.Helpers; +using Microsoft.PowerToys.Settings.UI.Lib; +using Microsoft.PowerToys.Settings.UI.ViewModels.Commands; +using Microsoft.PowerToys.Settings.UI.Views; +using Windows.System; +using Windows.UI.Popups; +using Windows.UI.Xaml; namespace Microsoft.PowerToys.Settings.UI.ViewModels { public class GeneralViewModel : Observable { + private GeneralSettings GeneralSettingsConfigs { get; set; } + + public ButtonClickCommand CheckFoUpdatesEventHandler { get; set; } + + public ButtonClickCommand RestartElevatedButtonEventHandler { get; set; } + public GeneralViewModel() { + this.CheckFoUpdatesEventHandler = new ButtonClickCommand(CheckForUpdates_Click); + this.RestartElevatedButtonEventHandler = new ButtonClickCommand(Restart_Elevated); + + try + { + GeneralSettingsConfigs = SettingsUtils.GetSettings(string.Empty); + } + catch + { + GeneralSettingsConfigs = new GeneralSettings(); + SettingsUtils.SaveSettings(GeneralSettingsConfigs.ToJsonString(), string.Empty); + } + + switch (GeneralSettingsConfigs.Theme.ToLower()) + { + case "light": + _isLightThemeRadioButtonChecked = true; + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light; + break; + case "dark": + _isDarkThemeRadioButtonChecked = true; + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark; + break; + case "system": + _isSystemThemeRadioButtonChecked = true; + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default; + break; + } + + _startup = GeneralSettingsConfigs.Startup; + } + + private bool _packaged = false; + private bool _startup = false; + private bool _isElevated = false; + private bool _runElevated = false; + private bool _isDarkThemeRadioButtonChecked = false; + private bool _isLightThemeRadioButtonChecked = false; + private bool _isSystemThemeRadioButtonChecked = false; + + // Gets or sets a value indicating whether packaged. + public bool Packaged + { + get + { + return _packaged; + } + + set + { + if (_packaged != value) + { + _packaged = value; + RaisePropertyChanged(); + } + } + } + + // Gets or sets a value indicating whether run powertoys on start-up. + public bool Startup + { + get + { + return _startup; + } + + set + { + if (_startup != value) + { + _startup = value; + RaisePropertyChanged(); + } + } + } + + // Gets or sets a value indicating whether the powertoy elevated. + public bool IsElevated + { + get + { + return _isElevated; + } + + set + { + if (_isElevated != value) + { + _isElevated = value; + RaisePropertyChanged(); + } + } + } + + // Gets or sets a value indicating whether powertoys should run elevated. + public bool RunElevated + { + get + { + return _runElevated; + } + + set + { + if (_runElevated != value) + { + _runElevated = value; + RaisePropertyChanged(); + } + } + } + + public bool IsDarkThemeRadioButtonChecked + { + get + { + return _isDarkThemeRadioButtonChecked; + } + + set + { + if (value == true) + { + GeneralSettingsConfigs.Theme = "dark"; + _isDarkThemeRadioButtonChecked = value; + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark; + RaisePropertyChanged(); + } + } + } + + public bool IsLightThemeRadioButtonChecked + { + get + { + return _isLightThemeRadioButtonChecked; + } + + set + { + if (value == true) + { + GeneralSettingsConfigs.Theme = "light"; + _isLightThemeRadioButtonChecked = value; + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light; + RaisePropertyChanged(); + } + } + } + + public bool IsSystemThemeRadioButtonChecked + { + get + { + return _isSystemThemeRadioButtonChecked; + } + + set + { + if (value == true) + { + GeneralSettingsConfigs.Theme = "system"; + _isSystemThemeRadioButtonChecked = value; + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default; + RaisePropertyChanged(); + } + } + } + + public void RaisePropertyChanged([CallerMemberName] string propertyName = null) + { + // Notify UI of property change + OnPropertyChanged(propertyName); + + OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfigs); + + ShellPage.DefaultSndMSGCallback(outsettings.ToString()); + } + + // callback function to launch the URL to check for updates. + private async void CheckForUpdates_Click() + { + await Launcher.LaunchUriAsync(new Uri("https://github.com/microsoft/PowerToys/releases")); + } + + private void Restart_Elevated() + { + GeneralSettings settings = SettingsUtils.GetSettings(string.Empty); + settings.RunElevated = true; + OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings); + + if (ShellPage.DefaultSndMSGCallback != null) + { + ShellPage.DefaultSndMSGCallback(outsettings.ToString()); + } } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs new file mode 100644 index 0000000000..b8014c7a53 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs @@ -0,0 +1,86 @@ +// 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.Runtime.CompilerServices; +using Microsoft.PowerToys.Settings.UI.Helpers; +using Microsoft.PowerToys.Settings.UI.Lib; +using Microsoft.PowerToys.Settings.UI.Views; + +namespace Microsoft.PowerToys.Settings.UI.ViewModels +{ + public class PowerPreviewViewModel : Observable + { + private const string ModuleName = "File Explorer Preview"; + + private PowerPreviewSettings Settings { get; set; } + + public PowerPreviewViewModel() + { + try + { + Settings = SettingsUtils.GetSettings(ModuleName); + } + catch + { + Settings = new PowerPreviewSettings(); + SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); + } + + this._svgRenderIsEnabled = Settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.Value; + this._mdRenderIsEnabled = Settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.Value; + } + + private bool _svgRenderIsEnabled = false; + private bool _mdRenderIsEnabled = false; + + public bool SVGRenderIsEnebled + { + get + { + return _svgRenderIsEnabled; + } + + set + { + if (value != _svgRenderIsEnabled) + { + _svgRenderIsEnabled = value; + Settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.Value = value; + RaisePropertyChanged(); + } + } + } + + public bool MDRenderIsEnebled + { + get + { + return _mdRenderIsEnabled; + } + + set + { + if (value != _mdRenderIsEnabled) + { + _mdRenderIsEnabled = value; + Settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.Value = value; + RaisePropertyChanged(); + } + } + } + + private void RaisePropertyChanged([CallerMemberName] string propertyName = null) + { + // Notify UI of property change + OnPropertyChanged(propertyName); + + if (ShellPage.DefaultSndMSGCallback != null) + { + SndPowerPreviewSettings snd = new SndPowerPreviewSettings(Settings); + SndModuleSettings ipcMessage = new SndModuleSettings(snd); + ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString()); + } + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerRenameViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerRenameViewModel.cs index dda10c1783..a1b9078c4a 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerRenameViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerRenameViewModel.cs @@ -2,14 +2,186 @@ // 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.Runtime.CompilerServices; using Microsoft.PowerToys.Settings.UI.Helpers; +using Microsoft.PowerToys.Settings.UI.Lib; +using Microsoft.PowerToys.Settings.UI.Views; namespace Microsoft.PowerToys.Settings.UI.ViewModels { public class PowerRenameViewModel : Observable { + private const string ModuleName = "PowerRename"; + + private PowerRenameSettings Settings { get; set; } + public PowerRenameViewModel() { + try + { + PowerRenameLocalProperties localSettings = SettingsUtils.GetSettings(ModuleName, "power-rename-settings.json"); + Settings = new PowerRenameSettings(localSettings); + } + catch + { + PowerRenameLocalProperties localSettings = new PowerRenameLocalProperties(); + Settings = new PowerRenameSettings(localSettings); + SettingsUtils.SaveSettings(localSettings.ToJsonString(), ModuleName, "power-rename-settings.json"); + } + + _powerRenameEnabledOnContextMenu = Settings.properties.ShowIcon.Value; + _powerRenameEnabledOnContextExtendedMenu = Settings.properties.ExtendedContextMenuOnly.Value; + _powerRenameRestoreFlagsOnLaunch = Settings.properties.PersistState.Value; + _powerRenameMaxDispListNumValue = Settings.properties.MaxMRUSize.Value; + _autoComplete = Settings.properties.MRUEnabled.Value; + + GeneralSettings generalSettings; + try + { + generalSettings = SettingsUtils.GetSettings(string.Empty); + } + catch + { + generalSettings = new GeneralSettings(); + SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty); + } + + _powerRenameEnabled = generalSettings.Enabled.PowerRename; + } + + private bool _powerRenameEnabled = false; + private bool _powerRenameEnabledOnContextMenu = false; + private bool _powerRenameEnabledOnContextExtendedMenu = false; + private bool _powerRenameRestoreFlagsOnLaunch = false; + private int _powerRenameMaxDispListNumValue = 0; + private bool _autoComplete = false; + + public bool IsEnabled + { + get + { + return _powerRenameEnabled; + } + + set + { + if (value != _powerRenameEnabled) + { + if (ShellPage.DefaultSndMSGCallback != null) + { + GeneralSettings generalSettings = SettingsUtils.GetSettings(string.Empty); + generalSettings.Enabled.PowerRename = value; + OutGoingGeneralSettings snd = new OutGoingGeneralSettings(generalSettings); + ShellPage.DefaultSndMSGCallback(snd.ToString()); + + _powerRenameEnabled = value; + RaisePropertyChanged(); + } + } + } + } + + public bool MRUEnabled + { + get + { + return _autoComplete; + } + + set + { + if (value != _autoComplete) + { + _autoComplete = value; + Settings.properties.MRUEnabled.Value = value; + RaisePropertyChanged(); + } + } + } + + public bool EnabledOnContextMenu + { + get + { + return _powerRenameEnabledOnContextMenu; + } + + set + { + if (value != _powerRenameEnabledOnContextMenu) + { + _powerRenameEnabledOnContextMenu = value; + Settings.properties.ShowIcon.Value = value; + RaisePropertyChanged(); + } + } + } + + public bool EnabledOnContextExtendedMenu + { + get + { + return _powerRenameEnabledOnContextExtendedMenu; + } + + set + { + if (value != _powerRenameEnabledOnContextExtendedMenu) + { + _powerRenameEnabledOnContextExtendedMenu = value; + Settings.properties.ExtendedContextMenuOnly.Value = value; + RaisePropertyChanged(); + } + } + } + + public bool RestoreFlagsOnLaunch + { + get + { + return _powerRenameRestoreFlagsOnLaunch; + } + + set + { + if (value != _powerRenameRestoreFlagsOnLaunch) + { + _powerRenameRestoreFlagsOnLaunch = value; + Settings.properties.PersistState.Value = value; + RaisePropertyChanged(); + } + } + } + + public int MaxDispListNum + { + get + { + return _powerRenameMaxDispListNumValue; + } + + set + { + if (value != _powerRenameMaxDispListNumValue) + { + _powerRenameMaxDispListNumValue = value; + Settings.properties.MaxMRUSize.Value = value; + RaisePropertyChanged(); + } + } + } + + private void RaisePropertyChanged([CallerMemberName] string propertyName = null) + { + // Notify UI of property change + OnPropertyChanged(propertyName); + + if (ShellPage.DefaultSndMSGCallback != null) + { + SndPowerRenameSettings snd = new SndPowerRenameSettings(Settings); + SndModuleSettings ipcMessage = new SndModuleSettings(snd); + ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString()); + } } } -} +} \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml b/src/core/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml index be25f86ce4..49ba3bc672 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml @@ -130,12 +130,12 @@ HorizontalAlignment="Left" Margin="{StaticResource SmallTopMargin}" IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}"/> - + - + IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}" + DataContext="{Binding ZoneHighlightColor, Source={StaticResource eventViewModel}}"/> -