ColorPickerProperties.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; 7 using System.Text.Json.Serialization; 8 9 using ManagedCommon; 10 using Microsoft.PowerToys.Settings.UI.Library.Enumerations; 11 using Settings.UI.Library.Attributes; 12 13 namespace Microsoft.PowerToys.Settings.UI.Library 14 { 15 public class ColorPickerProperties 16 { 17 [CmdConfigureIgnore] 18 public HotkeySettings DefaultActivationShortcut => new HotkeySettings(true, false, false, true, 0x43); 19 20 public ColorPickerProperties() 21 { 22 ActivationShortcut = DefaultActivationShortcut; 23 ChangeCursor = false; 24 ColorHistoryLimit = 20; 25 VisibleColorFormats = new Dictionary<string, KeyValuePair<bool, string>>(); 26 VisibleColorFormats.Add("HEX", new KeyValuePair<bool, string>(true, ColorFormatHelper.GetDefaultFormat("HEX"))); 27 VisibleColorFormats.Add("RGB", new KeyValuePair<bool, string>(true, ColorFormatHelper.GetDefaultFormat("RGB"))); 28 VisibleColorFormats.Add("HSL", new KeyValuePair<bool, string>(true, ColorFormatHelper.GetDefaultFormat("HSL"))); 29 VisibleColorFormats.Add("HSV", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("HSV"))); 30 VisibleColorFormats.Add("CMYK", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("CMYK"))); 31 VisibleColorFormats.Add("HSB", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("HSB"))); 32 VisibleColorFormats.Add("HSI", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("HSI"))); 33 VisibleColorFormats.Add("HWB", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("HWB"))); 34 VisibleColorFormats.Add("NCol", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("NCol"))); 35 VisibleColorFormats.Add("CIEXYZ", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("CIEXYZ"))); 36 VisibleColorFormats.Add("CIELAB", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("CIELAB"))); 37 VisibleColorFormats.Add("Oklab", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("Oklab"))); 38 VisibleColorFormats.Add("Oklch", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("Oklch"))); 39 VisibleColorFormats.Add("VEC4", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("VEC4"))); 40 VisibleColorFormats.Add("Decimal", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("Decimal"))); 41 VisibleColorFormats.Add("HEX Int", new KeyValuePair<bool, string>(false, ColorFormatHelper.GetDefaultFormat("HEX Int"))); 42 ShowColorName = false; 43 ActivationAction = ColorPickerActivationAction.OpenColorPicker; 44 PrimaryClickAction = ColorPickerClickAction.PickColorThenEditor; 45 MiddleClickAction = ColorPickerClickAction.PickColorAndClose; 46 SecondaryClickAction = ColorPickerClickAction.Close; 47 CopiedColorRepresentation = "HEX"; 48 } 49 50 public HotkeySettings ActivationShortcut { get; set; } 51 52 [JsonPropertyName("changecursor")] 53 [JsonConverter(typeof(BoolPropertyJsonConverter))] 54 [CmdConfigureIgnoreAttribute] 55 public bool ChangeCursor { get; set; } 56 57 [JsonPropertyName("copiedcolorrepresentation")] 58 public string CopiedColorRepresentation { get; set; } 59 60 [JsonPropertyName("activationaction")] 61 public ColorPickerActivationAction ActivationAction { get; set; } 62 63 [JsonPropertyName("primaryclickaction")] 64 public ColorPickerClickAction PrimaryClickAction { get; set; } 65 66 [JsonPropertyName("middleclickaction")] 67 public ColorPickerClickAction MiddleClickAction { get; set; } 68 69 [JsonPropertyName("secondaryclickaction")] 70 public ColorPickerClickAction SecondaryClickAction { get; set; } 71 72 // Property ColorHistory is not used, the color history is saved separately in the colorHistory.json file 73 [JsonPropertyName("colorhistory")] 74 [CmdConfigureIgnoreAttribute] 75 public List<string> ColorHistory { get; set; } 76 77 [JsonPropertyName("colorhistorylimit")] 78 [CmdConfigureIgnoreAttribute] 79 public int ColorHistoryLimit { get; set; } 80 81 [JsonPropertyName("visiblecolorformats")] 82 [CmdConfigureIgnoreAttribute] 83 public Dictionary<string, KeyValuePair<bool, string>> VisibleColorFormats { get; set; } 84 85 [JsonPropertyName("showcolorname")] 86 [JsonConverter(typeof(BoolPropertyJsonConverter))] 87 public bool ShowColorName { get; set; } 88 89 public override string ToString() 90 => JsonSerializer.Serialize(this, SettingsSerializationContext.Default.ColorPickerProperties); 91 } 92 }