From b908b49e65636e3020efc70b469ea7b7a3fed076 Mon Sep 17 00:00:00 2001 From: "Martijn van Berkel (Flitskikker)" Date: Sat, 10 Feb 2024 00:01:26 +0100 Subject: [PATCH] Everything seems to be working now --- src/libse/Common/Settings.cs | 33 ++++ src/ui/Forms/Main.cs | 68 ++++---- src/ui/Forms/VerifyCompleteness.Designer.cs | 80 +++++++++- src/ui/Forms/VerifyCompleteness.cs | 163 ++++++++++++++++---- src/ui/Forms/VerifyCompleteness.resx | 3 + src/ui/Logic/Language.cs | 6 +- src/ui/Logic/LanguageStructure.cs | 4 + 7 files changed, 281 insertions(+), 76 deletions(-) diff --git a/src/libse/Common/Settings.cs b/src/libse/Common/Settings.cs index 22129b22f..fba1edcce 100644 --- a/src/libse/Common/Settings.cs +++ b/src/libse/Common/Settings.cs @@ -3143,11 +3143,28 @@ $HorzAlign = Center } } + public class VerifyCompletenessSettings + { + public ListSortEnum ListSort { get; set; } + + public enum ListSortEnum : int + { + Coverage = 0, + Time = 1, + } + + public VerifyCompletenessSettings() + { + ListSort = ListSortEnum.Coverage; + } + } + public class Settings { public string Version { get; set; } public bool InitialLoad { get; set; } public CompareSettings Compare { get; set; } + public VerifyCompletenessSettings VerifyCompleteness { get; set; } public RecentFilesSettings RecentFiles { get; set; } public GeneralSettings General { get; set; } public ToolsSettings Tools { get; set; } @@ -3183,6 +3200,7 @@ $HorzAlign = Center RemoveTextForHearingImpaired = new RemoveTextForHearingImpairedSettings(); SubtitleBeaming = new SubtitleBeaming(); Compare = new CompareSettings(); + VerifyCompleteness = new VerifyCompletenessSettings(); BeautifyTimeCodes = new BeautifyTimeCodesSettings(); } @@ -3371,6 +3389,17 @@ $HorzAlign = Center } } + // Verify completeness + XmlNode nodeVerifyCompleteness = doc.DocumentElement.SelectSingleNode("VerifyCompleteness"); + if (nodeVerifyCompleteness != null) + { + XmlNode xnode = nodeVerifyCompleteness.SelectSingleNode("ListSort"); + if (xnode != null) + { + settings.VerifyCompleteness.ListSort = (VerifyCompletenessSettings.ListSortEnum)Enum.Parse(typeof(VerifyCompletenessSettings.ListSortEnum), xnode.InnerText); + } + } + // Recent files XmlNode node = doc.DocumentElement.SelectSingleNode("RecentFiles"); foreach (XmlNode listNode in node.SelectNodes("FileNames/FileName")) @@ -11329,6 +11358,10 @@ $HorzAlign = Center textWriter.WriteElementString("IgnoreFormatting", settings.Compare.IgnoreFormatting.ToString(CultureInfo.InvariantCulture)); textWriter.WriteEndElement(); + textWriter.WriteStartElement("VerifyCompleteness", string.Empty); + textWriter.WriteElementString("ListSort", settings.VerifyCompleteness.ListSort.ToString()); + textWriter.WriteEndElement(); + textWriter.WriteStartElement("RecentFiles", string.Empty); textWriter.WriteStartElement("FileNames", string.Empty); foreach (var item in settings.RecentFiles.Files) diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index 70544b82e..859b5cb9b 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -21935,9 +21935,9 @@ namespace Nikse.SubtitleEdit.Forms var verifyCompleteness = new VerifyCompleteness( _subtitle, controlSubtitle, - (timeMillis) => + (timeSeconds) => { - GoToTimeAndSelectPrecedingParagraph(timeMillis); + GoToTimeAndSelectPrecedingParagraph(timeSeconds); }, (newParagraph) => { @@ -21953,47 +21953,43 @@ namespace Nikse.SubtitleEdit.Forms } } - private void GoToTimeAndSelectPrecedingParagraph(double timeMillis) + private void GoToTimeAndSelectPrecedingParagraph(double timeSeconds) { - /*if (mediaPlayer.VideoPlayer is null) - { - return; - } + var index = 0; - mediaPlayer.Pause(); + // Select correct paragraph + for (int i = 0; i < _subtitle.Paragraphs.Count; i++) + { + if (timeSeconds > _subtitle.Paragraphs[i].EndTime.TotalSeconds) + { + index = i - 1; + SelectListViewIndexAndEnsureVisible(index); + break; + } + } - if (SubtitleListview1.SelectedItems.Count > 0) - { - int index = SubtitleListview1.SelectedItems[0].Index; - if (index == -1 || index >= _subtitle.Paragraphs.Count) - { - return; - } + if (index < 0) + { + index = 0; + } - var p = _subtitle.Paragraphs[index]; - - if (p.StartTime.IsMaxTime) - { - return; - } + // Seek in waveform + if (mediaPlayer.VideoPlayer is null) + { + return; + } - double newPos = p.StartTime.TotalSeconds + adjustSeconds; - if (newPos < 0) - { - newPos = 0; - } + mediaPlayer.Pause(); + mediaPlayer.CurrentPosition = timeSeconds; + ShowSubtitle(); - mediaPlayer.CurrentPosition = newPos; - ShowSubtitle(); + double startPos = mediaPlayer.CurrentPosition - 1; + if (startPos < 0) + { + startPos = 0; + } - double startPos = mediaPlayer.CurrentPosition - 1; - if (startPos < 0) - { - startPos = 0; - } - - SetWaveformPosition(startPos, mediaPlayer.CurrentPosition, index); - }*/ + SetWaveformPosition(startPos, mediaPlayer.CurrentPosition, index); } private void InsertAndSelectParagraph(Paragraph paragraph, bool selectInsertedParagraph = true) diff --git a/src/ui/Forms/VerifyCompleteness.Designer.cs b/src/ui/Forms/VerifyCompleteness.Designer.cs index 4a72f053e..a7d105fb2 100644 --- a/src/ui/Forms/VerifyCompleteness.Designer.cs +++ b/src/ui/Forms/VerifyCompleteness.Designer.cs @@ -28,6 +28,7 @@ /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.buttonOK = new System.Windows.Forms.Button(); this.labelControlSubtitleFilename = new System.Windows.Forms.Label(); this.buttonOpenControlSubtitle = new System.Windows.Forms.Button(); @@ -35,7 +36,13 @@ this.buttonInsertAndNext = new System.Windows.Forms.Button(); this.buttonReload = new System.Windows.Forms.Button(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.contextMenuStripListView = new System.Windows.Forms.ContextMenuStrip(this.components); + this.toolStripMenuItemSortByCoverage = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItemSortByTime = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonInsert = new System.Windows.Forms.Button(); + this.buttonDismiss = new System.Windows.Forms.Button(); this.subtitleListView = new Nikse.SubtitleEdit.Controls.SubtitleListView(); + this.contextMenuStripListView.SuspendLayout(); this.SuspendLayout(); // // buttonOK @@ -75,10 +82,10 @@ this.buttonDismissAndNext.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDismissAndNext.Enabled = false; this.buttonDismissAndNext.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.buttonDismissAndNext.Location = new System.Drawing.Point(432, 551); + this.buttonDismissAndNext.Location = new System.Drawing.Point(412, 551); this.buttonDismissAndNext.Name = "buttonDismissAndNext"; - this.buttonDismissAndNext.Size = new System.Drawing.Size(217, 36); - this.buttonDismissAndNext.TabIndex = 5; + this.buttonDismissAndNext.Size = new System.Drawing.Size(170, 36); + this.buttonDismissAndNext.TabIndex = 6; this.buttonDismissAndNext.Text = "Dismiss and go to next"; this.buttonDismissAndNext.UseVisualStyleBackColor = true; this.buttonDismissAndNext.Click += new System.EventHandler(this.buttonDismissAndNext_Click); @@ -88,10 +95,10 @@ this.buttonInsertAndNext.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonInsertAndNext.Enabled = false; this.buttonInsertAndNext.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.buttonInsertAndNext.Location = new System.Drawing.Point(655, 551); + this.buttonInsertAndNext.Location = new System.Drawing.Point(702, 551); this.buttonInsertAndNext.Name = "buttonInsertAndNext"; - this.buttonInsertAndNext.Size = new System.Drawing.Size(217, 36); - this.buttonInsertAndNext.TabIndex = 6; + this.buttonInsertAndNext.Size = new System.Drawing.Size(170, 36); + this.buttonInsertAndNext.TabIndex = 8; this.buttonInsertAndNext.Text = "Insert and go to next"; this.buttonInsertAndNext.UseVisualStyleBackColor = true; this.buttonInsertAndNext.Click += new System.EventHandler(this.buttonInsertAndNext_Click); @@ -108,12 +115,61 @@ this.buttonReload.UseVisualStyleBackColor = true; this.buttonReload.Click += new System.EventHandler(this.buttonReload_Click); // + // contextMenuStripListView + // + this.contextMenuStripListView.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItemSortByCoverage, + this.toolStripMenuItemSortByTime}); + this.contextMenuStripListView.Name = "contextMenuStripListView"; + this.contextMenuStripListView.Size = new System.Drawing.Size(163, 48); + // + // toolStripMenuItemSortByCoverage + // + this.toolStripMenuItemSortByCoverage.Name = "toolStripMenuItemSortByCoverage"; + this.toolStripMenuItemSortByCoverage.Size = new System.Drawing.Size(162, 22); + this.toolStripMenuItemSortByCoverage.Text = "Sort by coverage"; + this.toolStripMenuItemSortByCoverage.Click += new System.EventHandler(this.toolStripMenuItemSortByCoverage_Click); + // + // toolStripMenuItemSortByTime + // + this.toolStripMenuItemSortByTime.Name = "toolStripMenuItemSortByTime"; + this.toolStripMenuItemSortByTime.Size = new System.Drawing.Size(162, 22); + this.toolStripMenuItemSortByTime.Text = "Sort by time"; + this.toolStripMenuItemSortByTime.Click += new System.EventHandler(this.toolStripMenuItemSortByTime_Click); + // + // buttonInsert + // + this.buttonInsert.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonInsert.Enabled = false; + this.buttonInsert.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.buttonInsert.Location = new System.Drawing.Point(588, 551); + this.buttonInsert.Name = "buttonInsert"; + this.buttonInsert.Size = new System.Drawing.Size(115, 36); + this.buttonInsert.TabIndex = 7; + this.buttonInsert.Text = "Insert"; + this.buttonInsert.UseVisualStyleBackColor = true; + this.buttonInsert.Click += new System.EventHandler(this.buttonInsert_Click); + // + // buttonDismiss + // + this.buttonDismiss.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDismiss.Enabled = false; + this.buttonDismiss.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.buttonDismiss.Location = new System.Drawing.Point(298, 551); + this.buttonDismiss.Name = "buttonDismiss"; + this.buttonDismiss.Size = new System.Drawing.Size(115, 36); + this.buttonDismiss.TabIndex = 5; + this.buttonDismiss.Text = "Dismiss"; + this.buttonDismiss.UseVisualStyleBackColor = true; + this.buttonDismiss.Click += new System.EventHandler(this.buttonDismiss_Click); + // // subtitleListView // this.subtitleListView.AllowColumnReorder = true; this.subtitleListView.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.subtitleListView.ContextMenuStrip = this.contextMenuStripListView; this.subtitleListView.FirstVisibleIndex = -1; this.subtitleListView.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.subtitleListView.FullRowSelect = true; @@ -133,6 +189,9 @@ this.subtitleListView.UseSyntaxColoring = false; this.subtitleListView.View = System.Windows.Forms.View.Details; this.subtitleListView.SelectedIndexChanged += new System.EventHandler(this.subtitleListView_SelectedIndexChanged); + this.subtitleListView.Click += new System.EventHandler(this.subtitleListView_Click); + this.subtitleListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.subtitleListView_DragDrop); + this.subtitleListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.subtitleListView_DragEnter); this.subtitleListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.subtitleListView_KeyDown); this.subtitleListView.Resize += new System.EventHandler(this.subtitleListView_Resize); // @@ -141,6 +200,8 @@ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(884, 636); + this.Controls.Add(this.buttonDismiss); + this.Controls.Add(this.buttonInsert); this.Controls.Add(this.buttonReload); this.Controls.Add(this.buttonInsertAndNext); this.Controls.Add(this.buttonDismissAndNext); @@ -151,12 +212,14 @@ this.DoubleBuffered = true; this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.MinimumSize = new System.Drawing.Size(750, 400); this.Name = "VerifyCompleteness"; this.ShowIcon = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Verify completeness against other subtitle"; this.Shown += new System.EventHandler(this.VerifyCompleteness_Shown); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.VerifyCompleteness_KeyDown); + this.contextMenuStripListView.ResumeLayout(false); this.ResumeLayout(false); } @@ -171,5 +234,10 @@ private System.Windows.Forms.Button buttonInsertAndNext; private System.Windows.Forms.Button buttonReload; private System.Windows.Forms.OpenFileDialog openFileDialog; + private System.Windows.Forms.ContextMenuStrip contextMenuStripListView; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSortByCoverage; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSortByTime; + private System.Windows.Forms.Button buttonInsert; + private System.Windows.Forms.Button buttonDismiss; } } \ No newline at end of file diff --git a/src/ui/Forms/VerifyCompleteness.cs b/src/ui/Forms/VerifyCompleteness.cs index aafe181cb..7cb0d4dd1 100644 --- a/src/ui/Forms/VerifyCompleteness.cs +++ b/src/ui/Forms/VerifyCompleteness.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; +using static Nikse.SubtitleEdit.Core.Common.VerifyCompletenessSettings; namespace Nikse.SubtitleEdit.Forms { @@ -18,7 +18,7 @@ namespace Nikse.SubtitleEdit.Forms private readonly Action _seekAction; private readonly Action _insertAction; - private Subtitle sortedControlSubtitle = new Subtitle(); + private List> sortedControlParagraphsWithCoverage = new List>(); public VerifyCompleteness(Subtitle subtitle, Subtitle controlSubtitle, Action seekAction, Action insertAction) { @@ -34,8 +34,12 @@ namespace Nikse.SubtitleEdit.Forms var language = LanguageSettings.Current.VerifyCompleteness; Text = language.Title; buttonReload.Text = language.Reload; + buttonDismiss.Text = language.Dismiss; buttonDismissAndNext.Text = language.DismissAndNext; + buttonInsert.Text = language.Insert; buttonInsertAndNext.Text = language.InsertAndNext; + toolStripMenuItemSortByCoverage.Text = language.SortByCoverage; + toolStripMenuItemSortByTime.Text = language.SortByTime; subtitleListView.HideColumn(SubtitleListView.SubtitleColumn.CharactersPerSeconds); subtitleListView.HideColumn(SubtitleListView.SubtitleColumn.WordsPerMinute); @@ -45,7 +49,13 @@ namespace Nikse.SubtitleEdit.Forms buttonOK.Text = LanguageSettings.Current.General.Ok; UiUtil.FixLargeFonts(this, buttonOK); + var settings = Configuration.Settings.VerifyCompleteness; + toolStripMenuItemSortByCoverage.Checked = settings.ListSort == ListSortEnum.Coverage; + toolStripMenuItemSortByTime.Checked = settings.ListSort == ListSortEnum.Time; + + buttonDismiss.Font = new Font(buttonDismissAndNext.Font, FontStyle.Bold); buttonDismissAndNext.Font = new Font(buttonDismissAndNext.Font, FontStyle.Bold); + buttonInsert.Font = new Font(buttonInsertAndNext.Font, FontStyle.Bold); buttonInsertAndNext.Font = new Font(buttonInsertAndNext.Font, FontStyle.Bold); subtitleListView.InitializeLanguage(LanguageSettings.Current.General, Configuration.Settings); @@ -53,19 +63,20 @@ namespace Nikse.SubtitleEdit.Forms subtitleListView.ShowExtraColumn(language.Coverage); subtitleListView.AutoSizeAllColumns(this); - PopulateListView(); + LoadData(); } - private void PopulateListView() + private void LoadData() { Cursor = Cursors.WaitCursor; // Update filename label labelControlSubtitleFilename.Text = String.Format(LanguageSettings.Current.VerifyCompleteness.ControlSubtitleX, _controlSubtitle.FileName); - // Calculate coverages and sort paragraphs - List> overlapTotals = new List>(); + // Clear previous control paragraphs + sortedControlParagraphsWithCoverage.Clear(); + // Calculate coverages and sort paragraphs foreach (Paragraph p in _controlSubtitle.Paragraphs) { double overlapTotal = 0; @@ -84,35 +95,45 @@ namespace Nikse.SubtitleEdit.Forms } } - overlapTotals.Add(new Tuple(p, overlapTotal)); + sortedControlParagraphsWithCoverage.Add(new Tuple(p, overlapTotal)); } - overlapTotals = overlapTotals.OrderBy(t => t.Item2).ToList(); + // Populate list view + PopulateListView(); - // Create new sorted subtitle - sortedControlSubtitle = new Subtitle(overlapTotals.Select(t => t.Item1).ToList()); + Cursor = Cursors.Default; + } + + private void PopulateListView() + { + // Sort the paragraphs + if (toolStripMenuItemSortByTime.Checked) + { + sortedControlParagraphsWithCoverage = sortedControlParagraphsWithCoverage.OrderBy(t => t.Item1.StartTime.TotalMilliseconds).ToList(); + } + else + { + sortedControlParagraphsWithCoverage = sortedControlParagraphsWithCoverage.OrderBy(t => t.Item2).ToList(); + } // Init listview subtitleListView.Items.Clear(); subtitleListView.BeginUpdate(); - // Fill the listview with the control subtitle - subtitleListView.Fill(sortedControlSubtitle); + // Fill the listview with the sorted control paragraphs + subtitleListView.Fill(sortedControlParagraphsWithCoverage.Select(t => t.Item1).ToList()); // Show coverage - for (int i = 0; i < sortedControlSubtitle.Paragraphs.Count; i++) + for (int i = 0; i < sortedControlParagraphsWithCoverage.Count; i++) { - var p = sortedControlSubtitle.Paragraphs[i]; - var overlap = overlapTotals[i].Item2; - + var overlap = sortedControlParagraphsWithCoverage[i].Item2; + subtitleListView.SetExtraText(i, String.Format(LanguageSettings.Current.VerifyCompleteness.CoveragePercentageX, overlap * 100.0), subtitleListView.ForeColor); subtitleListView.SetBackgroundColor(i, CalculateColor(overlap * 100), subtitleListView.ColumnIndexExtra); } // Finalize update subtitleListView.EndUpdate(); - - Cursor = Cursors.Default; } private Color CalculateColor(double percentage) @@ -136,11 +157,16 @@ namespace Nikse.SubtitleEdit.Forms return; } - var controlSubtitle = LoadSubtitle(openFileDialog.FileName); + TryLoadSubtitle(openFileDialog.FileName); + } + + private void TryLoadSubtitle(string fileName) + { + var controlSubtitle = LoadSubtitle(fileName); if (controlSubtitle.Paragraphs.Count > 0) { _controlSubtitle = controlSubtitle; - PopulateListView(); + LoadData(); } else { @@ -150,25 +176,35 @@ namespace Nikse.SubtitleEdit.Forms private void buttonReload_Click(object sender, System.EventArgs e) { - PopulateListView(); + LoadData(); + } + + private void buttonDismiss_Click(object sender, EventArgs e) + { + ProcessParagraph(false, false); } private void buttonDismissAndNext_Click(object sender, System.EventArgs e) { - RemoveParagraphAndSelectNext(false); + ProcessParagraph(false, true); + } + + private void buttonInsert_Click(object sender, EventArgs e) + { + ProcessParagraph(true, false); } private void buttonInsertAndNext_Click(object sender, System.EventArgs e) { - RemoveParagraphAndSelectNext(true); + ProcessParagraph(true, true); } - private void RemoveParagraphAndSelectNext(bool insertIntoSubtitle) + private void ProcessParagraph(bool insertIntoSubtitle, bool goToNext) { if (subtitleListView.SelectedIndices.Count == 1) { var index = subtitleListView.SelectedIndices[0]; - var paragraph = sortedControlSubtitle.Paragraphs[index]; + var paragraph = sortedControlParagraphsWithCoverage[index].Item1; // Insert the paragragh in the parent subtitle if requested if (insertIntoSubtitle) @@ -177,16 +213,22 @@ namespace Nikse.SubtitleEdit.Forms } // Remove the paragragh from the list - sortedControlSubtitle.Paragraphs.RemoveAt(index); + sortedControlParagraphsWithCoverage.RemoveAt(index); subtitleListView.Items.RemoveAt(index); // Select the next paragraph - subtitleListView.SelectIndexAndEnsureVisible(index); + if (goToNext) + { + subtitleListView.SelectIndexAndEnsureVisible(index); + } } } private void buttonOK_Click(object sender, EventArgs e) { + // Save settings + Configuration.Settings.VerifyCompleteness.ListSort = toolStripMenuItemSortByTime.Checked ? ListSortEnum.Time : ListSortEnum.Coverage; + this.Close(); } @@ -195,21 +237,32 @@ namespace Nikse.SubtitleEdit.Forms if (subtitleListView.SelectedIndices.Count == 1) { var index = subtitleListView.SelectedIndices[0]; - var paragraph = sortedControlSubtitle.Paragraphs[index]; + var paragraph = sortedControlParagraphsWithCoverage[index].Item1; // Tell parent to seek to the paragraph's time - _seekAction.Invoke(paragraph.StartTime.TotalMilliseconds); + _seekAction.Invoke(paragraph.StartTime.TotalSeconds); - buttonDismissAndNext.Enabled = true; - buttonInsertAndNext.Enabled = true; + EnableButtons(true); } else { - buttonDismissAndNext.Enabled = false; - buttonInsertAndNext.Enabled = false; + EnableButtons(false); } } + private void EnableButtons(bool enable) + { + buttonDismiss.Enabled = enable; + buttonDismissAndNext.Enabled = enable; + buttonInsert.Enabled = enable; + buttonInsertAndNext.Enabled = enable; + } + + private void subtitleListView_Click(object sender, EventArgs e) + { + subtitleListView_SelectedIndexChanged(sender, e); + } + private void subtitleListView_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete && subtitleListView.SelectedItems.Count > 0) @@ -231,6 +284,50 @@ namespace Nikse.SubtitleEdit.Forms subtitleListView.Columns[columnsCount].Width = -2; } + private void subtitleListView_DragEnter(object sender, DragEventArgs e) + { + e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None; + } + + private void subtitleListView_DragDrop(object sender, DragEventArgs e) + { + if (!(e.Data.GetData(DataFormats.FileDrop) is string[] files)) + { + return; + } + + if (files.Length > 1) + { + MessageBox.Show(this, LanguageSettings.Current.Main.DropOnlyOneFile, LanguageSettings.Current.General.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + var filePath = files[0]; + if (FileUtil.IsDirectory(filePath)) + { + MessageBox.Show(this, LanguageSettings.Current.Main.ErrorDirectoryDropNotAllowed, LanguageSettings.Current.General.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + TryLoadSubtitle(filePath); + } + + private void toolStripMenuItemSortByCoverage_Click(object sender, EventArgs e) + { + toolStripMenuItemSortByTime.Checked = false; + toolStripMenuItemSortByCoverage.Checked = true; + + PopulateListView(); + } + + private void toolStripMenuItemSortByTime_Click(object sender, EventArgs e) + { + toolStripMenuItemSortByCoverage.Checked = false; + toolStripMenuItemSortByTime.Checked = true; + + PopulateListView(); + } + private void VerifyCompleteness_Shown(object sender, EventArgs e) { subtitleListView.Focus(); diff --git a/src/ui/Forms/VerifyCompleteness.resx b/src/ui/Forms/VerifyCompleteness.resx index 12048a9f5..8b7b9263e 100644 --- a/src/ui/Forms/VerifyCompleteness.resx +++ b/src/ui/Forms/VerifyCompleteness.resx @@ -120,4 +120,7 @@ 17, 17 + + 150, 17 + \ No newline at end of file diff --git a/src/ui/Logic/Language.cs b/src/ui/Logic/Language.cs index aec832350..df9f60b38 100644 --- a/src/ui/Logic/Language.cs +++ b/src/ui/Logic/Language.cs @@ -1894,7 +1894,7 @@ namespace Nikse.SubtitleEdit.Logic CloseTranslation = "Close translated subtitle", OpenContainingFolder = "Open containing folder", Compare = "&Compare...", - VerifyCompleteness = "Verify completeness against other subtitle...", + VerifyCompleteness = "Verify completeness...", Statistics = "S&tatistics...", Plugins = "&Plugins...", ImportSubtitleFromVideoFile = "Subtitle from video file...", @@ -3563,8 +3563,12 @@ can edit in same subtitle file (collaboration)", ControlSubtitleX = "Control subtitle: {0}", Coverage = "Coverage", CoveragePercentageX = "{0:0.##}%", + SortByCoverage = "Sort by coverage", + SortByTime = "Sort by time", Reload = "Re-verify", + Insert = "Insert", InsertAndNext = "Insert and go to next", + Dismiss = "Dismiss", DismissAndNext = "Dismiss and go to next", }; diff --git a/src/ui/Logic/LanguageStructure.cs b/src/ui/Logic/LanguageStructure.cs index 93452119d..cf6dbe6ce 100644 --- a/src/ui/Logic/LanguageStructure.cs +++ b/src/ui/Logic/LanguageStructure.cs @@ -3375,8 +3375,12 @@ public string ControlSubtitleX { get; set; } public string Coverage { get; set; } public string CoveragePercentageX { get; set; } + public string SortByCoverage { get; set; } + public string SortByTime { get; set; } public string Reload { get; set; } + public string Insert { get; set; } public string InsertAndNext { get; set; } + public string Dismiss { get; set; } public string DismissAndNext { get; set; } }