Skip to content

Commit e1bbbe0

Browse files
committed
feature: supports to use ComboBox input control in cutom actions (#1482)
Signed-off-by: leo <[email protected]>
1 parent 9a7be7e commit e1bbbe0

File tree

10 files changed

+95
-11
lines changed

10 files changed

+95
-11
lines changed

src/Models/CustomAction.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public enum CustomActionControlType
1616
TextBox = 0,
1717
PathSelector,
1818
CheckBox,
19+
ComboBox,
1920
}
2021

2122
public class CustomActionControl : ObservableObject

src/Resources/Locales/de_DE.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue" xml:space="preserve">Wert bei Markierung:</x:String>
209209
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue.Tip" xml:space="preserve">Wenn markiert, wird dieser Wert in Kommandozeilen-Argumenten benutzt</x:String>
210210
<x:String x:Key="Text.ConfigureCustomActionControls.Description" xml:space="preserve">Beschreibung:</x:String>
211-
<x:String x:Key="Text.ConfigureCustomActionControls.Description.Tip" xml:space="preserve">Dient als Platzhalter in TextBox/Path Selector (Pfadeingabe) oder als Tooltip in CheckBox (Kontrollkästchen)</x:String>
211+
<x:String x:Key="Text.ConfigureCustomActionControls.Description.Tip" xml:space="preserve">Dient als Platzhalter in TextBox/Path Selector (Pfadeingabe) oder als Tooltip in ComboBox/CheckBox (Kontrollkästchen)</x:String>
212212
<x:String x:Key="Text.ConfigureCustomActionControls.DefaultValue" xml:space="preserve">Standardwert:</x:String>
213213
<x:String x:Key="Text.ConfigureCustomActionControls.IsFolder" xml:space="preserve">Ordner?</x:String>
214214
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">Bezeichnung:</x:String>

src/Resources/Locales/en_US.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,12 @@
204204
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue" xml:space="preserve">Checked Value:</x:String>
205205
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue.Tip" xml:space="preserve">When checked, this value will be used in command-line arguments</x:String>
206206
<x:String x:Key="Text.ConfigureCustomActionControls.Description" xml:space="preserve">Description:</x:String>
207-
<x:String x:Key="Text.ConfigureCustomActionControls.Description.Tip" xml:space="preserve">Used as placeholder in TextBox/PathSelector or tooltip in CheckBox</x:String>
207+
<x:String x:Key="Text.ConfigureCustomActionControls.Description.Tip" xml:space="preserve">Used as placeholder in TextBox/PathSelector or tooltip in CheckBox/ComboBox</x:String>
208208
<x:String x:Key="Text.ConfigureCustomActionControls.DefaultValue" xml:space="preserve">Default:</x:String>
209209
<x:String x:Key="Text.ConfigureCustomActionControls.IsFolder" xml:space="preserve">Is Folder:</x:String>
210210
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">Label:</x:String>
211+
<x:String x:Key="Text.ConfigureCustomActionControls.Options" xml:space="preserve">Options:</x:String>
212+
<x:String x:Key="Text.ConfigureCustomActionControls.Options.Tip" xml:space="preserve">Use '|' as delimitter for options</x:String>
211213
<x:String x:Key="Text.ConfigureCustomActionControls.Type" xml:space="preserve">Type:</x:String>
212214
<x:String x:Key="Text.ConfigureWorkspace" xml:space="preserve">Workspaces</x:String>
213215
<x:String x:Key="Text.ConfigureWorkspace.Color" xml:space="preserve">Color</x:String>

src/Resources/Locales/es_ES.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue" xml:space="preserve">Valor Comprobado:</x:String>
209209
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue.Tip" xml:space="preserve">Cuando sea comprobado, este valor será usado en argumentos de la línea de comandos</x:String>
210210
<x:String x:Key="Text.ConfigureCustomActionControls.Description" xml:space="preserve">Descripción:</x:String>
211-
<x:String x:Key="Text.ConfigureCustomActionControls.Description.Tip" xml:space="preserve">Utilizado como marcador de posición en CajaDeTexto/SelectorDeRuta ó tooltip en CheckBox</x:String>
211+
<x:String x:Key="Text.ConfigureCustomActionControls.Description.Tip" xml:space="preserve">Utilizado como marcador de posición en CajaDeTexto/SelectorDeRuta ó tooltip en CheckBox/ComboBox</x:String>
212212
<x:String x:Key="Text.ConfigureCustomActionControls.DefaultValue" xml:space="preserve">Por defecto:</x:String>
213213
<x:String x:Key="Text.ConfigureCustomActionControls.IsFolder" xml:space="preserve">Es Carpeta:</x:String>
214214
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">Etiqueta:</x:String>

