From 1e66a57260fe7a3a18337f7053a2499de5f65755 Mon Sep 17 00:00:00 2001 From: niksedk Date: Tue, 10 Jan 2012 07:12:56 +0000 Subject: [PATCH] Some improvements for Remove Text for HI - thx Majid :) git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@915 99eadd0c-20b8-1223-b5c4-2a2b2df33de2 --- src/Forms/RemoveTextFromHearImpaired.cs | 27 +++++++++++++++++++---- src/Test/RemoveTextForHearImpairedTest.cs | 4 ---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Forms/RemoveTextFromHearImpaired.cs b/src/Forms/RemoveTextFromHearImpaired.cs index 3f4b11851..3d77d4728 100644 --- a/src/Forms/RemoveTextFromHearImpaired.cs +++ b/src/Forms/RemoveTextFromHearImpaired.cs @@ -294,6 +294,9 @@ namespace Nikse.SubtitleEdit.Forms string newText = string.Empty; string[] parts = text.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); int noOfNames = 0; + int count = 0; + bool removedInFirstLine = false; + bool removedInSecondLine = false; foreach (string s in parts) { int indexOfColon = s.IndexOf(":"); @@ -332,6 +335,11 @@ namespace Nikse.SubtitleEdit.Forms newText = newText + Environment.NewLine + "(" + content; else newText = newText + Environment.NewLine + content; + + if (count == 0) + removedInFirstLine = true; + else if (count == 1) + removedInSecondLine = true; } newText = newText.Trim(); @@ -378,6 +386,11 @@ namespace Nikse.SubtitleEdit.Forms s2 = s2.Remove(0, colonIndex - endIndex); else if (endIndex > 0) s2 = s2.Remove(endIndex + 1, colonIndex - endIndex); + + if (count == 0) + removedInFirstLine = true; + else if (count == 1) + removedInSecondLine = true; } } newText = newText + Environment.NewLine + s2; @@ -394,6 +407,7 @@ namespace Nikse.SubtitleEdit.Forms newText = "" + newText; } + count++; } newText = newText.Trim(); if (noOfNames > 0 && Utilities.CountTagInText(newText, Environment.NewLine) == 1) @@ -420,6 +434,8 @@ namespace Nikse.SubtitleEdit.Forms insertDash = false; } + if (removedInFirstLine && !removedInSecondLine && !text.StartsWith("-") && !text.StartsWith("-")) + insertDash = false; } if (insertDash) @@ -566,10 +582,13 @@ namespace Nikse.SubtitleEdit.Forms { if (part0.Length > 0 && ".!?".Contains(part0.Substring(part0.Length - 1))) { - if (!st.Pre.Contains("-")) - text = "- " + text.Replace(Environment.NewLine, Environment.NewLine + "- "); - if (!text.Contains(Environment.NewLine + "-") && !text.Contains(Environment.NewLine + "-")) - text = text.Replace(Environment.NewLine, Environment.NewLine + "- "); + if (noOfNamesRemovedNotInLineOne > 0) + { + if (!st.Pre.Contains("-")) + text = "- " + text.Replace(Environment.NewLine, Environment.NewLine + "- "); + if (!text.Contains(Environment.NewLine + "-") && !text.Contains(Environment.NewLine + "-")) + text = text.Replace(Environment.NewLine, Environment.NewLine + "- "); + } } } } diff --git a/src/Test/RemoveTextForHearImpairedTest.cs b/src/Test/RemoveTextForHearImpairedTest.cs index 970eb1d91..f52e8b777 100644 --- a/src/Test/RemoveTextForHearImpairedTest.cs +++ b/src/Test/RemoveTextForHearImpairedTest.cs @@ -157,10 +157,6 @@ namespace Test [DeploymentItem("SubtitleEdit.exe")] public void RemoveHISecondLineDelay() { - var config = new Nikse.SubtitleEdit.Logic.Configuration_Accessor(); - config._settings.RemoveTextForHearingImpaired.RemoveInterjections = false; - config._settings.RemoveTextForHearingImpaired.RemoveTextBeforeColon = true; - config._settings.RemoveTextForHearingImpaired.RemoveTextBetweenCustom = false; FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor(); string text = "- JOHN: Hey." + Environment.NewLine + "- ...hey.";