// 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; using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; namespace Microsoft.PowerToys.Settings.UI.Library { public class PluginAdditionalOption { public enum AdditionalOptionType { Checkbox = 0, Combobox = 1, Textbox = 2, Numberbox = 3, MultilineTextbox = 4, CheckboxAndCombobox = 11, CheckboxAndTextbox = 12, CheckboxAndNumberbox = 13, CheckboxAndMultilineTextbox = 14, } /// /// Gets or sets the layout type of the option in settings ui (Optional; Default is checkbox) /// public AdditionalOptionType PluginOptionType { get; set; } public string Key { get; set; } public string DisplayLabel { get; set; } /// /// Gets or sets a value to show a description of this setting in the settings ui. (Optional) /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string DisplayDescription { get; set; } /// /// Gets or sets a value to show a label for the second setting if two combined settings are shown /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string SecondDisplayLabel { get; set; } /// /// Gets or sets a value to show a description for the second setting in the settings ui if two combined settings are shown. (Optional) /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string SecondDisplayDescription { get; set; } /// /// Gets or sets a value indicating whether the checkbox is set or not set /// public bool Value { get; set; } public int ComboBoxValue { get; set; } /// /// Gets or sets the list of dropdown items for the ComboBox. Please use the item name as Key and an integer as Value. /// The value gets converted in settings UI to an integer and will be saved in . /// You can define the visibility order in settings ui by arranging the list items. /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public List> ComboBoxItems { get; set; } private string _textValue; /// /// Gets or sets the text of a (multiline) text setting. /// /// /// For multiline text "\r" is used as line break. Alternatively you can use the property. /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string TextValue { get { return _textValue; } set { _textValue = value; } } /// /// Gets or sets the text value for multiline texts using a list of type string. /// /// /// Getter: It reads the property and converts it to a list.
/// Setter: It converts the list to a string separated by "\r" and sets the property. ///
// 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. [JsonIgnore] public List TextValueAsMultilineList { get { return _textValue?.Split("\r", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)?.ToList() ?? new List(); } set { _textValue = (value != null && value.Count > 0) ? string.Join("\r", value.ToArray()) : string.Empty; } } /// /// 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.) /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? TextBoxMaxLength { get; set; } /// /// Gets or sets a value for the placeholder of a textbox. /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string PlaceholderText { get; set; } public double NumberValue { get; set; } /// /// Gets or sets a minimal value for the number box. (Optional; Default is Double.MinValue) /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public double? NumberBoxMin { get; set; } /// /// Gets or sets a maximal value for the number box. (Optional; Default is Double.MaxValue) /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public double? NumberBoxMax { get; set; } /// /// Gets or sets the value for small changes of the number box. (Optional; Default is 1) /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public double? NumberBoxSmallChange { get; set; } /// /// Gets or sets the value for large changes of the number box. (Optional; Default is 10) /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public double? NumberBoxLargeChange { get; set; } // 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.) #pragma warning disable SA1623 // Property summary documentation should match accessors /// /// PLEASE DON'T USE ANYMORE!! (The property was used for the list of combobox items in the past and is not functional anymore.) /// [JsonIgnore] public List ComboBoxOptions { get; set; } #pragma warning restore SA1623 // Property summary documentation should match accessors } }