[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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 80 additions and 13 deletions

View File

@ -251,12 +251,7 @@ namespace Microsoft.Plugin.Indexer
var excludedPatternsOption = settings.AdditionalOptions.FirstOrDefault(x => x.Key == ExcludedPatterns);
if (excludedPatternsOption != null)
{
_excludedPatterns = excludedPatternsOption.TextValue
.Split("\r", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.ToList();
}
_excludedPatterns = excludedPatternsOption == null ? new List<string>() : excludedPatternsOption.TextValueAsMultilineList;
}
_driveDetection.IsDriveDetectionWarningCheckBoxSelected = driveDetection;

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.)

View File

@ -562,6 +562,47 @@
Text="{x:Bind TextValue, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
</StackPanel>
<!-- Checkbox And MultilineTextBox setting -->
<StackPanel
HorizontalAlignment="Stretch"
Orientation="Vertical"
Visibility="{x:Bind Path=ShowCheckboxAndMultilineTextbox, Converter={StaticResource BoolToVisibilityConverter}}">
<tkcontrols:SettingsCard
MinHeight="0"
Margin="1"
Padding="0,6,0,4"
Background="Transparent"
BorderThickness="0,0,0,0"
ContentAlignment="Left"
CornerRadius="0">
<controls:CheckBoxWithDescriptionControl
Margin="56,0,0,0"
Description="{x:Bind Path=DisplayDescription}"
Header="{x:Bind Path=DisplayLabel}"
IsChecked="{x:Bind Value, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard
MinHeight="0"
Margin="84,0,45,8"
HorizontalContentAlignment="Stretch"
Background="Transparent"
BorderThickness="0,0,0,0"
ContentAlignment="Vertical"
CornerRadius="0"
Description="{x:Bind Path=SecondDisplayDescription}"
Header="{x:Bind Path=SecondDisplayLabel}"
IsEnabled="{x:Bind SecondSettingIsEnabled, Mode=OneWay}">
<TextBox
MinWidth="{StaticResource SettingActionControlMinWidth}"
MinHeight="160"
AcceptsReturn="True"
PlaceholderText="{x:Bind Path=PlaceholderText}"
ScrollViewer.IsVerticalRailEnabled="True"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollMode="Enabled"
Text="{x:Bind TextValue, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
</StackPanel>
<!-- Checkbox And NumberBox setting -->
<StackPanel
HorizontalAlignment="Stretch"

View File

@ -65,11 +65,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
// TextBox setting
// TextBox and MultilineTextBox setting
public bool ShowTextBox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.Textbox;
public bool ShowMultilineTextBox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.MultilineTextbox;
public int TextBoxMaxLength => (_additionalOption.TextBoxMaxLength == null) ? 0 : _additionalOption.TextBoxMaxLength.Value; // 0 is the default and means no limit.
public string PlaceholderText => _additionalOption.PlaceholderText;
public string TextValue
{
get => _additionalOption.TextValue;
@ -83,11 +87,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
// MultilineTextBox setting
public bool ShowMultilineTextBox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.MultilineTextbox;
public string PlaceholderText => _additionalOption.PlaceholderText;
// NumberBox setting
public bool ShowNumberBox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.Numberbox;
@ -119,6 +118,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
public bool ShowCheckboxAndNumberbox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.CheckboxAndNumberbox;
public bool ShowCheckboxAndMultilineTextbox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.CheckboxAndMultilineTextbox;
// Enabled state of ComboBox, TextBox, NumberBox (If combined with checkbox then checkbox value decides it.)
public bool SecondSettingIsEnabled => (int)_additionalOption.PluginOptionType > 10 ? _additionalOption.Value : true;