From 8708bacf7689dfe01af965a2ce7364f9ea5cfdfe Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 2 Mar 2013 19:48:27 +0000 Subject: WinGui: Port advanced tab caching code to trunk git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5285 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../ViewModels/EncoderOptionsViewModel.cs | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'win/CS/HandBrakeWPF') diff --git a/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs index e578d9688..f1da43828 100644 --- a/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs @@ -9,6 +9,8 @@ namespace HandBrakeWPF.ViewModels { + using System.Collections.Generic; + using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Parsing; using HandBrake.Interop.Model.Encoding; @@ -20,6 +22,11 @@ namespace HandBrakeWPF.ViewModels /// public class EncoderOptionsViewModel : ViewModelBase, IEncoderOptionsViewModel, ITabInterface { + /// + /// The cached options. + /// + private readonly Dictionary cachedOptions = new Dictionary(); + /// /// Initializes a new instance of the class. /// @@ -33,6 +40,16 @@ namespace HandBrakeWPF.ViewModels /// public EncodeTask Task { get; set; } + /// + /// Gets or sets the preset. + /// + public Preset Preset { get; set; } + + /// + /// Gets or sets the current video encoder. + /// + public VideoEncoder CurrentVideoEncoder { get; set; } + /// /// Gets or sets the options string. /// @@ -64,6 +81,7 @@ namespace HandBrakeWPF.ViewModels public void SetSource(Title selectedTitle, Preset currentPreset, EncodeTask task) { this.Task = task; + this.Preset = currentPreset; this.NotifyOfPropertyChange(() => this.AdvancedOptionsString); } @@ -79,6 +97,7 @@ namespace HandBrakeWPF.ViewModels public void SetPreset(Preset preset, EncodeTask task) { this.Task = task; + this.Preset = preset; this.AdvancedOptionsString = preset.Task.AdvancedEncoderOptions; } @@ -102,6 +121,28 @@ namespace HandBrakeWPF.ViewModels /// public void SetEncoder(VideoEncoder encoder) { + // Cache the existing string so it can be reused if the user changes the encoder back. + if (!string.IsNullOrEmpty(this.AdvancedOptionsString)) + { + this.cachedOptions[CurrentVideoEncoder] = this.AdvancedOptionsString; + } + + this.CurrentVideoEncoder = encoder; + + // Set the option from the cached version if we have one. + string advacnedOptionsString; + if (cachedOptions.TryGetValue(encoder, out advacnedOptionsString) + && !string.IsNullOrEmpty(advacnedOptionsString)) + { + this.AdvancedOptionsString = advacnedOptionsString; + } + else + { + this.AdvancedOptionsString = this.Preset != null && this.Preset.Task != null + && !string.IsNullOrEmpty(this.Preset.Task.AdvancedEncoderOptions) + ? this.Preset.Task.AdvancedEncoderOptions + : string.Empty; + } } /// -- cgit v1.2.3