src/Resources/Locales/ru_RU.axaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@
208208
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue" xml:space="preserve">Проверяемое значение:</x:String>
209209
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue.Tip" xml:space="preserve">Если установлено, то данное значение будет использоваться в аргументах командной строки</x:String>
210210
<x:String x:Key="Text.ConfigureCustomActionControls.Description" xml:space="preserve">Описание:</x:String>
211-
<x:String x:Key="Text.ConfigureCustomActionControls.Description.Tip" xml:space="preserve">Используется в качестве заполнителя в текстовом поле/селекторе пути или всплывающей подсказки в флажке</x:String>
212211
<x:String x:Key="Text.ConfigureCustomActionControls.DefaultValue" xml:space="preserve">По умолчанию:</x:String>
213212
<x:String x:Key="Text.ConfigureCustomActionControls.IsFolder" xml:space="preserve">Это каталог:</x:String>
214213
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">Метка:</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,12 @@
208208
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue" xml:space="preserve">启用时命令行参数 :</x:String>
209209
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue.Tip" xml:space="preserve">此CheckBox勾选后,该值会被应用于命令行参数</x:String>
210210
<x:String x:Key="Text.ConfigureCustomActionControls.Description" xml:space="preserve">描述 :</x:String>
211-
<x:String x:Key="Text.ConfigureCustomActionControls.Description.Tip" xml:space="preserve">TextBox及Path Selector中用作Placeholder,CheckBox中用作ToolTip</x:String>
211+
<x:String x:Key="Text.ConfigureCustomActionControls.Description.Tip" xml:space="preserve">TextBox及Path Selector中用作Placeholder,CheckBox及ComboBox中用作ToolTip</x:String>
212212
<x:String x:Key="Text.ConfigureCustomActionControls.DefaultValue" xml:space="preserve">默认值 :</x:String>
213213
<x:String x:Key="Text.ConfigureCustomActionControls.IsFolder" xml:space="preserve">目标是否是目录 :</x:String>
214214
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">名称 :</x:String>
215+
<x:String x:Key="Text.ConfigureCustomActionControls.Options" xml:space="preserve">选项列表 :</x:String>
216+
<x:String x:Key="Text.ConfigureCustomActionControls.Options.Tip" xml:space="preserve">选项之间请使用英文 '|' 作为分隔符</x:String>
215217
<x:String x:Key="Text.ConfigureCustomActionControls.Type" xml:space="preserve">类型 :</x:String>
216218
<x:String x:Key="Text.ConfigureWorkspace" xml:space="preserve">工作区</x:String>
217219
<x:String x:Key="Text.ConfigureWorkspace.Color" xml:space="preserve">颜色</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,12 @@
208208
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue" xml:space="preserve">啟用時的指令行參數:</x:String>
209209
<x:String x:Key="Text.ConfigureCustomActionControls.CheckedValue.Tip" xml:space="preserve">勾選 CheckBox 後,此值將用於命令列參數中</x:String>
210210
<x:String x:Key="Text.ConfigureCustomActionControls.Description" xml:space="preserve">描述:</x:String>
211-
<x:String x:Key="Text.ConfigureCustomActionControls.Description.Tip" xml:space="preserve">在 TextBox/PathSelector 中用作占位符,或在 CheckBox 中用作工具提示</x:String>
211+
<x:String x:Key="Text.ConfigureCustomActionControls.Description.Tip" xml:space="preserve">在 TextBox/PathSelector 中用作占位符,或在 CheckBox/ComboBox 中用作工具提示</x:String>
212212
<x:String x:Key="Text.ConfigureCustomActionControls.DefaultValue" xml:space="preserve">預設值:</x:String>
213213
<x:String x:Key="Text.ConfigureCustomActionControls.IsFolder" xml:space="preserve">目標路徑是否為資料夾:</x:String>
214214
<x:String x:Key="Text.ConfigureCustomActionControls.Label" xml:space="preserve">名稱:</x:String>
215+
<x:String x:Key="Text.ConfigureCustomActionControls.Options" xml:space="preserve">選項列表:</x:String>
216+
<x:String x:Key="Text.ConfigureCustomActionControls.Options.Tip" xml:space="preserve">請使用英文「|」符號分隔選項</x:String>
215217
<x:String x:Key="Text.ConfigureCustomActionControls.Type" xml:space="preserve">類型:</x:String>
216218
<x:String x:Key="Text.ConfigureWorkspace" xml:space="preserve">工作區</x:String>
217219
<x:String x:Key="Text.ConfigureWorkspace.Color" xml:space="preserve">顏色</x:String>

