diff --git a/Application/FileConverter/Properties/Resources.Designer.cs b/Application/FileConverter/Properties/Resources.Designer.cs
index 0c0ca11..0964a38 100644
--- a/Application/FileConverter/Properties/Resources.Designer.cs
+++ b/Application/FileConverter/Properties/Resources.Designer.cs
@@ -897,6 +897,15 @@ namespace FileConverter.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to No preset selected.
+ ///
+ public static string NoPresetSelected {
+ get {
+ return ResourceManager.GetString("NoPresetSelected", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Ok.
///
diff --git a/Application/FileConverter/Properties/Resources.resx b/Application/FileConverter/Properties/Resources.resx
index 7412c0e..a3c4912 100644
--- a/Application/FileConverter/Properties/Resources.resx
+++ b/Application/FileConverter/Properties/Resources.resx
@@ -571,4 +571,7 @@ use maj for uppercase version
Custom FFMPEG command line arguments
+
+ No preset selected
+
\ No newline at end of file
diff --git a/Application/FileConverter/ViewModels/InputExtension.cs b/Application/FileConverter/ViewModels/InputExtension.cs
index 65cf46b..d3dcd51 100644
--- a/Application/FileConverter/ViewModels/InputExtension.cs
+++ b/Application/FileConverter/ViewModels/InputExtension.cs
@@ -6,10 +6,13 @@ namespace FileConverter.ViewModels
using System.Runtime.CompilerServices;
using System.Windows.Media;
+ using CommonServiceLocator;
+ using GalaSoft.MvvmLight;
+
using FileConverter.Annotations;
using FileConverter.ConversionJobs;
- public class InputExtension : INotifyPropertyChanged
+ public class InputExtension : ObservableObject
{
private readonly Brush defaultBrush = new SolidColorBrush(Color.FromRgb(0, 0, 0));
private readonly Brush errorBrush = new SolidColorBrush(Color.FromRgb(255, 65, 0));
@@ -48,54 +51,69 @@ namespace FileConverter.ViewModels
}
}
- public event PropertyChangedEventHandler PropertyChanged;
-
public string Name
{
- get
- {
- return this.name;
- }
+ get => this.name;
set
{
this.name = value;
- this.OnPropertyChanged();
+ this.RaisePropertyChanged();
}
}
public Brush ForegroundBrush
{
- get
- {
- return this.foregroundBrush;
- }
+ get => this.foregroundBrush;
set
{
this.foregroundBrush = value;
- this.OnPropertyChanged();
+ this.RaisePropertyChanged();
}
}
public string ToolTip
{
- get
- {
- return this.toolTip;
- }
+ get => this.toolTip;
set
{
this.toolTip = value;
- this.OnPropertyChanged();
+ this.RaisePropertyChanged();
}
}
- [NotifyPropertyChangedInvocator]
- protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
+ public bool IsChecked
{
- this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ get
+ {
+ SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance();
+ PresetNode selectedPreset = settingsViewModel.SelectedPreset;
+ if (selectedPreset == null)
+ {
+ return false;
+ }
+
+ return selectedPreset.Preset.InputTypes.Contains(this.name.ToLowerInvariant());
+ }
+
+ set
+ {
+ SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance();
+ PresetNode selectedPreset = settingsViewModel.SelectedPreset;
+
+ if (value)
+ {
+ selectedPreset?.Preset.AddInputType(this.name.ToLowerInvariant());
+ }
+ else
+ {
+ selectedPreset?.Preset.RemoveInputType(this.name.ToLowerInvariant());
+ }
+
+ this.RaisePropertyChanged(nameof(this.IsChecked));
+ }
}
}
}
\ No newline at end of file
diff --git a/Application/FileConverter/ViewModels/InputExtensionCategory.cs b/Application/FileConverter/ViewModels/InputExtensionCategory.cs
index 95c9842..f5c483b 100644
--- a/Application/FileConverter/ViewModels/InputExtensionCategory.cs
+++ b/Application/FileConverter/ViewModels/InputExtensionCategory.cs
@@ -1,5 +1,10 @@
// License: http://www.gnu.org/licenses/gpl.html GPL version 3.
+using System.ComponentModel;
+using CommonServiceLocator;
+using FileConverter.Services;
+using GalaSoft.MvvmLight.Ioc;
+
namespace FileConverter.ViewModels
{
using System.Collections.Generic;
@@ -7,8 +12,8 @@ namespace FileConverter.ViewModels
public class InputExtensionCategory : ObservableObject
{
+ private readonly List inputExtensions = new List();
private string name;
- private List inputExtensions = new List();
public InputExtensionCategory(string name)
{
@@ -17,10 +22,7 @@ namespace FileConverter.ViewModels
public string Name
{
- get
- {
- return this.name;
- }
+ get => this.name;
set
{
@@ -29,13 +31,7 @@ namespace FileConverter.ViewModels
}
}
- public IEnumerable InputExtensions
- {
- get
- {
- return this.inputExtensions;
- }
- }
+ public IEnumerable InputExtensions => this.inputExtensions;
public IEnumerable InputExtensionNames
{
@@ -55,9 +51,77 @@ namespace FileConverter.ViewModels
{
inputExtension = new InputExtension(extension);
this.inputExtensions.Add(inputExtension);
- this.RaisePropertyChanged("InputExtensions");
- this.RaisePropertyChanged("InputExtensionNames");
+
+ inputExtension.PropertyChanged += this.OnExtensionPropertyChange;
+
+ this.RaisePropertyChanged(nameof(this.InputExtensions));
+ this.RaisePropertyChanged(nameof(this.InputExtensionNames));
+ this.RaisePropertyChanged(nameof(this.IsChecked));
}
}
+
+ public bool? IsChecked
+ {
+ get
+ {
+ SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance();
+ PresetNode selectedPreset = settingsViewModel.SelectedPreset;
+ if (selectedPreset == null)
+ {
+ return false;
+ }
+
+ bool all = true;
+ bool none = true;
+ foreach (string extension in this.InputExtensionNames)
+ {
+ bool contains = selectedPreset.Preset.InputTypes.Contains(extension);
+ all &= contains;
+ none &= !contains;
+ }
+
+ if (all)
+ {
+ return true;
+ }
+ else if (none)
+ {
+ return false;
+ }
+
+ return null;
+ }
+
+ set
+ {
+ SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance();
+ PresetNode selectedPreset = settingsViewModel.SelectedPreset;
+
+ foreach (string extension in this.InputExtensionNames)
+ {
+ if (value == true)
+ {
+ selectedPreset?.Preset.AddInputType(extension);
+ }
+ else
+ {
+ selectedPreset?.Preset.RemoveInputType(extension);
+ }
+ }
+
+ // Raise property change for extensions.
+ foreach (InputExtension inputExtension in this.InputExtensions)
+ {
+ inputExtension.RaisePropertyChanged(nameof(inputExtension.IsChecked));
+ }
+
+ this.RaisePropertyChanged(nameof(this.IsChecked));
+ }
+ }
+
+ private void OnExtensionPropertyChange(object sender, PropertyChangedEventArgs e)
+ {
+ this.RaisePropertyChanged(nameof(this.IsChecked));
+ }
}
}
\ No newline at end of file
diff --git a/Application/FileConverter/Views/SettingsWindow.xaml b/Application/FileConverter/Views/SettingsWindow.xaml
index 63bf555..6dc82af 100644
--- a/Application/FileConverter/Views/SettingsWindow.xaml
+++ b/Application/FileConverter/Views/SettingsWindow.xaml
@@ -29,6 +29,178 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -167,165 +339,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
diff --git a/Application/FileConverter/Views/SettingsWindow.xaml.cs b/Application/FileConverter/Views/SettingsWindow.xaml.cs
index f820b4e..76a5687 100644
--- a/Application/FileConverter/Views/SettingsWindow.xaml.cs
+++ b/Application/FileConverter/Views/SettingsWindow.xaml.cs
@@ -19,6 +19,10 @@ namespace FileConverter.Views
///
public partial class SettingsWindow : Window
{
+ private TextBox selectedPresetNameTextBox;
+ private TextBox selectedFolderNameTextBox;
+ private string focusMessage;
+
private enum DragDropTargetPosition
{
Before,
@@ -35,102 +39,21 @@ namespace FileConverter.Views
public void DoFocus(string message)
{
+ this.focusMessage = message;
switch (message)
{
case "PresetName":
- this.PresetNameTextBox.Focus();
- this.PresetNameTextBox.SelectAll();
+ this.selectedPresetNameTextBox?.Focus();
+ this.selectedPresetNameTextBox?.SelectAll();
break;
case "FolderName":
- this.FolderNameTextBox.Focus();
- this.FolderNameTextBox.SelectAll();
+ this.selectedFolderNameTextBox?.Focus();
+ this.selectedFolderNameTextBox?.SelectAll();
break;
}
}
- private void OnInputTypeChecked(object sender, RoutedEventArgs e)
- {
- SettingsViewModel dataContext = this.DataContext as SettingsViewModel;
- if (dataContext.SelectedPreset == null)
- {
- return;
- }
-
- CheckBox checkBox = sender as CheckBox;
- if (!checkBox.IsVisible)
- {
- return;
- }
-
- string inputFormat = (checkBox.Content as string).ToLowerInvariant();
-
- dataContext.SelectedPreset.Preset.AddInputType(inputFormat);
- }
-
- private void OnInputTypeUnchecked(object sender, RoutedEventArgs e)
- {
- SettingsViewModel dataContext = this.DataContext as SettingsViewModel;
- if (dataContext.SelectedPreset == null)
- {
- return;
- }
-
- CheckBox checkBox = sender as CheckBox;
- if (!checkBox.IsVisible)
- {
- return;
- }
-
- string inputFormat = (checkBox.Content as string).ToLowerInvariant();
-
- dataContext.SelectedPreset.Preset.RemoveInputType(inputFormat);
- }
-
- private void OnInputTypeCategoryChecked(object sender, RoutedEventArgs e)
- {
- SettingsViewModel dataContext = this.DataContext as SettingsViewModel;
- if (dataContext.SelectedPreset == null)
- {
- return;
- }
-
- CheckBox checkBox = sender as CheckBox;
- string categoryName = checkBox.Content as string;
- InputExtensionCategory category = dataContext.InputCategories.FirstOrDefault(match => match.Name == categoryName);
- if (category == null)
- {
- return;
- }
-
- foreach (string inputExtension in category.InputExtensionNames)
- {
- dataContext.SelectedPreset.Preset.AddInputType(inputExtension);
- }
- }
-
- private void OnInputTypeCategoryUnchecked(object sender, RoutedEventArgs e)
- {
- SettingsViewModel dataContext = this.DataContext as SettingsViewModel;
- if (dataContext.SelectedPreset == null)
- {
- return;
- }
-
- CheckBox checkBox = sender as CheckBox;
- string categoryName = checkBox.Content as string;
- InputExtensionCategory category = dataContext.InputCategories.FirstOrDefault(match => match.Name == categoryName);
- if (category == null)
- {
- return;
- }
-
- foreach (string inputExtension in category.InputExtensionNames)
- {
- dataContext.SelectedPreset.Preset.RemoveInputType(inputExtension);
- }
- }
-
private void TreeView_MouseMove(object sender, MouseEventArgs args)
{
if (args.LeftButton == MouseButtonState.Pressed &&
@@ -380,5 +303,25 @@ namespace FileConverter.Views
return null;
}
+
+ private void SelectedPresetName_OnLoaded(object sender, RoutedEventArgs e)
+ {
+ this.selectedPresetNameTextBox = (TextBox)sender;
+ if (this.focusMessage == "PresetName")
+ {
+ this.DoFocus(this.focusMessage);
+ this.focusMessage = null;
+ }
+ }
+
+ private void SelectedFolderName_OnLoaded(object sender, RoutedEventArgs e)
+ {
+ this.selectedFolderNameTextBox = (TextBox)sender;
+ if (this.focusMessage == "FolderName")
+ {
+ this.DoFocus(this.focusMessage);
+ this.focusMessage = null;
+ }
+ }
}
}