Disable input extensions that are not compatible with output type.

This commit is contained in:
Tichau committed 2015-11-17 08:40:34 +01:00
1 parent 9b0777d54d
commit 73d3255e76
4 files changed
+96 -2

No files matched your search

@@ -70,6 +70,7 @@ namespace FileConverter
this.outputType = value;
this.InitializeDefaultSettings(this.outputType);
this.OnPropertyChanged();
this.CoerceInputTypes();
}
}
@@ -88,7 +89,7 @@ namespace FileConverter
{
this.inputTypes[index] = this.inputTypes[index].ToLowerInvariant();
}
this.OnPropertyChanged();
}
}
@@ -241,6 +242,8 @@ namespace FileConverter
{
this.InputTypes[index] = this.InputTypes[index].ToLowerInvariant();
}
this.CoerceInputTypes();
}
public void AddInputType(string inputType)
@@ -328,6 +331,20 @@ namespace FileConverter
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void CoerceInputTypes()
{
for (int index = 0; index < this.inputTypes.Count; index++)
{
string inputType = this.inputTypes[index];
string inputCategory = PathHelpers.GetExtensionCategory(inputType);
if (!PathHelpers.IsOutputTypeCompatibleWithCategory(this.OutputType, inputCategory))
{
this.RemoveInputType(inputType);
index--;
}
}
}
private bool IsRelevantSetting(string settingsKey)
{
switch (this.OutputType)
@@ -103,6 +103,7 @@
<Compile Include="ValueConverters\Generic\StringToValueType.cs" />
<Compile Include="ValueConverters\InputTypesToBool.cs" />
<Compile Include="Settings.cs" />
<Compile Include="ValueConverters\IsOutputTypeCompatibleWithCategoryConverter.cs" />
<Compile Include="ValueConverters\OutputTypeToVisibility.cs" />
<Compile Include="ValueConverters\Generic\StringToEnum.cs" />
<Compile Include="ValueConverters\Generic\ValueConverterGroup.cs" />
@@ -0,0 +1,56 @@
// <copyright file="IsOutputTypeCompatibleWithCategoryConverter.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.ValueConverters
{
using System;
using System.Globalization;
using System.Windows.Data;
public class IsOutputTypeCompatibleWithCategoryConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null || values.Length != 2)
{
throw new ArgumentException("The values must contains the collection of elements and the researched element.");
}
if (!(values[0] is OutputType))
{
return false;
}
OutputType outputType = (OutputType)values[0];
string category = null;
string input = values[1] as string;
if (input == null)
{
return false;
}
string stringParameter = parameter as string;
if (stringParameter != null && stringParameter == "InputType")
{
category = PathHelpers.GetExtensionCategory(input);
}
else if (stringParameter != null && stringParameter == "Category")
{
category = input;
}
if (category == null)
{
return false;
}
return PathHelpers.IsOutputTypeCompatibleWithCategory(outputType, category);
}
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
@@ -17,6 +17,7 @@
<valueConverters:OutputTypeToVisibility x:Key="OutputTypeToVisibility"/>
<valueConverters:ApplicationVersionToApplicationName x:Key="ApplicationVersionToApplicationName"/>
<generic:CollectionContainsElementToBool x:Key="CollectionContainsElementToBool"/>
<valueConverters:IsOutputTypeCompatibleWithCategoryConverter x:Key="IsOutputTypeCompatibleWithCategory"/>
<generic:ValueConverterGroup x:Key="ConversionSettingsToEnum">
<valueConverters:ConversionSettingsToString/>
@@ -247,6 +248,12 @@
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:InputExtensionCategory}" ItemsSource="{Binding InputExtensions}">
<CheckBox Content="{Binding Name}" Height="20" VerticalAlignment="Top" Margin="2" Checked="OnInputTypeCategoryChecked" Unchecked="OnInputTypeCategoryUnchecked" IsThreeState="True" >
<CheckBox.IsEnabled>
<MultiBinding Converter="{StaticResource IsOutputTypeCompatibleWithCategory}" ConverterParameter="Category" Mode="OneWay">
<Binding ElementName="window" Path="SelectedPreset.OutputType" Mode="OneWay"/>
<Binding Path="Name" Mode="OneWay"/>
</MultiBinding>
</CheckBox.IsEnabled>
<CheckBox.IsChecked>
<MultiBinding Converter="{StaticResource CollectionContainsElementToBool}" Mode="OneWay">
<Binding ElementName="window" Path="SelectedPreset.InputTypes" Mode="OneWay"/>
@@ -257,6 +264,12 @@
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type local:InputExtension}">
<CheckBox Content="{Binding Name}" Height="20" VerticalAlignment="Top" Margin="2" Checked="OnInputTypeChecked" Unchecked="OnInputTypeUnchecked">
<CheckBox.IsEnabled>
<MultiBinding Converter="{StaticResource IsOutputTypeCompatibleWithCategory}" ConverterParameter="InputType" Mode="OneWay">
<Binding ElementName="window" Path="SelectedPreset.OutputType" Mode="OneWay"/>
<Binding Path="Name" Mode="OneWay"/>
</MultiBinding>
</CheckBox.IsEnabled>
<CheckBox.IsChecked>
<MultiBinding Converter="{StaticResource CollectionContainsElementToBool}" Mode="OneWay">
<Binding ElementName="window" Path="SelectedPreset.InputTypes" Mode="OneWay"/>
@@ -268,7 +281,14 @@
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="True" />
<Setter Property="IsExpanded">
<Setter.Value>
<MultiBinding Converter="{StaticResource IsOutputTypeCompatibleWithCategory}" ConverterParameter="Category" Mode="OneWay">
<Binding ElementName="window" Path="SelectedPreset.OutputType" Mode="OneWay"/>
<Binding Path="Name" Mode="OneWay"/>
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>