]> granicus.if.org Git - handbrake/commitdiff
WinGui: Don't update config when user cancels file/folder dialogs - Patch by jorrit
authorsr55 <sr55.hb@outlook.com>
Sun, 23 Aug 2015 14:15:22 +0000 (14:15 +0000)
committersr55 <sr55.hb@outlook.com>
Sun, 23 Aug 2015 14:15:22 +0000 (14:15 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7408 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs

index cca7b2334e22bd1eb29c570e5e82b49708673020..e270e3c154b20e0cf2fcd23e48b1acad4ad40f6b 100644 (file)
@@ -38,7 +38,7 @@ namespace HandBrakeWPF.ViewModels
         /// <summary>\r
         /// The source chapters backing field\r
         /// </summary>\r
-        private List<Chapter> sourceChaptersList; \r
+        private List<Chapter> sourceChaptersList;\r
 \r
         #region Constructors and Destructors\r
 \r
@@ -99,13 +99,13 @@ namespace HandBrakeWPF.ViewModels
         public void Export()\r
         {\r
             var saveFileDialog = new OpenFileDialog\r
-                {\r
-                    Filter = "Csv File|*.csv",\r
-                    DefaultExt = "csv",\r
-                    CheckPathExists = true\r
-                };\r
-            saveFileDialog.ShowDialog();\r
-            if (!string.IsNullOrEmpty(saveFileDialog.FileName))\r
+            {\r
+                Filter = "Csv File|*.csv",\r
+                DefaultExt = "csv",\r
+                CheckPathExists = true\r
+            };\r
+            bool? dialogResult = saveFileDialog.ShowDialog();\r
+            if (dialogResult.HasValue && dialogResult.Value && !string.IsNullOrEmpty(saveFileDialog.FileName))\r
             {\r
                 this.ExportChaptersToCSV(saveFileDialog.FileName);\r
             }\r
@@ -153,10 +153,10 @@ namespace HandBrakeWPF.ViewModels
         public void Import()\r
         {\r
             var dialog = new OpenFileDialog { Filter = "CSV files (*.csv)|*.csv", CheckFileExists = true };\r
-            dialog.ShowDialog();\r
+            bool? dialogResult = dialog.ShowDialog();\r
             string filename = dialog.FileName;\r
 \r
-            if (string.IsNullOrEmpty(filename))\r
+            if (!dialogResult.HasValue || !dialogResult.Value || string.IsNullOrEmpty(filename))\r
             {\r
                 return;\r
             }\r
index 320ffbf23da1d3748e4678fc5561a42595688a84..c614dde2d49c9b09780e2b768b82d16b45a94643 100644 (file)
@@ -264,8 +264,8 @@ namespace HandBrakeWPF.ViewModels
         /// The static Preview View Model.\r
         /// </param>\r
         public MainViewModel(IUserSettingService userSettingService, IScan scanService, IEncode encodeService, IPresetService presetService,\r
-            IErrorService errorService,  IUpdateService updateService, INotificationService notificationService,\r
-            IPrePostActionService whenDoneService, IWindowManager windowManager, IPictureSettingsViewModel pictureSettingsViewModel, IVideoViewModel videoViewModel, \r
+            IErrorService errorService, IUpdateService updateService, INotificationService notificationService,\r
+            IPrePostActionService whenDoneService, IWindowManager windowManager, IPictureSettingsViewModel pictureSettingsViewModel, IVideoViewModel videoViewModel,\r
             IFiltersViewModel filtersViewModel, IAudioViewModel audioViewModel, ISubtitlesViewModel subtitlesViewModel,\r
             IAdvancedViewModel advancedViewModel, IChaptersViewModel chaptersViewModel, IStaticPreviewViewModel staticPreviewViewModel)\r
         {\r
@@ -569,7 +569,7 @@ namespace HandBrakeWPF.ViewModels
             {\r
                 return new List<PointToPointMode>\r
                     {\r
-                        PointToPointMode.Chapters, PointToPointMode.Seconds, PointToPointMode.Frames \r
+                        PointToPointMode.Chapters, PointToPointMode.Seconds, PointToPointMode.Frames\r
                     };\r
             }\r
         }\r
@@ -1228,7 +1228,7 @@ namespace HandBrakeWPF.ViewModels
 \r
             // Queue Recovery\r
             QueueRecoveryHelper.RecoverQueue(this.queueProcessor, this.errorService);\r
-    \r
+\r
             this.SelectedPreset = this.presetService.DefaultPreset;\r
 \r
             // Log Cleaning\r
@@ -1467,13 +1467,13 @@ namespace HandBrakeWPF.ViewModels
             IQueueSelectionViewModel viewModel = IoC.Get<IQueueSelectionViewModel>();\r
 \r
             viewModel.Setup(this.ScannedSource, this.SourceName, (tasks) =>\r
+            {\r
+                foreach (SelectionTitle title in tasks)\r
                 {\r
-                    foreach (SelectionTitle title in tasks)\r
-                    {\r
-                        this.SelectedTitle = title.Title;\r
-                        this.AddToQueue();\r
-                    }\r
-                });\r
+                    this.SelectedTitle = title.Title;\r
+                    this.AddToQueue();\r
+                }\r
+            });\r
 \r
             if (window != null)\r
             {\r
@@ -1491,11 +1491,14 @@ namespace HandBrakeWPF.ViewModels
         public void FolderScan()\r
         {\r
             VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog { Description = Resources.Main_PleaseSelectFolder, UseDescriptionForTitle = true };\r
-            dialog.ShowDialog();\r
+            bool? dialogResult = dialog.ShowDialog();\r
 \r
-            ShowSourceSelection = false;\r
+            if (dialogResult.HasValue && dialogResult.Value)\r
+            {\r
+                ShowSourceSelection = false;\r
 \r
-            this.StartScan(dialog.SelectedPath, this.TitleSpecificScan);\r
+                this.StartScan(dialog.SelectedPath, this.TitleSpecificScan);\r
+            }\r
         }\r
 \r
         /// <summary>\r
@@ -1504,11 +1507,14 @@ namespace HandBrakeWPF.ViewModels
         public void FileScan()\r
         {\r
             OpenFileDialog dialog = new OpenFileDialog { Filter = "All files (*.*)|*.*" };\r
-            dialog.ShowDialog();\r
+            bool? dialogResult = dialog.ShowDialog();\r
 \r
-            ShowSourceSelection = false;\r
+            if (dialogResult.HasValue && dialogResult.Value)\r
+            {\r
+                ShowSourceSelection = false;\r
 \r
-            this.StartScan(dialog.FileName, this.TitleSpecificScan);\r
+                this.StartScan(dialog.FileName, this.TitleSpecificScan);\r
+            }\r
         }\r
 \r
         /// <summary>\r
@@ -1674,13 +1680,13 @@ namespace HandBrakeWPF.ViewModels
         public void BrowseDestination()\r
         {\r
             SaveFileDialog saveFileDialog = new SaveFileDialog\r
-                {\r
-                    Filter = "mp4|*.mp4;*.m4v|mkv|*.mkv",\r
-                    CheckPathExists = true,\r
-                    AddExtension = true,\r
-                    DefaultExt = ".mp4",\r
-                    OverwritePrompt = true,\r
-                };\r
+            {\r
+                Filter = "mp4|*.mp4;*.m4v|mkv|*.mkv",\r
+                CheckPathExists = true,\r
+                AddExtension = true,\r
+                DefaultExt = ".mp4",\r
+                OverwritePrompt = true,\r
+            };\r
 \r
             string extension = Path.GetExtension(this.CurrentTask.Destination);\r
 \r
@@ -1849,9 +1855,12 @@ namespace HandBrakeWPF.ViewModels
         public void PresetImport()\r
         {\r
             OpenFileDialog dialog = new OpenFileDialog { Filter = "Preset Files|*.json;*.plist", CheckFileExists = true };\r
-            dialog.ShowDialog();\r
-            this.presetService.Import(dialog.FileName);\r
-            this.NotifyOfPropertyChange(() => this.Presets);\r
+            bool? dialogResult = dialog.ShowDialog();\r
+            if (dialogResult.HasValue && dialogResult.Value)\r
+            {\r
+                this.presetService.Import(dialog.FileName);\r
+                this.NotifyOfPropertyChange(() => this.Presets);\r
+            }\r
         }\r
 \r
         /// <summary>\r
@@ -1860,14 +1869,14 @@ namespace HandBrakeWPF.ViewModels
         public void PresetExport()\r
         {\r
             SaveFileDialog savefiledialog = new SaveFileDialog\r
-                                                     {\r
-                                                         Filter = "json|*.json",\r
-                                                         CheckPathExists = true,\r
-                                                         AddExtension = true,\r
-                                                         DefaultExt = ".json",\r
-                                                         OverwritePrompt = true,\r
-                                                         FilterIndex = 0\r
-                                                     };\r
+            {\r
+                Filter = "json|*.json",\r
+                CheckPathExists = true,\r
+                AddExtension = true,\r
+                DefaultExt = ".json",\r
+                OverwritePrompt = true,\r
+                FilterIndex = 0\r
+            };\r
             if (this.selectedPreset != null)\r
             {\r
                 savefiledialog.ShowDialog();\r
@@ -1944,41 +1953,41 @@ namespace HandBrakeWPF.ViewModels
         {\r
             /* TODO Fix this. */\r
             Execute.OnUIThread(() =>\r
-                {\r
-                    // Copy all the Scan data into the UI\r
-                    scannedSource.CopyTo(this.ScannedSource);\r
-                    this.NotifyOfPropertyChange(() => this.ScannedSource);\r
-                    this.NotifyOfPropertyChange(() => this.ScannedSource.Titles);\r
+            {\r
+                // Copy all the Scan data into the UI\r
+                scannedSource.CopyTo(this.ScannedSource);\r
+                this.NotifyOfPropertyChange(() => this.ScannedSource);\r
+                this.NotifyOfPropertyChange(() => this.ScannedSource.Titles);\r
 \r
-                    // Select the Users Title\r
-                    this.SelectedTitle = this.ScannedSource.Titles.FirstOrDefault();\r
-                    this.CurrentTask = new EncodeTask(queueEditTask);\r
-                    this.NotifyOfPropertyChange(() => this.CurrentTask);\r
-                    this.HasSource = true;\r
+                // Select the Users Title\r
+                this.SelectedTitle = this.ScannedSource.Titles.FirstOrDefault();\r
+                this.CurrentTask = new EncodeTask(queueEditTask);\r
+                this.NotifyOfPropertyChange(() => this.CurrentTask);\r
+                this.HasSource = true;\r
 \r
-                    // Update the Main Window\r
-                    this.NotifyOfPropertyChange(() => this.Destination);\r
-                    this.NotifyOfPropertyChange(() => this.SelectedStartPoint);\r
-                    this.NotifyOfPropertyChange(() => this.SelectedEndPoint);\r
-                    this.NotifyOfPropertyChange(() => this.SelectedAngle);\r
-                    this.NotifyOfPropertyChange(() => this.SelectedPointToPoint);\r
-                    this.NotifyOfPropertyChange(() => this.SelectedOutputFormat);\r
-                    this.NotifyOfPropertyChange(() => IsMkv);\r
+                // Update the Main Window\r
+                this.NotifyOfPropertyChange(() => this.Destination);\r
+                this.NotifyOfPropertyChange(() => this.SelectedStartPoint);\r
+                this.NotifyOfPropertyChange(() => this.SelectedEndPoint);\r
+                this.NotifyOfPropertyChange(() => this.SelectedAngle);\r
+                this.NotifyOfPropertyChange(() => this.SelectedPointToPoint);\r
+                this.NotifyOfPropertyChange(() => this.SelectedOutputFormat);\r
+                this.NotifyOfPropertyChange(() => IsMkv);\r
 \r
-                    // Update the Tab Controls\r
-                    this.PictureSettingsViewModel.UpdateTask(this.CurrentTask);\r
-                    this.VideoViewModel.UpdateTask(this.CurrentTask);\r
-                    this.FiltersViewModel.UpdateTask(this.CurrentTask);\r
-                    this.AudioViewModel.UpdateTask(this.CurrentTask);\r
-                    this.SubtitleViewModel.UpdateTask(this.CurrentTask);\r
-                    this.ChaptersViewModel.UpdateTask(this.CurrentTask);\r
-                    this.AdvancedViewModel.UpdateTask(this.CurrentTask);\r
-\r
-                    // Cleanup\r
-                    this.ShowStatusWindow = false;\r
-                    this.SourceLabel = this.SourceName;\r
-                    this.StatusLabel = Resources.Main_ScanCompleted;\r
-                });\r
+                // Update the Tab Controls\r
+                this.PictureSettingsViewModel.UpdateTask(this.CurrentTask);\r
+                this.VideoViewModel.UpdateTask(this.CurrentTask);\r
+                this.FiltersViewModel.UpdateTask(this.CurrentTask);\r
+                this.AudioViewModel.UpdateTask(this.CurrentTask);\r
+                this.SubtitleViewModel.UpdateTask(this.CurrentTask);\r
+                this.ChaptersViewModel.UpdateTask(this.CurrentTask);\r
+                this.AdvancedViewModel.UpdateTask(this.CurrentTask);\r
+\r
+                // Cleanup\r
+                this.ShowStatusWindow = false;\r
+                this.SourceLabel = this.SourceName;\r
+                this.StatusLabel = Resources.Main_ScanCompleted;\r
+            });\r
         }\r
 \r
         /// <summary>\r
@@ -2146,36 +2155,36 @@ namespace HandBrakeWPF.ViewModels
             }\r
 \r
             Execute.OnUIThread(() =>\r
+            {\r
+                if (e.Successful)\r
                 {\r
-                    if (e.Successful)\r
-                    {\r
-                        this.NotifyOfPropertyChange(() => this.ScannedSource);\r
-                        this.NotifyOfPropertyChange(() => this.ScannedSource.Titles);\r
-                        this.HasSource = true;\r
-                        this.SelectedTitle = this.ScannedSource.Titles.FirstOrDefault(t => t.MainTitle) ?? this.ScannedSource.Titles.FirstOrDefault();\r
-                    }\r
-                    else\r
-                    {\r
-                        this.OpenAlertWindow(Resources.Main_ScanNoTitlesFound, Resources.Main_ScanNoTitlesFoundMessage);\r
-                    }\r
+                    this.NotifyOfPropertyChange(() => this.ScannedSource);\r
+                    this.NotifyOfPropertyChange(() => this.ScannedSource.Titles);\r
+                    this.HasSource = true;\r
+                    this.SelectedTitle = this.ScannedSource.Titles.FirstOrDefault(t => t.MainTitle) ?? this.ScannedSource.Titles.FirstOrDefault();\r
+                }\r
+                else\r
+                {\r
+                    this.OpenAlertWindow(Resources.Main_ScanNoTitlesFound, Resources.Main_ScanNoTitlesFoundMessage);\r
+                }\r
 \r
-                    this.ShowStatusWindow = false;\r
-                    if (e.Successful)\r
-                    {\r
-                        this.SourceLabel = this.SourceName;\r
-                        this.StatusLabel = Resources.Main_ScanCompleted;\r
-                    }\r
-                    else if (e.Cancelled)\r
-                    {\r
-                        this.SourceLabel = Resources.Main_ScanCancelled;\r
-                        this.StatusLabel = Resources.Main_ScanCancelled;\r
-                    }\r
-                    else\r
-                    {\r
-                        this.SourceLabel = Resources.Main_ScanFailled_CheckLog;\r
-                        this.StatusLabel = Resources.Main_ScanFailled_CheckLog;\r
-                    }\r
-                });\r
+                this.ShowStatusWindow = false;\r
+                if (e.Successful)\r
+                {\r
+                    this.SourceLabel = this.SourceName;\r
+                    this.StatusLabel = Resources.Main_ScanCompleted;\r
+                }\r
+                else if (e.Cancelled)\r
+                {\r
+                    this.SourceLabel = Resources.Main_ScanCancelled;\r
+                    this.StatusLabel = Resources.Main_ScanCancelled;\r
+                }\r
+                else\r
+                {\r
+                    this.SourceLabel = Resources.Main_ScanFailled_CheckLog;\r
+                    this.StatusLabel = Resources.Main_ScanFailled_CheckLog;\r
+                }\r
+            });\r
         }\r
 \r
         /// <summary>\r
