CursorWrapSettings.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Collections.Generic; 6 using System.Text.Json.Serialization; 7 using ManagedCommon; 8 using Microsoft.PowerToys.Settings.UI.Library.Helpers; 9 using Microsoft.PowerToys.Settings.UI.Library.Interfaces; 10 11 namespace Microsoft.PowerToys.Settings.UI.Library 12 { 13 public class CursorWrapSettings : BasePTModuleSettings, ISettingsConfig, IHotkeyConfig 14 { 15 public const string ModuleName = "CursorWrap"; 16 17 [JsonPropertyName("properties")] 18 public CursorWrapProperties Properties { get; set; } 19 20 public CursorWrapSettings() 21 { 22 Name = ModuleName; 23 Properties = new CursorWrapProperties(); 24 Version = "1.0"; 25 } 26 27 public string GetModuleName() 28 { 29 return Name; 30 } 31 32 public ModuleType GetModuleType() => ModuleType.CursorWrap; 33 34 public HotkeyAccessor[] GetAllHotkeyAccessors() 35 { 36 var hotkeyAccessors = new List<HotkeyAccessor> 37 { 38 new HotkeyAccessor( 39 () => Properties.ActivationShortcut, 40 value => Properties.ActivationShortcut = value ?? Properties.DefaultActivationShortcut, 41 "MouseUtils_CursorWrap_ActivationShortcut"), 42 }; 43 44 return hotkeyAccessors.ToArray(); 45 } 46 47 // This can be utilized in the future if the settings.json file is to be modified/deleted. 48 public bool UpgradeSettingsConfiguration() 49 { 50 bool settingsUpgraded = false; 51 52 // Add WrapMode property if it doesn't exist (for users upgrading from older versions) 53 if (Properties.WrapMode == null) 54 { 55 Properties.WrapMode = new IntProperty(0); // Default to Both 56 settingsUpgraded = true; 57 } 58 59 // Add DisableCursorWrapOnSingleMonitor property if it doesn't exist (for users upgrading from older versions) 60 if (Properties.DisableCursorWrapOnSingleMonitor == null) 61 { 62 Properties.DisableCursorWrapOnSingleMonitor = new BoolProperty(false); // Default to false 63 settingsUpgraded = true; 64 } 65 66 return settingsUpgraded; 67 } 68 } 69 }