WinGui: Lay the foundation for editing presets with a simple rename window.
authorsr55 <sr55.hb@outlook.com>
Mon, 25 Jul 2016 19:29:44 +0000 (20:29 +0100)
committersr55 <sr55.hb@outlook.com>
Mon, 25 Jul 2016 19:29:44 +0000 (20:29 +0100)
13 files changed:
win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs
win/CS/HandBrakeWPF/Properties/ResourcesUI.resx
win/CS/HandBrakeWPF/Services/Presets/Interfaces/IPresetService.cs
win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs
win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs
win/CS/HandBrakeWPF/ViewModels/Interfaces/IManagePresetViewModel.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
win/CS/HandBrakeWPF/ViewModels/ManagePresetViewModel.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/Views/MainView.xaml
win/CS/HandBrakeWPF/Views/ManagePresetView.xaml [new file with mode: 0644]
win/CS/HandBrakeWPF/Views/ManagePresetView.xaml.cs [new file with mode: 0644]

index 0898308eb03218b72da66d0833b2a5ac9fbf9dec..8425d731478347ef1a7cfe0feee6c4f8fe0df9bc 100644 (file)
     <Compile Include="Utilities\SystemInfo.cs" />\r
     <Compile Include="Utilities\Win32.cs" />\r
     <Compile Include="Utilities\Win7.cs" />\r
+    <Compile Include="ViewModels\Interfaces\IManagePresetViewModel.cs" />\r
+    <Compile Include="ViewModels\ManagePresetViewModel.cs" />\r
     <Compile Include="ViewModels\AudioDefaultsViewModel.cs" />\r
     <Compile Include="ViewModels\CountdownAlertViewModel.cs" />\r
     <Compile Include="ViewModels\Interfaces\IAudioDefaultsViewModel.cs" />\r
     <Compile Include="ViewModels\PopupWindowViewModel.cs" />\r
     <Compile Include="ViewModels\StaticPreviewViewModel.cs" />\r
     <Compile Include="ViewModels\SubtitlesDefaultsViewModel.cs" />\r
+    <Compile Include="Views\ManagePresetView.xaml.cs">\r
+      <DependentUpon>ManagePresetView.xaml</DependentUpon>\r
+    </Compile>\r
     <Compile Include="Views\AudioDefaultsView.xaml.cs">\r
       <DependentUpon>AudioDefaultsView.xaml</DependentUpon>\r
     </Compile>\r
       <Generator>MSBuild:Compile</Generator>\r
       <SubType>Designer</SubType>\r
     </Page>\r
+    <Page Include="Views\ManagePresetView.xaml">\r
+      <Generator>MSBuild:Compile</Generator>\r
+      <SubType>Designer</SubType>\r
+    </Page>\r
     <Page Include="Views\AudioDefaultsView.xaml">\r
       <Generator>MSBuild:Compile</Generator>\r
       <SubType>Designer</SubType>\r
