From 6f5e5ea1703a9a40a54d8d677b1c24e45dff7b32 Mon Sep 17 00:00:00 2001 From: sr55 Date: Mon, 11 Sep 2017 19:48:03 +0100 Subject: [PATCH] WinGui: Improve selection behaviour of the new preset controls. --- .../Presets/Interfaces/IPresetService.cs | 10 +++ .../Services/Presets/PresetService.cs | 63 ++++++++++++++++--- win/CS/HandBrakeWPF/UserSettingConstants.cs | 7 ++- .../HandBrakeWPF/ViewModels/MainViewModel.cs | 44 +++++++------ 4 files changed, 95 insertions(+), 29 deletions(-) diff --git a/win/CS/HandBrakeWPF/Services/Presets/Interfaces/IPresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/Interfaces/IPresetService.cs index 6c6b8ceb6..f75c054c5 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Interfaces/IPresetService.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Interfaces/IPresetService.cs @@ -35,6 +35,16 @@ namespace HandBrakeWPF.Services.Presets.Interfaces /// void Load(); + /// + /// Save the state of the Preset Treview + /// + void SaveCategoryStates(); + + /// + /// Load the state of the Preset Treeview. + /// + void LoadCategoryStates(); + /// /// Add a new preset to the system /// diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs index 16db5359a..f4057dbc3 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs @@ -472,7 +472,7 @@ namespace HandBrakeWPF.Services.Presets foreach (var hbpreset in category.ChildrenArray) { Preset preset = JsonPresetFactory.ImportPreset(hbpreset); - preset.IsBuildIn = true; + preset.IsBuildIn = true; preset.Category = category.PresetName; preset.Task.AllowedPassthruOptions = new AllowedPassthru(true); // We don't want to override the built-in preset @@ -543,6 +543,39 @@ namespace HandBrakeWPF.Services.Presets selectedPreset.IsSelected = true; } + public void SaveCategoryStates() + { + StringCollection expandedPresets = new StringCollection(); + foreach (IPresetObject presetObject in this.presets) + { + PresetDisplayCategory category = presetObject as PresetDisplayCategory; + if (category != null && category.IsExpanded) + { + expandedPresets.Add(category.Category); + } + } + + this.userSettingService.SetUserSetting(UserSettingConstants.PresetExpandedStateList, expandedPresets); + } + + public void LoadCategoryStates() + { + StringCollection expandedPresets = this.userSettingService.GetUserSetting(UserSettingConstants.PresetExpandedStateList); + if (expandedPresets == null || expandedPresets.Count == 0) + { + return; + } + + foreach (IPresetObject presetObject in this.presets) + { + PresetDisplayCategory category = presetObject as PresetDisplayCategory; + if (category != null && expandedPresets.Contains(category.Category)) + { + category.IsExpanded = true; + } + } + } + #endregion #region Private Helpers @@ -654,10 +687,10 @@ namespace HandBrakeWPF.Services.Presets { string filename = this.RecoverFromCorruptedPresetFile(this.presetFile); this.errorService.ShowMessageBox( - Resources.PresetService_UnableToLoadPresets + filename, - Resources.PresetService_UnableToLoad, - MessageBoxButton.OK, - MessageBoxImage.Exclamation); + Resources.PresetService_UnableToLoadPresets + filename, + Resources.PresetService_UnableToLoad, + MessageBoxButton.OK, + MessageBoxImage.Exclamation); this.UpdateBuiltInPresets(); return; // Update built-in presets stores the presets locally, so just return. @@ -707,7 +740,16 @@ namespace HandBrakeWPF.Services.Presets foreach (HBPreset hbpreset in category.ChildrenArray) { Preset preset = JsonPresetFactory.ImportPreset(hbpreset); - preset.Category = category.PresetName; + + // Migration + if (category.PresetName == "User Presets") + { + preset.Category = UserPresetCatgoryName; + } + else + { + preset.Category = category.PresetName; + } preset.IsBuildIn = hbpreset.Type == 0; // IF we are using Source Max, Set the Max Width / Height values. @@ -797,9 +839,10 @@ namespace HandBrakeWPF.Services.Presets // Wrap the categories in a container. JsonSerializerSettings settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore }; PresetTransportContainer container = new PresetTransportContainer( - Constants.PresetVersionMajor, - Constants.PresetVersionMinor, - Constants.PresetVersionMicro) { PresetList = new List() }; + Constants.PresetVersionMajor, + Constants.PresetVersionMinor, + Constants.PresetVersionMicro) + { PresetList = new List() }; container.PresetList.AddRange(presetCategories.Values); container.PresetList.AddRange(uncategorisedPresets); @@ -867,4 +910,4 @@ namespace HandBrakeWPF.Services.Presets #endregion } -} +} \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs index 74c901d2d..cde030c23 100644 --- a/win/CS/HandBrakeWPF/UserSettingConstants.cs +++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs @@ -105,7 +105,7 @@ namespace HandBrakeWPF /// The last preview duration /// public const string LastPreviewDuration = "LastPreviewDuration"; - + /// /// When Complete Action /// @@ -146,6 +146,11 @@ namespace HandBrakeWPF /// public const string RemovePunctuation = "RemovePunctuation"; + /// + /// The Show Preset Panel + /// + public const string ShowPresetPanel = "ShowPresetPanel"; + /// /// The reset when done action. /// diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index de4476367..c8cf354ac 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -418,6 +418,11 @@ namespace HandBrakeWPF.ViewModels { this.selectedPreset = value; this.NotifyOfPropertyChange(() => this.SelectedPreset); + + if (value != null) + { + this.PresetSelect(value); + } } } } @@ -1192,6 +1197,7 @@ namespace HandBrakeWPF.ViewModels this.presetService.Load(); this.PresetsCategories = this.presetService.Presets; this.NotifyOfPropertyChange(() => this.PresetsCategories); + this.presetService.LoadCategoryStates(); this.SummaryViewModel.OutputFormatChanged += this.SummaryViewModel_OutputFormatChanged; @@ -1249,6 +1255,7 @@ namespace HandBrakeWPF.ViewModels { // Shutdown Service this.queueProcessor.Stop(); + this.presetService.SaveCategoryStates(); // Unsubscribe from Events. this.scanService.ScanStarted -= this.ScanStared; @@ -1897,7 +1904,8 @@ namespace HandBrakeWPF.ViewModels Preset preset = presetViewModel.Preset; this.NotifyOfPropertyChange(() => this.CategoryPresets); - this.SelectedPreset = preset; // Reselect the preset + this.selectedPreset = preset; // Reselect the preset + this.NotifyOfPropertyChange(() => this.SelectedPreset); } /// @@ -2037,23 +2045,24 @@ namespace HandBrakeWPF.ViewModels this.SelectedPresetCategory = this.PresetsCategories.FirstOrDefault(c => c.Category == preset.Category); } - this.SelectedPreset = preset; - } + this.selectedPreset = preset; + this.NotifyOfPropertyChange(() => this.SelectedPreset); - this.presetService.SetSelected(this.selectedPreset); - - if (this.selectedPreset != null) - { - // Tab Settings - this.PictureSettingsViewModel.SetPreset(this.selectedPreset, this.CurrentTask); - this.VideoViewModel.SetPreset(this.selectedPreset, this.CurrentTask); - this.FiltersViewModel.SetPreset(this.selectedPreset, this.CurrentTask); - this.AudioViewModel.SetPreset(this.selectedPreset, this.CurrentTask); - this.SubtitleViewModel.SetPreset(this.selectedPreset, this.CurrentTask); - this.ChaptersViewModel.SetPreset(this.selectedPreset, this.CurrentTask); - this.AdvancedViewModel.SetPreset(this.selectedPreset, this.CurrentTask); - this.MetaDataViewModel.SetPreset(this.selectedPreset, this.CurrentTask); - this.SummaryViewModel.SetPreset(this.selectedPreset, this.CurrentTask); + this.presetService.SetSelected(this.selectedPreset); + + if (this.selectedPreset != null) + { + // Tab Settings + this.PictureSettingsViewModel.SetPreset(this.selectedPreset, this.CurrentTask); + this.VideoViewModel.SetPreset(this.selectedPreset, this.CurrentTask); + this.FiltersViewModel.SetPreset(this.selectedPreset, this.CurrentTask); + this.AudioViewModel.SetPreset(this.selectedPreset, this.CurrentTask); + this.SubtitleViewModel.SetPreset(this.selectedPreset, this.CurrentTask); + this.ChaptersViewModel.SetPreset(this.selectedPreset, this.CurrentTask); + this.AdvancedViewModel.SetPreset(this.selectedPreset, this.CurrentTask); + this.MetaDataViewModel.SetPreset(this.selectedPreset, this.CurrentTask); + this.SummaryViewModel.SetPreset(this.selectedPreset, this.CurrentTask); + } } } @@ -2252,7 +2261,6 @@ namespace HandBrakeWPF.ViewModels this.SelectedPresetCategory = category; this.SelectedPreset = this.presetService.DefaultPreset; - this.PresetSelect(); } } -- 2.40.0