diff options
author | sr55 <[email protected]> | 2018-05-24 20:59:08 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2018-05-24 20:59:33 +0100 |
commit | f6e6fc6c47298a0dd17dad6a6c387c18fe13c6b8 (patch) | |
tree | 6735481855a3367294ed053257052ff4c8d213a9 | |
parent | 91bef558463a2635a934de99a61439696682c9c1 (diff) |
WinGui: Add support for dropping .srt files onto the main window. When you do this, the Subtitles tab is activated and a subtitle track for each file dropped will be added.
3 files changed, 62 insertions, 15 deletions
diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/ISubtitlesViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/ISubtitlesViewModel.cs index 46086836b..c5f0f5e3c 100644 --- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/ISubtitlesViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/ISubtitlesViewModel.cs @@ -20,5 +20,13 @@ namespace HandBrakeWPF.ViewModels.Interfaces /// Gets the subtitle behaviours.
/// </summary>
SubtitleBehaviours SubtitleBehaviours { get; }
+
+ /// <summary>
+ /// Import Subtitle files. Used for Drag/drop support which is handled by the MainViewModel.
+ /// </summary>
+ /// <param name="subtitleFiles">
+ /// String array of files.
+ /// </param>
+ void Import(string[] subtitleFiles);
}
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 082e662fc..3d19a81f5 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -1832,7 +1832,20 @@ namespace HandBrakeWPF.ViewModels string[] fileNames = e.Data.GetData(DataFormats.FileDrop, true) as string[];
if (fileNames != null && fileNames.Any() && (File.Exists(fileNames[0]) || Directory.Exists(fileNames[0])))
{
- this.StartScan(fileNames[0], 0);
+ string videoContent = fileNames.FirstOrDefault(f => Path.GetExtension(f)?.ToLower() != ".srt");
+ if (!string.IsNullOrEmpty(videoContent))
+ {
+ this.StartScan(videoContent, 0);
+ return;
+ }
+
+ // StartScan is not synchronous, so for now we don't support adding both srt and video file at the same time.
+ string[] subtitleFiles = fileNames.Where(f => Path.GetExtension(f)?.ToLower() == ".srt").ToArray();
+ if (this.SelectedTab != 5 && subtitleFiles.Any())
+ {
+ this.SwitchTab(5);
+ this.SubtitleViewModel.Import(subtitleFiles);
+ }
}
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs index 7b090841c..cd6d2aa1e 100644 --- a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs @@ -13,6 +13,7 @@ namespace HandBrakeWPF.ViewModels using System.Collections.Generic;
using System.IO;
using System.Linq;
+ using System.Runtime.CompilerServices;
using Caliburn.Micro;
@@ -245,19 +246,15 @@ namespace HandBrakeWPF.ViewModels dialog.ShowDialog();
- foreach (var srtFile in dialog.FileNames)
+ this.AddInputSubtitles(dialog.FileNames);
+ }
+
+ public void Import(string[] subtitleFiles)
+ {
+ if (subtitleFiles != null && subtitleFiles.Any())
{
- SubtitleTrack track = new SubtitleTrack
- {
- SrtFileName = Path.GetFileNameWithoutExtension(srtFile),
- SrtOffset = 0,
- SrtCharCode = "UTF-8",
- SrtLang = "English",
- SubtitleType = SubtitleType.SRT,
- SrtPath = srtFile
- };
- this.Task.SubtitleTracks.Add(track);
- }
+ this.AddInputSubtitles(subtitleFiles);
+ }
}
/// <summary>
@@ -293,6 +290,7 @@ namespace HandBrakeWPF.ViewModels {
continue; // Skip the track the user selected.
}
+
track.Default = false;
}
@@ -313,8 +311,10 @@ namespace HandBrakeWPF.ViewModels {
continue; // Skip the track the user selected.
}
+
track.Burned = false;
}
+
this.NotifyOfPropertyChange(() => this.Task);
}
@@ -357,6 +357,7 @@ namespace HandBrakeWPF.ViewModels break;
}
}
+
break;
case SubtitleBurnInBehaviourModes.ForeignAudio:
foreach (var track in this.Task.SubtitleTracks)
@@ -370,6 +371,7 @@ namespace HandBrakeWPF.ViewModels break;
}
}
+
break;
case SubtitleBurnInBehaviourModes.FirstTrack:
foreach (var track in this.Task.SubtitleTracks)
@@ -387,7 +389,8 @@ namespace HandBrakeWPF.ViewModels track.Burned = true;
this.SetBurnedToFalseForAllExcept(track);
}
- }
+ }
+
break;
case SubtitleBurnInBehaviourModes.ForeignAudioPreferred:
foreach (var track in this.Task.SubtitleTracks)
@@ -408,7 +411,8 @@ namespace HandBrakeWPF.ViewModels this.SetBurnedToFalseForAllExcept(track);
break;
}
- }
+ }
+
break;
}
}
@@ -665,6 +669,28 @@ namespace HandBrakeWPF.ViewModels : this.SourceTracks.Where(subtitle => !this.Task.SubtitleTracks.Any(track => Equals(track.SourceTrack, subtitle))).ToList();
}
+ private void AddInputSubtitles(string[] filenames)
+ {
+ foreach (var srtFile in filenames)
+ {
+ if (!File.Exists(srtFile))
+ {
+ continue;
+ }
+
+ SubtitleTrack track = new SubtitleTrack
+ {
+ SrtFileName = Path.GetFileNameWithoutExtension(srtFile),
+ SrtOffset = 0,
+ SrtCharCode = "UTF-8",
+ SrtLang = "English",
+ SubtitleType = SubtitleType.SRT,
+ SrtPath = srtFile
+ };
+ this.Task.SubtitleTracks.Add(track);
+ }
+ }
+
#endregion
}
}
|