diff --git a/src/ui/Forms/Ocr/VobSubOcr.Designer.cs b/src/ui/Forms/Ocr/VobSubOcr.Designer.cs index f82ac3d30..ab2377ecf 100644 --- a/src/ui/Forms/Ocr/VobSubOcr.Designer.cs +++ b/src/ui/Forms/Ocr/VobSubOcr.Designer.cs @@ -33,6 +33,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr this.bluraySupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.vobSubToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dOSTToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.finalCutProImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparatorImageCompare = new System.Windows.Forms.ToolStripSeparator(); this.toolStripMenuItemInspectNOcrMatches = new System.Windows.Forms.ToolStripMenuItem(); this.inspectImageCompareMatchesForCurrentImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -154,7 +155,18 @@ namespace Nikse.SubtitleEdit.Forms.Ocr this.textBoxCurrentText = new Nikse.SubtitleEdit.Controls.SETextBox(); this.subtitleListView1 = new Nikse.SubtitleEdit.Controls.SubtitleListView(); this.timerHideStatus = new System.Windows.Forms.Timer(this.components); - this.finalCutProImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.contextMenuStripTextBox = new System.Windows.Forms.ContextMenuStrip(this.components); + this.cutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.pasteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator18 = new System.Windows.Forms.ToolStripSeparator(); + this.selectAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator17 = new System.Windows.Forms.ToolStripSeparator(); + this.normalToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.boldToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.italicToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.underlineToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.contextMenuStripListview.SuspendLayout(); this.groupBoxOcrMethod.SuspendLayout(); this.groupBoxNOCR.SuspendLayout(); @@ -189,6 +201,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr this.splitContainerBottom.Panel1.SuspendLayout(); this.splitContainerBottom.Panel2.SuspendLayout(); this.splitContainerBottom.SuspendLayout(); + this.contextMenuStripTextBox.SuspendLayout(); this.SuspendLayout(); // // contextMenuStripListview @@ -216,7 +229,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr this.toolStripSeparator3, this.deleteToolStripMenuItem}); this.contextMenuStripListview.Name = "contextMenuStripListview"; - this.contextMenuStripListview.Size = new System.Drawing.Size(306, 408); + this.contextMenuStripListview.Size = new System.Drawing.Size(306, 386); this.contextMenuStripListview.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStripListviewOpening); // // normalToolStripMenuItem @@ -318,6 +331,13 @@ namespace Nikse.SubtitleEdit.Forms.Ocr this.dOSTToolStripMenuItem.Text = "DOST..."; this.dOSTToolStripMenuItem.Click += new System.EventHandler(this.DOSTToolStripMenuItem_Click); // + // finalCutProImageToolStripMenuItem + // + this.finalCutProImageToolStripMenuItem.Name = "finalCutProImageToolStripMenuItem"; + this.finalCutProImageToolStripMenuItem.Size = new System.Drawing.Size(198, 22); + this.finalCutProImageToolStripMenuItem.Text = "Final Cut Pro + image..."; + this.finalCutProImageToolStripMenuItem.Click += new System.EventHandler(this.finalCutProImageToolStripMenuItem_Click); + // // toolStripSeparatorImageCompare // this.toolStripSeparatorImageCompare.Name = "toolStripSeparatorImageCompare"; @@ -1761,10 +1781,18 @@ namespace Nikse.SubtitleEdit.Forms.Ocr this.textBoxCurrentText.AllowDrop = true; this.textBoxCurrentText.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxCurrentText.BackColor = System.Drawing.SystemColors.WindowFrame; + this.textBoxCurrentText.ContextMenuStrip = this.contextMenuStripTextBox; this.textBoxCurrentText.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.textBoxCurrentText.HideSelection = true; this.textBoxCurrentText.Location = new System.Drawing.Point(8, 214); this.textBoxCurrentText.Multiline = true; this.textBoxCurrentText.Name = "textBoxCurrentText"; + this.textBoxCurrentText.Padding = new System.Windows.Forms.Padding(1); + this.textBoxCurrentText.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None; + this.textBoxCurrentText.SelectedText = ""; + this.textBoxCurrentText.SelectionLength = 0; + this.textBoxCurrentText.SelectionStart = 0; this.textBoxCurrentText.Size = new System.Drawing.Size(354, 77); this.textBoxCurrentText.TabIndex = 1; this.textBoxCurrentText.TextChanged += new System.EventHandler(this.TextBoxCurrentTextTextChanged); @@ -1803,12 +1831,100 @@ namespace Nikse.SubtitleEdit.Forms.Ocr this.timerHideStatus.Interval = 2000; this.timerHideStatus.Tick += new System.EventHandler(this.timerHideStatus_Tick); // - // finalCutProImageToolStripMenuItem + // contextMenuStripTextBox // - this.finalCutProImageToolStripMenuItem.Name = "finalCutProImageToolStripMenuItem"; - this.finalCutProImageToolStripMenuItem.Size = new System.Drawing.Size(198, 22); - this.finalCutProImageToolStripMenuItem.Text = "Final Cut Pro + image..."; - this.finalCutProImageToolStripMenuItem.Click += new System.EventHandler(this.finalCutProImageToolStripMenuItem_Click); + this.contextMenuStripTextBox.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.cutToolStripMenuItem, + this.copyToolStripMenuItem, + this.pasteToolStripMenuItem, + this.toolStripMenuItem1, + this.toolStripSeparator18, + this.selectAllToolStripMenuItem, + this.toolStripSeparator17, + this.normalToolStripMenuItem1, + this.boldToolStripMenuItem1, + this.italicToolStripMenuItem1, + this.underlineToolStripMenuItem1}); + this.contextMenuStripTextBox.Name = "contextMenuStripTextBoxListView"; + this.contextMenuStripTextBox.Size = new System.Drawing.Size(163, 214); + // + // cutToolStripMenuItem + // + this.cutToolStripMenuItem.Name = "cutToolStripMenuItem"; + this.cutToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.X))); + this.cutToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.cutToolStripMenuItem.Text = "Cut"; + this.cutToolStripMenuItem.Click += new System.EventHandler(this.cutToolStripMenuItem_Click); + // + // copyToolStripMenuItem + // + this.copyToolStripMenuItem.Name = "copyToolStripMenuItem"; + this.copyToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C))); + this.copyToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.copyToolStripMenuItem.Text = "Copy"; + this.copyToolStripMenuItem.Click += new System.EventHandler(this.copyToolStripMenuItem_Click); + // + // pasteToolStripMenuItem + // + this.pasteToolStripMenuItem.Name = "pasteToolStripMenuItem"; + this.pasteToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.V))); + this.pasteToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.pasteToolStripMenuItem.Text = "Paste"; + this.pasteToolStripMenuItem.Click += new System.EventHandler(this.pasteToolStripMenuItem_Click); + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.toolStripMenuItem1.Text = "Delete"; + this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click); + // + // toolStripSeparator18 + // + this.toolStripSeparator18.Name = "toolStripSeparator18"; + this.toolStripSeparator18.Size = new System.Drawing.Size(177, 6); + // + // selectAllToolStripMenuItem + // + this.selectAllToolStripMenuItem.Name = "selectAllToolStripMenuItem"; + this.selectAllToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.A))); + this.selectAllToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.selectAllToolStripMenuItem.Text = "Select all"; + this.selectAllToolStripMenuItem.Click += new System.EventHandler(this.selectAllToolStripMenuItem_Click); + // + // toolStripSeparator17 + // + this.toolStripSeparator17.Name = "toolStripSeparator17"; + this.toolStripSeparator17.Size = new System.Drawing.Size(177, 6); + // + // normalToolStripMenuItem1 + // + this.normalToolStripMenuItem1.Name = "normalToolStripMenuItem1"; + this.normalToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.normalToolStripMenuItem1.Text = "Normal"; + this.normalToolStripMenuItem1.Click += new System.EventHandler(this.normalToolStripMenuItem1_Click); + // + // boldToolStripMenuItem1 + // + this.boldToolStripMenuItem1.Name = "boldToolStripMenuItem1"; + this.boldToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.boldToolStripMenuItem1.Text = "Bold"; + this.boldToolStripMenuItem1.Click += new System.EventHandler(this.boldToolStripMenuItem1_Click); + // + // italicToolStripMenuItem1 + // + this.italicToolStripMenuItem1.Name = "italicToolStripMenuItem1"; + this.italicToolStripMenuItem1.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.I))); + this.italicToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.italicToolStripMenuItem1.Text = "Italic"; + this.italicToolStripMenuItem1.Click += new System.EventHandler(this.italicToolStripMenuItem1_Click); + // + // underlineToolStripMenuItem1 + // + this.underlineToolStripMenuItem1.Name = "underlineToolStripMenuItem1"; + this.underlineToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.underlineToolStripMenuItem1.Text = "Underline"; + this.underlineToolStripMenuItem1.Click += new System.EventHandler(this.underlineToolStripMenuItem1_Click); // // VobSubOcr // @@ -1878,6 +1994,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr this.splitContainerBottom.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainerBottom)).EndInit(); this.splitContainerBottom.ResumeLayout(false); + this.contextMenuStripTextBox.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -2022,5 +2139,17 @@ namespace Nikse.SubtitleEdit.Forms.Ocr private System.Windows.Forms.Label label3; private System.Windows.Forms.ComboBox comboBoxNOcrLineSplitMinHeight; private System.Windows.Forms.ToolStripMenuItem finalCutProImageToolStripMenuItem; + private System.Windows.Forms.ContextMenuStrip contextMenuStripTextBox; + private System.Windows.Forms.ToolStripMenuItem cutToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem copyToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem pasteToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator18; + private System.Windows.Forms.ToolStripMenuItem selectAllToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator17; + private System.Windows.Forms.ToolStripMenuItem normalToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem boldToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem italicToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem underlineToolStripMenuItem1; } } \ No newline at end of file diff --git a/src/ui/Forms/Ocr/VobSubOcr.cs b/src/ui/Forms/Ocr/VobSubOcr.cs index af49b3de0..270bdc3b5 100644 --- a/src/ui/Forms/Ocr/VobSubOcr.cs +++ b/src/ui/Forms/Ocr/VobSubOcr.cs @@ -1,6 +1,7 @@ using Nikse.SubtitleEdit.Controls; using Nikse.SubtitleEdit.Core; using Nikse.SubtitleEdit.Core.BluRaySup; +using Nikse.SubtitleEdit.Core.Common; using Nikse.SubtitleEdit.Core.ContainerFormats; using Nikse.SubtitleEdit.Core.ContainerFormats.TransportStream; using Nikse.SubtitleEdit.Core.Interfaces; @@ -25,7 +26,6 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; -using Nikse.SubtitleEdit.Core.Common; namespace Nikse.SubtitleEdit.Forms.Ocr { @@ -7333,6 +7333,23 @@ namespace Nikse.SubtitleEdit.Forms.Ocr private void ItalicToolStripMenuItemClick(object sender, EventArgs e) { const string tag = "i"; + var removeTag = true; + if (_subtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) + { + foreach (ListViewItem item in subtitleListView1.SelectedItems) + { + var p = _subtitle.GetParagraphOrDefault(item.Index); + if (p != null) + { + if (!Utilities.RemoveSsaTags(p.Text).StartsWith("")) + { + removeTag = false; + break; + } + } + } + } + if (_subtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) { foreach (ListViewItem item in subtitleListView1.SelectedItems) @@ -7346,7 +7363,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr p.Text = p.Text.Replace("", string.Empty); } - p.Text = $"<{tag}>{p.Text}"; + if (!removeTag) + { + p.Text = $"<{tag}>{p.Text}"; + } + subtitleListView1.SetText(item.Index, p.Text); if (item.Index == _selectedIndex) { @@ -9329,5 +9350,170 @@ namespace Nikse.SubtitleEdit.Forms.Ocr _numericUpDownPixelsIsSpace = (int)numericUpDownNumberOfPixelsIsSpaceNOCR.Value; } + + private void cutToolStripMenuItem_Click(object sender, EventArgs e) + { + textBoxCurrentText.Cut(); + } + + private void copyToolStripMenuItem_Click(object sender, EventArgs e) + { + textBoxCurrentText.Copy(); + } + + private void pasteToolStripMenuItem_Click(object sender, EventArgs e) + { + textBoxCurrentText.Paste(); + } + + private void toolStripMenuItem1_Click(object sender, EventArgs e) + { + textBoxCurrentText.SelectedText = string.Empty; + } + + private void selectAllToolStripMenuItem_Click(object sender, EventArgs e) + { + textBoxCurrentText.SelectAll(); + } + + private void normalToolStripMenuItem1_Click(object sender, EventArgs e) + { + var tb = textBoxCurrentText; + if (tb.SelectionLength == 0) + { + var allText = HtmlUtil.RemoveHtmlTags(tb.Text); + allText = NetflixImsc11Japanese.RemoveTags(allText); + tb.Text = allText; + return; + } + + string text = tb.SelectedText; + int selectionStart = tb.SelectionStart; + text = HtmlUtil.RemoveHtmlTags(text); + text = NetflixImsc11Japanese.RemoveTags(text); + tb.SelectedText = text; + tb.SelectionStart = selectionStart; + tb.SelectionLength = text.Length; + } + + private void TextBoxListViewToggleTag(string tag) + { + var tb = textBoxCurrentText; + string text; + int selectionStart = tb.SelectionStart; + + // No text selected. + if (tb.SelectedText.Length == 0) + { + text = tb.Text; + + // Split lines (split a subtitle into its lines). + var lines = text.SplitToLines(); + + // Get current line index (the line where the cursor is current located). + int numberOfNewLines = 0; + for (int i = 0; i < tb.SelectionStart && i < text.Length; i++) + { + if (text[i] == '\n') + { + numberOfNewLines++; + } + } + int selectedLineIdx = numberOfNewLines; // Do not use 'GetLineFromCharIndex' as it also counts when lines are wrapped + + // Get line from index. + string selectedLine = lines[selectedLineIdx]; + + // Test if line at where cursor is current at is a dialog. + bool isDialog = selectedLine.StartsWith('-') || + selectedLine.StartsWith("<" + tag + ">-", StringComparison.OrdinalIgnoreCase); + + // Will be used keep cursor in its previous location after toggle/untoggle. + int textLen = text.Length; + + // 1st set the cursor position to zero. + tb.SelectionStart = 0; + + // If is dialog, only toggle/Untoggle line where caret/cursor is current at. + if (isDialog) + { + lines[selectedLineIdx] = HtmlUtil.ToggleTag(selectedLine, tag); + text = string.Join(Environment.NewLine, lines); + } + else + { + text = HtmlUtil.ToggleTag(text, tag); + } + + tb.Text = text; + // Note: Math.Max will prevent blowing if caret is at the begining and tag was untoggled. + tb.SelectionStart = textLen > text.Length ? Math.Max(selectionStart - 3, 0) : selectionStart + 3; + } + else + { + string post = string.Empty; + string pre = string.Empty; + // There is text selected + text = tb.SelectedText; + while (text.EndsWith(' ') || text.EndsWith(Environment.NewLine, StringComparison.Ordinal) || text.StartsWith(' ') || text.StartsWith(Environment.NewLine, StringComparison.Ordinal)) + { + if (text.EndsWith(' ')) + { + post += " "; + text = text.Remove(text.Length - 1); + } + + if (text.EndsWith(Environment.NewLine, StringComparison.Ordinal)) + { + post += Environment.NewLine; + text = text.Remove(text.Length - 2); + } + + if (text.StartsWith(' ')) + { + pre += " "; + text = text.Remove(0, 1); + } + + if (text.StartsWith(Environment.NewLine, StringComparison.Ordinal)) + { + pre += Environment.NewLine; + text = text.Remove(0, 2); + } + } + + text = HtmlUtil.ToggleTag(text, tag); + // Update text and maintain selection. + if (pre.Length > 0) + { + text = pre + text; + selectionStart += pre.Length; + } + + if (post.Length > 0) + { + text = text + post; + } + + tb.SelectedText = text; + tb.SelectionStart = selectionStart; + tb.SelectionLength = text.Length; + } + } + + private void boldToolStripMenuItem1_Click(object sender, EventArgs e) + { + TextBoxListViewToggleTag(HtmlUtil.TagBold); + } + + private void italicToolStripMenuItem1_Click(object sender, EventArgs e) + { + TextBoxListViewToggleTag(HtmlUtil.TagItalic); + } + + private void underlineToolStripMenuItem1_Click(object sender, EventArgs e) + { + TextBoxListViewToggleTag(HtmlUtil.TagUnderline); + } } } diff --git a/src/ui/Forms/Ocr/VobSubOcr.resx b/src/ui/Forms/Ocr/VobSubOcr.resx index 2a36e6018..705af8ffe 100644 --- a/src/ui/Forms/Ocr/VobSubOcr.resx +++ b/src/ui/Forms/Ocr/VobSubOcr.resx @@ -144,6 +144,9 @@ 621, 17 + + 339, 56 + 17, 56