From 7bcf47b9a5b8a7d3e76838d151102483cb0e83a1 Mon Sep 17 00:00:00 2001 From: niksedk Date: Sat, 4 Nov 2023 18:23:02 +0100 Subject: [PATCH] Work on interjections skip-if-starts-with list - thx darnn :) Work on #7563 --- LanguageBaseEnglish.xml | 2 + .../Forms/RemoveTextForHearImpairedTest.cs | 2 +- src/libse/Common/InterjectionsRepository.cs | 13 +- .../Forms/InterjectionsEditList.Designer.cs | 26 +++- src/ui/Forms/InterjectionsEditList.cs | 19 ++- .../InterjectionsEditSkipList.Designer.cs | 111 ++++++++++++++++ src/ui/Forms/InterjectionsEditSkipList.cs | 54 ++++++++ src/ui/Forms/InterjectionsEditSkipList.resx | 120 ++++++++++++++++++ src/ui/Forms/RemoveTextForHearImpaired.cs | 9 +- src/ui/Logic/Language.cs | 2 + src/ui/Logic/LanguageDeserializer.cs | 6 + src/ui/Logic/LanguageStructure.cs | 2 + src/ui/SubtitleEdit.csproj | 9 ++ 13 files changed, 361 insertions(+), 14 deletions(-) create mode 100644 src/ui/Forms/InterjectionsEditSkipList.Designer.cs create mode 100644 src/ui/Forms/InterjectionsEditSkipList.cs create mode 100644 src/ui/Forms/InterjectionsEditSkipList.resx diff --git a/LanguageBaseEnglish.xml b/LanguageBaseEnglish.xml index 5ffb36db9..6f997b46f 100644 --- a/LanguageBaseEnglish.xml +++ b/LanguageBaseEnglish.xml @@ -1140,6 +1140,8 @@ To use an API key, go to "Options -> Settings -> Tools" to enter your Goog Interjections + Edit skip list... + Interjections will be skipped if source text starts with these: Join subtitles diff --git a/src/Test/Logic/Forms/RemoveTextForHearImpairedTest.cs b/src/Test/Logic/Forms/RemoveTextForHearImpairedTest.cs index 3b04cde91..410309827 100644 --- a/src/Test/Logic/Forms/RemoveTextForHearImpairedTest.cs +++ b/src/Test/Logic/Forms/RemoveTextForHearImpairedTest.cs @@ -70,7 +70,7 @@ namespace Test.Logic.Forms "Uhh", "Uhhh", "Whew", - }); + }, new List()); } } diff --git a/src/libse/Common/InterjectionsRepository.cs b/src/libse/Common/InterjectionsRepository.cs index c7ca72c04..898292c99 100644 --- a/src/libse/Common/InterjectionsRepository.cs +++ b/src/libse/Common/InterjectionsRepository.cs @@ -43,7 +43,7 @@ namespace Nikse.SubtitleEdit.Core.Common }; } - public static void SaveInterjections(string twoLetterIsoLanguageName, List interjections) + public static void SaveInterjections(string twoLetterIsoLanguageName, List interjections, List skipList) { var seFileName = twoLetterIsoLanguageName + SeFileName; var userFileName = twoLetterIsoLanguageName + UserFileName; @@ -59,7 +59,8 @@ namespace Nikse.SubtitleEdit.Core.Common } var xmlDocument = new XmlDocument(); - xmlDocument.LoadXml(""); + xmlDocument.LoadXml(""); + var ignoreNode = xmlDocument.DocumentElement.SelectSingleNode("ignore"); foreach (var w in ignoreList) { @@ -68,6 +69,14 @@ namespace Nikse.SubtitleEdit.Core.Common ignoreNode.AppendChild(node); } + var skipNode = xmlDocument.DocumentElement.SelectSingleNode("skipIfStartsWith"); + foreach (var w in skipList) + { + var node = xmlDocument.CreateElement("text"); + node.InnerText = w; + skipNode.AppendChild(node); + } + foreach (var w in interjections) { if (!se.Contains(w)) diff --git a/src/ui/Forms/InterjectionsEditList.Designer.cs b/src/ui/Forms/InterjectionsEditList.Designer.cs index 0a62fcac4..5986726b5 100644 --- a/src/ui/Forms/InterjectionsEditList.Designer.cs +++ b/src/ui/Forms/InterjectionsEditList.Designer.cs @@ -33,13 +33,14 @@ this.TextBoxInterjections = new Nikse.SubtitleEdit.Controls.NikseTextBox(); this.buttonSort = new System.Windows.Forms.Button(); this.labelInfo = new System.Windows.Forms.Label(); + this.buttonEditSkipList = new System.Windows.Forms.Button(); this.SuspendLayout(); // // buttonCancel // this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.buttonCancel.Location = new System.Drawing.Point(339, 460); + this.buttonCancel.Location = new System.Drawing.Point(395, 460); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 5; @@ -50,7 +51,7 @@ // this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK; - this.buttonOK.Location = new System.Drawing.Point(260, 460); + this.buttonOK.Location = new System.Drawing.Point(316, 460); this.buttonOK.Name = "buttonOK"; this.buttonOK.Size = new System.Drawing.Size(75, 23); this.buttonOK.TabIndex = 4; @@ -68,15 +69,15 @@ this.TextBoxInterjections.Multiline = true; this.TextBoxInterjections.Name = "TextBoxInterjections"; this.TextBoxInterjections.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.TextBoxInterjections.Size = new System.Drawing.Size(282, 406); + this.TextBoxInterjections.Size = new System.Drawing.Size(290, 406); this.TextBoxInterjections.TabIndex = 6; // // buttonSort // this.buttonSort.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonSort.Location = new System.Drawing.Point(311, 42); + this.buttonSort.Location = new System.Drawing.Point(319, 42); this.buttonSort.Name = "buttonSort"; - this.buttonSort.Size = new System.Drawing.Size(106, 23); + this.buttonSort.Size = new System.Drawing.Size(154, 23); this.buttonSort.TabIndex = 23; this.buttonSort.Text = "Sort"; this.buttonSort.UseVisualStyleBackColor = true; @@ -91,11 +92,23 @@ this.labelInfo.TabIndex = 24; this.labelInfo.Text = "Edit all interjections (one interjection on each line)"; // + // buttonEditSkipList + // + this.buttonEditSkipList.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonEditSkipList.Location = new System.Drawing.Point(319, 71); + this.buttonEditSkipList.Name = "buttonEditSkipList"; + this.buttonEditSkipList.Size = new System.Drawing.Size(154, 23); + this.buttonEditSkipList.TabIndex = 27; + this.buttonEditSkipList.Text = "Edit skip list..."; + this.buttonEditSkipList.UseVisualStyleBackColor = true; + this.buttonEditSkipList.Click += new System.EventHandler(this.EditSkipListStartsWithToolStripMenuItem_Click); + // // InterjectionsEditList // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(429, 494); + this.ClientSize = new System.Drawing.Size(485, 494); + this.Controls.Add(this.buttonEditSkipList); this.Controls.Add(this.labelInfo); this.Controls.Add(this.buttonSort); this.Controls.Add(this.TextBoxInterjections); @@ -121,5 +134,6 @@ private Controls.NikseTextBox TextBoxInterjections; private System.Windows.Forms.Button buttonSort; private System.Windows.Forms.Label labelInfo; + private System.Windows.Forms.Button buttonEditSkipList; } } \ No newline at end of file diff --git a/src/ui/Forms/InterjectionsEditList.cs b/src/ui/Forms/InterjectionsEditList.cs index 6911e793b..954fd2d17 100644 --- a/src/ui/Forms/InterjectionsEditList.cs +++ b/src/ui/Forms/InterjectionsEditList.cs @@ -12,12 +12,15 @@ namespace Nikse.SubtitleEdit.Forms public sealed partial class InterjectionsEditList : Form { public List Interjections { get; set; } + public List SkipList { get; set; } - public InterjectionsEditList(List interjections) + public InterjectionsEditList(List interjections, List skipList) { UiUtil.PreInitialize(this); InitializeComponent(); UiUtil.FixFonts(this); + + SkipList = skipList; TextBoxInterjections.Text = string.Join(Environment.NewLine, interjections); Text = LanguageSettings.Current.Interjections.Title; buttonCancel.Text = LanguageSettings.Current.General.Cancel; @@ -65,5 +68,19 @@ namespace Nikse.SubtitleEdit.Forms TextBoxInterjections.SelectionLength = 0; TextBoxInterjections.Focus(); } + + private void EditSkipListStartsWithToolStripMenuItem_Click(object sender, EventArgs e) + { + using (var form = new InterjectionsEditSkipList(SkipList)) + { + var dr = form.ShowDialog(this); + if (dr != DialogResult.OK) + { + return; + } + + SkipList = form.SkipList; + } + } } } \ No newline at end of file diff --git a/src/ui/Forms/InterjectionsEditSkipList.Designer.cs b/src/ui/Forms/InterjectionsEditSkipList.Designer.cs new file mode 100644 index 000000000..24da675cd --- /dev/null +++ b/src/ui/Forms/InterjectionsEditSkipList.Designer.cs @@ -0,0 +1,111 @@ +namespace Nikse.SubtitleEdit.Forms +{ + partial class InterjectionsEditSkipList + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonOK = new System.Windows.Forms.Button(); + this.TextBoxInterjections = new Nikse.SubtitleEdit.Controls.NikseTextBox(); + this.labelInfo = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.buttonCancel.Location = new System.Drawing.Point(339, 460); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "C&ancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // buttonOK + // + this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK; + this.buttonOK.Location = new System.Drawing.Point(260, 460); + this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(75, 23); + this.buttonOK.TabIndex = 4; + this.buttonOK.Text = "&OK"; + this.buttonOK.UseVisualStyleBackColor = true; + this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); + // + // TextBoxInterjections + // + this.TextBoxInterjections.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.TextBoxInterjections.FocusedColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); + this.TextBoxInterjections.Location = new System.Drawing.Point(23, 42); + this.TextBoxInterjections.Multiline = true; + this.TextBoxInterjections.Name = "TextBoxInterjections"; + this.TextBoxInterjections.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.TextBoxInterjections.Size = new System.Drawing.Size(391, 406); + this.TextBoxInterjections.TabIndex = 6; + // + // labelInfo + // + this.labelInfo.AutoSize = true; + this.labelInfo.Location = new System.Drawing.Point(23, 18); + this.labelInfo.Name = "labelInfo"; + this.labelInfo.Size = new System.Drawing.Size(177, 13); + this.labelInfo.TabIndex = 24; + this.labelInfo.Text = "Edit interjections skip list (starts with)"; + // + // InterjectionsEditSkipList + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(429, 494); + this.Controls.Add(this.labelInfo); + this.Controls.Add(this.TextBoxInterjections); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOK); + this.KeyPreview = true; + this.MinimumSize = new System.Drawing.Size(445, 533); + this.Name = "InterjectionsEditSkipList"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Interjections"; + this.Shown += new System.EventHandler(this.InterjectionsEditList_Shown); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Interjections_KeyDown); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.Button buttonOK; + private Controls.NikseTextBox TextBoxInterjections; + private System.Windows.Forms.Label labelInfo; + } +} \ No newline at end of file diff --git a/src/ui/Forms/InterjectionsEditSkipList.cs b/src/ui/Forms/InterjectionsEditSkipList.cs new file mode 100644 index 000000000..10f1bf191 --- /dev/null +++ b/src/ui/Forms/InterjectionsEditSkipList.cs @@ -0,0 +1,54 @@ +using Nikse.SubtitleEdit.Logic; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using Nikse.SubtitleEdit.Core.Common; +using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox; + +namespace Nikse.SubtitleEdit.Forms +{ + public sealed partial class InterjectionsEditSkipList : Form + { + public List SkipList { get; set; } + + public InterjectionsEditSkipList(List skipList) + { + UiUtil.PreInitialize(this); + InitializeComponent(); + UiUtil.FixFonts(this); + TextBoxInterjections.Text = string.Join(Environment.NewLine, skipList); + Text = LanguageSettings.Current.Interjections.EditSkipList.Trim('.'); + labelInfo.Text = LanguageSettings.Current.Interjections.EditSkipListInfo; + buttonCancel.Text = LanguageSettings.Current.General.Cancel; + buttonOK.Text = LanguageSettings.Current.General.Ok; + UiUtil.FixLargeFonts(this, buttonOK); + } + + private void Interjections_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + DialogResult = DialogResult.Cancel; + } + else if (e.KeyData == UiUtil.HelpKeys) + { + UiUtil.ShowHelp("#remove_text_for_hi"); + } + } + + private void buttonOK_Click(object sender, EventArgs e) + { + var lines = TextBoxInterjections.Lines.ToList(); + SkipList = lines.Select(p => p.Trim().ToLowerInvariant().CapitalizeFirstLetter()).Where(p => !string.IsNullOrWhiteSpace(p)).ToList(); + DialogResult = DialogResult.OK; + } + + private void InterjectionsEditList_Shown(object sender, EventArgs e) + { + TextBoxInterjections.SelectionStart = 0; + TextBoxInterjections.SelectionLength = 0; + TextBoxInterjections.Focus(); + } + } +} \ No newline at end of file diff --git a/src/ui/Forms/InterjectionsEditSkipList.resx b/src/ui/Forms/InterjectionsEditSkipList.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/src/ui/Forms/InterjectionsEditSkipList.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/ui/Forms/RemoveTextForHearImpaired.cs b/src/ui/Forms/RemoveTextForHearImpaired.cs index a8858287e..7af29a39d 100644 --- a/src/ui/Forms/RemoveTextForHearImpaired.cs +++ b/src/ui/Forms/RemoveTextForHearImpaired.cs @@ -313,11 +313,12 @@ namespace Nikse.SubtitleEdit.Forms lang = l.Code.TwoLetterISOLanguageName; } - using (var editInterjections = new InterjectionsEditList(InterjectionsRepository.LoadInterjections(lang).Interjections)) + var interjections = InterjectionsRepository.LoadInterjections(lang); + using (var editInterjections = new InterjectionsEditList(interjections.Interjections, interjections.SkipIfStartsWith)) { if (editInterjections.ShowDialog(this) == DialogResult.OK) { - SaveInterjections(editInterjections.Interjections); + SaveInterjections(editInterjections.Interjections, editInterjections.SkipList); if (checkBoxRemoveInterjections.Checked) { GeneratePreview(); @@ -326,7 +327,7 @@ namespace Nikse.SubtitleEdit.Forms } } - private void SaveInterjections(List interjections) + private void SaveInterjections(List interjections, List skipList) { var lang = "en"; if (comboBoxLanguage.SelectedIndex >= 0 && comboBoxLanguage.Items[comboBoxLanguage.SelectedIndex] is LanguageItem l) @@ -334,7 +335,7 @@ namespace Nikse.SubtitleEdit.Forms lang = l.Code.TwoLetterISOLanguageName; } - InterjectionsRepository.SaveInterjections(lang, interjections); + InterjectionsRepository.SaveInterjections(lang, interjections, skipList); } private void FormRemoveTextForHearImpaired_Resize(object sender, EventArgs e) diff --git a/src/ui/Logic/Language.cs b/src/ui/Logic/Language.cs index 2e34d9cc7..39a437e05 100644 --- a/src/ui/Logic/Language.cs +++ b/src/ui/Logic/Language.cs @@ -1409,6 +1409,8 @@ namespace Nikse.SubtitleEdit.Logic Interjections = new LanguageStructure.Interjections { Title = "Interjections", + EditSkipList = "Edit skip list...", + EditSkipListInfo = "Interjections will be skipped if source text starts with these:", }; JoinSubtitles = new LanguageStructure.JoinSubtitles diff --git a/src/ui/Logic/LanguageDeserializer.cs b/src/ui/Logic/LanguageDeserializer.cs index 8404a0026..427b0274d 100644 --- a/src/ui/Logic/LanguageDeserializer.cs +++ b/src/ui/Logic/LanguageDeserializer.cs @@ -2989,6 +2989,12 @@ namespace Nikse.SubtitleEdit.Logic case "Interjections/Title": language.Interjections.Title = reader.Value; break; + case "Interjections/EditSkipList": + language.Interjections.EditSkipList = reader.Value; + break; + case "Interjections/EditSkipListInfo": + language.Interjections.EditSkipListInfo = reader.Value; + break; case "JoinSubtitles/Title": language.JoinSubtitles.Title = reader.Value; break; diff --git a/src/ui/Logic/LanguageStructure.cs b/src/ui/Logic/LanguageStructure.cs index d50dd7f03..c40af3ac2 100644 --- a/src/ui/Logic/LanguageStructure.cs +++ b/src/ui/Logic/LanguageStructure.cs @@ -1231,6 +1231,8 @@ public class Interjections { public string Title { get; set; } + public string EditSkipList { get; set; } + public string EditSkipListInfo { get; set; } } public class JoinSubtitles diff --git a/src/ui/SubtitleEdit.csproj b/src/ui/SubtitleEdit.csproj index 47096493a..ef1019516 100644 --- a/src/ui/SubtitleEdit.csproj +++ b/src/ui/SubtitleEdit.csproj @@ -406,6 +406,12 @@ GenerateVideoWithSoftSubs.cs + + Form + + + InterjectionsEditSkipList.cs + Form @@ -1757,6 +1763,9 @@ GetVideoPosition.cs + + InterjectionsEditSkipList.cs + InterjectionsEditList.cs