[PTRun]Add CheckboxAndMultilineTextBox type and improvements to multiline text handling (#31967)

* code improvements and adding CheckboxAndMultilineTextBox type

* Update xaml code

* add alias property for multiline text box content

* improve comments

* final improvements
This commit is contained in:
Heiko
2024-03-21 13:02:57 +01:00
committed by GitHub
parent d67b02bae3
commit 79a7987874
4 changed files with 80 additions and 13 deletions

View File

@@ -2,7 +2,9 @@
// 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
@@ -19,6 +21,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
CheckboxAndCombobox = 11,
CheckboxAndTextbox = 12,
CheckboxAndNumberbox = 13,
CheckboxAndMultilineTextbox = 14,
}
/// <summary>
@@ -63,8 +66,35 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<KeyValuePair<string, string>> ComboBoxItems { get; set; }
private string _textValue;
/// <summary>
/// Gets or sets the text of a (multiline) text setting.
/// </summary>
/// <remarks>
/// For multiline text "\r" is used as line break. Alternatively you can use the <see cref="TextValueAsMultilineList" /> property.
/// </remarks>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string TextValue { get; set; }
public string TextValue
{
get { return _textValue; }
set { _textValue = value; }
}
/// <summary>
/// Gets or sets the text value for multiline texts using a list of type string.
/// </summary>
/// <remarks>
/// Getter: It reads the <see cref="TextValue" /> property and converts it to a list.<br />
/// Setter: It converts the list to a string separated by "\r" and sets the <see cref="TextValue"/> property.
/// </remarks>
// 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<string> TextValueAsMultilineList
{
get { return _textValue?.Split("\r", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)?.ToList() ?? new List<string>(); }
set { _textValue = (value != null && value.Count > 0) ? string.Join("\r", value.ToArray()) : string.Empty; }
}
/// <summary>
/// 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.)