]> granicus.if.org Git - handbrake/commitdiff
WinGui: Open and Save File dialogs on the main window, now have their own "MRU" initi...
authorsr55 <sr55.hb@outlook.com>
Thu, 24 May 2018 20:24:48 +0000 (21:24 +0100)
committersr55 <sr55.hb@outlook.com>
Thu, 24 May 2018 20:24:48 +0000 (21:24 +0100)
win/CS/HandBrakeWPF/Constants.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs

index 37d0f923b1ec2e1f4e7cc985c4a4e1d83c2b8704..cf322e85ce3469263d3e9e94fcc1de33c2a30504 100644 (file)
@@ -83,5 +83,8 @@ namespace HandBrakeWPF
         /// Preset Micro Version\r
         /// </summary>\r
         public const string PresetVersionMicro = "0";\r
+\r
+        public const string FileScanMru = "FileScanMru";\r
+        public const string FileSaveMru = "FileSaveMru";\r
     }\r
 }\r
index a081d28d50dffdf2745a779b9f5be49a53006275..4af305d4709dd32a172fee59dba7b3934c8d2124 100644 (file)
@@ -169,6 +169,7 @@ namespace HandBrakeWPF.ViewModels
             IFiltersViewModel filtersViewModel, IAudioViewModel audioViewModel, ISubtitlesViewModel subtitlesViewModel,\r
             IX264ViewModel advancedViewModel, IChaptersViewModel chaptersViewModel, IStaticPreviewViewModel staticPreviewViewModel,\r
             IQueueViewModel queueViewModel, IMetaDataViewModel metaDataViewModel, INotifyIconService notifyIconService)\r
