summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs
diff options
context:
space:
mode:
authorsr55 <[email protected]>2018-05-24 20:59:08 +0100
committersr55 <[email protected]>2018-05-24 20:59:33 +0100
commitf6e6fc6c47298a0dd17dad6a6c387c18fe13c6b8 (patch)
tree6735481855a3367294ed053257052ff4c8d213a9 /win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs
parent91bef558463a2635a934de99a61439696682c9c1 (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.
Diffstat (limited to 'win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs')
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs54
1 files changed, 40 insertions, 14 deletions
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
}
}