Skip to content

Commit fb70806

Browse files
committed
feature: add String Formatter for TextBox in custom action (sourcegit-scm#2274)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 9144dae commit fb70806

6 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/Models/CustomAction.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public string StringValue
5151
set => SetProperty(ref _stringValue, value);
5252
}
5353

54+
public string StringFormatter
55+
{
56+
get => _stringFormatter;
57+
set => SetProperty(ref _stringFormatter, value);
58+
}
59+
5460
public bool BoolValue
5561
{
5662
get => _boolValue;
@@ -61,6 +67,7 @@ public bool BoolValue
6167
private string _label = string.Empty;
6268
private string _description = string.Empty;
6369
private string _stringValue = string.Empty;
70+
private string _stringFormatter = string.Empty;
6471
private bool _boolValue = false;
6572
}
6673

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@
278278
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">Label:</x:String>
279279
<x:String x:Key="Text.ConfigureCustomActionControls.Options" xml:space="preserve">Options:</x:String>
280280
<x:String x:Key="Text.ConfigureCustomActionControls.Options.Tip" xml:space="preserve">Use '|' as delimiter for options</x:String>
281+
<x:String x:Key="Text.ConfigureCustomActionControls.StringFormatter" xml:space="preserve">String Formatter:</x:String>
282+
<x:String x:Key="Text.ConfigureCustomActionControls.StringFormatter.Tip" xml:space="preserve">Optional. Used to format output string. Ignored when input is empty. Please use `${VALUE}` to represent the input string.</x:String>
281283
<x:String x:Key="Text.ConfigureCustomActionControls.StringValue.Tip" xml:space="preserve">The built-in variables ${REPO}, ${REMOTE}, ${BRANCH}, ${BRANCH_FRIENDLY_NAME}, ${SHA}, ${FILE}, and ${TAG} remain available here</x:String>
282284
<x:String x:Key="Text.ConfigureCustomActionControls.Type" xml:space="preserve">Type:</x:String>
283285
<x:String x:Key="Text.ConfigureCustomActionControls.UseFriendlyName" xml:space="preserve">Use Friendly Name:</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@
282282
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">名称 :</x:String>
283283
<x:String x:Key="Text.ConfigureCustomActionControls.Options" xml:space="preserve">选项列表 :</x:String>
284284
<x:String x:Key="Text.ConfigureCustomActionControls.Options.Tip" xml:space="preserve">选项之间请使用英文 '|' 作为分隔符</x:String>
285+
<x:String x:Key="Text.ConfigureCustomActionControls.StringFormatter" xml:space="preserve">输出内容格式化字串:</x:String>
286+
<x:String x:Key="Text.ConfigureCustomActionControls.StringFormatter.Tip" xml:space="preserve">可选。用于格式化输出结果。当用户输入为空时忽略该操作。请使用`${VALUE}`代替用户输入。 </x:String>
285287
<x:String x:Key="Text.ConfigureCustomActionControls.StringValue.Tip" xml:space="preserve">内置变量 ${REPO}, ${REMOTE}, ${BRANCH}, ${BRANCH_FRIENDLY_NAME}, ${SHA}, ${FILE} 与 ${TAG} 在这里仍然可用</x:String>
286288
<x:String x:Key="Text.ConfigureCustomActionControls.Type" xml:space="preserve">类型 :</x:String>
287289
<x:String x:Key="Text.ConfigureCustomActionControls.UseFriendlyName" xml:space="preserve">输出结果带有远程名:</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@
282282
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">名稱:</x:String>
283283
<x:String x:Key="Text.ConfigureCustomActionControls.Options" xml:space="preserve">選項列表:</x:String>
284284
<x:String x:Key="Text.ConfigureCustomActionControls.Options.Tip" xml:space="preserve">請使用英文「|」符號分隔選項</x:String>
285+
<x:String x:Key="Text.ConfigureCustomActionControls.StringFormatter" xml:space="preserve">字串格式化器:</x:String>
286+
<x:String x:Key="Text.ConfigureCustomActionControls.StringFormatter.Tip" xml:space="preserve">可選。用於格式化輸出字串。當輸入為空時將被忽略。請使用 `${VALUE}` 來表示輸入字串。</x:String>
285287
<x:String x:Key="Text.ConfigureCustomActionControls.StringValue.Tip" xml:space="preserve">內建變數 ${REPO}、${REMOTE}、${BRANCH}、${BRANCH_FRIENDLY_NAME}、${SHA}、${FILE} 及 ${TAG} 在此處仍可使用</x:String>
286288
<x:String x:Key="Text.ConfigureCustomActionControls.Type" xml:space="preserve">類型:</x:String>
287289
<x:String x:Key="Text.ConfigureCustomActionControls.UseFriendlyName" xml:space="preserve">輸出包含遠端的名稱:</x:String>

