Set categories invisible if they are not compatible with the current output type.

This commit is contained in:
Tichau committed 2015-11-17 19:06:23 +01:00
1 parent 1f94578556
commit 43cfa7cd11
4 files changed
+48 -86

No files matched your search

@@ -103,7 +103,6 @@
<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" />
@@ -1,56 +0,0 @@
// <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,7 +17,6 @@
<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/>
@@ -248,12 +247,6 @@
<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"/>
@@ -264,12 +257,6 @@
</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"/>
@@ -281,14 +268,7 @@
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<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>
<Setter Property="IsExpanded" Value="True"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
@@ -1,5 +1,7 @@
// <copyright file="SettingsWindow.xaml.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
using System.Linq;
namespace FileConverter
{
using System;
@@ -69,22 +71,48 @@ namespace FileConverter
set
{
if (this.selectedPreset != null)
{
this.selectedPreset.PropertyChanged -= this.SelectedPresetPropertyChanged;
}
this.selectedPreset = value;
if (this.selectedPreset != null)
{
this.selectedPreset.PropertyChanged += this.SelectedPresetPropertyChanged;
}
this.OnPropertyChanged();
this.OnPropertyChanged("InputCategories");
}
}
public InputExtensionCategory[] InputCategories
private void SelectedPresetPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "OutputType")
{
this.OnPropertyChanged("InputCategories");
}
}
public IEnumerable<InputExtensionCategory> InputCategories
{
get
{
return this.inputCategories;
}
if (this.inputCategories == null)
{
yield break;
}
set
{
this.inputCategories = value;
this.OnPropertyChanged();
for (int index = 0; index < this.inputCategories.Length; index++)
{
InputExtensionCategory category = this.inputCategories[index];
if (this.SelectedPreset == null || PathHelpers.IsOutputTypeCompatibleWithCategory(this.SelectedPreset.OutputType, category.Name))
{
yield return category;
}
}
}
}
@@ -102,6 +130,11 @@ namespace FileConverter
}
CheckBox checkBox = sender as System.Windows.Controls.CheckBox;
if (!checkBox.IsVisible)
{
return;
}
string inputFormat = (checkBox.Content as string).ToLowerInvariant();
this.selectedPreset.AddInputType(inputFormat);
@@ -115,6 +148,11 @@ namespace FileConverter
}
CheckBox checkBox = sender as System.Windows.Controls.CheckBox;
if (!checkBox.IsVisible)
{
return;
}
string inputFormat = (checkBox.Content as string).ToLowerInvariant();
this.selectedPreset.RemoveInputType(inputFormat);
@@ -278,7 +316,8 @@ namespace FileConverter
category.AddExtension(compatibleInputExtension);
}
this.InputCategories = categories.ToArray();
this.inputCategories = categories.ToArray();
this.OnPropertyChanged("InputCategories");
}
}
}