Refactor input types system.
This commit is contained in:
parent
8963bdb6c0
commit
d66723d510
@ -1,7 +1,5 @@
|
||||
// <copyright file="FileConverter.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
using FileConverter.ValueConverters;
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
using System;
|
||||
@ -12,10 +10,11 @@ namespace FileConverter
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using FileConverter.Annotations;
|
||||
using FileConverter.ValueConverters;
|
||||
|
||||
[XmlRoot]
|
||||
[XmlType]
|
||||
public class ConversionPreset : INotifyPropertyChanged, IDataErrorInfo
|
||||
public class ConversionPreset : INotifyPropertyChanged, IDataErrorInfo, IXmlSerializable
|
||||
{
|
||||
private string name;
|
||||
private OutputType outputType;
|
||||
@ -34,8 +33,10 @@ namespace FileConverter
|
||||
{
|
||||
this.Name = name;
|
||||
this.OutputType = outputType;
|
||||
this.InputTypes = new List<string>();
|
||||
this.InputTypes.AddRange(inputTypes);
|
||||
List<string> inputTypeList = new List<string>();
|
||||
inputTypeList.AddRange(inputTypes);
|
||||
this.InputTypes = inputTypeList;
|
||||
|
||||
this.outputFileNameTemplate = "(p)(f)";
|
||||
}
|
||||
|
||||
@ -83,6 +84,11 @@ namespace FileConverter
|
||||
set
|
||||
{
|
||||
this.inputTypes = value;
|
||||
for (int index = 0; index < this.inputTypes.Count; index++)
|
||||
{
|
||||
this.inputTypes[index] = this.inputTypes[index].ToLowerInvariant();
|
||||
}
|
||||
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
@ -215,6 +221,14 @@ namespace FileConverter
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDeserializationComplete()
|
||||
{
|
||||
for (int index = 0; index < this.InputTypes.Count; index++)
|
||||
{
|
||||
this.InputTypes[index] = this.InputTypes[index].ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
|
||||
public string GenerateOutputFilePath(string inputFilePath)
|
||||
{
|
||||
return (string)this.outputFileNameConverter.Convert(new object[] {inputFilePath, this.OutputType, this.OutputFileNameTemplate}, typeof (string), null, null);
|
||||
|
@ -83,6 +83,7 @@
|
||||
<Compile Include="EncodingMode.cs" />
|
||||
<Compile Include="ConversionPreset\IConversionSettings.cs" />
|
||||
<Compile Include="InputPostConversionAction.cs" />
|
||||
<Compile Include="IXmlSerializable.cs" />
|
||||
<Compile Include="PathHelpers.cs" />
|
||||
<Compile Include="Properties\Resources.en.Designer.cs">
|
||||
<DependentUpon>Resources.en.resx</DependentUpon>
|
||||
@ -97,6 +98,7 @@
|
||||
<Compile Include="ValueConverters\ConversionSettingsToString.cs" />
|
||||
<Compile Include="ValueConverters\Generic\BoolInverterConverter.cs" />
|
||||
<Compile Include="ValueConverters\Generic\EqualsConverter.cs" />
|
||||
<Compile Include="ValueConverters\Generic\CollectionContainsElementToBool.cs" />
|
||||
<Compile Include="ValueConverters\Generic\StringToValueType.cs" />
|
||||
<Compile Include="ValueConverters\InputTypesToBool.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
@ -107,6 +109,8 @@
|
||||
<DependentUpon>DiagnosticsWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Windows\ConversionSettingsTemplateSelector.cs" />
|
||||
<Compile Include="Windows\InputExtension.cs" />
|
||||
<Compile Include="Windows\InputExtensionCategory.cs" />
|
||||
<Compile Include="Windows\SettingsWindow.xaml.cs">
|
||||
<DependentUpon>SettingsWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
@ -58,5 +58,26 @@ namespace FileConverter
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static string GetExtensionCategory(string extension)
|
||||
{
|
||||
switch (extension)
|
||||
{
|
||||
case "ape":
|
||||
case "flac":
|
||||
case "mp3":
|
||||
case "m4a":
|
||||
case "ogg":
|
||||
case "wav":
|
||||
case "wma":
|
||||
return "Audio";
|
||||
|
||||
case "avi":
|
||||
case "mp4":
|
||||
return "Video";
|
||||
}
|
||||
|
||||
return "Misc";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
// <copyright file="CollectionContainsElementToBool.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace FileConverter.ValueConverters.Generic
|
||||
{
|
||||
public class CollectionContainsElementToBool : 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.");
|
||||
}
|
||||
|
||||
// TODO: Make this converter generic.
|
||||
|
||||
if (!(values[0] is ICollection<string>))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ICollection<string> collection = values[0] as ICollection<string>;
|
||||
string objectToFind = values[1] as string;
|
||||
|
||||
return collection.Contains(objectToFind);
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
40
Application/FileConverter/Windows/InputExtension.cs
Normal file
40
Application/FileConverter/Windows/InputExtension.cs
Normal file
@ -0,0 +1,40 @@
|
||||
// <copyright file="SettingsWindow.xaml.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using FileConverter.Annotations;
|
||||
|
||||
public class InputExtension : INotifyPropertyChanged
|
||||
{
|
||||
public string name;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public InputExtension(string name)
|
||||
{
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.name = value;
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
61
Application/FileConverter/Windows/InputExtensionCategory.cs
Normal file
61
Application/FileConverter/Windows/InputExtensionCategory.cs
Normal file
@ -0,0 +1,61 @@
|
||||
// <copyright file="InputExtensionCategory.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using FileConverter.Annotations;
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
public class InputExtensionCategory : INotifyPropertyChanged
|
||||
{
|
||||
private string name;
|
||||
private List<InputExtension> inputExtensions = new List<InputExtension>();
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public InputExtensionCategory(string name)
|
||||
{
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.name = value;
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<InputExtension> InputExtensions
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.inputExtensions;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddExtension(string extension)
|
||||
{
|
||||
InputExtension inputExtension = this.inputExtensions.Find(match => match.Name == extension);
|
||||
if (inputExtension == null)
|
||||
{
|
||||
inputExtension = new InputExtension(extension);
|
||||
this.inputExtensions.Add(inputExtension);
|
||||
this.OnPropertyChanged("InputExtensions");
|
||||
}
|
||||
}
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<Window x:Name="window" x:Class="FileConverter.SettingsWindow"
|
||||
<Window
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:FileConverter"
|
||||
xmlns:controls="clr-namespace:FileConverter.Controls"
|
||||
@ -6,6 +6,7 @@
|
||||
xmlns:generic="clr-namespace:FileConverter.ValueConverters.Generic"
|
||||
xmlns:windows="clr-namespace:FileConverter.Windows"
|
||||
xmlns:project="clr-namespace:FileConverter.Properties"
|
||||
xmlns:System="clr-namespace:System;assembly=mscorlib" x:Name="window" x:Class="FileConverter.SettingsWindow"
|
||||
Height="600" Width="800" MinHeight="400" MinWidth="600"
|
||||
WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon.ico"
|
||||
Closing="SettingsWindow_OnClosing">
|
||||
@ -15,6 +16,8 @@
|
||||
<valueConverters:InputTypesToBool x:Key="InputTypesToBool"/>
|
||||
<valueConverters:OutputTypeToVisibility x:Key="OutputTypeToVisibility"/>
|
||||
<valueConverters:ApplicationVersionToApplicationName x:Key="ApplicationVersionToApplicationName"/>
|
||||
<generic:CollectionContainsElementToBool x:Key="CollectionContainsElementToBool"/>
|
||||
|
||||
|
||||
<generic:ValueConverterGroup x:Key="ConversionSettingsToEnum">
|
||||
<valueConverters:ConversionSettingsToString/>
|
||||
@ -81,8 +84,8 @@
|
||||
<DockPanel>
|
||||
<Label Content="Quality :" />
|
||||
<controls:EncodingQualitySliderControl x:Name="EncodingQualitySlider"
|
||||
EncodingMode="{Binding SelectedPreset.Settings, ConverterParameter=Encoding|FileConverter.EncodingMode, Converter={StaticResource ConversionSettingsToEnum}, ElementName=window, Mode=OneWay, TargetNullValue=VBR}"
|
||||
Bitrate="{Binding SelectedPreset.Settings, ConverterParameter=Bitrate|System.Double, Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay, TargetNullValue=190}" />
|
||||
EncodingMode="{Binding SelectedPreset.Settings, ConverterParameter=Encoding|FileConverter.EncodingMode, Converter={StaticResource ConversionSettingsToEnum}, ElementName=window, Mode=OneWay, TargetNullValue=VBR}"
|
||||
Bitrate="{Binding SelectedPreset.Settings, ConverterParameter=Bitrate|System.Double, Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay, TargetNullValue=190}" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
@ -92,7 +95,7 @@
|
||||
<DockPanel>
|
||||
<Label Content="Quality :" />
|
||||
<controls:EncodingQualitySliderControl x:Name="EncodingQualitySlider" EncodingMode="OggVBR"
|
||||
Bitrate="{Binding SelectedPreset.Settings, ConverterParameter=Bitrate|System.Double, Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay, TargetNullValue=160}" />
|
||||
Bitrate="{Binding SelectedPreset.Settings, ConverterParameter=Bitrate|System.Double, Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay, TargetNullValue=160}" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
@ -127,11 +130,7 @@
|
||||
|
||||
<Image HorizontalAlignment="Left" Height="48" Width="48" VerticalAlignment="Top" Source="..\Resources\ApplicationIcon.png" />
|
||||
<Label Content="Settings" FontSize="20" Margin="4" Grid.Column="1" VerticalAlignment="Center" />
|
||||
<Label HorizontalAlignment="Right" FontStyle="Italic" FontSize="14" Grid.Column="2" VerticalAlignment="Center">
|
||||
<Label.Content>
|
||||
<Binding Converter="{StaticResource ApplicationVersionToApplicationName}" Mode="OneWay" Path="(local:Application.ApplicationVersion)"/>
|
||||
</Label.Content>
|
||||
</Label>
|
||||
<Label HorizontalAlignment="Right" FontStyle="Italic" FontSize="14" Grid.Column="2" VerticalAlignment="Center" Content="{Binding (local:Application.ApplicationVersion), Converter={StaticResource ApplicationVersionToApplicationName}, Mode=OneWay}"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1">
|
||||
@ -150,22 +149,22 @@
|
||||
<RowDefinition Height="30"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Label Content="Presets" Grid.Row="0" VerticalAlignment="Top" HorizontalContentAlignment="Center" HorizontalAlignment="Left" Width="{Binding ActualWidth, ElementName=PresetListGrid, Mode=OneWay}" />
|
||||
<ListBox Name="PresetList" Grid.Row="1" HorizontalAlignment="Left" IsSynchronizedWithCurrentItem="True" SelectedItem="{Binding SelectedPreset, ElementName=window}" Width="{Binding ActualWidth, ElementName=PresetListGrid, Mode=OneWay}">
|
||||
<ItemsControl.DataContext>
|
||||
<ListBox x:Name="PresetList" Grid.Row="1" HorizontalAlignment="Left" IsSynchronizedWithCurrentItem="True" SelectedItem="{Binding SelectedPreset, ElementName=window}" Width="{Binding ActualWidth, ElementName=PresetListGrid, Mode=OneWay}">
|
||||
<ListBox.DataContext>
|
||||
<local:ConversionPreset/>
|
||||
</ItemsControl.DataContext>
|
||||
<ItemsControl.ItemTemplate>
|
||||
</ListBox.DataContext>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Label Content="{Binding Name}"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<DockPanel Grid.Row="2" Margin="0,5,0,0">
|
||||
<Button Name="MoveUpPresetButton" Content="^" HorizontalAlignment="Left" Width="25" Margin="0,0,2,0" Click="MovePresetUpButton_Click"/>
|
||||
<Button Name="AddPresetButton" Content="+" HorizontalAlignment="Left" Width="25" Margin="2,0" Click="AddPresetButton_Click"/>
|
||||
<Button Name="RemovePresetButton" Content="-" HorizontalAlignment="Left" Width="25" Margin="2,0" Click="RemovePresetButton_Click"/>
|
||||
<Button Name="MoveDownPresetButton" Content="v" HorizontalAlignment="Left" Width="25" Margin="2,0,0,0" Click="MovePresetDownButton_Click"/>
|
||||
<Button x:Name="MoveUpPresetButton" Content="^" HorizontalAlignment="Left" Width="25" Margin="0,0,2,0" Click="MovePresetUpButton_Click"/>
|
||||
<Button x:Name="AddPresetButton" Content="+" HorizontalAlignment="Left" Width="25" Margin="2,0" Click="AddPresetButton_Click"/>
|
||||
<Button x:Name="RemovePresetButton" Content="-" HorizontalAlignment="Left" Width="25" Margin="2,0" Click="RemovePresetButton_Click"/>
|
||||
<Button x:Name="MoveDownPresetButton" Content="v" HorizontalAlignment="Left" Width="25" Margin="2,0,0,0" Click="MovePresetDownButton_Click"/>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
|
||||
@ -181,7 +180,7 @@
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Label Content="Preset name" Grid.Row="0" HorizontalContentAlignment="Right" Margin="0,0,5,0"/>
|
||||
<TextBox Name="PresetNameTextBox" Grid.Row="0" Grid.Column="1" Margin="5,2,25,2" Text="{Binding SelectedPreset.Name, Mode=TwoWay, ElementName=window, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" TextWrapping="Wrap" Width="Auto" />
|
||||
<TextBox x:Name="PresetNameTextBox" Grid.Row="0" Grid.Column="1" Margin="5,2,25,2" Text="{Binding SelectedPreset.Name, ElementName=window, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" TextWrapping="Wrap" Width="Auto" />
|
||||
|
||||
<GroupBox Grid.Row="1" Grid.Column="0" Header="Input formats" Margin="5">
|
||||
<Grid Margin="5">
|
||||
@ -194,34 +193,41 @@
|
||||
<RowDefinition Height="25"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TreeView x:Name="treeView">
|
||||
<TreeViewItem Header="Audio" IsExpanded="True">
|
||||
<CheckBox Content="Ape" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Ape', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Flac" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Flac', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Mp3" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Mp3', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Ogg" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Ogg', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Wav" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Wav', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Wma" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Wma', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="M4a" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='M4a', ElementName=window, Mode=OneWay}"/>
|
||||
</TreeViewItem>
|
||||
<TreeViewItem Header="Video" IsExpanded="True">
|
||||
<CheckBox Content="Avi" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Avi', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Mp4" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Mp4', ElementName=window, Mode=OneWay}"/>
|
||||
</TreeViewItem>
|
||||
<TreeView x:Name="InputTypesTreeView" ItemsSource="{Binding InputCategories, ElementName=window}" >
|
||||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type local:InputExtensionCategory}" ItemsSource="{Binding InputExtensions}">
|
||||
<TextBlock Text="{Binding Name}" Height="20" Margin="2"/>
|
||||
</HierarchicalDataTemplate>
|
||||
<DataTemplate DataType="{x:Type local:InputExtension}">
|
||||
<CheckBox Content="{Binding Name}" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked">
|
||||
<CheckBox.IsChecked>
|
||||
<MultiBinding Converter="{StaticResource CollectionContainsElementToBool}" Mode="OneWay">
|
||||
<Binding ElementName="window" Path="SelectedPreset.InputTypes" Mode="OneWay"/>
|
||||
<Binding Path="Name" Mode="OneWay"/>
|
||||
</MultiBinding>
|
||||
</CheckBox.IsChecked>
|
||||
</CheckBox>
|
||||
</DataTemplate>
|
||||
</TreeView.Resources>
|
||||
<TreeView.ItemContainerStyle>
|
||||
<Style TargetType="TreeViewItem">
|
||||
<Setter Property="IsExpanded" Value="True" />
|
||||
</Style>
|
||||
</TreeView.ItemContainerStyle>
|
||||
</TreeView>
|
||||
|
||||
<Label Grid.Row="1" Content="Action when conversion succeed"/>
|
||||
<ComboBox Grid.Row="2" Name="PostConversionActionComboBox" SelectedItem="{Binding SelectedPreset.InputPostConversionAction, ElementName=window, Mode=TwoWay}" />
|
||||
<ComboBox Grid.Row="2" x:Name="PostConversionActionComboBox" SelectedItem="{Binding SelectedPreset.InputPostConversionAction, ElementName=window, Mode=TwoWay}" />
|
||||
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Output format" Grid.Row="1" Grid.Column="1" Margin="5">
|
||||
<StackPanel>
|
||||
<ComboBox Name="OutputFormats" Margin="5" Height="25" VerticalAlignment="Top" SelectedItem="{Binding SelectedPreset.OutputType, ElementName=window, Mode=TwoWay}"/>
|
||||
<ComboBox x:Name="OutputFormats" Margin="5" Height="25" VerticalAlignment="Top" SelectedItem="{Binding SelectedPreset.OutputType, ElementName=window, Mode=TwoWay}"/>
|
||||
|
||||
<ContentControl ContentTemplateSelector="{StaticResource ResourceKey=ConversionSettingsSelector}"
|
||||
Content="{Binding SelectedPreset.OutputType, UpdateSourceTrigger=PropertyChanged, ElementName=window}" />
|
||||
Content="{Binding SelectedPreset.OutputType, ElementName=window, UpdateSourceTrigger=PropertyChanged}" />
|
||||
|
||||
<Separator/>
|
||||
|
||||
@ -237,7 +243,7 @@
|
||||
<RowDefinition Height="23"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Label Content="File name template" Grid.Row="0" HorizontalContentAlignment="Right" Margin="0,0,5,0"/>
|
||||
<TextBox Name="FileNameTemplateTextBox" Grid.Row="0" Grid.Column="1" Margin="5,2,25,2" Text="{Binding SelectedPreset.OutputFileNameTemplate, Mode=TwoWay, ElementName=window, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" TextWrapping="Wrap" Width="Auto" ToolTip="{x:Static project:Resources.OutputFilePathTemplateHelp}" />
|
||||
<TextBox x:Name="FileNameTemplateTextBox" Grid.Row="0" Grid.Column="1" Margin="5,2,25,2" Text="{Binding SelectedPreset.OutputFileNameTemplate, ElementName=window, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" TextWrapping="Wrap" Width="Auto" ToolTip="{x:Static project:Resources.OutputFilePathTemplateHelp}" />
|
||||
<Label Content="Input example" Grid.Row="1" Grid.Column="0" HorizontalContentAlignment="Right" Margin="0,0,5,0" Foreground="Gray" FontSize="10"/>
|
||||
<TextBlock Text="{x:Static project:Resources.OuputFileNameTemplateSample}" Grid.Row="1" Grid.Column="1" Margin="5,0,5,0" Foreground="Gray" FontSize="10" VerticalAlignment="Center"/>
|
||||
<Label Content="Output" Grid.Row="2" Grid.Column="0" HorizontalContentAlignment="Right" Margin="0,0,5,0" Foreground="Gray" FontSize="10"/>
|
||||
@ -258,8 +264,8 @@
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
|
||||
<Button Name="CloseButton" Grid.Row="2" Content="Close" HorizontalAlignment="Right" Width="100" Margin="0,4,105,0" Click="CloseButton_Click" />
|
||||
<Button Name="SaveButton" Grid.Row="2" Content="Save" HorizontalAlignment="Right" Width="100" Margin="0,4,0,0" Click="SaveButton_Click" Command="New"/>
|
||||
<Button x:Name="CloseButton" Grid.Row="2" Content="Close" HorizontalAlignment="Right" Width="100" Margin="0,4,105,0" Click="CloseButton_Click" />
|
||||
<Button x:Name="SaveButton" Grid.Row="2" Content="Save" HorizontalAlignment="Right" Width="100" Margin="0,4,0,0" Click="SaveButton_Click" Command="New"/>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.ComponentModel;
|
||||
@ -20,6 +22,8 @@ namespace FileConverter
|
||||
|
||||
private Settings settings;
|
||||
|
||||
private InputExtensionCategory[] inputCategories;
|
||||
|
||||
public SettingsWindow()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
@ -46,6 +50,8 @@ namespace FileConverter
|
||||
};
|
||||
|
||||
this.PostConversionActionComboBox.ItemsSource = postConversionActions;
|
||||
|
||||
this.InitializeCompatibleInputExtensions();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
@ -65,7 +71,21 @@ namespace FileConverter
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public InputExtensionCategory[] InputCategories
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.inputCategories;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.inputCategories = value;
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
@ -80,7 +100,7 @@ namespace FileConverter
|
||||
}
|
||||
|
||||
CheckBox checkBox = sender as System.Windows.Controls.CheckBox;
|
||||
string inputFormat = checkBox.Content as string;
|
||||
string inputFormat = (checkBox.Content as string).ToLowerInvariant();
|
||||
|
||||
if (!this.selectedPreset.InputTypes.Contains(inputFormat))
|
||||
{
|
||||
@ -96,7 +116,7 @@ namespace FileConverter
|
||||
}
|
||||
|
||||
CheckBox checkBox = sender as System.Windows.Controls.CheckBox;
|
||||
string inputFormat = checkBox.Content as string;
|
||||
string inputFormat = (checkBox.Content as string).ToLowerInvariant();
|
||||
|
||||
this.selectedPreset.InputTypes.Remove(inputFormat);
|
||||
}
|
||||
@ -183,5 +203,41 @@ namespace FileConverter
|
||||
|
||||
this.settings.ConversionPresets.Move(indexOfSelectedPreset, newIndexOfSelectedPreset);
|
||||
}
|
||||
|
||||
private void InitializeCompatibleInputExtensions()
|
||||
{
|
||||
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\FileConverter");
|
||||
if (registryKey == null)
|
||||
{
|
||||
MessageBox.Show("Can't retrieve the list of compatible input extensions. (code 0x09)", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
string registryValue = registryKey.GetValue("CompatibleInputExtensions") as string;
|
||||
if (registryValue == null)
|
||||
{
|
||||
MessageBox.Show("Can't retrieve the list of compatible input extensions. (code 0x0A)", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
string[] compatibleInputExtensions = registryValue.Split(';');
|
||||
|
||||
List<InputExtensionCategory> categories = new List<InputExtensionCategory>();
|
||||
for (int index = 0; index < compatibleInputExtensions.Length; index++)
|
||||
{
|
||||
string compatibleInputExtension = compatibleInputExtensions[index];
|
||||
string extensionCategory = PathHelpers.GetExtensionCategory(compatibleInputExtension);
|
||||
InputExtensionCategory category = categories.Find(match => match.Name == extensionCategory);
|
||||
if (category == null)
|
||||
{
|
||||
category = new InputExtensionCategory(extensionCategory);
|
||||
categories.Add(category);
|
||||
}
|
||||
|
||||
category.AddExtension(compatibleInputExtension);
|
||||
}
|
||||
|
||||
this.InputCategories = categories.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ namespace FileConverterExtension
|
||||
private string fileConverterPath;
|
||||
private RegistryKey fileConverterRegistryKey;
|
||||
private List<PresetDefinition> presetList = new List<PresetDefinition>();
|
||||
private List<string> compatibleInputExtensions = new List<string>();
|
||||
|
||||
private RegistryKey FileConverterRegistryKey
|
||||
{
|
||||
@ -57,6 +58,27 @@ namespace FileConverterExtension
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<string> CompatibleInputExtensions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.compatibleInputExtensions != null && this.compatibleInputExtensions.Count > 0)
|
||||
{
|
||||
return this.compatibleInputExtensions;
|
||||
}
|
||||
|
||||
this.compatibleInputExtensions.Clear();
|
||||
string registryValue = this.FileConverterRegistryKey.GetValue("CompatibleInputExtensions") as string;
|
||||
string[] extensions = registryValue.Split(';');
|
||||
for (int index = 0; index < extensions.Length; index++)
|
||||
{
|
||||
this.compatibleInputExtensions.Add(extensions[index]);
|
||||
}
|
||||
|
||||
return this.compatibleInputExtensions;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool CanShowMenu()
|
||||
{
|
||||
foreach (string filePath in this.SelectedItemPaths)
|
||||
@ -68,15 +90,9 @@ namespace FileConverterExtension
|
||||
}
|
||||
|
||||
extension = extension.Substring(1).ToLowerInvariant();
|
||||
switch (extension)
|
||||
if (this.CompatibleInputExtensions.Contains(extension))
|
||||
{
|
||||
case "ape":
|
||||
case "mp3":
|
||||
case "wav":
|
||||
case "ogg":
|
||||
case "flac":
|
||||
case "wma":
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user