src/ViewModels/ExecuteCustomAction.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,36 @@ public CustomActionControlCheckBox(string label, string tooltip, string checkedV
7272
public string GetValue() => IsChecked ? CheckedValue : string.Empty;
7373
}
7474

75+
public class CustomActionControlComboBox : ObservableObject, ICustomActionControlParameter
76+
{
77+
public string Label { get; set; } = string.Empty;
78+
public string Description { get; set; } = string.Empty;
79+
public List<string> Options { get; set; } = [];
80+
81+
public string Value
82+
{
83+
get => _value;
84+
set => SetProperty(ref _value, value);
85+
}
86+
87+
public CustomActionControlComboBox(string label, string description, string options)
88+
{
89+
Label = label;
90+
Description = description;
91+
92+
var parts = options.Split('|', StringSplitOptions.TrimEntries);
93+
if (parts.Length > 0)
94+
{
95+
Options.AddRange(parts);
96+
_value = parts[0];
97+
}
98+
}
99+
100+
public string GetValue() => _value;
101+
102+
private string _value = string.Empty;
103+
}
104+
75105
public class ExecuteCustomAction : Popup
76106
{
77107
public Models.CustomAction CustomAction
@@ -160,11 +190,14 @@ private void PrepareControlParameters()
160190
case Models.CustomActionControlType.TextBox:
161191
ControlParameters.Add(new CustomActionControlTextBox(ctl.Label, ctl.Description, PrepareStringByTarget(ctl.StringValue)));
162192
break;
193+
case Models.CustomActionControlType.PathSelector:
194+
ControlParameters.Add(new CustomActionControlPathSelector(ctl.Label, ctl.Description, ctl.BoolValue, PrepareStringByTarget(ctl.StringValue)));
195+
break;
163196
case Models.CustomActionControlType.CheckBox:
164197
ControlParameters.Add(new CustomActionControlCheckBox(ctl.Label, ctl.Description, ctl.StringValue, ctl.BoolValue));
165198
break;
166-
case Models.CustomActionControlType.PathSelector:
167-
ControlParameters.Add(new CustomActionControlPathSelector(ctl.Label, ctl.Description, ctl.BoolValue, PrepareStringByTarget(ctl.StringValue)));
199+
case Models.CustomActionControlType.ComboBox:
200+
ControlParameters.Add(new CustomActionControlComboBox(ctl.Label, ctl.Description, PrepareStringByTarget(ctl.StringValue)));
168201
break;
169202
}
170203
}

src/Views/ConfigureCustomActionControls.axaml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<ComboBoxItem Content="TextBox"/>
132132
<ComboBoxItem Content="Path Selector"/>
133133
<ComboBoxItem Content="CheckBox"/>
134+
<ComboBoxItem Content="ComboBox"/>
134135
</ComboBox>
135136

136137
<!-- Description -->
@@ -140,22 +141,43 @@
140141
Height="28"
141142
Text="{Binding Description, Mode=TwoWay}"/>
142143
<TextBlock Margin="0,2,0,0"
144+
Classes="small"
143145
TextWrapping="Wrap"
144146
Text="{DynamicResource Text.ConfigureCustomActionControls.Description.Tip}"
145147
Foreground="{DynamicResource Brush.FG2}"/>
146148