index 41dc93291c00d431067be90caafb1c1b858c50d9..331c9bf5c73af0f46da51c35a4f7e5108770bebc 100644 (file)
@@ -552,6 +552,7 @@ namespace HandBrakeWPF.ViewModels
             }\r
         }\r
 \r
+\r
         #endregion\r
 \r
         #region Output Files\r
@@ -1217,10 +1218,13 @@ namespace HandBrakeWPF.ViewModels
         /// </summary>\r
         public void BrowseSendFileTo()\r
         {\r
-            VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "All files (*.*)|*.*" };\r
-            dialog.ShowDialog();\r
-            this.SendFileTo = Path.GetFileNameWithoutExtension(dialog.FileName);\r
-            this.sendFileToPath = dialog.FileName;\r
+            VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "All files (*.*)|*.*", FileName = this.sendFileToPath };\r
+            bool? dialogResult = dialog.ShowDialog();\r
+            if (dialogResult.HasValue && dialogResult.Value)\r
+            {\r
+                this.SendFileTo = Path.GetFileNameWithoutExtension(dialog.FileName);\r
+                this.sendFileToPath = dialog.FileName;\r
+            }\r
         }\r
 \r
         /// <summary>\r
@@ -1228,9 +1232,12 @@ namespace HandBrakeWPF.ViewModels
         /// </summary>\r
         public void BrowseAutoNamePath()\r
         {\r
-            VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog { Description = "Please select a folder.", UseDescriptionForTitle = true };\r
-            dialog.ShowDialog();\r
-            this.AutoNameDefaultPath = dialog.SelectedPath;\r
+            VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog { Description = "Please select a folder.", UseDescriptionForTitle = true, SelectedPath = this.AutoNameDefaultPath };\r
+            bool? dialogResult = dialog.ShowDialog();\r
+            if (dialogResult.HasValue && dialogResult.Value)\r
+            {\r
+                this.AutoNameDefaultPath = dialog.SelectedPath;\r
+            }\r
         }\r
 \r
         /// <summary>\r