+            : base(userSettingService)\r
         {\r
             this.scanService = scanService;\r
             this.presetService = presetService;\r
@@ -1656,10 +1657,19 @@ namespace HandBrakeWPF.ViewModels
         public void FileScan()\r
         {\r
             OpenFileDialog dialog = new OpenFileDialog { Filter = "All files (*.*)|*.*" };\r
+\r
+            string mruDir = this.GetMru(Constants.FileScanMru);\r
+            if (!string.IsNullOrEmpty(mruDir))\r
+            {\r
+                dialog.InitialDirectory = mruDir;\r
+            }\r
+\r
             bool? dialogResult = dialog.ShowDialog();\r
 \r
             if (dialogResult.HasValue && dialogResult.Value)\r
             {\r
+                this.SetMru(Constants.FileScanMru, Path.GetDirectoryName(dialog.FileName));\r
+\r
                 this.StartScan(dialog.FileName, this.TitleSpecificScan);\r
             }\r
         }\r
@@ -1850,7 +1860,7 @@ namespace HandBrakeWPF.ViewModels
 \r
                     // StartScan is not synchronous, so for now we don't support adding both srt and video file at the same time. \r
                     string[] subtitleFiles = fileNames.Where(f => Path.GetExtension(f)?.ToLower() == ".srt").ToArray();\r
-                    if (this.SelectedTab != 5 && subtitleFiles.Any())\r
+                    if (subtitleFiles.Any())\r
                     {\r
                         this.SwitchTab(5);\r
                         this.SubtitleViewModel.Import(subtitleFiles);\r
@@ -1888,6 +1898,13 @@ namespace HandBrakeWPF.ViewModels
                                              ? (extension == ".mp4" || extension == ".m4v" ? 1 : 2)\r
                                              : (this.CurrentTask.OutputFormat == OutputFormat.Mkv ? 2 : 0);\r
 \r
+            string mruDir = this.GetMru(Constants.FileSaveMru);\r
+            if (!string.IsNullOrEmpty(mruDir))\r
+            {\r
+                saveFileDialog.InitialDirectory = mruDir;\r
+            }\r
+\r
+            // If we have a current directory, override the MRU.\r
             if (this.CurrentTask != null && !string.IsNullOrEmpty(this.CurrentTask.Destination))\r
             {\r
                 if (Directory.Exists(Path.GetDirectoryName(this.CurrentTask.Destination)))\r
@@ -1901,6 +1918,8 @@ namespace HandBrakeWPF.ViewModels
             bool? result = saveFileDialog.ShowDialog();\r
             if (result.HasValue && result.Value)\r
             {\r
+                this.SetMru(Constants.FileSaveMru, Path.GetDirectoryName(saveFileDialog.FileName));\r
+\r
                 if (saveFileDialog.FileName == this.ScannedSource.ScanPath)\r
                 {\r
                     this.errorService.ShowMessageBox(Resources.Main_SourceDestinationMatchError, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
@@ -2769,7 +2788,6 @@ namespace HandBrakeWPF.ViewModels
                 this.NotifyOfPropertyChange(() => this.ShowAdvancedTab);\r
             }\r
         }\r
-\r
         #endregion\r
     }\r
 }
\ No newline at end of file
index d2f381e55a515438d0881baf94975a810e520e8a..54da681dccee917275b042fbe2be31c45dab8be1 100644 (file)
@@ -9,8 +9,12 @@
 \r
 namespace HandBrakeWPF.ViewModels\r
 {\r
+    using System;\r
+    using System.IO;\r
+\r
     using Caliburn.Micro;\r
 \r
+    using HandBrakeWPF.Services.Interfaces;\r
     using HandBrakeWPF.ViewModels.Interfaces;\r
 \r
     /// <summary>\r
@@ -18,30 +22,19 @@ namespace HandBrakeWPF.ViewModels
     /// </summary>\r
     public class ViewModelBase : Screen, IViewModelBase\r
     {\r
-        #region Constants and Fields\r
+        private readonly IUserSettingService userSettingService;\r
 \r
-        /// <summary>\r
-        /// Backing Field to prevent the Load method being called more than once.\r
-        /// </summary>\r
         private bool hasLoaded;\r
-\r
-        /// <summary>\r
-        /// The title.\r
-        /// </summary>\r
         private string title;\r
 \r
-        #endregion\r
-\r
-        #region Constructors and Destructors\r
-\r
-        /// <summary>\r
-        /// Initializes a new instance of the <see cref="ViewModelBase"/> class.\r
-        /// </summary>\r
         public ViewModelBase()\r
         {\r
         }\r
 \r
-        #endregion\r
+        public ViewModelBase(IUserSettingService userSettingService)\r
+        {\r
+            this.userSettingService = userSettingService;\r
+        }\r
 \r
         #region Properties\r
 \r
@@ -58,7 +51,7 @@ namespace HandBrakeWPF.ViewModels
             set\r
             {\r
                 this.title = value;\r
-                this.NotifyOfPropertyChange("Title");\r
+                this.NotifyOfPropertyChange();\r
             }\r
         }\r
 \r
@@ -88,6 +81,38 @@ namespace HandBrakeWPF.ViewModels
             // Implement in the ViewModel to perform viewmodel specific code.\r
         }\r
 \r
+        public string GetMru(string key)\r
+        {\r
+            if (this.userSettingService == null)\r
+            {\r
+                throw new NotImplementedException("You must use the constructor with UserSettingService to use this function.");\r
+            }\r
+\r
+            string filePath = this.userSettingService.GetUserSetting<string>("mru" + key);\r
+            if (!string.IsNullOrEmpty(filePath) && Directory.Exists(filePath))\r
+            {\r
+                return filePath;\r
+            }\r
+\r
+            return null;\r
+        }\r
+\r
+        public void SetMru(string key, string value)\r
+        {\r
+            if (this.userSettingService == null)\r
+            {\r
+                throw new NotImplementedException("You must use the constructor with UserSettingService to use this function.");\r
+            }\r
+\r
+            if (string.IsNullOrEmpty(value) || !Directory.Exists(value))\r
+            {\r
+                this.userSettingService.SetUserSetting("mru" + key, string.Empty);\r
+                return;\r
+            }\r
+\r
+            this.userSettingService.SetUserSetting("mru" + key, value);\r
+        }\r
+\r
         #endregion\r
     }\r
 }
\ No newline at end of file