diff --git a/src/ui/Forms/GenerateVideoWithSoftSubs.Designer.cs b/src/ui/Forms/GenerateVideoWithSoftSubs.Designer.cs index bcce9ed6e8..167cc540b7 100644 --- a/src/ui/Forms/GenerateVideoWithSoftSubs.Designer.cs +++ b/src/ui/Forms/GenerateVideoWithSoftSubs.Designer.cs @@ -38,6 +38,7 @@ private void InitializeComponent() this.groupBoxSettings = new System.Windows.Forms.GroupBox(); this.contextMenuStripMain = new System.Windows.Forms.ContextMenuStrip(this.components); this.setSuffixToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.progressBarDragDrop = new System.Windows.Forms.ProgressBar(); this.labelNotSupported = new System.Windows.Forms.Label(); this.buttonSetLanguage = new System.Windows.Forms.Button(); this.buttonSetDefault = new System.Windows.Forms.Button(); @@ -49,11 +50,11 @@ private void InitializeComponent() this.buttonAddSubtitles = new System.Windows.Forms.Button(); this.labelSubtitles = new System.Windows.Forms.Label(); this.listViewSubtitles = new System.Windows.Forms.ListView(); - this.columnHeader1Type = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader2Language = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader3Default = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader4Forced = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader5FileName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader1Type = new System.Windows.Forms.ColumnHeader(); + this.columnHeader2Language = new System.Windows.Forms.ColumnHeader(); + this.columnHeader3Default = new System.Windows.Forms.ColumnHeader(); + this.columnHeader4Forced = new System.Windows.Forms.ColumnHeader(); + this.columnHeader5FileName = new System.Windows.Forms.ColumnHeader(); this.contextMenuSubtitles = new System.Windows.Forms.ContextMenuStrip(this.components); this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); @@ -112,8 +113,7 @@ private void InitializeComponent() // // contextMenuStripGenerate // - this.contextMenuStripGenerate.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.promptParameterBeforeGenerateToolStripMenuItem}); + this.contextMenuStripGenerate.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.promptParameterBeforeGenerateToolStripMenuItem }); this.contextMenuStripGenerate.Name = "contextMenuStripGenerate"; this.contextMenuStripGenerate.Size = new System.Drawing.Size(290, 26); // @@ -148,10 +148,9 @@ private void InitializeComponent() // // groupBoxSettings // - this.groupBoxSettings.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.groupBoxSettings.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBoxSettings.ContextMenuStrip = this.contextMenuStripMain; + this.groupBoxSettings.Controls.Add(this.progressBarDragDrop); this.groupBoxSettings.Controls.Add(this.labelNotSupported); this.groupBoxSettings.Controls.Add(this.buttonSetLanguage); this.groupBoxSettings.Controls.Add(this.buttonSetDefault); @@ -174,8 +173,7 @@ private void InitializeComponent() // // contextMenuStripMain // - this.contextMenuStripMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.setSuffixToolStripMenuItem}); + this.contextMenuStripMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.setSuffixToolStripMenuItem }); this.contextMenuStripMain.Name = "contextMenuStripMain"; this.contextMenuStripMain.Size = new System.Drawing.Size(132, 26); // @@ -186,6 +184,17 @@ private void InitializeComponent() this.setSuffixToolStripMenuItem.Text = "Set suffix..."; this.setSuffixToolStripMenuItem.Click += new System.EventHandler(this.setSuffixToolStripMenuItem_Click); // + // progressBarDragDrop + // + this.progressBarDragDrop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.progressBarDragDrop.Location = new System.Drawing.Point(263, 248); + this.progressBarDragDrop.MarqueeAnimationSpeed = 30; + this.progressBarDragDrop.Name = "progressBarDragDrop"; + this.progressBarDragDrop.Size = new System.Drawing.Size(299, 31); + this.progressBarDragDrop.Style = System.Windows.Forms.ProgressBarStyle.Marquee; + this.progressBarDragDrop.TabIndex = 37; + this.progressBarDragDrop.Visible = false; + // // labelNotSupported // this.labelNotSupported.AutoSize = true; @@ -296,15 +305,8 @@ private void InitializeComponent() // listViewSubtitles // this.listViewSubtitles.AllowDrop = true; - this.listViewSubtitles.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.listViewSubtitles.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { - this.columnHeader1Type, - this.columnHeader2Language, - this.columnHeader3Default, - this.columnHeader4Forced, - this.columnHeader5FileName}); + this.listViewSubtitles.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.listViewSubtitles.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.columnHeader1Type, this.columnHeader2Language, this.columnHeader3Default, this.columnHeader4Forced, this.columnHeader5FileName }); this.listViewSubtitles.ContextMenuStrip = this.contextMenuSubtitles; this.listViewSubtitles.FullRowSelect = true; this.listViewSubtitles.HideSelection = false; @@ -344,19 +346,7 @@ private void InitializeComponent() // // contextMenuSubtitles // - this.contextMenuSubtitles.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.addToolStripMenuItem, - this.toolStripSeparator1, - this.toolStripMenuItemStorageRemove, - this.toolStripMenuItemStorageRemoveAll, - this.toolStripSeparator2, - this.toolStripMenuItemStorageMoveUp, - this.toolStripMenuItemStorageMoveDown, - this.toggleForcedToolStripMenuItem, - this.toggleDefaultToolStripMenuItem, - this.setLanguageToolStripMenuItem, - this.toolStripSeparator3, - this.viewToolStripMenuItem}); + this.contextMenuSubtitles.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.addToolStripMenuItem, this.toolStripSeparator1, this.toolStripMenuItemStorageRemove, this.toolStripMenuItemStorageRemoveAll, this.toolStripSeparator2, this.toolStripMenuItemStorageMoveUp, this.toolStripMenuItemStorageMoveDown, this.toggleForcedToolStripMenuItem, this.toggleDefaultToolStripMenuItem, this.setLanguageToolStripMenuItem, this.toolStripSeparator3, this.viewToolStripMenuItem }); this.contextMenuSubtitles.Name = "contextMenuStrip1"; this.contextMenuSubtitles.Size = new System.Drawing.Size(203, 220); // @@ -457,8 +447,7 @@ private void InitializeComponent() // // textBoxInputFileName // - this.textBoxInputFileName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxInputFileName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.textBoxInputFileName.FocusedColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); this.textBoxInputFileName.Location = new System.Drawing.Point(22, 44); this.textBoxInputFileName.Name = "textBoxInputFileName"; @@ -468,21 +457,7 @@ private void InitializeComponent() // // contextMenuStripRes // - this.contextMenuStripRes.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.x2160ToolStripMenuItem, - this.uHD3840x2160ToolStripMenuItem, - this.k2048x1080ToolStripMenuItem, - this.dCI2KScope2048x858ToolStripMenuItem, - this.dCI2KFlat1998x1080ToolStripMenuItem, - this.p1920x1080ToolStripMenuItem, - this.x1080ToolStripMenuItem, - this.p1280x720ToolStripMenuItem, - this.x720ToolStripMenuItem, - this.p848x480ToolStripMenuItem, - this.pAL720x576ToolStripMenuItem, - this.nTSC720x480ToolStripMenuItem, - this.x352ToolStripMenuItem, - this.x272ToolStripMenuItem}); + this.contextMenuStripRes.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.x2160ToolStripMenuItem, this.uHD3840x2160ToolStripMenuItem, this.k2048x1080ToolStripMenuItem, this.dCI2KScope2048x858ToolStripMenuItem, this.dCI2KFlat1998x1080ToolStripMenuItem, this.p1920x1080ToolStripMenuItem, this.x1080ToolStripMenuItem, this.p1280x720ToolStripMenuItem, this.x720ToolStripMenuItem, this.p848x480ToolStripMenuItem, this.pAL720x576ToolStripMenuItem, this.nTSC720x480ToolStripMenuItem, this.x352ToolStripMenuItem, this.x272ToolStripMenuItem }); this.contextMenuStripRes.Name = "contextMenuStripRes"; this.contextMenuStripRes.Size = new System.Drawing.Size(204, 312); // @@ -603,8 +578,7 @@ private void InitializeComponent() // // contextMenuStripMain2 // - this.contextMenuStripMain2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripMenuItemSuffix2}); + this.contextMenuStripMain2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItemSuffix2 }); this.contextMenuStripMain2.Name = "contextMenuStripMain"; this.contextMenuStripMain2.Size = new System.Drawing.Size(132, 26); // @@ -647,9 +621,10 @@ private void InitializeComponent() this.contextMenuStripMain2.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); - } + private System.Windows.Forms.ProgressBar progressBarDragDrop; + #endregion private System.Windows.Forms.Button buttonGenerate; private System.Windows.Forms.Button buttonCancel; diff --git a/src/ui/Forms/GenerateVideoWithSoftSubs.cs b/src/ui/Forms/GenerateVideoWithSoftSubs.cs index 73d79adc3f..868c90e4dd 100644 --- a/src/ui/Forms/GenerateVideoWithSoftSubs.cs +++ b/src/ui/Forms/GenerateVideoWithSoftSubs.cs @@ -13,6 +13,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading.Tasks; using System.Windows.Forms; using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox; @@ -45,7 +46,6 @@ public GenerateVideoWithSoftSubs(Subtitle subtitle, string inputVideoFileName, V _videoInfo = videoInfo; _subtitle = new Subtitle(subtitle); - _inputVideoFileName = inputVideoFileName; Text = LanguageSettings.Current.GenerateVideoWithEmbeddedSubs.Title; labelInputVideoFile.Text = LanguageSettings.Current.GenerateVideoWithEmbeddedSubs.InputVideoFile; @@ -107,7 +107,7 @@ private void AddCurrentSubtitle() File.WriteAllText(fileName, targetFormat.ToText(_subtitle, string.Empty)); fileName = GetKnownFileNameOrConvertToSrtOrUtf8(fileName, _subtitle); - AddListViewItem(fileName); + AddListViewItem(CreateVideoPreviewGeneratorSub(fileName)); if (listViewSubtitles.Items.Count > 0) { @@ -186,6 +186,11 @@ private void AddListViewItem(Trak track) private void AddListViewItem(VideoPreviewGeneratorSub sub) { + if (sub is null) + { + return; + } + var item = new ListViewItem { Tag = sub, @@ -284,17 +289,17 @@ private void AddListViewItem(MatroskaTrackInfo track, MatroskaFile matroska) }); } - private void AddListViewItem(string fileName) + private VideoPreviewGeneratorSub CreateVideoPreviewGeneratorSub(string fileName) { if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName)) { - return; + return null; } if (fileName.EndsWith(".sup", StringComparison.OrdinalIgnoreCase) && FileUtil.IsBluRaySup(fileName)) { - AddListViewItem(new VideoPreviewGeneratorSub + return new VideoPreviewGeneratorSub { Name = Path.GetFileName(fileName), Language = GetLanguageFromFileName(fileName), @@ -304,15 +309,13 @@ private void AddListViewItem(string fileName) IsForced = false, IsDefault = false, FileName = fileName, - }); - - return; + }; } var subtitle = Subtitle.Parse(fileName); if (subtitle == null || subtitle.Paragraphs.Count == 0) { - return; + return null; } fileName = GetKnownFileNameOrConvertToSrtOrUtf8(fileName, subtitle); @@ -334,7 +337,7 @@ private void AddListViewItem(string fileName) } } - AddListViewItem(new VideoPreviewGeneratorSub + return new VideoPreviewGeneratorSub { Name = Path.GetFileName(fileName), Language = language, @@ -345,7 +348,7 @@ private void AddListViewItem(string fileName) IsForced = false, IsDefault = false, FileName = fileName, - }); + }; } private static string GetLanguageFromFileName(string fileName) @@ -782,7 +785,7 @@ private void buttonAddSubtitles_Click(object sender, EventArgs e) foreach (var fileName in openFileDialog1.FileNames) { - AddListViewItem(fileName); + AddListViewItem(CreateVideoPreviewGeneratorSub(fileName)); } } @@ -840,18 +843,46 @@ private void listViewSubtitles_DragEnter(object sender, DragEventArgs e) } } - private void listViewSubtitles_DragDrop(object sender, DragEventArgs e) + private async void listViewSubtitles_DragDrop(object sender, DragEventArgs e) { var fileNames = (string[])e.Data.GetData(DataFormats.FileDrop); - foreach (var fileName in fileNames) + + ActivateWaitState(); + var previewGeneratorSubs = await Task.Run(() => { - if (!FileUtil.IsDirectory(fileName)) + var previewItems = new List(); + foreach (var fileName in fileNames) { - AddListViewItem(fileName); + if (!FileUtil.IsDirectory(fileName)) + { + previewItems.Add(CreateVideoPreviewGeneratorSub(fileName)); + } } - } + + return previewItems.Where(previewItem => previewItem != null).ToList(); + }).ConfigureAwait(true); + + listViewSubtitles.BeginUpdate(); + previewGeneratorSubs.ForEach(AddListViewItem); + listViewSubtitles.EndUpdate(); + + DeactivateWaitState(); } + private void ActivateWaitState() + { + progressBarDragDrop.Visible = true; + labelPleaseWait.Text = LanguageSettings.Current.General.PleaseWait; + Cursor = Cursors.WaitCursor; + } + + private void DeactivateWaitState() + { + progressBarDragDrop.Visible = false; + labelPleaseWait.Text = string.Empty; + Cursor = Cursors.Default; + } + private void ButtonRemoveSubtitles_Click(object sender, EventArgs e) { if (listViewSubtitles.Items.Count <= 0)