mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-21 10:01:58 +01:00
Fixed: Incorrect update of conversion settings du to dependency property update order.
Fixed using two binding instead of events.
This commit is contained in:
1 parent
19e9e1d50a
commit
a223ee1610
11 files changed
+163
-53
No files matched your search
@@ -19,8 +19,9 @@
|
||||
<ColumnDefinition Width="65"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Slider Grid.Column="0" x:Name="slider" Margin="0,2,0,0" VerticalAlignment="Top" Maximum="245" AutoToolTipPlacement="TopLeft" SmallChange="8" IsSnapToTickEnabled="True" IsSelectionRangeEnabled="True" SelectionStart="115" SelectionEnd="245" Minimum="65" TickPlacement="BottomRight" LargeChange="32" TickFrequency="8" Ticks="65 85 100 115 130 165 175 190 225 245" Foreground="#004B82"/>
|
||||
<Label Grid.Column="1" Content="{Binding Value, Converter={StaticResource BitrateToString}, ElementName=slider}" Width="65" />
|
||||
<Label Grid.Column="0" Grid.Row="1" Content="Recommended bitrate range in blue" Foreground="#E5004B82" FontSize="10.667" />
|
||||
<Slider Grid.Column="0" x:Name="slider" Margin="0,2,0,0" VerticalAlignment="Top" Maximum="245" AutoToolTipPlacement="TopLeft" SmallChange="8" IsSnapToTickEnabled="True" IsSelectionRangeEnabled="True" SelectionStart="115" SelectionEnd="245" Minimum="65" TickPlacement="BottomRight" LargeChange="32" TickFrequency="8" Ticks="65 85 100 115 130 165 175 190 225 245" Foreground="#004B82"
|
||||
/>
|
||||
<Label Grid.Column="1" Content="{Binding Value, Converter={StaticResource BitrateToString}, ElementName=slider, Mode=OneWay}" Width="65" />
|
||||
<Label Grid.Column="0" Grid.Row="1" Content="Recommended bitrate range in blue" Foreground="#E5004B82" FontSize="11" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -25,11 +25,6 @@ namespace FileConverter.Controls
|
||||
typeof(EncodingQualitySliderControl),
|
||||
new PropertyMetadata(new PropertyChangedCallback(EncodingQualitySliderControl.OnEncodingModeValueChanged)));
|
||||
|
||||
[Category("Behavior")]
|
||||
public event EventHandler<double> BitrateValueChanged;
|
||||
|
||||
private bool dontPropagateSliderValueChanged;
|
||||
|
||||
public EncodingQualitySliderControl()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
@@ -69,9 +64,7 @@ namespace FileConverter.Controls
|
||||
private static void OnBitrateValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
EncodingQualitySliderControl encodingQualitySliderControl = sender as EncodingQualitySliderControl;
|
||||
encodingQualitySliderControl.dontPropagateSliderValueChanged = true;
|
||||
encodingQualitySliderControl.slider.Value = (double)eventArgs.NewValue;
|
||||
encodingQualitySliderControl.dontPropagateSliderValueChanged = false;
|
||||
}
|
||||
|
||||
private static object CoerceBitrateValue(DependencyObject sender, object basevalue)
|
||||
@@ -168,12 +161,6 @@ namespace FileConverter.Controls
|
||||
}
|
||||
|
||||
this.SetCurrentValue(EncodingQualitySliderControl.BitrateProperty, e.NewValue);
|
||||
|
||||
if (!this.dontPropagateSliderValueChanged)
|
||||
{
|
||||
// Only send the bitrate value changed event if the value change come from the slider.
|
||||
this.BitrateValueChanged?.Invoke(this, e.NewValue);
|
||||
}
|
||||
}
|
||||
|
||||
private double GetNearestTickValue(double value)
|
||||
|
||||
@@ -111,12 +111,35 @@ namespace FileConverter
|
||||
}
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public IConversionSettings Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<string, string> conversionSetting in value)
|
||||
{
|
||||
if (!this.settings.ContainsKey(conversionSetting.Key))
|
||||
{
|
||||
this.settings.Add(conversionSetting.Key, conversionSetting.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.settings[conversionSetting.Key] = conversionSetting.Value;
|
||||
}
|
||||
}
|
||||
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string this[string columnName]
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
public struct ConversionSettingsOverride : IConversionSettings
|
||||
{
|
||||
private string key;
|
||||
private string value;
|
||||
|
||||
public ConversionSettingsOverride(string key, string value)
|
||||
{
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.GetEnumerator();
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
|
||||
{
|
||||
yield return new KeyValuePair<string, string>(this.key, this.value);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsKey(string key)
|
||||
{
|
||||
return key == this.key;
|
||||
}
|
||||
|
||||
public bool TryGetValue(string key, out string value)
|
||||
{
|
||||
value = null;
|
||||
|
||||
if (key == this.key)
|
||||
{
|
||||
value = this.value;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public string this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (key == this.key)
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> Keys
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return this.key;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> Values
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,7 @@
|
||||
</Compile>
|
||||
<Compile Include="ConversionJobs\ConversionJobFactory.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_FFMPEG.cs" />
|
||||
<Compile Include="ConversionPreset\ConversionSettingsOverride.cs" />
|
||||
<Compile Include="ConversionPreset\ConversionSettings.cs" />
|
||||
<Compile Include="EncodingMode.cs" />
|
||||
<Compile Include="ConversionPreset\IConversionSettings.cs" />
|
||||
@@ -88,7 +89,7 @@
|
||||
<Compile Include="ValueConverters\ConversionSettingsToString.cs" />
|
||||
<Compile Include="ValueConverters\Generic\BoolInverterConverter.cs" />
|
||||
<Compile Include="ValueConverters\Generic\EqualsConverter.cs" />
|
||||
<Compile Include="ValueConverters\Generic\ObjectToValueType.cs" />
|
||||
<Compile Include="ValueConverters\Generic\StringToValueType.cs" />
|
||||
<Compile Include="ValueConverters\InputTypesToBool.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
<Compile Include="ValueConverters\OutputTypeToVisibility.cs" />
|
||||
|
||||
@@ -51,7 +51,26 @@ namespace FileConverter.ValueConverters
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (value == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(value is string))
|
||||
{
|
||||
throw new ArgumentException("value");
|
||||
}
|
||||
|
||||
string settingsValue = (string)value;
|
||||
|
||||
if (!(parameter is string))
|
||||
{
|
||||
throw new ArgumentException("parameter");
|
||||
}
|
||||
|
||||
string settingsKey = (string)parameter;
|
||||
|
||||
return new ConversionSettingsOverride(settingsKey, settingsValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,18 @@ namespace FileConverter.ValueConverters.Generic
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (!(value is bool))
|
||||
{
|
||||
throw new ArgumentException("value");
|
||||
}
|
||||
|
||||
bool equals = (bool)value;
|
||||
if (equals)
|
||||
{
|
||||
return parameter;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-3
@@ -1,4 +1,4 @@
|
||||
// <copyright file="ObjectToValueType.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
// <copyright file="StringToValueType.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ValueConverters.Generic
|
||||
{
|
||||
@@ -6,7 +6,7 @@ namespace FileConverter.ValueConverters.Generic
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
public class ObjectToValueType : IValueConverter
|
||||
public class StringToValueType : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
@@ -32,7 +32,12 @@ namespace FileConverter.ValueConverters.Generic
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (value == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ namespace FileConverter.ValueConverters.Generic
|
||||
}
|
||||
|
||||
object result = value;
|
||||
for (int index = this.Count - 1; index >= 0; index++)
|
||||
for (int index = this.Count - 1; index >= 0; index--)
|
||||
{
|
||||
IValueConverter converter = this[index];
|
||||
result = converter.ConvertBack(result, targetType, parameters[index], culture);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
<generic:ValueConverterGroup x:Key="ConversionSettingsToValueType">
|
||||
<valueConverters:ConversionSettingsToString/>
|
||||
<generic:ObjectToValueType/>
|
||||
<generic:StringToValueType/>
|
||||
</generic:ValueConverterGroup>
|
||||
|
||||
<generic:ValueConverterGroup x:Key="ReferenceToVisibility">
|
||||
@@ -62,14 +62,14 @@
|
||||
<StackPanel>
|
||||
<DockPanel>
|
||||
<Label Content="Encoding :" />
|
||||
<RadioButton Name="VBRradioButton" Content="VBR" ToolTip="Variable bitrate encoding" Margin="5" Checked="EncodingTypeRadio_Checked" IsChecked="{Binding SelectedPreset.Settings, ConverterParameter='Encoding|Mp3VBR', Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=OneWay}" />
|
||||
<RadioButton Name="CBRradioButton" Content="CBR" ToolTip="Constant bitrate encoding" Margin="5" Checked="EncodingTypeRadio_Checked" IsChecked="{Binding SelectedPreset.Settings, ConverterParameter='Encoding|Mp3CBR', Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=OneWay}"/>
|
||||
<RadioButton Name="VBRradioButton" Content="VBR" ToolTip="Variable bitrate encoding" Margin="5" IsChecked="{Binding SelectedPreset.Settings, ConverterParameter='Encoding|Mp3VBR', Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=TwoWay}" />
|
||||
<RadioButton Name="CBRradioButton" Content="CBR" ToolTip="Constant bitrate encoding" Margin="5" IsChecked="{Binding SelectedPreset.Settings, ConverterParameter='Encoding|Mp3CBR', Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=TwoWay}"/>
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
<Label Content="Quality :" />
|
||||
<controls:EncodingQualitySliderControl x:Name="EncodingQualitySlider" BitrateValueChanged="EncodingQualitySlider_ValueChanged"
|
||||
<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=OneWay, TargetNullValue=190}" />
|
||||
Bitrate="{Binding SelectedPreset.Settings, ConverterParameter='Bitrate|System.Double', Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay, TargetNullValue=190}" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
@@ -78,8 +78,8 @@
|
||||
<StackPanel>
|
||||
<DockPanel>
|
||||
<Label Content="Quality :" />
|
||||
<controls:EncodingQualitySliderControl x:Name="EncodingQualitySlider" BitrateValueChanged="EncodingQualitySlider_ValueChanged" EncodingMode="OggVBR"
|
||||
Bitrate="{Binding SelectedPreset.Settings, ConverterParameter='Bitrate|System.Double', Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=OneWay, TargetNullValue=160}" />
|
||||
<controls:EncodingQualitySliderControl x:Name="EncodingQualitySlider" EncodingMode="OggVBR"
|
||||
Bitrate="{Binding SelectedPreset.Settings, ConverterParameter='Bitrate|System.Double', Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay, TargetNullValue=160}" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
|
||||
@@ -130,29 +130,6 @@ namespace FileConverter
|
||||
e.CanExecute = this.settings != null && string.IsNullOrEmpty(this.settings.Error);
|
||||
}
|
||||
|
||||
private void EncodingTypeRadio_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RadioButton radioButton = sender as RadioButton;
|
||||
string content = radioButton.Content as string;
|
||||
if (content == "VBR")
|
||||
{
|
||||
this.SelectedPreset?.SetSettingsValue("Encoding", EncodingMode.Mp3VBR.ToString());
|
||||
}
|
||||
else if (content == "CBR")
|
||||
{
|
||||
this.SelectedPreset?.SetSettingsValue("Encoding", EncodingMode.Mp3CBR.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unknown encoding type.");
|
||||
}
|
||||
}
|
||||
|
||||
private void EncodingQualitySlider_ValueChanged(object sender, double bitrateValue)
|
||||
{
|
||||
this.SelectedPreset?.SetSettingsValue("Bitrate", bitrateValue.ToString("0"));
|
||||
}
|
||||
|
||||
private void SettingsWindow_OnClosing(object sender, CancelEventArgs e)
|
||||
{
|
||||
e.Cancel = true;
|
||||
|
||||
Reference in new issue
Block a user