index e24ab338f395988afe29781401aa7bd4dfb27ece..b7b5332d01696c8b8cf9c585de74c5b19ac64971 100644 (file)
@@ -789,6 +789,15 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Rename Preset.\r
+        /// </summary>\r
+        public static string MainView_PresetManage {\r
+            get {\r
+                return ResourceManager.GetString("MainView_PresetManage", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to Presets.\r
         /// </summary>\r
@@ -951,6 +960,15 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Manage Preset.\r
+        /// </summary>\r
+        public static string ManagePresetView_ManagePreset {\r
+            get {\r
+                return ResourceManager.GetString("ManagePresetView_ManagePreset", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to Meta Data.\r
         /// </summary>\r
index ca5ecd6f7768fb059feeda8c6b3404d32406db9c..d332c0ca4a449cf24b1854948c006ee28380f050 100644 (file)
@@ -884,4 +884,10 @@ This will not affect your current settings in the Subtitle tab.</value>
   <data name="MainView_MetaDataTab" xml:space="preserve">\r
     <value>Meta Data</value>\r
   </data>\r
+  <data name="MainView_PresetManage" xml:space="preserve">\r
+    <value>Rename Preset</value>\r
+  </data>\r
+  <data name="ManagePresetView_ManagePreset" xml:space="preserve">\r
+    <value>Manage Preset</value>\r
+  </data>\r
 </root>
\ No newline at end of file
index 88fd341b0acf735dbe9da637a7d739a34233b69d..4cc177a3d162bb46dea1160944b70583dea4f180 100644 (file)
@@ -144,5 +144,10 @@ namespace HandBrakeWPF.Services.Presets.Interfaces
         /// <param name="name">Name of the preset</param>\r
         /// <returns>True if found</returns>\r
         bool CheckIfPresetExists(string name);\r
+\r
+        /// <summary>\r
+        /// Replace an existing preset with a modified one.\r
+        /// </summary>\r
+        void Replace(Preset existing, Preset replacement);\r
     }\r
 }
\ No newline at end of file
index a6190052e79a3f8449264630846f8cf6b887ca92..4ecc0c5022c0fb9f63987cc5ad5e5f5439db5c6f 100644 (file)
@@ -35,6 +35,30 @@ namespace HandBrakeWPF.Services.Presets.Model
 \r
         #endregion\r
 \r
+        /// <summary>\r
+        /// Initializes a new instance of the <see cref="PropertyChangedBase"/> class. \r
+        /// Creates an instance of <see cref="T:HandBrakeWPF.Utilities.PropertyChangedBase"/>.\r
+        /// </summary>\r
+        public Preset()\r
+        {\r
+        }\r
+\r
+        /// <summary>\r
+        /// Initializes a new instance of the <see cref="PropertyChangedBase"/> class. \r
+        /// Creates an instance of <see cref="T:HandBrakeWPF.Utilities.PropertyChangedBase"/>.\r
+        /// </summary>\r
+        public Preset(Preset preset)\r
+        {\r
+            this.Category = preset.Category;\r
+            this.Description = preset.Description;\r
+            this.IsBuildIn = preset.IsBuildIn;\r
+            this.Name = preset.Name;\r
+            this.PictureSettingsMode = preset.PictureSettingsMode;\r
+            this.Task = new EncodeTask(preset.Task);\r
+            this.AudioTrackBehaviours = new AudioBehaviours(preset.AudioTrackBehaviours);\r
+            this.SubtitleTrackBehaviours = new SubtitleBehaviours(preset.SubtitleTrackBehaviours);\r
+        }\r
+\r
         #region Properties\r
 \r
         /// <summary>\r
index 55915329bdc2ea1bbb40d39a4decb50cff97e770..6c4a4886436461d393037c833950dcaeee0ef297 100644 (file)
@@ -253,6 +253,15 @@ namespace HandBrakeWPF.Services.Presets
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Replace an existing preset with a modified one.\r
+        /// </summary>\r
+        public void Replace(Preset existing, Preset replacement)\r
+        {\r
+            this.Remove(existing);\r
+            this.Add(replacement);\r
+        }\r
+\r
         /// <summary>\r
         /// Remove a preset with a given name from either the built in or user preset list.\r
         /// </summary>\r
index 70fe9e306422c9079b8608095d4f8ffe3dd3f6e4..1e4a8a8ad93d171e1720d5ac9cf5f04ac277e7b9 100644 (file)
@@ -73,6 +73,7 @@ namespace HandBrakeWPF.Startup
             this.container.Singleton<IMainViewModel, MainViewModel>();\r
             this.container.Singleton<IQueueViewModel, QueueViewModel>();\r
             this.container.PerRequest<IAddPresetViewModel, AddPresetViewModel>();\r
+            this.container.PerRequest<IManagePresetViewModel, ManagePresetViewModel>();\r
             this.container.Singleton<ILogViewModel, LogViewModel>();\r
             this.container.Singleton<IAboutViewModel, AboutViewModel>();\r
             this.container.Singleton<IOptionsViewModel, OptionsViewModel>();\r
diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IManagePresetViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IManagePresetViewModel.cs
new file mode 100644 (file)
index 0000000..2af41b1
--- /dev/null
@@ -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; }
+    }
+}
index a5796a0453cb308f9c4ddd85b4f9692e0d429677..357ac85fee1d0460fdc59cf65cd3818e13982c29 100644 (file)
@@ -1844,6 +1844,34 @@ namespace HandBrakeWPF.ViewModels
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Manage the current Preset\r
+        /// </summary>\r
+        public void PresetManage()\r
+        {\r
+            if (this.SelectedPreset == null)\r
+            {\r
+                this.errorService.ShowMessageBox(\r
+                    Resources.Main_SelectPresetForUpdate, Resources.Main_NoPresetSelected, MessageBoxButton.OK, MessageBoxImage.Warning);\r
+\r
+                return;\r
+            }\r
+\r
+            if (this.SelectedPreset.IsBuildIn)\r
+            {\r
+                this.errorService.ShowMessageBox(\r
+                    Resources.Main_NoUpdateOfBuiltInPresets, Resources.Main_NoPresetSelected, MessageBoxButton.OK, MessageBoxImage.Warning);\r
+                return;\r
+            }\r
+\r
+            IManagePresetViewModel presetViewModel = IoC.Get<IManagePresetViewModel>();\r
+            presetViewModel.Setup(this.SelectedPreset);\r
+            this.windowManager.ShowDialog(presetViewModel);\r
+            Preset preset = presetViewModel.Preset;\r
+\r
+            this.SelectedPreset = preset; // Reselect the preset\r
+        }\r
+\r
         /// <summary>\r
         /// Remove a Preset\r
         /// </summary>\r
diff --git a/win/CS/HandBrakeWPF/ViewModels/ManagePresetViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/ManagePresetViewModel.cs
new file mode 100644 (file)
index 0000000..2f559bb
--- /dev/null
@@ -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();
+        }
+    }
+}
index cf880ce701fcd6298f274569827bbdec695ac0b0..a12de9e49f01be948ff1af7214269d12418f9dba 100644 (file)
                                 <MenuItem Header="{x:Static Properties:ResourcesUI.MainView_SetDefault}" cal:Message.Attach="[Event Click] = [Action PresetSetDefault]" />\r
                                 <Separator />\r
                                 <MenuItem Header="{x:Static Properties:ResourcesUI.MainView_UpdateSelectedPreset}" cal:Message.Attach="[Event Click] = [Action PresetUpdate]" />\r
+                                <MenuItem Header="{x:Static Properties:ResourcesUI.MainView_PresetManage}" cal:Message.Attach="[Event Click] = [Action PresetManage]" />\r
                                 <Separator />\r
                                 <MenuItem Header="{x:Static Properties:ResourcesUI.Preset_Import}" cal:Message.Attach="[Event Click] = [Action PresetImport]" />\r
                                 <MenuItem Header="{x:Static Properties:ResourcesUI.Preset_Export}" cal:Message.Attach="[Event Click] = [Action PresetExport]" />\r
diff --git a/win/CS/HandBrakeWPF/Views/ManagePresetView.xaml b/win/CS/HandBrakeWPF/Views/ManagePresetView.xaml
new file mode 100644 (file)
index 0000000..fb16780
--- /dev/null
@@ -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 (file)
index 0000000..d0964a9
--- /dev/null
@@ -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();
+        }
+    }
+}