147-
<!-- Default value -->
148-
<TextBlock Margin="0,12,0,0" Text="{DynamicResource Text.ConfigureCustomActionControls.DefaultValue}"/>
149+
<!-- Default value/Options -->
150+
<TextBlock Margin="0,12,0,0"
151+
Text="{DynamicResource Text.ConfigureCustomActionControls.DefaultValue}"
152+
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.NotEqual}, ConverterParameter={x:Static m:CustomActionControlType.ComboBox}}"/>
153+
<TextBlock Margin="0,12,0,0"
154+
Text="{DynamicResource Text.ConfigureCustomActionControls.Options}"
155+
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:CustomActionControlType.ComboBox}}"/>
149156
<TextBox Margin="0,4,0,0"
150157
CornerRadius="3"
151158
Height="28"
152159
Text="{Binding StringValue, Mode=TwoWay}"
153160
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.NotEqual}, ConverterParameter={x:Static m:CustomActionControlType.CheckBox}}"/>
154161
<TextBlock Margin="0,2,0,0"
162+
Classes="small"
155163
TextWrapping="Wrap"
156164
Text="{DynamicResource Text.Configure.CustomAction.Arguments.Tip}"
157165
Foreground="{DynamicResource Brush.FG2}"
158-
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.NotEqual}, ConverterParameter={x:Static m:CustomActionControlType.CheckBox}}"/>
166+
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.NotEqual}, ConverterParameter={x:Static m:CustomActionControlType.CheckBox}}">
167+
<TextBlock.IsVisible>
168+
<MultiBinding Converter="{x:Static BoolConverters.Or}">
169+
<Binding Path="Type" Converter="{x:Static ObjectConverters.Equal}" ConverterParameter="{x:Static m:CustomActionControlType.TextBox}"/>
170+
<Binding Path="Type" Converter="{x:Static ObjectConverters.Equal}" ConverterParameter="{x:Static m:CustomActionControlType.PathSelector}"/>
171+
</MultiBinding>
172+
</TextBlock.IsVisible>
173+
</TextBlock>
174+
<TextBlock Margin="0,2,0,0"
175+
Classes="small"
176+
TextWrapping="Wrap"
177+
Text="{DynamicResource Text.ConfigureCustomActionControls.Options.Tip}"
178+
Foreground="{DynamicResource Brush.FG2}"
179+
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:CustomActionControlType.ComboBox}}">
180+
</TextBlock>
159181
<CheckBox Height="28"
160182
Margin="0,4,0,0"
161183
IsChecked="{Binding BoolValue, Mode=TwoWay}"
@@ -180,6 +202,7 @@
180202
Text="{Binding StringValue, Mode=TwoWay}"
181203
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:CustomActionControlType.CheckBox}}"/>
182204
<TextBlock Margin="0,2,0,0"
205+
Classes="small"
183206
TextWrapping="Wrap"
184207
Text="{DynamicResource Text.ConfigureCustomActionControls.CheckedValue.Tip}"
185208
IsVisible="{Binding Type, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:CustomActionControlType.CheckBox}}"

src/Views/ExecuteCustomAction.axaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,28 @@
106106
</TextBox>
107107
</Grid>
108108
</DataTemplate>
109+
110+
<DataTemplate DataType="vm:CustomActionControlComboBox">
111+
<Grid RowDefinitions="32,Auto" ColumnDefinitions="150,*">
112+
<TextBlock Grid.Row="0" Grid.Column="0"
113+
Text="{Binding Label}"
114+
HorizontalAlignment="Right" VerticalAlignment="Center"
115+
Margin="0,0,8,0"/>
116+
<ComboBox Grid.Row="0" Grid.Column="1"
117+
Height="28" Padding="8,0"
118+
VerticalAlignment="Center" HorizontalAlignment="Stretch"
119+
ItemsSource="{Binding Options}"
120+
SelectedItem="{Binding Value, Mode=TwoWay}"/>
121+
122+
<TextBlock Grid.Row="1" Grid.Column="1"
123+
Classes="small"
124+
Margin="0,2"
125+
TextWrapping="Wrap"
126+
Text="{Binding Description}"
127+
Foreground="{DynamicResource Brush.FG2}"
128+
IsVisible="{Binding Description, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
129+
</Grid>
130+
</DataTemplate>
109131
</ItemsControl.DataTemplates>
110132
</ItemsControl>
111133
</StackPanel>

0 commit comments

Comments
 (0)