From 323bdbfa94e94c490b58856fabffb5d6d0540f47 Mon Sep 17 00:00:00 2001 From: niksedk Date: Mon, 29 Aug 2022 15:22:33 +0200 Subject: [PATCH] nOCR selected lines --- LanguageMaster.xml | 2 +- src/ui/Forms/Ocr/VobSubOcr.Designer.cs | 20 +++++++++++- src/ui/Forms/Ocr/VobSubOcr.cs | 45 +++++++++++++++++++++++--- src/ui/Logic/Language.cs | 2 +- src/ui/Logic/LanguageDeserializer.cs | 6 ++-- src/ui/Logic/LanguageStructure.cs | 2 +- 6 files changed, 66 insertions(+), 11 deletions(-) diff --git a/LanguageMaster.xml b/LanguageMaster.xml index 0df50081d..110582d0c 100644 --- a/LanguageMaster.xml +++ b/LanguageMaster.xml @@ -1339,7 +1339,6 @@ To use an API key go to "Options -> Settings -> Tools" to enter your Googl Split line at cursor/video position Auto duration (current line) Select all - Insert Insert line Insert before Insert after @@ -1355,6 +1354,7 @@ To use an API key go to "Options -> Settings -> Tools" to enter your Googl Text up Text down Copy text from original to current + OCR selected lines Split Merge selected lines Merge selected lines as dialog diff --git a/src/ui/Forms/Ocr/VobSubOcr.Designer.cs b/src/ui/Forms/Ocr/VobSubOcr.Designer.cs index 9c43bfb8e..7ea1a1a5f 100644 --- a/src/ui/Forms/Ocr/VobSubOcr.Designer.cs +++ b/src/ui/Forms/Ocr/VobSubOcr.Designer.cs @@ -19,6 +19,8 @@ namespace Nikse.SubtitleEdit.Forms.Ocr { this.components = new System.ComponentModel.Container(); this.contextMenuStripListview = new System.Windows.Forms.ContextMenuStrip(this.components); + this.oCRSelectedLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparatorOcrSelected = new System.Windows.Forms.ToolStripSeparator(); this.normalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.italicToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); @@ -209,6 +211,8 @@ namespace Nikse.SubtitleEdit.Forms.Ocr // contextMenuStripListview // this.contextMenuStripListview.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.oCRSelectedLinesToolStripMenuItem, + this.toolStripSeparatorOcrSelected, this.normalToolStripMenuItem, this.italicToolStripMenuItem, this.toolStripSeparator1, @@ -231,9 +235,21 @@ namespace Nikse.SubtitleEdit.Forms.Ocr this.toolStripSeparator3, this.deleteToolStripMenuItem}); this.contextMenuStripListview.Name = "contextMenuStripListview"; - this.contextMenuStripListview.Size = new System.Drawing.Size(306, 386); + this.contextMenuStripListview.Size = new System.Drawing.Size(306, 436); this.contextMenuStripListview.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStripListviewOpening); // + // oCRSelectedLinesToolStripMenuItem + // + this.oCRSelectedLinesToolStripMenuItem.Name = "oCRSelectedLinesToolStripMenuItem"; + this.oCRSelectedLinesToolStripMenuItem.Size = new System.Drawing.Size(305, 22); + this.oCRSelectedLinesToolStripMenuItem.Text = "OCR selected lines..."; + this.oCRSelectedLinesToolStripMenuItem.Click += new System.EventHandler(this.oCRSelectedLinesToolStripMenuItem_Click); + // + // toolStripSeparatorOcrSelected + // + this.toolStripSeparatorOcrSelected.Name = "toolStripSeparatorOcrSelected"; + this.toolStripSeparatorOcrSelected.Size = new System.Drawing.Size(302, 6); + // // normalToolStripMenuItem // this.normalToolStripMenuItem.Name = "normalToolStripMenuItem"; @@ -2175,5 +2191,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr private System.Windows.Forms.ToolStripMenuItem underlineToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem imageWithTimeCodeInFileNameToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem removeAllXToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem oCRSelectedLinesToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparatorOcrSelected; } } \ No newline at end of file diff --git a/src/ui/Forms/Ocr/VobSubOcr.cs b/src/ui/Forms/Ocr/VobSubOcr.cs index 1ac690358..bd3f30933 100644 --- a/src/ui/Forms/Ocr/VobSubOcr.cs +++ b/src/ui/Forms/Ocr/VobSubOcr.cs @@ -284,6 +284,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr private int _mainOcrIndex; private bool _mainOcrRunning; private Bitmap _mainOcrBitmap; + private List _mainOcrSelectedIndices; private Type _modiType; private object _modiDoc; @@ -543,6 +544,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr checkBoxShowOnlyForced.Text = language.ShowOnlyForcedSubtitles; checkBoxUseTimeCodesFromIdx.Text = language.UseTimeCodesFromIdx; + oCRSelectedLinesToolStripMenuItem.Text = LanguageSettings.Current.Main.Menu.ContextMenu.OcrSelectedLines; normalToolStripMenuItem.Text = LanguageSettings.Current.Main.Menu.ContextMenu.RemoveFormattingAll; italicToolStripMenuItem.Text = LanguageSettings.Current.General.Italic; importTextWithMatchingTimeCodesToolStripMenuItem.Text = language.ImportTextWithMatchingTimeCodes; @@ -5078,6 +5080,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr subtitleListView1.MultiSelect = true; checkBoxUseTimeCodesFromIdx.Enabled = checkBoxUseTimeCodesFromIdx.Visible; checkBoxShowOnlyForced.Enabled = _hasForcedSubtitles; + _mainOcrSelectedIndices = null; } private bool _isLatinDb; @@ -5672,7 +5675,24 @@ namespace Nikse.SubtitleEdit.Forms.Ocr } else { - _mainOcrIndex++; + if (_mainOcrSelectedIndices != null) + { + var idx = _mainOcrSelectedIndices.IndexOf(_mainOcrIndex); + if (idx >= 0 && idx + 1 < _mainOcrSelectedIndices.Count) + { + _mainOcrIndex = _mainOcrSelectedIndices[idx + 1]; + } + else + { + _abort = true; + _mainOcrSelectedIndices = null; + } + } + else + { + _mainOcrIndex++; + } + _mainOcrTimer.Start(); } } @@ -7543,24 +7563,35 @@ namespace Nikse.SubtitleEdit.Forms.Ocr e.Cancel = true; } - // Enable toolstrips if event was raised by Subtitle listview. + // Enable toolstrips if event was raised by Subtitle listview bool enableIfRaisedBySubListView = contextMenuStripListview.SourceControl == subtitleListView1; normalToolStripMenuItem.Visible = enableIfRaisedBySubListView; italicToolStripMenuItem.Visible = enableIfRaisedBySubListView; toolStripSeparator1.Visible = enableIfRaisedBySubListView && subtitleListView1.SelectedItems.Count == 1; saveImageAsToolStripMenuItem.Visible = !enableIfRaisedBySubListView || subtitleListView1.SelectedItems.Count == 1; - // Image compare. + // Image compare bool enableIfImageCompare = _ocrMethodIndex == _ocrMethodBinaryImageCompare; inspectImageCompareMatchesForCurrentImageToolStripMenuItem.Visible = enableIfImageCompare; EditLastAdditionsToolStripMenuItem.Visible = enableIfImageCompare && _lastAdditions != null && _lastAdditions.Count > 0; - // Use N-OCR compare. (Only available in Beta mode). + // Use N-OCR compare bool useNocrCompare = _ocrMethodIndex == _ocrMethodNocr; toolStripMenuItemInspectNOcrMatches.Visible = useNocrCompare; OcrTrainingToolStripMenuItem.Visible = useNocrCompare || enableIfImageCompare; toolStripSeparatorImageCompare.Visible = useNocrCompare || enableIfImageCompare; + + if (subtitleListView1.SelectedItems.Count > 0 && (_ocrMethodIndex == _ocrMethodNocr || _ocrMethodIndex == _ocrMethodBinaryImageCompare)) + { + oCRSelectedLinesToolStripMenuItem.Visible = true; + toolStripSeparatorOcrSelected.Visible = true; + } + else + { + oCRSelectedLinesToolStripMenuItem.Visible = true; + toolStripSeparatorOcrSelected.Visible = true; + } } private void SaveImageAsToolStripMenuItemClick(object sender, EventArgs e) @@ -10010,5 +10041,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr removeAllXToolStripMenuItem.Text = string.Format(LanguageSettings.Current.Settings.RemoveX.RemoveChar('?'), word); } } + + private void oCRSelectedLinesToolStripMenuItem_Click(object sender, EventArgs e) + { + _mainOcrSelectedIndices = subtitleListView1.GetSelectedIndices().ToList(); + ButtonStartOcrClick(null, null); + } } } diff --git a/src/ui/Logic/Language.cs b/src/ui/Logic/Language.cs index 688378840..a111d4c4c 100644 --- a/src/ui/Logic/Language.cs +++ b/src/ui/Logic/Language.cs @@ -1889,7 +1889,6 @@ namespace Nikse.SubtitleEdit.Logic SplitLineAtCursorAndWaveformPosition = "Split line at cursor/video position", AutoDurationCurrentLine = "Auto duration (current line)", SelectAll = "Select all", - Insert = "Insert", InsertFirstLine = "Insert line", InsertBefore = "Insert before", InsertAfter = "Insert after", @@ -1905,6 +1904,7 @@ namespace Nikse.SubtitleEdit.Logic ColumnTextUp = "Text up", ColumnTextDown = "Text down", ColumnCopyOriginalTextToCurrent = "Copy text from original to current", + OcrSelectedLines = "OCR selected lines", Split = "Split", MergeSelectedLines = "Merge selected lines", MergeSelectedLinesAsDialog = "Merge selected lines as dialog", diff --git a/src/ui/Logic/LanguageDeserializer.cs b/src/ui/Logic/LanguageDeserializer.cs index 36f1b2480..321a87a0a 100644 --- a/src/ui/Logic/LanguageDeserializer.cs +++ b/src/ui/Logic/LanguageDeserializer.cs @@ -4387,9 +4387,6 @@ namespace Nikse.SubtitleEdit.Logic case "Main/Menu/ContextMenu/SelectAll": language.Main.Menu.ContextMenu.SelectAll = reader.Value; break; - case "Main/Menu/ContextMenu/Insert": - language.Main.Menu.ContextMenu.Insert = reader.Value; - break; case "Main/Menu/ContextMenu/InsertFirstLine": language.Main.Menu.ContextMenu.InsertFirstLine = reader.Value; break; @@ -4435,6 +4432,9 @@ namespace Nikse.SubtitleEdit.Logic case "Main/Menu/ContextMenu/ColumnCopyOriginalTextToCurrent": language.Main.Menu.ContextMenu.ColumnCopyOriginalTextToCurrent = reader.Value; break; + case "Main/Menu/ContextMenu/OcrSelectedLines": + language.Main.Menu.ContextMenu.OcrSelectedLines = reader.Value; + break; case "Main/Menu/ContextMenu/Split": language.Main.Menu.ContextMenu.Split = reader.Value; break; diff --git a/src/ui/Logic/LanguageStructure.cs b/src/ui/Logic/LanguageStructure.cs index 8b643b358..91ce60dea 100644 --- a/src/ui/Logic/LanguageStructure.cs +++ b/src/ui/Logic/LanguageStructure.cs @@ -1734,7 +1734,6 @@ public string SplitLineAtCursorAndWaveformPosition { get; set; } public string AutoDurationCurrentLine { get; set; } public string SelectAll { get; set; } - public string Insert { get; set; } public string InsertFirstLine { get; set; } public string InsertBefore { get; set; } public string InsertAfter { get; set; } @@ -1750,6 +1749,7 @@ public string ColumnTextUp { get; set; } public string ColumnTextDown { get; set; } public string ColumnCopyOriginalTextToCurrent { get; set; } + public string OcrSelectedLines { get; set; } public string Split { get; set; } public string MergeSelectedLines { get; set; } public string MergeSelectedLinesAsDialog { get; set; }