From 79a798787477de66118ec41795e83cf1ed724c8f Mon Sep 17 00:00:00 2001 From: Heiko <61519853+htcfreek@users.noreply.github.com> Date: Thu, 21 Mar 2024 13:02:57 +0100 Subject: [PATCH] [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 --- .../Plugins/Microsoft.Plugin.Indexer/Main.cs | 7 +--- .../PluginAdditionalOption.cs | 32 ++++++++++++++- .../SettingsXAML/Views/PowerLauncherPage.xaml | 41 +++++++++++++++++++ .../PluginAdditionalOptionViewModel.cs | 13 +++--- 4 files changed, 80 insertions(+), 13 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs index 7be30b8cb0..3786c5179d 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs @@ -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() : excludedPatternsOption.TextValueAsMultilineList; } _driveDetection.IsDriveDetectionWarningCheckBoxSelected = driveDetection; diff --git a/src/settings-ui/Settings.UI.Library/PluginAdditionalOption.cs b/src/settings-ui/Settings.UI.Library/PluginAdditionalOption.cs index 36adc1e5f0..05aff5216f 100644 --- a/src/settings-ui/Settings.UI.Library/PluginAdditionalOption.cs +++ b/src/settings-ui/Settings.UI.Library/PluginAdditionalOption.cs @@ -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, } /// @@ -63,8 +66,35 @@ namespace Microsoft.PowerToys.Settings.UI.Library [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; set; } + 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.) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml index 445477be85..ca9a4d647d 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml @@ -562,6 +562,47 @@ Text="{x:Bind TextValue, Mode=TwoWay}" /> + + + + + + + + + _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;