mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-20 21:01:06 +08:00
feature: add String Formatter for TextBox in custom action (#2274)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -51,6 +51,12 @@ namespace SourceGit.Models
|
||||
set => SetProperty(ref _stringValue, value);
|
||||
}
|
||||
|
||||
public string StringFormatter
|
||||
{
|
||||
get => _stringFormatter;
|
||||
set => SetProperty(ref _stringFormatter, value);
|
||||
}
|
||||
|
||||
public bool BoolValue
|
||||
{
|
||||
get => _boolValue;
|
||||
@@ -61,6 +67,7 @@ namespace SourceGit.Models
|
||||
private string _label = string.Empty;
|
||||
private string _description = string.Empty;
|
||||
private string _stringValue = string.Empty;
|
||||
private string _stringFormatter = string.Empty;
|
||||
private bool _boolValue = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -278,6 +278,8 @@
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">Label:</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Options" xml:space="preserve">Options:</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Options.Tip" xml:space="preserve">Use '|' as delimiter for options</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.StringFormatter" xml:space="preserve">String Formatter:</x:String>
|
||||
<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>
|
||||
<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>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Type" xml:space="preserve">Type:</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.UseFriendlyName" xml:space="preserve">Use Friendly Name:</x:String>
|
||||
|
||||
@@ -282,6 +282,8 @@
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">名称 :</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Options" xml:space="preserve">选项列表 :</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Options.Tip" xml:space="preserve">选项之间请使用英文 '|' 作为分隔符</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.StringFormatter" xml:space="preserve">输出内容格式化字串:</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.StringFormatter.Tip" xml:space="preserve">可选。用于格式化输出结果。当用户输入为空时忽略该操作。请使用`${VALUE}`代替用户输入。 </x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.StringValue.Tip" xml:space="preserve">内置变量 ${REPO}, ${REMOTE}, ${BRANCH}, ${BRANCH_FRIENDLY_NAME}, ${SHA}, ${FILE} 与 ${TAG} 在这里仍然可用</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Type" xml:space="preserve">类型 :</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.UseFriendlyName" xml:space="preserve">输出结果带有远程名:</x:String>
|
||||
|
||||
@@ -282,6 +282,8 @@
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">名稱:</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Options" xml:space="preserve">選項列表:</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Options.Tip" xml:space="preserve">請使用英文「|」符號分隔選項</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.StringFormatter" xml:space="preserve">字串格式化器:</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.StringFormatter.Tip" xml:space="preserve">可選。用於格式化輸出字串。當輸入為空時將被忽略。請使用 `${VALUE}` 來表示輸入字串。</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.StringValue.Tip" xml:space="preserve">內建變數 ${REPO}、${REMOTE}、${BRANCH}、${BRANCH_FRIENDLY_NAME}、${SHA}、${FILE} 及 ${TAG} 在此處仍可使用</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.Type" xml:space="preserve">類型:</x:String>
|
||||
<x:String x:Key="Text.ConfigureCustomActionControls.UseFriendlyName" xml:space="preserve">輸出包含遠端的名稱:</x:String>
|
||||
|
||||
@@ -18,15 +18,22 @@ namespace SourceGit.ViewModels
|
||||
public string Label { get; set; }
|
||||
public string Placeholder { get; set; }
|
||||
public string Text { get; set; }
|
||||
public string Formatter { get; set; }
|
||||
|
||||
public CustomActionControlTextBox(string label, string placeholder, string defaultValue)
|
||||
public CustomActionControlTextBox(string label, string placeholder, string defaultValue, string formatter)
|
||||
{
|
||||
Label = label + ":";
|
||||
Placeholder = placeholder;
|
||||
Text = defaultValue;
|
||||
Formatter = formatter;
|
||||
}
|
||||
|
||||
public string GetValue() => Text;
|
||||
public string GetValue()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Text))
|
||||
return string.Empty;
|
||||
return string.IsNullOrEmpty(Formatter) ? Text : Formatter.Replace("${VALUE}", Text);
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomActionControlPathSelector : ObservableObject, ICustomActionControlParameter
|
||||
@@ -187,7 +194,7 @@ namespace SourceGit.ViewModels
|
||||
switch (ctl.Type)
|
||||
{
|
||||
case Models.CustomActionControlType.TextBox:
|
||||
ControlParameters.Add(new CustomActionControlTextBox(ctl.Label, ctl.Description, PrepareStringByTarget(ctl.StringValue)));
|
||||
ControlParameters.Add(new CustomActionControlTextBox(ctl.Label, ctl.Description, PrepareStringByTarget(ctl.StringValue), ctl.StringFormatter));
|
||||
break;
|
||||
case Models.CustomActionControlType.PathSelector:
|
||||
ControlParameters.Add(new CustomActionControlPathSelector(ctl.Label, ctl.Description, ctl.BoolValue, PrepareStringByTarget(ctl.StringValue)));
|
||||
|
||||
@@ -196,6 +196,22 @@
|
||||
</TextBlock.IsVisible>
|
||||
</TextBlock>
|
||||
|
||||
<!-- String Formatter -->
|
||||
<TextBlock Margin="0,12,0,0"
|
||||
Text="{DynamicResource Text.ConfigureCustomActionControls.StringFormatter}"
|
||||
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:CustomActionControlType.TextBox}}"/>
|
||||
<TextBox Margin="0,4,0,0"
|
||||
CornerRadius="3"
|
||||
Height="28"
|
||||
Text="{Binding StringFormatter, Mode=TwoWay}"
|
||||
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:CustomActionControlType.TextBox}}"/>
|
||||
<TextBlock Margin="0,2,0,0"
|
||||
Classes="small"
|
||||
TextWrapping="Wrap"
|
||||
Text="{DynamicResource Text.ConfigureCustomActionControls.StringFormatter.Tip}"
|
||||
Foreground="{DynamicResource Brush.FG2}"
|
||||
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:CustomActionControlType.TextBox}}"/>
|
||||
|
||||
<!-- BoolValue is needed by CheckBox/PathSelector -->
|
||||
<Grid Margin="0,8,0,0" ColumnDefinitions="Auto,*">
|
||||
<Grid.IsVisible>
|
||||
|
||||
Reference in New Issue
Block a user