From 96e2f705a48ed96db9172203ade1c6ab30937dde Mon Sep 17 00:00:00 2001 From: sr55 Date: Mon, 25 Jul 2016 20:29:44 +0100 Subject: WinGui: Lay the foundation for editing presets with a simple rename window. --- win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 9 ++ .../Properties/ResourcesUI.Designer.cs | 18 ++++ win/CS/HandBrakeWPF/Properties/ResourcesUI.resx | 6 ++ .../Services/Presets/Interfaces/IPresetService.cs | 5 + .../HandBrakeWPF/Services/Presets/Model/Preset.cs | 24 +++++ .../HandBrakeWPF/Services/Presets/PresetService.cs | 9 ++ win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs | 1 + .../Interfaces/IManagePresetViewModel.cs | 29 +++++ win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 28 +++++ .../ViewModels/ManagePresetViewModel.cs | 118 +++++++++++++++++++++ win/CS/HandBrakeWPF/Views/MainView.xaml | 1 + win/CS/HandBrakeWPF/Views/ManagePresetView.xaml | 111 +++++++++++++++++++ win/CS/HandBrakeWPF/Views/ManagePresetView.xaml.cs | 27 +++++ 13 files changed, 386 insertions(+) create mode 100644 win/CS/HandBrakeWPF/ViewModels/Interfaces/IManagePresetViewModel.cs create mode 100644 win/CS/HandBrakeWPF/ViewModels/ManagePresetViewModel.cs create mode 100644 win/CS/HandBrakeWPF/Views/ManagePresetView.xaml create mode 100644 win/CS/HandBrakeWPF/Views/ManagePresetView.xaml.cs (limited to 'win') diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 0898308eb..8425d7314 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -261,6 +261,8 @@ + + @@ -278,6 +280,9 @@ + + ManagePresetView.xaml + AudioDefaultsView.xaml @@ -495,6 +500,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs b/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs index e24ab338f..b7b5332d0 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs @@ -789,6 +789,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Rename Preset. + /// + public static string MainView_PresetManage { + get { + return ResourceManager.GetString("MainView_PresetManage", resourceCulture); + } + } + /// /// Looks up a localized string similar to Presets. /// @@ -951,6 +960,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Manage Preset. + /// + public static string ManagePresetView_ManagePreset { + get { + return ResourceManager.GetString("ManagePresetView_ManagePreset", resourceCulture); + } + } + /// /// Looks up a localized string similar to Meta Data. /// diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx b/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx index ca5ecd6f7..d332c0ca4 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx +++ b/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx @@ -884,4 +884,10 @@ This will not affect your current settings in the Subtitle tab. Meta Data + + Rename Preset + + + Manage Preset + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Presets/Interfaces/IPresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/Interfaces/IPresetService.cs index 88fd341b0..4cc177a3d 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Interfaces/IPresetService.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Interfaces/IPresetService.cs @@ -144,5 +144,10 @@ namespace HandBrakeWPF.Services.Presets.Interfaces /// Name of the preset /// True if found bool CheckIfPresetExists(string name); + + /// + /// Replace an existing preset with a modified one. + /// + void Replace(Preset existing, Preset replacement); } } \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs b/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs index a6190052e..4ecc0c502 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs @@ -35,6 +35,30 @@ namespace HandBrakeWPF.Services.Presets.Model #endregion + /// + /// Initializes a new instance of the class. + /// Creates an instance of . + /// + public Preset() + { + } + + /// + /// Initializes a new instance of the class. + /// Creates an instance of . + /// + public Preset(Preset preset) + { + this.Category = preset.Category; + this.Description = preset.Description; + this.IsBuildIn = preset.IsBuildIn; + this.Name = preset.Name; + this.PictureSettingsMode = preset.PictureSettingsMode; + this.Task = new EncodeTask(preset.Task); + this.AudioTrackBehaviours = new AudioBehaviours(preset.AudioTrackBehaviours); + this.SubtitleTrackBehaviours = new SubtitleBehaviours(preset.SubtitleTrackBehaviours); + } + #region Properties /// diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs index 55915329b..6c4a48864 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs @@ -253,6 +253,15 @@ namespace HandBrakeWPF.Services.Presets } } + /// + /// Replace an existing preset with a modified one. + /// + public void Replace(Preset existing, Preset replacement) + { + this.Remove(existing); + this.Add(replacement); + } + /// /// Remove a preset with a given name from either the built in or user preset list. /// diff --git a/win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs index 70fe9e306..1e4a8a8ad 100644 --- a/win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs +++ b/win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs @@ -73,6 +73,7 @@ namespace HandBrakeWPF.Startup this.container.Singleton(); this.container.Singleton(); this.container.PerRequest(); + this.container.PerRequest(); this.container.Singleton(); this.container.Singleton(); this.container.Singleton(); diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IManagePresetViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IManagePresetViewModel.cs new file mode 100644 index 000000000..2af41b1de --- /dev/null +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IManagePresetViewModel.cs @@ -0,0 +1,29 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The Manage Preset View Model Interface +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.ViewModels.Interfaces +{ + using HandBrakeWPF.Services.Presets.Model; + + /// + /// The Add Preset View Model + /// + public interface IManagePresetViewModel + { + /// + /// Prepare the Preset window + /// + void Setup(Preset preset); + + /// + /// Get the managed preset. + /// + Preset Preset { get; } + } +} diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index a5796a045..357ac85fe 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -1844,6 +1844,34 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Manage the current Preset + /// + public void PresetManage() + { + if (this.SelectedPreset == null) + { + this.errorService.ShowMessageBox( + Resources.Main_SelectPresetForUpdate, Resources.Main_NoPresetSelected, MessageBoxButton.OK, MessageBoxImage.Warning); + + return; + } + + if (this.SelectedPreset.IsBuildIn) + { + this.errorService.ShowMessageBox( + Resources.Main_NoUpdateOfBuiltInPresets, Resources.Main_NoPresetSelected, MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + + IManagePresetViewModel presetViewModel = IoC.Get(); + presetViewModel.Setup(this.SelectedPreset); + this.windowManager.ShowDialog(presetViewModel); + Preset preset = presetViewModel.Preset; + + this.SelectedPreset = preset; // Reselect the preset + } + /// /// Remove a Preset /// diff --git a/win/CS/HandBrakeWPF/ViewModels/ManagePresetViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/ManagePresetViewModel.cs new file mode 100644 index 000000000..2f559bb65 --- /dev/null +++ b/win/CS/HandBrakeWPF/ViewModels/ManagePresetViewModel.cs @@ -0,0 +1,118 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The Add Preset View Model +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.ViewModels +{ + using System.Windows; + + using Caliburn.Micro; + + using HandBrakeWPF.Properties; + using HandBrakeWPF.Services.Interfaces; + using HandBrakeWPF.Services.Presets; + using HandBrakeWPF.Services.Presets.Interfaces; + using HandBrakeWPF.Services.Presets.Model; + using HandBrakeWPF.ViewModels.Interfaces; + + /// + /// The Add Preset View Model + /// + public class ManagePresetViewModel : ViewModelBase, IManagePresetViewModel + { + private readonly IPresetService presetService; + private readonly IErrorService errorService; + private readonly IWindowManager windowManager; + private Preset existingPreset; + + /// + /// Initializes a new instance of the class. + /// + /// + /// The Preset Service + /// + /// + /// The Error Service + /// + /// + /// The window Manager. + /// + public ManagePresetViewModel(IPresetService presetService, IErrorService errorService, IWindowManager windowManager) + { + this.presetService = presetService; + this.errorService = errorService; + this.windowManager = windowManager; + this.Title = "Manage Preset"; + this.Preset = new Preset { IsBuildIn = false, IsDefault = false, Category = PresetService.UserPresetCatgoryName}; + } + + /// + /// Gets the Preset + /// + public Preset Preset { get; private set; } + + /// + /// Prepare the Preset window to create a Preset Object later. + /// + public void Setup(Preset presetToEdit) + { + this.Preset = new Preset(presetToEdit); // Clone. We will not touch the existing object. + this.existingPreset = presetToEdit; + } + + /// + /// Add a Preset + /// + public void Save() + { + if (string.IsNullOrEmpty(this.Preset.Name)) + { + this.errorService.ShowMessageBox( + Resources.AddPresetViewModel_PresetMustProvideName, + Resources.Error, + MessageBoxButton.OK, + MessageBoxImage.Error); + return; + } + + if (this.presetService.CheckIfPresetExists(this.Preset.Name)) + { + MessageBoxResult result = + this.errorService.ShowMessageBox( + Resources.AddPresetViewModel_PresetWithSameNameOverwriteWarning, + Resources.Error, + MessageBoxButton.YesNo, + MessageBoxImage.Error); + if (result == MessageBoxResult.No) + { + return; + } + } + + // Save the Preset + this.presetService.Replace(this.existingPreset, this.Preset); + this.Close(); + } + + /// + /// Cancel adding a preset + /// + public void Cancel() + { + this.Close(); + } + + /// + /// Close this window. + /// + public void Close() + { + this.TryClose(); + } + } +} diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml b/win/CS/HandBrakeWPF/Views/MainView.xaml index cf880ce70..a12de9e49 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml @@ -541,6 +541,7 @@ + diff --git a/win/CS/HandBrakeWPF/Views/ManagePresetView.xaml b/win/CS/HandBrakeWPF/Views/ManagePresetView.xaml new file mode 100644 index 000000000..fb16780e0 --- /dev/null +++ b/win/CS/HandBrakeWPF/Views/ManagePresetView.xaml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +