]> granicus.if.org Git - handbrake/commitdiff
WinGui: Add support for dropping .srt files onto the main window. When you do this...
authorsr55 <sr55.hb@outlook.com>
Thu, 24 May 2018 19:59:08 +0000 (20:59 +0100)
committersr55 <sr55.hb@outlook.com>
Thu, 24 May 2018 19:59:33 +0000 (20:59 +0100)
win/CS/HandBrakeWPF/ViewModels/Interfaces/ISubtitlesViewModel.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs

index 46086836b0c0c7247f1f9543bb2bc1d54e87d846..c5f0f5e3c7f60557c591beba6849b8d686e0ed2b 100644 (file)
@@ -20,5 +20,13 @@ namespace HandBrakeWPF.ViewModels.Interfaces
         /// Gets the subtitle behaviours.\r
         /// </summary>\r
         SubtitleBehaviours SubtitleBehaviours { get; }\r
+\r
+        /// <summary>\r
+        /// Import Subtitle files. Used for Drag/drop support which is handled by the MainViewModel.\r
+        /// </summary>\r
+        /// <param name="subtitleFiles">\r
+        /// String array of files.\r
+        /// </param>\r
+        void Import(string[] subtitleFiles);\r
     }\r
 }\r
index 082e662fc715715474a920111c80a931f01e7e13..3d19a81f5d22e279d0f8e4519d4ec0d62622a194 100644 (file)
@@ -1832,7 +1832,20 @@ namespace HandBrakeWPF.ViewModels
                 string[] fileNames = e.Data.GetData(DataFormats.FileDrop, true) as string[];\r
                 if (fileNames != null && fileNames.Any() && (File.Exists(fileNames[0]) || Directory.Exists(fileNames[0])))\r
                 {\r
-                    this.StartScan(fileNames[0], 0);\r
+                    string videoContent = fileNames.FirstOrDefault(f => Path.GetExtension(f)?.ToLower() != ".srt");\r
+                    if (!string.IsNullOrEmpty(videoContent))\r
+                    {\r
+                        this.StartScan(videoContent, 0);\r
+                        return;\r
+                    }\r
+\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
+                    {\r
+                        this.SwitchTab(5);\r
+                        this.SubtitleViewModel.Import(subtitleFiles);\r
+                    }\r
                 }\r
             }\r
 \r
index 7b090841c379408189cafd0697f6be8581f81cca..cd6d2aa1ecc8f3ddb637fce61bc6b6ae33386b17 100644 (file)
@@ -13,6 +13,7 @@ namespace HandBrakeWPF.ViewModels
     using System.Collections.Generic;\r
     using System.IO;\r
     using System.Linq;\r
+    using System.Runtime.CompilerServices;\r
 \r
     using Caliburn.Micro;\r
 \r
@@ -245,19 +246,15 @@ namespace HandBrakeWPF.ViewModels
 \r
             dialog.ShowDialog();\r
 \r
-            foreach (var srtFile in dialog.FileNames)\r
+            this.AddInputSubtitles(dialog.FileNames);\r
+        }\r
+\r
+        public void Import(string[] subtitleFiles)\r
+        {\r
+            if (subtitleFiles != null && subtitleFiles.Any())\r
             {\r
-                SubtitleTrack track = new SubtitleTrack\r
-                    {\r
-                        SrtFileName = Path.GetFileNameWithoutExtension(srtFile),\r
-                        SrtOffset = 0,\r
-                        SrtCharCode = "UTF-8",\r
-                        SrtLang = "English",\r
-                        SubtitleType = SubtitleType.SRT,\r
-                        SrtPath = srtFile\r
-                    };\r
-                this.Task.SubtitleTracks.Add(track);\r
-            }\r
+                this.AddInputSubtitles(subtitleFiles);\r
+            }        \r
         }\r
 \r
         /// <summary>\r
@@ -293,6 +290,7 @@ namespace HandBrakeWPF.ViewModels
                 {\r
                     continue; // Skip the track the user selected.\r
                 }\r
+\r
                 track.Default = false;\r
             }\r
 \r
@@ -313,8 +311,10 @@ namespace HandBrakeWPF.ViewModels
                 {\r
                     continue; // Skip the track the user selected.\r
                 }\r
+\r
                 track.Burned = false;\r
             }\r
+\r
             this.NotifyOfPropertyChange(() => this.Task);\r
         }\r
 \r
@@ -357,6 +357,7 @@ namespace HandBrakeWPF.ViewModels
                                 break;\r
                             }\r
                         }\r
+\r
                         break;\r
                     case SubtitleBurnInBehaviourModes.ForeignAudio:\r
                         foreach (var track in this.Task.SubtitleTracks)\r
@@ -370,6 +371,7 @@ namespace HandBrakeWPF.ViewModels
                                 break;\r
                             }\r
                         }\r
+\r
                         break;\r
                     case SubtitleBurnInBehaviourModes.FirstTrack:                    \r
                         foreach (var track in this.Task.SubtitleTracks)\r
@@ -387,7 +389,8 @@ namespace HandBrakeWPF.ViewModels
                                 track.Burned = true;\r
                                 this.SetBurnedToFalseForAllExcept(track);\r
                             }\r
-                        }                  \r
+                        }   \r
+                        \r
                         break;\r
                     case SubtitleBurnInBehaviourModes.ForeignAudioPreferred:\r
                         foreach (var track in this.Task.SubtitleTracks)\r
@@ -408,7 +411,8 @@ namespace HandBrakeWPF.ViewModels
                                 this.SetBurnedToFalseForAllExcept(track);\r
                                 break;\r
                             }\r
-                        }            \r
+                        }       \r
+                        \r
                         break;\r
                 }\r
             }\r
@@ -665,6 +669,28 @@ namespace HandBrakeWPF.ViewModels
                        : this.SourceTracks.Where(subtitle => !this.Task.SubtitleTracks.Any(track => Equals(track.SourceTrack, subtitle))).ToList();\r
         }\r
 \r
+        private void AddInputSubtitles(string[] filenames)\r
+        {\r
+            foreach (var srtFile in filenames)\r
+            {\r
+                if (!File.Exists(srtFile))\r
+                {\r
+                    continue;\r
+                }\r
+\r
+                SubtitleTrack track = new SubtitleTrack\r
+                                          {\r
+                                              SrtFileName = Path.GetFileNameWithoutExtension(srtFile),\r
+                                              SrtOffset = 0,\r
+                                              SrtCharCode = "UTF-8",\r
+                                              SrtLang = "English",\r
+                                              SubtitleType = SubtitleType.SRT,\r
+                                              SrtPath = srtFile\r
+                                          };\r
+                this.Task.SubtitleTracks.Add(track);\r
+            }\r
+        }\r
+\r
         #endregion\r
     }\r
 }\r