diff options
author | sr55 <[email protected]> | 2016-07-25 20:29:44 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2016-07-25 20:29:44 +0100 |
commit | 96e2f705a48ed96db9172203ade1c6ab30937dde (patch) | |
tree | 1aa4554abf2ee1beedf7dfa7e94070b8a96305d3 | |
parent | 1903ac850ad0374b765ef3a058570a4bec067115 (diff) |
WinGui: Lay the foundation for editing presets with a simple rename window.
13 files changed, 386 insertions, 0 deletions
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 @@ <Compile Include="Utilities\SystemInfo.cs" />
<Compile Include="Utilities\Win32.cs" />
<Compile Include="Utilities\Win7.cs" />
+ <Compile Include="ViewModels\Interfaces\IManagePresetViewModel.cs" />
+ <Compile Include="ViewModels\ManagePresetViewModel.cs" />
<Compile Include="ViewModels\AudioDefaultsViewModel.cs" />
<Compile Include="ViewModels\CountdownAlertViewModel.cs" />
<Compile Include="ViewModels\Interfaces\IAudioDefaultsViewModel.cs" />
@@ -278,6 +280,9 @@ <Compile Include="ViewModels\PopupWindowViewModel.cs" />
<Compile Include="ViewModels\StaticPreviewViewModel.cs" />
<Compile Include="ViewModels\SubtitlesDefaultsViewModel.cs" />
+ <Compile Include="Views\ManagePresetView.xaml.cs">
+ <DependentUpon>ManagePresetView.xaml</DependentUpon>
+ </Compile>
<Compile Include="Views\AudioDefaultsView.xaml.cs">
<DependentUpon>AudioDefaultsView.xaml</DependentUpon>
</Compile>
@@ -495,6 +500,10 @@ <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
+ <Page Include="Views\ManagePresetView.xaml">
+ <Generator>MSBuild:Compile</Generator>
+ <SubType>Designer</SubType>
+ </Page>
<Page Include="Views\AudioDefaultsView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
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 @@ -790,6 +790,15 @@ namespace HandBrakeWPF.Properties { }
/// <summary>
+ /// Looks up a localized string similar to Rename Preset.
+ /// </summary>
+ public static string MainView_PresetManage {
+ get {
+ return ResourceManager.GetString("MainView_PresetManage", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Presets.
/// </summary>
public static string MainView_Presets {
@@ -952,6 +961,15 @@ namespace HandBrakeWPF.Properties { }
/// <summary>
+ /// Looks up a localized string similar to Manage Preset.
+ /// </summary>
+ public static string ManagePresetView_ManagePreset {
+ get {
+ return ResourceManager.GetString("ManagePresetView_ManagePreset", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Meta Data.
/// </summary>
public static string MetaDataView_Title {
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.</value> <data name="MainView_MetaDataTab" xml:space="preserve">
<value>Meta Data</value>
</data>
+ <data name="MainView_PresetManage" xml:space="preserve">
+ <value>Rename Preset</value>
+ </data>
+ <data name="ManagePresetView_ManagePreset" xml:space="preserve">
+ <value>Manage Preset</value>
+ </data>
</root>
\ 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 /// <param name="name">Name of the preset</param>
/// <returns>True if found</returns>
bool CheckIfPresetExists(string name);
+
+ /// <summary>
+ /// Replace an existing preset with a modified one.
+ /// </summary>
+ 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
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PropertyChangedBase"/> class.
+ /// Creates an instance of <see cref="T:HandBrakeWPF.Utilities.PropertyChangedBase"/>.
+ /// </summary>
+ public Preset()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PropertyChangedBase"/> class.
+ /// Creates an instance of <see cref="T:HandBrakeWPF.Utilities.PropertyChangedBase"/>.
+ /// </summary>
+ 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
/// <summary>
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 @@ -254,6 +254,15 @@ namespace HandBrakeWPF.Services.Presets }
/// <summary>
+ /// Replace an existing preset with a modified one.
+ /// </summary>
+ public void Replace(Preset existing, Preset replacement)
+ {
+ this.Remove(existing);
+ this.Add(replacement);
+ }
+
+ /// <summary>
/// Remove a preset with a given name from either the built in or user preset list.
/// </summary>
/// <param name="preset">
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<IMainViewModel, MainViewModel>();
this.container.Singleton<IQueueViewModel, QueueViewModel>();
this.container.PerRequest<IAddPresetViewModel, AddPresetViewModel>();
+ this.container.PerRequest<IManagePresetViewModel, ManagePresetViewModel>();
this.container.Singleton<ILogViewModel, LogViewModel>();
this.container.Singleton<IAboutViewModel, AboutViewModel>();
this.container.Singleton<IOptionsViewModel, OptionsViewModel>();
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 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="IManagePresetViewModel.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// The Manage Preset View Model Interface +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.ViewModels.Interfaces +{ + using HandBrakeWPF.Services.Presets.Model; + + /// <summary> + /// The Add Preset View Model + /// </summary> + public interface IManagePresetViewModel + { + /// <summary> + /// Prepare the Preset window + /// </summary> + void Setup(Preset preset); + + /// <summary> + /// Get the managed preset. + /// </summary> + 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 @@ -1845,6 +1845,34 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
+ /// Manage the current Preset
+ /// </summary>
+ 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<IManagePresetViewModel>();
+ presetViewModel.Setup(this.SelectedPreset);
+ this.windowManager.ShowDialog(presetViewModel);
+ Preset preset = presetViewModel.Preset;
+
+ this.SelectedPreset = preset; // Reselect the preset
+ }
+
+ /// <summary>
/// Remove a Preset
/// </summary>
public void PresetRemove()
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 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="ManagePresetViewModel.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// The Add Preset View Model +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +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; + + /// <summary> + /// The Add Preset View Model + /// </summary> + public class ManagePresetViewModel : ViewModelBase, IManagePresetViewModel + { + private readonly IPresetService presetService; + private readonly IErrorService errorService; + private readonly IWindowManager windowManager; + private Preset existingPreset; + + /// <summary> + /// Initializes a new instance of the <see cref="ManagePresetViewModel"/> class. + /// </summary> + /// <param name="presetService"> + /// The Preset Service + /// </param> + /// <param name="errorService"> + /// The Error Service + /// </param> + /// <param name="windowManager"> + /// The window Manager. + /// </param> + 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}; + } + + /// <summary> + /// Gets the Preset + /// </summary> + public Preset Preset { get; private set; } + + /// <summary> + /// Prepare the Preset window to create a Preset Object later. + /// </summary> + public void Setup(Preset presetToEdit) + { + this.Preset = new Preset(presetToEdit); // Clone. We will not touch the existing object. + this.existingPreset = presetToEdit; + } + + /// <summary> + /// Add a Preset + /// </summary> + 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(); + } + + /// <summary> + /// Cancel adding a preset + /// </summary> + public void Cancel() + { + this.Close(); + } + + /// <summary> + /// Close this window. + /// </summary> + 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 @@ <MenuItem Header="{x:Static Properties:ResourcesUI.MainView_SetDefault}" cal:Message.Attach="[Event Click] = [Action PresetSetDefault]" />
<Separator />
<MenuItem Header="{x:Static Properties:ResourcesUI.MainView_UpdateSelectedPreset}" cal:Message.Attach="[Event Click] = [Action PresetUpdate]" />
+ <MenuItem Header="{x:Static Properties:ResourcesUI.MainView_PresetManage}" cal:Message.Attach="[Event Click] = [Action PresetManage]" />
<Separator />
<MenuItem Header="{x:Static Properties:ResourcesUI.Preset_Import}" cal:Message.Attach="[Event Click] = [Action PresetImport]" />
<MenuItem Header="{x:Static Properties:ResourcesUI.Preset_Export}" cal:Message.Attach="[Event Click] = [Action PresetExport]" />
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 @@ +<Window x:Class="HandBrakeWPF.Views.ManagePresetView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:cal="http://www.caliburnproject.org" + xmlns:Converters="clr-namespace:HandBrakeWPF.Converters" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:Properties="clr-namespace:HandBrakeWPF.Properties" xmlns:controls="clr-namespace:HandBrakeWPF.Controls" + Title="{Binding Title}" + Width="350" + ResizeMode="NoResize" + SizeToContent="Height" + WindowStartupLocation="CenterScreen" + TextOptions.TextFormattingMode="Display" + mc:Ignorable="d"> + + <Window.Resources> + <Converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" /> + <Converters:EnumComboConverter x:Key="enumComboConverter" /> + + <Style x:Key="LongToolTipHolder" TargetType="FrameworkElement"> + <Setter Property="ToolTipService.ShowDuration" Value="20000" /> + <Setter Property="Margin" Value="0,2,0,2" /> + </Style> + </Window.Resources> + + <Grid HorizontalAlignment="Stretch" + VerticalAlignment="Stretch"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + + <TextBlock Text="{x:Static Properties:ResourcesUI.ManagePresetView_ManagePreset}" FontSize="26" FontFamily="Segoe UI Light" FontWeight="Bold" Margin="10,10,10,10" Grid.Row="0" /> + + <!-- Header --> + <Grid Grid.Row="1" Margin="10,0,10,0"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="120" /> + <ColumnDefinition Width="*" /> + </Grid.ColumnDefinitions> + + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + </Grid.RowDefinitions> + + <!-- Name --> + <TextBlock Grid.Row="0" + Grid.Column="0" + Text="{x:Static Properties:ResourcesUI.AddPresetView_Name}" /> + <TextBox Grid.Row="0" + Grid.Column="1" + HorizontalAlignment="Stretch" + Text="{Binding Preset.Name, UpdateSourceTrigger=PropertyChanged}" /> + + + <!-- Description --> + <TextBlock Grid.Row="2" + Grid.Column="0" Margin="0,10,0,0" + Text="{x:Static Properties:ResourcesUI.AddPresetView_Description}" /> + <TextBox Grid.Row="2" + Grid.Column="1" Margin="0,10,0,0" + + Text="{Binding Preset.Description, UpdateSourceTrigger=PropertyChanged}" /> + + <!-- Settings --> + + <StackPanel Grid.Row="4" + Grid.Column="1" + Margin="0,10,0,0" + Orientation="Horizontal" + Visibility="{Binding ShowCustomInputs, + Converter={StaticResource boolToVisConverter}}"/> + + </Grid> + + <!-- Controls --> + <Grid Grid.Row="3" + Margin="0,20,0,0"> + + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*" /> + <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="Auto" /> + </Grid.ColumnDefinitions> + + <Button Grid.Column="1" + Margin="0,5,10,10" + cal:Message.Attach="[Event Click] = [Action Cancel]" + Content="{x:Static Properties:ResourcesUI.Generic_Cancel}" + IsCancel="True" + Padding="8,2" /> + <Button Grid.Column="2" + Margin="0,5,10,10" + cal:Message.Attach="[Event Click] = [Action Save]" + Content="{x:Static Properties:ResourcesUI.Generic_Save}" + IsDefault="True" + Padding="8,2" /> + </Grid> + + </Grid> +</Window> diff --git a/win/CS/HandBrakeWPF/Views/ManagePresetView.xaml.cs b/win/CS/HandBrakeWPF/Views/ManagePresetView.xaml.cs new file mode 100644 index 000000000..d0964a982 --- /dev/null +++ b/win/CS/HandBrakeWPF/Views/ManagePresetView.xaml.cs @@ -0,0 +1,27 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="ManagePresetView.xaml.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Interaction logic for ManagePresetView.xaml +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Views +{ + using System.Windows; + + /// <summary> + /// Interaction logic for ManagePresetView.xaml + /// </summary> + public partial class ManagePresetView : Window + { + /// <summary> + /// Initializes a new instance of the <see cref="ManagePresetView"/> class. + /// </summary> + public ManagePresetView() + { + InitializeComponent(); + } + } +} |