src/ViewModels/ExecuteCustomAction.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,22 @@ public class CustomActionControlTextBox : ICustomActionControlParameter
1818
public string Label { get; set; }
1919
public string Placeholder { get; set; }
2020
public string Text { get; set; }
21+
public string Formatter { get; set; }
2122

22-
public CustomActionControlTextBox(string label, string placeholder, string defaultValue)
23+
public CustomActionControlTextBox(string label, string placeholder, string defaultValue, string formatter)
2324
{
2425
Label = label + ":";
2526
Placeholder = placeholder;
2627
Text = defaultValue;
28+
Formatter = formatter;
2729
}
2830

29-
public string GetValue() => Text;
31+
public string GetValue()
32+
{
33+
if (string.IsNullOrEmpty(Text))
34+
return string.Empty;
35+
return string.IsNullOrEmpty(Formatter) ? Text : Formatter.Replace("${VALUE}", Text);
36+
}
3037
}
3138

3239
public class CustomActionControlPathSelector : ObservableObject, ICustomActionControlParameter
@@ -187,7 +194,7 @@ private void PrepareControlParameters()
187194
switch (ctl.Type)
188195
{
189196
case Models.CustomActionControlType.TextBox:
190-
ControlParameters.Add(new CustomActionControlTextBox(ctl.Label, ctl.Description, PrepareStringByTarget(ctl.StringValue)));
197+
ControlParameters.Add(new CustomActionControlTextBox(ctl.Label, ctl.Description, PrepareStringByTarget(ctl.StringValue), ctl.StringFormatter));
191198
break;
192199
case Models.CustomActionControlType.PathSelector:
193200
ControlParameters.Add(new CustomActionControlPathSelector(ctl.Label, ctl.Description, ctl.BoolValue, PrepareStringByTarget(ctl.StringValue)));

src/Views/ConfigureCustomActionControls.axaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@
196196
</TextBlock.IsVisible>
197197
</TextBlock>
198198

199+
<!-- String Formatter -->
200+
<TextBlock Margin="0,12,0,0"
201+
Text="{DynamicResource Text.ConfigureCustomActionControls.StringFormatter}"
202+
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:CustomActionControlType.TextBox}}"/>
203+
<TextBox Margin="0,4,0,0"
204+
CornerRadius="3"
205+
Height="28"
206+
Text="{Binding StringFormatter, Mode=TwoWay}"
207+
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:CustomActionControlType.TextBox}}"/>
208+
<TextBlock Margin="0,2,0,0"
209+
Classes="small"
210+
TextWrapping="Wrap"
211+
Text="{DynamicResource Text.ConfigureCustomActionControls.StringFormatter.Tip}"
212+
Foreground="{DynamicResource Brush.FG2}"
213+
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:CustomActionControlType.TextBox}}"/>
214+
199215
<!-- BoolValue is needed by CheckBox/PathSelector -->
200216
<Grid Margin="0,8,0,0" ColumnDefinitions="Auto,*">
201217
<Grid.IsVisible>

0 commit comments

Comments
 (0)