@@ -1238,9 +1245,12 @@ namespace HandBrakeWPF.ViewModels
         /// </summary>\r
         public void BrowseVlcPath()\r
         {\r
-            VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "All files (*.exe)|*.exe" };\r
-            dialog.ShowDialog();\r
-            this.VLCPath = dialog.FileName;\r
+            VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "All files (*.exe)|*.exe", FileName = this.VLCPath };\r
+            bool? dialogResult = dialog.ShowDialog();\r
+            if (dialogResult.HasValue && dialogResult.Value)\r
+            {\r
+                this.VLCPath = dialog.FileName;\r
+            }\r
         }\r
 \r
         /// <summary>\r
@@ -1248,9 +1258,12 @@ namespace HandBrakeWPF.ViewModels
         /// </summary>\r
         public void BrowseLogPath()\r
         {\r
-            VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog { Description = "Please select a folder.", UseDescriptionForTitle = true };\r
-            dialog.ShowDialog();\r
-            this.LogDirectory = dialog.SelectedPath;\r
+            VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog { Description = "Please select a folder.", UseDescriptionForTitle = true, SelectedPath = this.LogDirectory };\r
+            bool? dialogResult = dialog.ShowDialog();\r
+            if (dialogResult.HasValue && dialogResult.Value)\r
+            {\r
+                this.LogDirectory = dialog.SelectedPath;\r
+            }\r
         }\r
 \r
         /// <summary>\r
@@ -1453,7 +1466,7 @@ namespace HandBrakeWPF.ViewModels
             this.MinLength = this.userSettingService.GetUserSetting<int>(UserSettingConstants.MinScanDuration);\r
 \r
             // Use dvdnav\r
-            this.DisableLibdvdNav = userSettingService.GetUserSetting<bool>(UserSettingConstants.DisableLibDvdNav);  \r
+            this.DisableLibdvdNav = userSettingService.GetUserSetting<bool>(UserSettingConstants.DisableLibDvdNav);\r
         }\r
 \r
         /// <summary>\r
@@ -1483,7 +1496,7 @@ namespace HandBrakeWPF.ViewModels
 \r
             /* Previews */\r
             this.userSettingService.SetUserSetting(UserSettingConstants.VLCPath, this.VLCPath);\r
-            \r
+\r
             /* Video */\r
             this.userSettingService.SetUserSetting(UserSettingConstants.DisableQuickSyncDecoding, this.DisableQuickSyncDecoding);\r
             this.userSettingService.SetUserSetting(UserSettingConstants.EnableDxva, this.EnableDxvaDecoding);\r