diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerLauncherProperties.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerLauncherProperties.cs index 26388cb11c..188d790cfe 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerLauncherProperties.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerLauncherProperties.cs @@ -1,45 +1,60 @@ -// Copyright (c) Microsoft Corporation +// 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.Serialization; + namespace Microsoft.PowerToys.Settings.UI.Lib { public class PowerLauncherProperties { - public string search_result_preference { get; set; } + [JsonPropertyName("search_result_preference")] + public string SearchResultPreference { get; set; } - public string search_type_preference { get; set; } + [JsonPropertyName("search_type_preference")] + public string SearchTypePreference { get; set; } - public int maximum_number_of_results { get; set; } + [JsonPropertyName("maximum_number_of_results")] + public int MaximumNumberOfResults { get; set; } - public HotkeySettings open_powerlauncher { get; set; } + [JsonPropertyName("open_powerlauncher")] + public HotkeySettings OpenPowerLauncher { get; set; } - public HotkeySettings open_file_location { get; set; } + [JsonPropertyName("open_file_location")] + public HotkeySettings OpenFileLocation { get; set; } - public HotkeySettings copy_path_location { get; set; } + [JsonPropertyName("copy_path_location")] + public HotkeySettings CopyPathLocation { get; set; } - public HotkeySettings open_console { get; set; } + [JsonPropertyName("open_console")] + public HotkeySettings OpenConsole { get; set; } - public bool override_win_r_key { get; set; } + [JsonPropertyName("override_win_r_key")] + public bool OverrideWinkeyR { get; set; } - public bool override_win_s_key { get; set; } + [JsonPropertyName("override_win_s_key")] + public bool OverrideWinkeyS { get; set; } - public bool ignore_hotkeys_in_fullscreen { get; set; } + [JsonPropertyName("ignore_hotkeys_in_fullscreen")] + public bool IgnoreHotkeysInFullscreen { get; set; } - public bool disable_drive_detection_warning { get; set; } - public bool clear_input_on_launch { get; set; } + [JsonPropertyName("disable_drive_detection_warning")] + public bool DisableDriveDetectionWarning { get; set; } + + [JsonPropertyName("clear_input_on_launch")] + public bool ClearInputOnLaunch { get; set; } public PowerLauncherProperties() { - open_powerlauncher = new HotkeySettings(); - open_file_location = new HotkeySettings(); - copy_path_location = new HotkeySettings(); - open_console = new HotkeySettings(); - search_result_preference = "most_recently_used"; - search_type_preference = "application_name"; - ignore_hotkeys_in_fullscreen = false; - disable_drive_detection_warning = false; - clear_input_on_launch = false; + OpenPowerLauncher = new HotkeySettings(); + OpenFileLocation = new HotkeySettings(); + CopyPathLocation = new HotkeySettings(); + OpenConsole = new HotkeySettings(); + SearchResultPreference = "most_recently_used"; + SearchTypePreference = "application_name"; + IgnoreHotkeysInFullscreen = false; + DisableDriveDetectionWarning = false; + ClearInputOnLaunch = false; } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs index 2b75371e84..afe67754f5 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs @@ -2,35 +2,29 @@ // 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; -using System.Text; -using System.Text.Json; using System.Text.Json.Serialization; namespace Microsoft.PowerToys.Settings.UI.Lib { public class PowerPreviewSettings : BasePTModuleSettings { - public PowerPreviewProperties properties { get; set; } + public const string ModuleName = "File Explorer"; + + [JsonPropertyName("Properties")] + public PowerPreviewProperties Properties { get; set; } public PowerPreviewSettings() { - properties = new PowerPreviewProperties(); + Properties = new PowerPreviewProperties(); Version = "1"; - Name = "File Explorer"; + Name = ModuleName; } public PowerPreviewSettings(string ptName) { - properties = new PowerPreviewProperties(); + Properties = new PowerPreviewProperties(); Version = "1"; Name = ptName; } - - public override string ToJsonString() - { - return JsonSerializer.Serialize(this); - } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerLauncherViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerLauncherViewModel.cs index b1e2128e2b..71ed10041a 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerLauncherViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerLauncherViewModel.cs @@ -34,9 +34,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels else { settings = new PowerLauncherSettings(); - settings.Properties.open_powerlauncher.Alt = true; - settings.Properties.open_powerlauncher.Code = (int)Windows.System.VirtualKey.Space; - settings.Properties.maximum_number_of_results = 4; + settings.Properties.OpenPowerLauncher.Alt = true; + settings.Properties.OpenPowerLauncher.Code = (int)Windows.System.VirtualKey.Space; + settings.Properties.MaximumNumberOfResults = 4; callback(settings); } @@ -87,14 +87,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { get { - return settings.Properties.search_result_preference; + return settings.Properties.SearchResultPreference; } set { - if (settings.Properties.search_result_preference != value) + if (settings.Properties.SearchResultPreference != value) { - settings.Properties.search_result_preference = value; + settings.Properties.SearchResultPreference = value; UpdateSettings(); } } @@ -104,14 +104,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { get { - return settings.Properties.search_type_preference; + return settings.Properties.SearchTypePreference; } set { - if (settings.Properties.search_type_preference != value) + if (settings.Properties.SearchTypePreference != value) { - settings.Properties.search_type_preference = value; + settings.Properties.SearchTypePreference = value; UpdateSettings(); } } @@ -121,14 +121,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { get { - return settings.Properties.maximum_number_of_results; + return settings.Properties.MaximumNumberOfResults; } set { - if (settings.Properties.maximum_number_of_results != value) + if (settings.Properties.MaximumNumberOfResults != value) { - settings.Properties.maximum_number_of_results = value; + settings.Properties.MaximumNumberOfResults = value; UpdateSettings(); } } @@ -138,14 +138,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { get { - return settings.Properties.open_powerlauncher; + return settings.Properties.OpenPowerLauncher; } set { - if (settings.Properties.open_powerlauncher != value) + if (settings.Properties.OpenPowerLauncher != value) { - settings.Properties.open_powerlauncher = value; + settings.Properties.OpenPowerLauncher = value; UpdateSettings(); } } @@ -155,14 +155,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { get { - return settings.Properties.open_file_location; + return settings.Properties.OpenFileLocation; } set { - if (settings.Properties.open_file_location != value) + if (settings.Properties.OpenFileLocation != value) { - settings.Properties.open_file_location = value; + settings.Properties.OpenFileLocation = value; UpdateSettings(); } } @@ -172,14 +172,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { get { - return settings.Properties.copy_path_location; + return settings.Properties.CopyPathLocation; } set { - if (settings.Properties.copy_path_location != value) + if (settings.Properties.CopyPathLocation != value) { - settings.Properties.copy_path_location = value; + settings.Properties.CopyPathLocation = value; UpdateSettings(); } } @@ -189,14 +189,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { get { - return settings.Properties.override_win_r_key; + return settings.Properties.OverrideWinkeyR; } set { - if (settings.Properties.override_win_r_key != value) + if (settings.Properties.OverrideWinkeyR != value) { - settings.Properties.override_win_r_key = value; + settings.Properties.OverrideWinkeyR = value; UpdateSettings(); } } @@ -206,14 +206,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { get { - return settings.Properties.override_win_s_key; + return settings.Properties.OverrideWinkeyS; } set { - if (settings.Properties.override_win_s_key != value) + if (settings.Properties.OverrideWinkeyS != value) { - settings.Properties.override_win_s_key = value; + settings.Properties.OverrideWinkeyS = value; UpdateSettings(); } } @@ -223,14 +223,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { get { - return settings.Properties.ignore_hotkeys_in_fullscreen; + return settings.Properties.IgnoreHotkeysInFullscreen; } set { - if (settings.Properties.ignore_hotkeys_in_fullscreen != value) + if (settings.Properties.IgnoreHotkeysInFullscreen != value) { - settings.Properties.ignore_hotkeys_in_fullscreen = value; + settings.Properties.IgnoreHotkeysInFullscreen = value; UpdateSettings(); } } @@ -240,14 +240,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { get { - return settings.Properties.clear_input_on_launch; + return settings.Properties.ClearInputOnLaunch; } set { - if (settings.Properties.clear_input_on_launch != value) + if (settings.Properties.ClearInputOnLaunch != value) { - settings.Properties.clear_input_on_launch = value; + settings.Properties.ClearInputOnLaunch = value; UpdateSettings(); } } @@ -257,14 +257,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { get { - return settings.Properties.disable_drive_detection_warning; + return settings.Properties.DisableDriveDetectionWarning; } set { - if (settings.Properties.disable_drive_detection_warning != value) + if (settings.Properties.DisableDriveDetectionWarning != value) { - settings.Properties.disable_drive_detection_warning = value; + settings.Properties.DisableDriveDetectionWarning = value; UpdateSettings(); } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs index ba92cfd181..1732660de2 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs @@ -27,9 +27,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); } - this._svgRenderIsEnabled = Settings.properties.EnableSvgPreview; - this._svgThumbnailIsEnabled = Settings.properties.EnableSvgThumbnail; - this._mdRenderIsEnabled = Settings.properties.EnableMdPreview; + this._svgRenderIsEnabled = Settings.Properties.EnableSvgPreview; + this._svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail; + this._mdRenderIsEnabled = Settings.Properties.EnableMdPreview; } private bool _svgRenderIsEnabled = false; @@ -48,7 +48,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels if (value != _svgRenderIsEnabled) { _svgRenderIsEnabled = value; - Settings.properties.EnableSvgPreview = value; + Settings.Properties.EnableSvgPreview = value; RaisePropertyChanged(); } } @@ -66,7 +66,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels if (value != _svgThumbnailIsEnabled) { _svgThumbnailIsEnabled = value; - Settings.properties.EnableSvgThumbnail = value; + Settings.Properties.EnableSvgThumbnail = value; RaisePropertyChanged(); } } @@ -84,7 +84,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels if (value != _mdRenderIsEnabled) { _mdRenderIsEnabled = value; - Settings.properties.EnableMdPreview = value; + Settings.Properties.EnableMdPreview = value; RaisePropertyChanged(); } } diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerLauncherViewModelTest.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerLauncherViewModelTest.cs index 9cdf51e5bd..7cab1c63ec 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerLauncherViewModelTest.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerLauncherViewModelTest.cs @@ -45,8 +45,8 @@ namespace ViewModelTests viewModel.SearchTypePreference = "SearchOptionsAreNotValidated"; Assert.AreEqual(sendCallbackMock.TimesSent, 2); - Assert.IsTrue(mockSettings.Properties.search_result_preference == "SearchOptionsAreNotValidated"); - Assert.IsTrue(mockSettings.Properties.search_type_preference == "SearchOptionsAreNotValidated"); + Assert.IsTrue(mockSettings.Properties.SearchResultPreference == "SearchOptionsAreNotValidated"); + Assert.IsTrue(mockSettings.Properties.SearchTypePreference == "SearchOptionsAreNotValidated"); } public void AssertHotkeySettings(HotkeySettings setting, bool win, bool ctrl, bool alt, bool shift, int code) @@ -85,7 +85,7 @@ namespace ViewModelTests Assert.AreEqual(4, sendCallbackMock.TimesSent); AssertHotkeySettings( - mockSettings.Properties.open_powerlauncher, + mockSettings.Properties.OpenPowerLauncher, true, false, false, @@ -93,7 +93,7 @@ namespace ViewModelTests (int)Windows.System.VirtualKey.S ); AssertHotkeySettings( - mockSettings.Properties.open_file_location, + mockSettings.Properties.OpenFileLocation, false, true, false, @@ -101,7 +101,7 @@ namespace ViewModelTests (int)Windows.System.VirtualKey.A ); AssertHotkeySettings( - mockSettings.Properties.open_console, + mockSettings.Properties.OpenConsole, false, false, true, @@ -109,7 +109,7 @@ namespace ViewModelTests (int)Windows.System.VirtualKey.D ); AssertHotkeySettings( - mockSettings.Properties.copy_path_location, + mockSettings.Properties.CopyPathLocation, false, false, false, @@ -127,8 +127,8 @@ namespace ViewModelTests Assert.AreEqual(1, sendCallbackMock.TimesSent); - Assert.IsTrue(mockSettings.Properties.override_win_r_key); - Assert.IsFalse(mockSettings.Properties.override_win_s_key); + Assert.IsTrue(mockSettings.Properties.OverrideWinkeyR); + Assert.IsFalse(mockSettings.Properties.OverrideWinkeyS); } [TestMethod] @@ -139,7 +139,7 @@ namespace ViewModelTests // Assert Assert.AreEqual(1, sendCallbackMock.TimesSent); - Assert.IsTrue(mockSettings.Properties.disable_drive_detection_warning); + Assert.IsTrue(mockSettings.Properties.DisableDriveDetectionWarning); } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerPreview.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerPreview.cs index 545969b713..be6d8dfb1d 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerPreview.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerPreview.cs @@ -59,7 +59,7 @@ namespace ViewModelTests ShellPage.DefaultSndMSGCallback = msg => { SndModuleSettings snd = JsonSerializer.Deserialize>(msg); - Assert.IsTrue(snd.powertoys.FileExplorerPreviewSettings.properties.EnableSvgPreview); + Assert.IsTrue(snd.powertoys.FileExplorerPreviewSettings.Properties.EnableSvgPreview); }; // act @@ -76,7 +76,7 @@ namespace ViewModelTests ShellPage.DefaultSndMSGCallback = msg => { SndModuleSettings snd = JsonSerializer.Deserialize>(msg); - Assert.IsTrue(snd.powertoys.FileExplorerPreviewSettings.properties.EnableSvgThumbnail); + Assert.IsTrue(snd.powertoys.FileExplorerPreviewSettings.Properties.EnableSvgThumbnail); }; // act @@ -93,7 +93,7 @@ namespace ViewModelTests ShellPage.DefaultSndMSGCallback = msg => { SndModuleSettings snd = JsonSerializer.Deserialize>(msg); - Assert.IsTrue(snd.powertoys.FileExplorerPreviewSettings.properties.EnableMdPreview); + Assert.IsTrue(snd.powertoys.FileExplorerPreviewSettings.Properties.EnableMdPreview); }; // act diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs index 469be74705..c589cf694a 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs @@ -202,8 +202,8 @@ namespace Microsoft.Plugin.Indexer } public void UpdateSettings(PowerLauncherSettings settings) { - _settings.MaxSearchCount = settings.Properties.maximum_number_of_results; - _driveDetection.IsDriveDetectionWarningCheckBoxSelected = settings.Properties.disable_drive_detection_warning; + _settings.MaxSearchCount = settings.Properties.MaximumNumberOfResults; + _driveDetection.IsDriveDetectionWarningCheckBoxSelected = settings.Properties.DisableDriveDetectionWarning; } public Control CreateSettingPanel() { diff --git a/src/modules/launcher/PowerLauncher/SettingsWatcher.cs b/src/modules/launcher/PowerLauncher/SettingsWatcher.cs index dc8f837dc9..466e14fca2 100644 --- a/src/modules/launcher/PowerLauncher/SettingsWatcher.cs +++ b/src/modules/launcher/PowerLauncher/SettingsWatcher.cs @@ -43,7 +43,7 @@ namespace PowerLauncher { var overloadSettings = SettingsUtils.GetSettings(PowerLauncherSettings.ModuleName); - var openPowerlauncher = ConvertHotkey(overloadSettings.Properties.open_powerlauncher); + var openPowerlauncher = ConvertHotkey(overloadSettings.Properties.OpenPowerLauncher); if (_settings.Hotkey != openPowerlauncher) { _settings.Hotkey = openPowerlauncher; @@ -56,14 +56,14 @@ namespace PowerLauncher shellSettings.UpdateSettings(overloadSettings); } - if (_settings.MaxResultsToShow != overloadSettings.Properties.maximum_number_of_results) + if (_settings.MaxResultsToShow != overloadSettings.Properties.MaximumNumberOfResults) { - _settings.MaxResultsToShow = overloadSettings.Properties.maximum_number_of_results; + _settings.MaxResultsToShow = overloadSettings.Properties.MaximumNumberOfResults; } - if (_settings.IgnoreHotkeysOnFullscreen != overloadSettings.Properties.ignore_hotkeys_in_fullscreen) + if (_settings.IgnoreHotkeysOnFullscreen != overloadSettings.Properties.IgnoreHotkeysInFullscreen) { - _settings.IgnoreHotkeysOnFullscreen = overloadSettings.Properties.ignore_hotkeys_in_fullscreen; + _settings.IgnoreHotkeysOnFullscreen = overloadSettings.Properties.IgnoreHotkeysInFullscreen; } var indexer = PluginManager.AllPlugins.Find(p => p.Metadata.Name.Equals("Windows Indexer Plugin", StringComparison.OrdinalIgnoreCase)); @@ -73,9 +73,9 @@ namespace PowerLauncher indexerSettings.UpdateSettings(overloadSettings); } - if (_settings.ClearInputOnLaunch != overloadSettings.Properties.clear_input_on_launch) + if (_settings.ClearInputOnLaunch != overloadSettings.Properties.ClearInputOnLaunch) { - _settings.ClearInputOnLaunch = overloadSettings.Properties.clear_input_on_launch; + _settings.ClearInputOnLaunch = overloadSettings.Properties.ClearInputOnLaunch; } } // the settings application can hold a lock on the settings.json file which will result in a IOException.