diff options
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
}
}
|