mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
[PT Run > PluginAdditionalOptions] Refactoring and more settings types (#28601)
* refactor existing code * fixes * fix combo box layout * improve layout * add more settings types * combined setting * enabled state * fix spelling * improve settings.json handling on null values * textbox improvements * rework xaml code * fix xaml style * spell fixes * spell fixes * update comment
This commit is contained in:
@@ -360,6 +360,7 @@
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="ViewModels:PluginAdditionalOptionViewModel">
|
||||
<StackPanel HorizontalAlignment="Stretch" Orientation="Vertical">
|
||||
<!-- Checkbox setting -->
|
||||
<controls:SettingsCard
|
||||
MinHeight="0"
|
||||
Margin="1"
|
||||
@@ -367,23 +368,172 @@
|
||||
Background="Transparent"
|
||||
BorderThickness="0,0,0,0"
|
||||
ContentAlignment="Left"
|
||||
CornerRadius="0">
|
||||
<StackPanel Orientation="Vertical">
|
||||
CornerRadius="0"
|
||||
Visibility="{x:Bind Path=ShowCheckBox, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<custom:CheckBoxWithDescriptionControl
|
||||
Margin="56,0,0,0"
|
||||
Description="{x:Bind Path=DisplayDescription}"
|
||||
Header="{x:Bind Path=DisplayLabel}"
|
||||
IsChecked="{x:Bind Path=Value, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
<!-- ComboBox setting -->
|
||||
<controls:SettingsCard
|
||||
MinHeight="0"
|
||||
Margin="56,8,45,8"
|
||||
Background="Transparent"
|
||||
BorderThickness="0,0,0,0"
|
||||
CornerRadius="0"
|
||||
Description="{x:Bind Path=DisplayDescription}"
|
||||
Header="{x:Bind Path=DisplayLabel}"
|
||||
Visibility="{x:Bind Path=ShowComboBox, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<ComboBox
|
||||
MinWidth="{StaticResource SettingActionControlMinWidth}"
|
||||
ItemsSource="{x:Bind Path=ComboBoxOptions}"
|
||||
SelectedIndex="{x:Bind Path=ComboBoxValue, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
<!-- TextBox setting -->
|
||||
<controls:SettingsCard
|
||||
MinHeight="0"
|
||||
Margin="56,8,45,8"
|
||||
Background="Transparent"
|
||||
BorderThickness="0,0,0,0"
|
||||
CornerRadius="0"
|
||||
Description="{x:Bind Path=DisplayDescription}"
|
||||
Header="{x:Bind Path=DisplayLabel}"
|
||||
Visibility="{x:Bind Path=ShowTextBox, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<TextBox
|
||||
MinWidth="{StaticResource SettingActionControlMinWidth}"
|
||||
MaxWidth="450"
|
||||
MaxLength="{x:Bind Path=TextBoxMaxLength, Mode=OneWay}"
|
||||
Text="{x:Bind Path=TextValue, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
<!-- NumberBox setting -->
|
||||
<controls:SettingsCard
|
||||
MinHeight="0"
|
||||
Margin="56,8,45,8"
|
||||
Background="Transparent"
|
||||
BorderThickness="0,0,0,0"
|
||||
CornerRadius="0"
|
||||
Description="{x:Bind Path=DisplayDescription}"
|
||||
Header="{x:Bind Path=DisplayLabel}"
|
||||
Visibility="{x:Bind Path=ShowNumberBox, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<NumberBox
|
||||
MinWidth="{StaticResource SettingActionControlMinWidth}"
|
||||
LargeChange="{x:Bind Path=NumberBoxLargeChange, Mode=OneWay}"
|
||||
Maximum="{x:Bind Path=NumberBoxMax, Mode=OneWay}"
|
||||
Minimum="{x:Bind Path=NumberBoxMin, Mode=OneWay}"
|
||||
SmallChange="{x:Bind Path=NumberBoxSmallChange, Mode=OneWay}"
|
||||
SpinButtonPlacementMode="Compact"
|
||||
Value="{x:Bind Path=NumberValue, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
<!-- Checkbox And ComboBox setting -->
|
||||
<StackPanel
|
||||
HorizontalAlignment="Stretch"
|
||||
Orientation="Vertical"
|
||||
Visibility="{x:Bind Path=ShowCheckboxAndCombobox, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<controls:SettingsCard
|
||||
MinHeight="0"
|
||||
Margin="1"
|
||||
Padding="0,6,0,4"
|
||||
Background="Transparent"
|
||||
BorderThickness="0,0,0,0"
|
||||
ContentAlignment="Left"
|
||||
CornerRadius="0">
|
||||
<custom:CheckBoxWithDescriptionControl
|
||||
Margin="56,0,0,0"
|
||||
Description="{x:Bind Path=DisplayDescription}"
|
||||
Header="{x:Bind Path=DisplayLabel}"
|
||||
IsChecked="{x:Bind Path=Value, Mode=TwoWay}"
|
||||
Visibility="{x:Bind Path=ShowCheckBox, Converter={StaticResource BoolToVisibilityConverter}}" />
|
||||
IsChecked="{x:Bind Path=Value, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
<controls:SettingsCard
|
||||
MinHeight="0"
|
||||
Margin="84,0,45,8"
|
||||
Background="Transparent"
|
||||
BorderThickness="0,0,0,0"
|
||||
CornerRadius="0"
|
||||
Description="{x:Bind Path=SecondDisplayDescription}"
|
||||
Header="{x:Bind Path=SecondDisplayLabel}"
|
||||
IsEnabled="{x:Bind Path=SecondSettingIsEnabled, Mode=OneWay}">
|
||||
<ComboBox
|
||||
MinWidth="{StaticResource SettingActionControlMinWidth}"
|
||||
ItemsSource="{x:Bind Path=ComboBoxOptions}"
|
||||
SelectedIndex="{x:Bind Path=ComboBoxValue, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
</StackPanel>
|
||||
<!-- Checkbox And TextBox setting -->
|
||||
<StackPanel
|
||||
HorizontalAlignment="Stretch"
|
||||
Orientation="Vertical"
|
||||
Visibility="{x:Bind Path=ShowCheckboxAndTextbox, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<controls:SettingsCard
|
||||
MinHeight="0"
|
||||
Margin="1"
|
||||
Padding="0,6,0,4"
|
||||
Background="Transparent"
|
||||
BorderThickness="0,0,0,0"
|
||||
ContentAlignment="Left"
|
||||
CornerRadius="0">
|
||||
<custom:CheckBoxWithDescriptionControl
|
||||
Margin="56,0,0,0"
|
||||
Description="{x:Bind Path=DisplayDescription}"
|
||||
Header="{x:Bind Path=DisplayLabel}"
|
||||
ItemsSource="{x:Bind Path=ComboBoxOptions}"
|
||||
SelectedIndex="{x:Bind Path=Option, Mode=TwoWay}"
|
||||
Visibility="{x:Bind Path=ShowComboBox, Converter={StaticResource BoolToVisibilityConverter}}" />
|
||||
</StackPanel>
|
||||
</controls:SettingsCard>
|
||||
IsChecked="{x:Bind Path=Value, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
<controls:SettingsCard
|
||||
MinHeight="0"
|
||||
Margin="84,0,45,8"
|
||||
Background="Transparent"
|
||||
BorderThickness="0,0,0,0"
|
||||
CornerRadius="0"
|
||||
Description="{x:Bind Path=SecondDisplayDescription}"
|
||||
Header="{x:Bind Path=SecondDisplayLabel}"
|
||||
IsEnabled="{x:Bind Path=SecondSettingIsEnabled, Mode=OneWay}">
|
||||
<TextBox
|
||||
MinWidth="{StaticResource SettingActionControlMinWidth}"
|
||||
MaxWidth="450"
|
||||
MaxLength="{x:Bind Path=TextBoxMaxLength, Mode=OneWay}"
|
||||
Text="{x:Bind Path=TextValue, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
</StackPanel>
|
||||
<!-- Checkbox And NumberBox setting -->
|
||||
<StackPanel
|
||||
HorizontalAlignment="Stretch"
|
||||
Orientation="Vertical"
|
||||
Visibility="{x:Bind Path=ShowCheckboxAndNumberbox, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<controls:SettingsCard
|
||||
MinHeight="0"
|
||||
Margin="1"
|
||||
Padding="0,6,0,4"
|
||||
Background="Transparent"
|
||||
BorderThickness="0,0,0,0"
|
||||
ContentAlignment="Left"
|
||||
CornerRadius="0">
|
||||
<custom:CheckBoxWithDescriptionControl
|
||||
Margin="56,0,0,0"
|
||||
Description="{x:Bind Path=DisplayDescription}"
|
||||
Header="{x:Bind Path=DisplayLabel}"
|
||||
IsChecked="{x:Bind Path=Value, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
<controls:SettingsCard
|
||||
MinHeight="0"
|
||||
Margin="84,0,45,8"
|
||||
Background="Transparent"
|
||||
BorderThickness="0,0,0,0"
|
||||
CornerRadius="0"
|
||||
Description="{x:Bind Path=SecondDisplayDescription}"
|
||||
Header="{x:Bind Path=SecondDisplayLabel}"
|
||||
IsEnabled="{x:Bind Path=SecondSettingIsEnabled, Mode=OneWay}">
|
||||
<NumberBox
|
||||
MinWidth="{StaticResource SettingActionControlMinWidth}"
|
||||
LargeChange="{x:Bind Path=NumberBoxLargeChange, Mode=OneWay}"
|
||||
Maximum="{x:Bind Path=NumberBoxMax, Mode=OneWay}"
|
||||
Minimum="{x:Bind Path=NumberBoxMin, Mode=OneWay}"
|
||||
SmallChange="{x:Bind Path=NumberBoxSmallChange, Mode=OneWay}"
|
||||
SpinButtonPlacementMode="Compact"
|
||||
Value="{x:Bind Path=NumberValue, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
</StackPanel>
|
||||
<!-- Separator line -->
|
||||
<Rectangle
|
||||
Height="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
|
||||
@@ -18,10 +18,19 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
_additionalOption = additionalOption;
|
||||
}
|
||||
|
||||
// Labels of single and first setting of combined types
|
||||
public string DisplayLabel => _additionalOption.DisplayLabel;
|
||||
|
||||
public string DisplayDescription => _additionalOption.DisplayDescription;
|
||||
|
||||
// Labels of second setting of combined types
|
||||
public string SecondDisplayLabel => _additionalOption.SecondDisplayLabel;
|
||||
|
||||
public string SecondDisplayDescription => _additionalOption.SecondDisplayDescription;
|
||||
|
||||
// Bool checkbox setting
|
||||
public bool ShowCheckBox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.Checkbox;
|
||||
|
||||
public bool Value
|
||||
{
|
||||
get => _additionalOption.Value;
|
||||
@@ -31,29 +40,83 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
_additionalOption.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(SecondSettingIsEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ComboBox setting
|
||||
public bool ShowComboBox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.Combobox &&
|
||||
_additionalOption.ComboBoxOptions != null && _additionalOption.ComboBoxOptions.Count > 0;
|
||||
|
||||
public List<string> ComboBoxOptions => _additionalOption.ComboBoxOptions;
|
||||
|
||||
public int Option
|
||||
public int ComboBoxValue
|
||||
{
|
||||
get => _additionalOption.Option;
|
||||
get => _additionalOption.ComboBoxValue;
|
||||
set
|
||||
{
|
||||
if (value != _additionalOption.Option)
|
||||
if (value != _additionalOption.ComboBoxValue)
|
||||
{
|
||||
_additionalOption.Option = value;
|
||||
_additionalOption.ComboBoxValue = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowComboBox => _additionalOption.SelectionTypeValue == (int)PluginAdditionalOption.SelectionType.Combobox && _additionalOption.ComboBoxOptions != null && _additionalOption.ComboBoxOptions.Count > 0;
|
||||
// TextBox setting
|
||||
public bool ShowTextBox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.Textbox;
|
||||
|
||||
public bool ShowCheckBox => _additionalOption.SelectionTypeValue == (int)PluginAdditionalOption.SelectionType.Checkbox;
|
||||
public int TextBoxMaxLength => (_additionalOption.TextBoxMaxLength == null) ? 0 : _additionalOption.TextBoxMaxLength.Value; // 0 ist the default and means no limit.
|
||||
|
||||
public string TextValue
|
||||
{
|
||||
get => _additionalOption.TextValue;
|
||||
set
|
||||
{
|
||||
if (value != _additionalOption.TextValue)
|
||||
{
|
||||
_additionalOption.TextValue = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NumberBox setting
|
||||
public bool ShowNumberBox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.Numberbox;
|
||||
|
||||
public double NumberBoxMin => (_additionalOption.NumberBoxMin == null) ? double.MinValue : _additionalOption.NumberBoxMin.Value;
|
||||
|
||||
public double NumberBoxMax => (_additionalOption.NumberBoxMax == null) ? double.MaxValue : _additionalOption.NumberBoxMax.Value;
|
||||
|
||||
public double NumberBoxSmallChange => (_additionalOption.NumberBoxSmallChange == null) ? 1 : _additionalOption.NumberBoxSmallChange.Value;
|
||||
|
||||
public double NumberBoxLargeChange => (_additionalOption.NumberBoxLargeChange == null) ? 10 : _additionalOption.NumberBoxLargeChange.Value;
|
||||
|
||||
public double NumberValue
|
||||
{
|
||||
get => _additionalOption.NumberValue;
|
||||
set
|
||||
{
|
||||
if (value != _additionalOption.NumberValue)
|
||||
{
|
||||
_additionalOption.NumberValue = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Show combined settings cards
|
||||
public bool ShowCheckboxAndCombobox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.CheckboxAndCombobox;
|
||||
|
||||
public bool ShowCheckboxAndTextbox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.CheckboxAndTextbox;
|
||||
|
||||
public bool ShowCheckboxAndNumberbox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.CheckboxAndNumberbox;
|
||||
|
||||
// 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;
|
||||
|
||||
// Handle property changes
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
|
||||
|
||||
Reference in New Issue
Block a user