/ src / settings-ui / Settings.UI.Library / PluginAdditionalOption.cs
PluginAdditionalOption.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;
  6  using System.Collections.Generic;
  7  using System.Linq;
  8  using System.Text.Json.Serialization;
  9  
 10  namespace Microsoft.PowerToys.Settings.UI.Library
 11  {
 12      public class PluginAdditionalOption
 13      {
 14          public enum AdditionalOptionType
 15          {
 16              Checkbox = 0,
 17              Combobox = 1,
 18              Textbox = 2,
 19              Numberbox = 3,
 20              MultilineTextbox = 4,
 21              CheckboxAndCombobox = 11,
 22              CheckboxAndTextbox = 12,
 23              CheckboxAndNumberbox = 13,
 24              CheckboxAndMultilineTextbox = 14,
 25          }
 26  
 27          /// <summary>
 28          /// Gets or sets the layout type of the option in settings ui (Optional; Default is checkbox)
 29          /// </summary>
 30          public AdditionalOptionType PluginOptionType { get; set; }
 31  
 32          public string Key { get; set; }
 33  
 34          public string DisplayLabel { get; set; }
 35  
 36          /// <summary>
 37          /// Gets or sets a value to show a description of this setting in the settings ui. (Optional)
 38          /// </summary>
 39          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
 40          public string DisplayDescription { get; set; }
 41  
 42          /// <summary>
 43          /// Gets or sets a value to show a label for the second setting if two combined settings are shown
 44          /// </summary>
 45          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
 46          public string SecondDisplayLabel { get; set; }
 47  
 48          /// <summary>
 49          /// Gets or sets a value to show a description for the second setting in the settings ui if two combined settings are shown. (Optional)
 50          /// </summary>
 51          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
 52          public string SecondDisplayDescription { get; set; }
 53  
 54          /// <summary>
 55          /// Gets or sets a value indicating whether the checkbox is set or not set
 56          /// </summary>
 57          public bool Value { get; set; }
 58  
 59          public int ComboBoxValue { get; set; }
 60  
 61          /// <summary>
 62          /// Gets or sets the list of dropdown items for the ComboBox. Please use the item name as Key and an integer as Value.
 63          /// The value gets converted in settings UI to an integer and will be saved in <see cref="ComboBoxValue"/>.
 64          /// You can define the visibility order in settings ui by arranging the list items.
 65          /// </summary>
 66          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
 67          public List<KeyValuePair<string, string>> ComboBoxItems { get; set; }
 68  
 69          private string _textValue;
 70  
 71          /// <summary>
 72          /// Gets or sets the text of a (multiline) text setting.
 73          /// </summary>
 74          /// <remarks>
 75          /// For multiline text "\r" is used as line break. Alternatively you can use the <see cref="TextValueAsMultilineList" /> property.
 76          /// </remarks>
 77          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
 78          public string TextValue
 79          {
 80              get { return _textValue; }
 81              set { _textValue = value; }
 82          }
 83  
 84          /// <summary>
 85          /// Gets or sets the text value for multiline texts using a list of type string.
 86          /// </summary>
 87          /// <remarks>
 88          /// Getter: It reads the <see cref="TextValue" /> property and converts it to a list.<br />
 89          /// Setter: It converts the list to a string separated by "\r" and sets the <see cref="TextValue"/> property.
 90          /// </remarks>
 91          // This property should help to deal with the line break handling. It is an alias for the TextValue property. Therefore, it should not be written to the json file.
 92          [JsonIgnore]
 93          public List<string> TextValueAsMultilineList
 94          {
 95              get { return _textValue?.Split("\r", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)?.ToList() ?? new List<string>(); }
 96              set { _textValue = (value != null && value.Count > 0) ? string.Join("\r", value.ToArray()) : string.Empty; }
 97          }
 98  
 99          /// <summary>
100          /// Gets or sets the value that specifies the maximum number of characters allowed for user input in the text box. (Optional; Default is 0 which means no limit.)
101          /// </summary>
102          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
103          public int? TextBoxMaxLength { get; set; }
104  
105          /// <summary>
106          /// Gets or sets a value for the placeholder of a textbox.
107          /// </summary>
108          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
109          public string PlaceholderText { get; set; }
110  
111          public double NumberValue { get; set; }
112  
113          /// <summary>
114          /// Gets or sets a minimal value for the number box. (Optional; Default is Double.MinValue)
115          /// </summary>
116          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
117          public double? NumberBoxMin { get; set; }
118  
119          /// <summary>
120          /// Gets or sets a maximal value for the number box. (Optional; Default is Double.MaxValue)
121          /// </summary>
122          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
123          public double? NumberBoxMax { get; set; }
124  
125          /// <summary>
126          /// Gets or sets the value for small changes of the number box. (Optional; Default is 1)
127          /// </summary>
128          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
129          public double? NumberBoxSmallChange { get; set; }
130  
131          /// <summary>
132          /// Gets or sets the value for large changes of the number box. (Optional; Default is 10)
133          /// </summary>
134          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
135          public double? NumberBoxLargeChange { get; set; }
136  
137          // Outdated properties kept for backward compatibility with third-party plugins. (They are only required to not have old third-party plugins crashing when propagating their plugin options.)
138  #pragma warning disable SA1623 // Property summary documentation should match accessors
139  
140          /// <summary>
141          /// PLEASE DON'T USE ANYMORE!! (The property was used for the list of combobox items in the past and is not functional anymore.)
142          /// </summary>
143          [JsonIgnore]
144          public List<string> ComboBoxOptions { get; set; }
145  #pragma warning restore SA1623 // Property summary documentation should match accessors
146      }
147  }