2010-10-12 13:17:56 +02:00
|
|
|
|
using System;
|
2011-01-25 13:42:08 +01:00
|
|
|
|
using System.Drawing;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
using System.Text;
|
2011-01-25 13:42:08 +01:00
|
|
|
|
using System.Text.RegularExpressions;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Nikse.SubtitleEdit.Logic;
|
|
|
|
|
|
|
|
|
|
namespace Nikse.SubtitleEdit.Forms
|
|
|
|
|
{
|
|
|
|
|
public sealed partial class FormRemoveTextForHearImpaired : Form
|
|
|
|
|
{
|
|
|
|
|
Subtitle _subtitle;
|
|
|
|
|
readonly LanguageStructure.RemoveTextFromHearImpaired _language;
|
|
|
|
|
|
|
|
|
|
public FormRemoveTextForHearImpaired()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2011-06-02 08:19:36 +02:00
|
|
|
|
checkBoxRemoveTextBeforeColon.Checked = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBeforeColor;
|
|
|
|
|
checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBeforeColorOnlyIfUppercase;
|
|
|
|
|
checkBoxRemoveInterjections.Checked = Configuration.Settings.RemoveTextForHearingImpaired.RemoveInterjections;
|
|
|
|
|
checkBoxRemoveWhereContains.Checked = Configuration.Settings.RemoveTextForHearingImpaired.RemoveIfContains;
|
|
|
|
|
comboBoxRemoveIfTextContains.Text = Configuration.Settings.RemoveTextForHearingImpaired.RemoveIfContainsText;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
|
2011-06-02 08:19:36 +02:00
|
|
|
|
_language = Configuration.Settings.Language.RemoveTextFromHearImpaired;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
Text = _language.Title;
|
|
|
|
|
groupBoxRemoveTextConditions.Text = _language.RemoveTextConditions;
|
|
|
|
|
labelAnd.Text = _language.And;
|
|
|
|
|
labelRemoveTextBetween.Text = _language.RemoveTextBetween;
|
|
|
|
|
checkBoxRemoveTextBeforeColon.Text = _language.RemoveTextBeforeColon;
|
|
|
|
|
checkBoxRemoveTextBeforeColonOnlyUppercase.Text = _language.OnlyIfTextIsUppercase;
|
|
|
|
|
checkBoxOnlyIfInSeparateLine.Text = _language.OnlyIfInSeparateLine;
|
|
|
|
|
checkBoxRemoveTextBetweenBrackets.Text = _language.Brackets;
|
|
|
|
|
checkBoxRemoveTextBetweenParentheses.Text = _language.Parentheses;
|
|
|
|
|
checkBoxRemoveTextBetweenQuestionMarks.Text = _language.QuestionMarks;
|
|
|
|
|
checkBoxRemoveTextBetweenSquares.Text = _language.SquareBrackets;
|
2011-01-25 13:42:08 +01:00
|
|
|
|
checkBoxRemoveWhereContains.Text = _language.RemoveTextIfContains;
|
|
|
|
|
checkBoxRemoveInterjections.Text = _language.RemoveInterjections;
|
|
|
|
|
buttonEditInterjections.Text = _language.EditInterjections;
|
|
|
|
|
buttonEditInterjections.Left = checkBoxRemoveInterjections.Left + checkBoxRemoveInterjections.Width;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
listViewFixes.Columns[0].Text = Configuration.Settings.Language.General.Apply;
|
|
|
|
|
listViewFixes.Columns[1].Text = _language.LineNumber;
|
|
|
|
|
listViewFixes.Columns[2].Text = _language.Before;
|
|
|
|
|
listViewFixes.Columns[3].Text = _language.After;
|
|
|
|
|
buttonOK.Text = Configuration.Settings.Language.General.OK;
|
|
|
|
|
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
|
2010-12-30 20:20:33 +01:00
|
|
|
|
FixLargeFonts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FixLargeFonts()
|
|
|
|
|
{
|
|
|
|
|
Graphics graphics = this.CreateGraphics();
|
|
|
|
|
SizeF textSize = graphics.MeasureString(buttonOK.Text, this.Font);
|
|
|
|
|
if (textSize.Height > buttonOK.Height - 4)
|
|
|
|
|
{
|
|
|
|
|
int newButtonHeight = (int)(textSize.Height + 7 + 0.5);
|
|
|
|
|
Utilities.SetButtonHeight(this, newButtonHeight, 1);
|
|
|
|
|
}
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string RemoveStartEndNoise(string text)
|
|
|
|
|
{
|
|
|
|
|
string s = text.Trim();
|
|
|
|
|
if (s.StartsWith("<b>") && s.Length > 3)
|
|
|
|
|
s = s.Substring(3);
|
|
|
|
|
if (s.StartsWith("<i>") && s.Length > 3)
|
|
|
|
|
s = s.Substring(3);
|
|
|
|
|
if (s.StartsWith("<u>") && s.Length > 3)
|
|
|
|
|
s = s.Substring(3);
|
|
|
|
|
if (s.StartsWith("<B>") && s.Length > 3)
|
|
|
|
|
s = s.Substring(3);
|
|
|
|
|
if (s.StartsWith("<I>") && s.Length > 3)
|
|
|
|
|
s = s.Substring(3);
|
|
|
|
|
if (s.StartsWith("<U>") && s.Length > 3)
|
|
|
|
|
s = s.Substring(3);
|
|
|
|
|
|
|
|
|
|
if (s.EndsWith("</b>") && s.Length > 4)
|
|
|
|
|
s = s.Substring(0, s.Length-4);
|
|
|
|
|
if (s.EndsWith("</i>") && s.Length > 4)
|
|
|
|
|
s = s.Substring(0, s.Length-4);
|
|
|
|
|
if (s.EndsWith("</u>") && s.Length > 4)
|
|
|
|
|
s = s.Substring(0, s.Length-4);
|
|
|
|
|
if (s.EndsWith("</B>") && s.Length > 4)
|
|
|
|
|
s = s.Substring(0, s.Length-4);
|
|
|
|
|
if (s.EndsWith("</I>") && s.Length > 4)
|
|
|
|
|
s = s.Substring(0, s.Length-4);
|
|
|
|
|
if (s.EndsWith("</U>") && s.Length > 4)
|
|
|
|
|
s = s.Substring(0, s.Length-4);
|
|
|
|
|
|
|
|
|
|
if (s.StartsWith("-") && s.Length > 2)
|
|
|
|
|
s = s.TrimStart('-');
|
2011-10-06 21:22:35 +02:00
|
|
|
|
|
2010-10-12 13:17:56 +02:00
|
|
|
|
return s.Trim();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-06 20:11:59 +02:00
|
|
|
|
private string RemoveTextBetweenTags(string startTag, string endTag, string text)
|
|
|
|
|
{
|
2011-06-14 20:02:37 +02:00
|
|
|
|
text = text.Trim();
|
2011-05-06 20:11:59 +02:00
|
|
|
|
if (startTag == "?" || endTag == "?")
|
|
|
|
|
{
|
|
|
|
|
if (text.StartsWith(startTag) && text.EndsWith(endTag))
|
|
|
|
|
return string.Empty;
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int start = text.IndexOf(startTag);
|
|
|
|
|
if (start == -1 || start == text.Length - 1)
|
|
|
|
|
return text;
|
|
|
|
|
|
|
|
|
|
int end = text.IndexOf(endTag, start + 1);
|
|
|
|
|
while (start >= 0 && end > start)
|
|
|
|
|
{
|
|
|
|
|
text = text.Remove(start, (end - start)+1);
|
|
|
|
|
start = text.IndexOf(startTag);
|
|
|
|
|
if (start >= 0 && start < text.Length - 1)
|
|
|
|
|
end = text.IndexOf(endTag, start);
|
|
|
|
|
else
|
|
|
|
|
end = -1;
|
|
|
|
|
}
|
|
|
|
|
return text.Replace(" " + Environment.NewLine, Environment.NewLine).TrimEnd();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string RemoveHearImpairedTags(string text)
|
|
|
|
|
{
|
|
|
|
|
if (checkBoxRemoveTextBetweenSquares.Checked)
|
|
|
|
|
{
|
|
|
|
|
text = RemoveTextBetweenTags("[", "]:", text);
|
|
|
|
|
text = RemoveTextBetweenTags("[", "]", text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (checkBoxRemoveTextBetweenBrackets.Checked)
|
|
|
|
|
{
|
|
|
|
|
text = RemoveTextBetweenTags("{", "}:", text);
|
|
|
|
|
text = RemoveTextBetweenTags("{", "}", text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (checkBoxRemoveTextBetweenQuestionMarks.Checked)
|
2011-10-06 21:22:35 +02:00
|
|
|
|
{
|
2011-05-06 20:11:59 +02:00
|
|
|
|
text = RemoveTextBetweenTags("?", "?:", text);
|
|
|
|
|
text = RemoveTextBetweenTags("?", "?", text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (checkBoxRemoveTextBetweenParentheses.Checked)
|
|
|
|
|
{
|
|
|
|
|
text = RemoveTextBetweenTags("(", "):", text);
|
|
|
|
|
text = RemoveTextBetweenTags("(", ")", text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (checkBoxRemoveTextBetweenCustomTags.Checked && comboBoxCustomStart.Text.Length > 0 && comboBoxCustomEnd.Text.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
text = RemoveTextBetweenTags(comboBoxCustomStart.Text, comboBoxCustomEnd.Text, text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool HasHearImpairedText(string text)
|
|
|
|
|
{
|
|
|
|
|
return RemoveHearImpairedTags(text) != text;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-12 13:17:56 +02:00
|
|
|
|
public bool HasHearImpariedTagsAtStart(string text)
|
|
|
|
|
{
|
|
|
|
|
if (checkBoxOnlyIfInSeparateLine.Checked)
|
|
|
|
|
return StartAndEndsWithHearImpariedTags(text);
|
2011-05-06 20:11:59 +02:00
|
|
|
|
|
|
|
|
|
return HasHearImpairedText(text);
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasHearImpariedTagsAtEnd(string text)
|
|
|
|
|
{
|
|
|
|
|
if (checkBoxOnlyIfInSeparateLine.Checked)
|
|
|
|
|
return StartAndEndsWithHearImpariedTags(text);
|
|
|
|
|
|
2011-05-06 20:11:59 +02:00
|
|
|
|
return HasHearImpairedText(text);
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool StartAndEndsWithHearImpariedTags(string text)
|
|
|
|
|
{
|
|
|
|
|
return (text.StartsWith("[") && text.EndsWith("]") && checkBoxRemoveTextBetweenSquares.Checked) ||
|
|
|
|
|
(text.StartsWith("{") && text.EndsWith("}") && checkBoxRemoveTextBetweenBrackets.Checked) ||
|
|
|
|
|
(text.StartsWith("?") && text.EndsWith("?") && checkBoxRemoveTextBetweenQuestionMarks.Checked) ||
|
|
|
|
|
(text.StartsWith("(") && text.EndsWith(")") && checkBoxRemoveTextBetweenParentheses.Checked) ||
|
|
|
|
|
(text.StartsWith("[") && text.EndsWith("]:") && checkBoxRemoveTextBetweenSquares.Checked) ||
|
|
|
|
|
(text.StartsWith("{") && text.EndsWith("}:") && checkBoxRemoveTextBetweenBrackets.Checked) ||
|
|
|
|
|
(text.StartsWith("?") && text.EndsWith("?:") && checkBoxRemoveTextBetweenQuestionMarks.Checked) ||
|
|
|
|
|
(text.StartsWith("(") && text.EndsWith("):") && checkBoxRemoveTextBetweenParentheses.Checked) ||
|
|
|
|
|
(checkBoxRemoveTextBetweenCustomTags.Checked &&
|
|
|
|
|
comboBoxCustomStart.Text.Length > 0 && comboBoxCustomEnd.Text.Length > 0 &&
|
|
|
|
|
text.StartsWith(comboBoxCustomStart.Text) && text.EndsWith(comboBoxCustomEnd.Text));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Initialize(Subtitle subtitle)
|
|
|
|
|
{
|
|
|
|
|
if (Environment.OSVersion.Version.Major < 6) // 6 == Vista/Win2008Server/Win7
|
|
|
|
|
{
|
2011-01-25 19:47:14 +01:00
|
|
|
|
string unicodeFontName = Utilities.WinXp2kUnicodeFontName;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
float fontSize = comboBoxCustomStart.Font.Size;
|
|
|
|
|
comboBoxCustomStart.Font = new System.Drawing.Font(unicodeFontName, fontSize);
|
|
|
|
|
comboBoxCustomEnd.Font = new System.Drawing.Font(unicodeFontName, fontSize);
|
|
|
|
|
comboBoxRemoveIfTextContains.Font = new System.Drawing.Font(unicodeFontName, fontSize);
|
|
|
|
|
}
|
|
|
|
|
comboBoxRemoveIfTextContains.Left = checkBoxRemoveWhereContains.Left + checkBoxRemoveWhereContains.Width;
|
|
|
|
|
|
|
|
|
|
_subtitle = subtitle;
|
|
|
|
|
GeneratePreview();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GeneratePreview()
|
|
|
|
|
{
|
2011-06-02 08:19:36 +02:00
|
|
|
|
if (_subtitle == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-10-12 13:17:56 +02:00
|
|
|
|
listViewFixes.BeginUpdate();
|
|
|
|
|
listViewFixes.Items.Clear();
|
|
|
|
|
int count = 0;
|
|
|
|
|
foreach (Paragraph p in _subtitle.Paragraphs)
|
|
|
|
|
{
|
2011-09-05 19:44:43 +02:00
|
|
|
|
string newText = RemoveTextFromHearImpaired(p.Text);
|
|
|
|
|
bool hit = p.Text.Replace(" ", string.Empty) != newText.Replace(" ", string.Empty);
|
2010-10-12 13:17:56 +02:00
|
|
|
|
if (hit)
|
|
|
|
|
{
|
|
|
|
|
count++;
|
|
|
|
|
AddToListView(p, newText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
listViewFixes.EndUpdate();
|
|
|
|
|
groupBoxLinesFound.Text = string.Format(_language.LinesFoundX, count);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:50:42 +01:00
|
|
|
|
private string RemoveHearImpairedtagsInsideLine(string newText)
|
|
|
|
|
{
|
|
|
|
|
int i = 5;
|
|
|
|
|
while (i < newText.Length)
|
|
|
|
|
{
|
|
|
|
|
string s = newText.Substring(i);
|
|
|
|
|
if (i > 5 && s.Length > 2 && (s.StartsWith(".") || s.StartsWith("!") || s.StartsWith("?")))
|
|
|
|
|
{
|
|
|
|
|
if (s[1] == ' ' || s.Substring(1).StartsWith("<i>") || s.Substring(1).StartsWith("</i>"))
|
|
|
|
|
{
|
|
|
|
|
string pre = " ";
|
|
|
|
|
if (s.Substring(1).StartsWith("<i>"))
|
|
|
|
|
pre = "<i>";
|
|
|
|
|
else if (s.Substring(1).StartsWith(" <i>"))
|
|
|
|
|
pre = " <i>";
|
|
|
|
|
else if (s.Substring(1).StartsWith("</i>"))
|
|
|
|
|
pre = "</i>";
|
|
|
|
|
|
|
|
|
|
s = s.Remove(0, 1 + pre.Length);
|
|
|
|
|
if (s.StartsWith(" ") && s.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
pre += " ";
|
|
|
|
|
s = s.Remove(0, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (HasHearImpariedTagsAtStart(s))
|
|
|
|
|
{
|
|
|
|
|
s = RemoveStartEndTags(s);
|
|
|
|
|
newText = newText.Substring(0, i+1) + pre + " " + s;
|
|
|
|
|
newText = newText.Replace("<i></i>", string.Empty);
|
|
|
|
|
newText = newText.Replace("<i> </i>", " ");
|
|
|
|
|
newText = newText.Replace(" ", " ");
|
|
|
|
|
newText = newText.Replace(" ", " ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return newText;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-12 13:17:56 +02:00
|
|
|
|
private string RemoveColon(string text)
|
|
|
|
|
{
|
2011-06-16 07:10:41 +02:00
|
|
|
|
if (!checkBoxRemoveTextBeforeColon.Checked)
|
|
|
|
|
return text;
|
|
|
|
|
|
2011-06-14 20:02:37 +02:00
|
|
|
|
if (text.IndexOf(":") < 0)
|
|
|
|
|
return text;
|
|
|
|
|
|
2010-10-12 13:17:56 +02:00
|
|
|
|
// House 7x01 line 52: and she would like you to do three things:
|
|
|
|
|
// Okay or remove???
|
|
|
|
|
if (text.IndexOf(':') > 0 && text.IndexOf(':') == text.Length - 1 && text != text.ToUpper())
|
|
|
|
|
return text;
|
|
|
|
|
|
2011-06-14 20:02:37 +02:00
|
|
|
|
string newText = string.Empty;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
string[] parts = text.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
2011-06-14 20:02:37 +02:00
|
|
|
|
int noOfNames = 0;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
foreach (string s in parts)
|
|
|
|
|
{
|
2011-06-14 20:02:37 +02:00
|
|
|
|
int indexOfColon = s.IndexOf(":");
|
|
|
|
|
if (indexOfColon > 0)
|
2010-10-12 13:17:56 +02:00
|
|
|
|
{
|
2011-06-14 20:02:37 +02:00
|
|
|
|
string pre = s.Substring(0, indexOfColon);
|
|
|
|
|
if (checkBoxRemoveTextBeforeColonOnlyUppercase.Checked && pre.Replace("<i>", string.Empty) != pre.Replace("<i>", string.Empty).ToUpper())
|
2010-10-12 13:17:56 +02:00
|
|
|
|
{
|
2011-06-14 20:02:37 +02:00
|
|
|
|
newText = newText + Environment.NewLine + s;
|
|
|
|
|
newText = newText.Trim();
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
2011-06-14 20:02:37 +02:00
|
|
|
|
else
|
2010-10-12 13:17:56 +02:00
|
|
|
|
{
|
2011-06-14 20:02:37 +02:00
|
|
|
|
StripableText st = new StripableText(pre);
|
2011-06-15 23:19:32 +02:00
|
|
|
|
if (Utilities.CountTagInText(s, ":") == 1)
|
2010-10-28 21:22:55 +02:00
|
|
|
|
{
|
2011-06-15 23:19:32 +02:00
|
|
|
|
bool remove = true;
|
|
|
|
|
if (indexOfColon > 0 && indexOfColon < s.Length - 1)
|
|
|
|
|
{
|
|
|
|
|
if ("1234567890".Contains(s.Substring(indexOfColon - 1, 1)) && "1234567890".Contains(s.Substring(indexOfColon + 1, 1)))
|
|
|
|
|
remove = false;
|
|
|
|
|
}
|
2011-09-08 10:52:04 +02:00
|
|
|
|
if (s.StartsWith("Previously on") || s.StartsWith("<i>Previously on"))
|
|
|
|
|
remove = false;
|
|
|
|
|
|
2011-06-15 23:19:32 +02:00
|
|
|
|
if (remove)
|
|
|
|
|
{
|
|
|
|
|
string content = s.Substring(indexOfColon + 1).Trim();
|
|
|
|
|
if (content != string.Empty)
|
2011-06-16 07:10:41 +02:00
|
|
|
|
{
|
2011-09-01 21:18:40 +02:00
|
|
|
|
if (pre.Contains("<i>") && content.Contains("</i>"))
|
2011-06-16 07:10:41 +02:00
|
|
|
|
newText = newText + Environment.NewLine + "<i>" + content;
|
2011-09-01 21:18:40 +02:00
|
|
|
|
else if (pre.Contains("[") && content.Contains("]"))
|
|
|
|
|
newText = newText + Environment.NewLine + "[" + content;
|
|
|
|
|
else if (pre.Contains("(") && content.EndsWith(")"))
|
|
|
|
|
newText = newText + Environment.NewLine + "(" + content;
|
2011-06-16 07:10:41 +02:00
|
|
|
|
else
|
|
|
|
|
newText = newText + Environment.NewLine + content;
|
|
|
|
|
}
|
2011-06-15 23:19:32 +02:00
|
|
|
|
newText = newText.Trim();
|
2011-08-09 00:08:50 +02:00
|
|
|
|
|
|
|
|
|
if (text.StartsWith("(") && newText.EndsWith(")") && !newText.Contains("("))
|
|
|
|
|
newText = newText.TrimEnd(')');
|
2011-09-08 10:52:04 +02:00
|
|
|
|
else if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
|
|
|
|
|
newText = "<i>" + newText;
|
2011-08-09 00:08:50 +02:00
|
|
|
|
|
2011-06-15 23:19:32 +02:00
|
|
|
|
if (!IsHIDescription(st.StrippedText))
|
|
|
|
|
noOfNames++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
newText = newText + Environment.NewLine + s;
|
|
|
|
|
newText = newText.Trim();
|
2011-09-08 10:52:04 +02:00
|
|
|
|
if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
|
|
|
|
|
newText = "<i>" + newText;
|
2011-06-15 23:19:32 +02:00
|
|
|
|
}
|
2010-10-28 21:22:55 +02:00
|
|
|
|
}
|
2011-06-15 23:19:32 +02:00
|
|
|
|
else
|
2010-10-12 13:17:56 +02:00
|
|
|
|
{
|
2011-06-15 23:19:32 +02:00
|
|
|
|
|
|
|
|
|
string s2 = s;
|
|
|
|
|
for (int k = 0; k < 2; k++)
|
2010-10-12 13:17:56 +02:00
|
|
|
|
{
|
2011-06-15 23:19:32 +02:00
|
|
|
|
if (s2.Contains(":"))
|
2010-10-12 13:17:56 +02:00
|
|
|
|
{
|
2011-06-15 23:19:32 +02:00
|
|
|
|
int colonIndex = s2.IndexOf(":");
|
|
|
|
|
string start = s2.Substring(0, colonIndex);
|
|
|
|
|
int periodIndex = start.LastIndexOf(". ");
|
|
|
|
|
int questIndex = start.LastIndexOf("? ");
|
|
|
|
|
int exclaIndex = start.LastIndexOf("! ");
|
|
|
|
|
int endIndex = periodIndex;
|
|
|
|
|
if (endIndex == -1 || questIndex > endIndex)
|
|
|
|
|
endIndex = questIndex;
|
|
|
|
|
if (endIndex == -1 || exclaIndex > endIndex)
|
|
|
|
|
endIndex = exclaIndex;
|
|
|
|
|
if (colonIndex > 0 && colonIndex < s2.Length - 1)
|
|
|
|
|
{
|
|
|
|
|
if ("1234567890".Contains(s2.Substring(colonIndex - 1, 1)) && "1234567890".Contains(s2.Substring(colonIndex + 1, 1)))
|
|
|
|
|
endIndex = -10;
|
|
|
|
|
}
|
|
|
|
|
if (endIndex == -1)
|
|
|
|
|
s2 = s2.Remove(0, colonIndex - endIndex);
|
|
|
|
|
else if (endIndex > 0)
|
|
|
|
|
s2 = s2.Remove(endIndex + 1, colonIndex - endIndex);
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-15 23:19:32 +02:00
|
|
|
|
newText = newText + Environment.NewLine + s2;
|
|
|
|
|
newText = newText.Trim();
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-06-14 20:02:37 +02:00
|
|
|
|
newText = newText + Environment.NewLine + s;
|
|
|
|
|
newText = newText.Trim();
|
2011-09-08 10:52:04 +02:00
|
|
|
|
|
|
|
|
|
if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
|
|
|
|
|
newText = "<i>" + newText;
|
|
|
|
|
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-14 20:02:37 +02:00
|
|
|
|
newText = newText.Trim();
|
|
|
|
|
if (noOfNames > 0 && Utilities.CountTagInText(newText, Environment.NewLine) == 1)
|
2011-10-06 21:22:35 +02:00
|
|
|
|
{
|
2011-06-14 20:02:37 +02:00
|
|
|
|
int indexOfDialogChar = newText.IndexOf('-');
|
2011-06-15 23:19:32 +02:00
|
|
|
|
bool insertDash = true;
|
2011-10-06 21:22:35 +02:00
|
|
|
|
string[] arr = newText.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
2011-06-15 23:19:32 +02:00
|
|
|
|
if (arr.Length == 2 && arr[0].Length > 1 && arr[1].Length > 1)
|
2010-10-12 13:17:56 +02:00
|
|
|
|
{
|
2011-06-16 07:10:41 +02:00
|
|
|
|
string arr0 = new StripableText(arr[0]).StrippedText;
|
|
|
|
|
string arr1 = new StripableText(arr[1]).StrippedText;
|
2011-06-25 11:11:11 +02:00
|
|
|
|
if (arr0.Length > 0 && arr1.Length > 1 && (Utilities.GetLetters(false, true, false) + ",").Contains(arr0.Substring(arr0.Length - 1)) &&
|
2011-06-15 23:19:32 +02:00
|
|
|
|
Utilities.GetLetters(false, true, false).Contains(arr1.Substring(0, 1)))
|
|
|
|
|
{
|
|
|
|
|
insertDash = false;
|
|
|
|
|
}
|
2011-06-25 11:11:11 +02:00
|
|
|
|
|
|
|
|
|
if (arr0.Length > 0 && arr1.Length > 1 && !(arr[0].EndsWith(".") || arr[0].EndsWith("!") || arr[0].EndsWith("?") || arr[0].EndsWith("</i>")) &&
|
|
|
|
|
!(new StripableText(arr[1]).Pre.Contains("-")))
|
|
|
|
|
{
|
|
|
|
|
insertDash = false;
|
|
|
|
|
}
|
2011-10-06 21:22:35 +02:00
|
|
|
|
|
2011-06-14 20:02:37 +02:00
|
|
|
|
}
|
2011-06-15 23:19:32 +02:00
|
|
|
|
|
|
|
|
|
if (insertDash)
|
2011-06-14 20:02:37 +02:00
|
|
|
|
{
|
2011-06-18 08:19:36 +02:00
|
|
|
|
if (indexOfDialogChar < 0 || indexOfDialogChar > 4)
|
2011-06-15 23:19:32 +02:00
|
|
|
|
{
|
|
|
|
|
StripableText st = new StripableText(newText, "", "");
|
|
|
|
|
newText = st.Pre + "- " + st.StrippedText + st.Post;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int indexOfNewLine = newText.IndexOf(Environment.NewLine);
|
|
|
|
|
string second = newText.Substring(indexOfNewLine).Trim();
|
|
|
|
|
indexOfDialogChar = second.IndexOf('-');
|
|
|
|
|
if (indexOfDialogChar < 0 || indexOfDialogChar > 6)
|
|
|
|
|
{
|
|
|
|
|
StripableText st = new StripableText(second, "", "");
|
|
|
|
|
second = st.Pre + "- " + st.StrippedText + st.Post;
|
|
|
|
|
newText = newText.Remove(indexOfNewLine) + Environment.NewLine + second;
|
|
|
|
|
}
|
2011-06-14 20:02:37 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!newText.Contains(Environment.NewLine) && newText.Contains("-"))
|
|
|
|
|
{
|
|
|
|
|
StripableText st = new StripableText(newText);
|
|
|
|
|
if (st.Pre.Contains("-"))
|
|
|
|
|
newText = st.Pre.Replace("-", string.Empty) + st.StrippedText + st.Post;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
return newText;
|
|
|
|
|
}
|
2011-10-06 21:22:35 +02:00
|
|
|
|
|
2011-06-15 23:19:32 +02:00
|
|
|
|
internal string RemoveTextFromHearImpaired(string text)
|
2010-10-12 13:17:56 +02:00
|
|
|
|
{
|
|
|
|
|
if (checkBoxRemoveWhereContains.Checked && comboBoxRemoveIfTextContains.Text.Length > 0 && text.Contains(comboBoxRemoveIfTextContains.Text))
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string oldText = text;
|
|
|
|
|
text = RemoveColon(text);
|
2011-06-14 20:02:37 +02:00
|
|
|
|
string pre = " >-\"'‘`´♪¿¡.…—";
|
|
|
|
|
string post = " -\"'`´♪.!?:…—";
|
|
|
|
|
if (checkBoxRemoveTextBetweenCustomTags.Checked)
|
|
|
|
|
{
|
|
|
|
|
pre = pre.Replace(comboBoxCustomStart.Text, string.Empty);
|
|
|
|
|
post = post.Replace(comboBoxCustomEnd.Text, string.Empty);
|
|
|
|
|
}
|
|
|
|
|
StripableText st = new StripableText(text, pre, post);
|
2010-10-12 13:17:56 +02:00
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
string[] parts = st.StrippedText.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
2010-12-04 14:07:02 +01:00
|
|
|
|
int lineNumber = 0;
|
2011-06-15 23:19:32 +02:00
|
|
|
|
bool removedDialogInFirstLine = false;
|
2011-06-14 20:02:37 +02:00
|
|
|
|
int noOfNamesRemoved = 0;
|
2011-06-15 23:19:32 +02:00
|
|
|
|
int noOfNamesRemovedNotInLineOne = 0;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
foreach (string s in parts)
|
2011-01-18 07:36:30 +01:00
|
|
|
|
{
|
2011-06-14 20:02:37 +02:00
|
|
|
|
StripableText stSub = new StripableText(s, pre, post);
|
2010-10-12 13:17:56 +02:00
|
|
|
|
if (!StartAndEndsWithHearImpariedTags(stSub.StrippedText))
|
|
|
|
|
{
|
2010-12-04 14:07:02 +01:00
|
|
|
|
if (removedDialogInFirstLine && stSub.Pre.Contains("- "))
|
|
|
|
|
stSub.Pre = stSub.Pre.Replace("- ", string.Empty);
|
|
|
|
|
|
2010-10-12 13:17:56 +02:00
|
|
|
|
string newText = stSub.StrippedText;
|
2011-06-14 20:02:37 +02:00
|
|
|
|
|
2011-05-06 20:11:59 +02:00
|
|
|
|
newText = RemoveHearImpairedTags(newText);
|
2011-06-14 20:02:37 +02:00
|
|
|
|
|
|
|
|
|
if (stSub.StrippedText.Length - newText.Length > 2)
|
|
|
|
|
{
|
|
|
|
|
string removedText = GetRemovedString(stSub.StrippedText, newText);
|
|
|
|
|
if (!IsHIDescription(removedText))
|
2011-06-15 23:19:32 +02:00
|
|
|
|
{
|
2011-06-14 20:02:37 +02:00
|
|
|
|
noOfNamesRemoved++;
|
2011-06-15 23:19:32 +02:00
|
|
|
|
if (lineNumber > 0)
|
|
|
|
|
noOfNamesRemovedNotInLineOne++;
|
|
|
|
|
}
|
2011-06-14 20:02:37 +02:00
|
|
|
|
}
|
2010-10-12 13:17:56 +02:00
|
|
|
|
sb.AppendLine(stSub.Pre + newText + stSub.Post);
|
|
|
|
|
}
|
2010-12-04 14:07:02 +01:00
|
|
|
|
else
|
2010-10-12 13:17:56 +02:00
|
|
|
|
{
|
2011-06-14 20:02:37 +02:00
|
|
|
|
if (!IsHIDescription(stSub.StrippedText))
|
2011-06-15 23:19:32 +02:00
|
|
|
|
{
|
2011-06-14 20:02:37 +02:00
|
|
|
|
noOfNamesRemoved++;
|
2011-06-15 23:19:32 +02:00
|
|
|
|
if (lineNumber > 0)
|
|
|
|
|
noOfNamesRemovedNotInLineOne++;
|
|
|
|
|
}
|
2011-06-14 20:02:37 +02:00
|
|
|
|
|
2010-12-04 14:07:02 +01:00
|
|
|
|
if (st.Pre.Contains("- ") && lineNumber == 0)
|
|
|
|
|
{
|
|
|
|
|
st.Pre = st.Pre.Replace("- ", string.Empty);
|
|
|
|
|
removedDialogInFirstLine = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (st.Pre.Contains("<i>") && stSub.Post.Contains("</i>"))
|
|
|
|
|
st.Pre = st.Pre.Replace("<i>", string.Empty);
|
2011-09-09 21:53:21 +02:00
|
|
|
|
|
|
|
|
|
if (s.Contains("<i>") && !s.Contains("</i>") && st.Post.Contains("</i>"))
|
|
|
|
|
st.Post = st.Post.Replace("</i>", string.Empty);
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
2010-12-04 14:07:02 +01:00
|
|
|
|
lineNumber++;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
text = st.Pre + sb.ToString().Trim() + st.Post;
|
2011-09-09 21:53:21 +02:00
|
|
|
|
text = text.Replace("<i></i>", string.Empty).Trim();
|
2010-10-12 13:17:56 +02:00
|
|
|
|
text = RemoveColon(text);
|
2011-02-01 18:50:42 +01:00
|
|
|
|
text = RemoveHearImpairedtagsInsideLine(text);
|
2011-01-25 13:42:08 +01:00
|
|
|
|
if (checkBoxRemoveInterjections.Checked)
|
|
|
|
|
text = RemoveInterjections(text);
|
2010-10-12 13:17:56 +02:00
|
|
|
|
|
2011-01-18 07:36:30 +01:00
|
|
|
|
st = new StripableText(text, " >-\"'‘`´♪¿¡.…—", " -\"'`´♪.!?:…—");
|
2010-10-12 13:17:56 +02:00
|
|
|
|
text = st.StrippedText;
|
|
|
|
|
if (StartAndEndsWithHearImpariedTags(text))
|
|
|
|
|
{
|
|
|
|
|
text = RemoveStartEndTags(text);
|
|
|
|
|
}
|
2011-06-14 20:02:37 +02:00
|
|
|
|
|
2011-06-16 07:10:41 +02:00
|
|
|
|
|
|
|
|
|
text = RemoveHearImpairedTags(text);
|
|
|
|
|
|
2011-10-06 21:22:35 +02:00
|
|
|
|
// fix 3 lines to two liners - if only two lines
|
2011-06-15 23:19:32 +02:00
|
|
|
|
if (noOfNamesRemoved >= 1 && Utilities.CountTagInText(text, Environment.NewLine) == 2)
|
|
|
|
|
{
|
|
|
|
|
string[] a = Utilities.RemoveHtmlTags(text).Replace(" ", string.Empty).Split("!?.".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
if (a.Length == 2)
|
|
|
|
|
{
|
|
|
|
|
StripableText temp = new StripableText(text);
|
|
|
|
|
temp.StrippedText = temp.StrippedText.Replace(Environment.NewLine, " ");
|
|
|
|
|
int splitIndex = temp.StrippedText.LastIndexOf("!");
|
|
|
|
|
if (splitIndex == -1)
|
|
|
|
|
splitIndex = temp.StrippedText.LastIndexOf("?");
|
|
|
|
|
if (splitIndex == -1)
|
|
|
|
|
splitIndex = temp.StrippedText.LastIndexOf(".");
|
|
|
|
|
if (splitIndex > 0)
|
|
|
|
|
{
|
|
|
|
|
text = temp.Pre + temp.StrippedText.Insert(splitIndex + 1, Environment.NewLine) + temp.Post;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!text.StartsWith("-") && noOfNamesRemoved >= 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1)
|
2011-06-14 20:02:37 +02:00
|
|
|
|
{
|
|
|
|
|
string[] arr = text.Split(Environment.NewLine.ToCharArray());
|
|
|
|
|
string part0 = arr[0].Trim().Replace("</i>", string.Empty).Trim();
|
2011-06-15 23:19:32 +02:00
|
|
|
|
if (!part0.EndsWith(",") && (!part0.EndsWith("-") || noOfNamesRemovedNotInLineOne > 0))
|
|
|
|
|
{
|
2011-06-27 15:27:28 +02:00
|
|
|
|
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 + "<i>-"))
|
|
|
|
|
text = text.Replace(Environment.NewLine, Environment.NewLine + "- ");
|
|
|
|
|
}
|
2011-06-15 23:19:32 +02:00
|
|
|
|
}
|
2011-06-14 20:02:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-12 13:17:56 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(text))
|
|
|
|
|
text = st.Pre + text + st.Post;
|
|
|
|
|
|
|
|
|
|
if (oldText.Trim().StartsWith("- ") &&
|
|
|
|
|
(oldText.Contains(Environment.NewLine + "- ") || oldText.Contains(Environment.NewLine + " - ")) &&
|
|
|
|
|
text != null && !text.Contains(Environment.NewLine))
|
|
|
|
|
{
|
|
|
|
|
text = text.TrimStart().TrimStart('-').TrimStart();
|
|
|
|
|
}
|
2011-06-14 20:02:37 +02:00
|
|
|
|
|
2011-06-15 23:19:32 +02:00
|
|
|
|
// insert spaces before "-"
|
2011-06-14 20:02:37 +02:00
|
|
|
|
text = text.Replace(Environment.NewLine + "- <i>", Environment.NewLine + "<i>- ");
|
2011-06-15 23:19:32 +02:00
|
|
|
|
text = text.Replace(Environment.NewLine + "-<i>", Environment.NewLine + "<i>- ");
|
|
|
|
|
if (text.StartsWith("-") && text.Length > 2 && text[1] != ' ' && text[1] != '-')
|
|
|
|
|
text = text.Insert(1, " ");
|
|
|
|
|
if (text.StartsWith("<i>-") && text.Length > 5 && text[4] != ' ' && text[4] != '-')
|
|
|
|
|
text = text.Insert(4, " ");
|
|
|
|
|
if (text.Contains(Environment.NewLine + "-"))
|
|
|
|
|
{
|
|
|
|
|
int index = text.IndexOf(Environment.NewLine + "-");
|
|
|
|
|
if (index + 4 < text.Length && text[index + Environment.NewLine.Length + 1] != ' ' && text[index + Environment.NewLine.Length + 1] != '-')
|
|
|
|
|
text = text.Insert(index + Environment.NewLine.Length + 1, " ");
|
|
|
|
|
}
|
|
|
|
|
if (text.Contains(Environment.NewLine + "<i>-"))
|
|
|
|
|
{
|
|
|
|
|
int index = text.IndexOf(Environment.NewLine + "<i>-");
|
|
|
|
|
if (index + 5 < text.Length && text[index + Environment.NewLine.Length + 4] != ' ' && text[index + Environment.NewLine.Length + 4] != '-')
|
|
|
|
|
text = text.Insert(index + Environment.NewLine.Length + 4, " ");
|
|
|
|
|
}
|
|
|
|
|
return text.Trim();
|
2011-06-14 20:02:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsHIDescription(string text)
|
|
|
|
|
{
|
|
|
|
|
text = text.ToLower();
|
|
|
|
|
text = text.TrimEnd(" ()[]?{}".ToCharArray());
|
|
|
|
|
text = text.TrimStart(" ()[]?{}".ToCharArray());
|
2011-10-06 21:22:35 +02:00
|
|
|
|
|
2011-06-14 20:02:37 +02:00
|
|
|
|
if (text == "sighing" ||
|
|
|
|
|
text == "laughs" ||
|
|
|
|
|
text == "chuckles" ||
|
2011-10-06 21:22:35 +02:00
|
|
|
|
text == "scoff" ||
|
2011-06-14 20:02:37 +02:00
|
|
|
|
text == "sighs" ||
|
|
|
|
|
text == "whispers" ||
|
|
|
|
|
text == "whisper" ||
|
|
|
|
|
text == "grunts" ||
|
|
|
|
|
text == "explosion" ||
|
|
|
|
|
text == "noise" ||
|
|
|
|
|
text == "exclaims" ||
|
|
|
|
|
text.StartsWith("engine ") ||
|
|
|
|
|
text == "singing" ||
|
|
|
|
|
text.EndsWith("ing"))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetRemovedString(string oldText, string newText)
|
|
|
|
|
{
|
|
|
|
|
oldText = oldText.ToLower();
|
|
|
|
|
newText = newText.ToLower();
|
|
|
|
|
int start = oldText.IndexOf(newText);
|
|
|
|
|
string result;
|
|
|
|
|
if (start > 0)
|
|
|
|
|
result = oldText.Substring(0, newText.Length);
|
|
|
|
|
else
|
|
|
|
|
result = oldText.Substring(newText.Length);
|
|
|
|
|
result = result.TrimEnd(" ()[]?{}".ToCharArray());
|
|
|
|
|
result = result.TrimStart(" ()[]?{}".ToCharArray());
|
|
|
|
|
return result;
|
2011-10-06 21:22:35 +02:00
|
|
|
|
}
|
2010-10-12 13:17:56 +02:00
|
|
|
|
|
2011-01-25 13:42:08 +01:00
|
|
|
|
private string RemoveInterjections(string text)
|
|
|
|
|
{
|
|
|
|
|
string[] arr = Configuration.Settings.Tools.Interjections.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
foreach (string s in arr)
|
|
|
|
|
{
|
|
|
|
|
if (text.Contains(s))
|
2011-10-06 21:22:35 +02:00
|
|
|
|
{
|
2011-01-25 13:42:08 +01:00
|
|
|
|
Regex regex = new Regex(s);
|
|
|
|
|
Match match = regex.Match(text);
|
|
|
|
|
if (match.Success)
|
|
|
|
|
{
|
|
|
|
|
int index = match.Index;
|
|
|
|
|
string temp = text.Remove(index, s.Length);
|
2011-02-01 18:50:42 +01:00
|
|
|
|
string pre = string.Empty;
|
|
|
|
|
if (index > 0)
|
|
|
|
|
{
|
|
|
|
|
pre = text.Substring(0, index);
|
|
|
|
|
temp = temp.Remove(0, index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-10 18:51:57 +02:00
|
|
|
|
while (temp.Length > 0 && (temp.StartsWith(" ") || temp.StartsWith(",") || temp.StartsWith(".") || temp.StartsWith("!") || temp.StartsWith("?")))
|
2011-01-25 13:42:08 +01:00
|
|
|
|
{
|
|
|
|
|
temp = temp.Remove(0, 1);
|
|
|
|
|
}
|
|
|
|
|
if (temp.Length > 0 && s[0].ToString() != s[0].ToString().ToLower())
|
|
|
|
|
{
|
|
|
|
|
temp = temp.Remove(0,1).Insert(0, temp[0].ToString().ToUpper());
|
|
|
|
|
}
|
2011-02-01 18:50:42 +01:00
|
|
|
|
temp = pre + temp;
|
2011-01-25 13:42:08 +01:00
|
|
|
|
|
|
|
|
|
StripableText st = new StripableText(temp);
|
|
|
|
|
if (st.StrippedText.Length == 0)
|
|
|
|
|
return string.Empty;
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return text;
|
2011-10-06 21:22:35 +02:00
|
|
|
|
}
|
2010-10-12 13:17:56 +02:00
|
|
|
|
|
|
|
|
|
private string RemoveStartEndTags(string text)
|
|
|
|
|
{
|
|
|
|
|
string newText = text;
|
|
|
|
|
string s = text;
|
|
|
|
|
if (s.StartsWith("[") && s.IndexOf("]") > 0 && checkBoxRemoveTextBetweenSquares.Checked)
|
|
|
|
|
newText = s.Remove(0, s.IndexOf("]") + 1);
|
|
|
|
|
else if (s.StartsWith("{") && s.IndexOf("}") > 0 && checkBoxRemoveTextBetweenBrackets.Checked)
|
|
|
|
|
newText = s.Remove(0, s.IndexOf("}") + 1);
|
|
|
|
|
else if (s.StartsWith("?") && s.IndexOf("?", 1) > 0 && checkBoxRemoveTextBetweenQuestionMarks.Checked)
|
|
|
|
|
newText = s.Remove(0, s.IndexOf("?", 1) + 1);
|
|
|
|
|
else if (s.StartsWith("(") && s.IndexOf(")") > 0 && checkBoxRemoveTextBetweenParentheses.Checked)
|
|
|
|
|
newText = s.Remove(0, s.IndexOf(")") + 1);
|
|
|
|
|
else if (s.StartsWith("[") && s.IndexOf("]:") > 0 && checkBoxRemoveTextBetweenSquares.Checked)
|
|
|
|
|
newText = s.Remove(0, s.IndexOf("]:") + 2);
|
|
|
|
|
else if (s.StartsWith("{") && s.IndexOf("}:") > 0 && checkBoxRemoveTextBetweenBrackets.Checked)
|
|
|
|
|
newText = s.Remove(0, s.IndexOf("}:") + 2);
|
|
|
|
|
else if (s.StartsWith("?") && s.IndexOf("?:", 1) > 0 && checkBoxRemoveTextBetweenQuestionMarks.Checked)
|
|
|
|
|
newText = s.Remove(0, s.IndexOf("?:") + 2);
|
|
|
|
|
else if (s.StartsWith("(") && s.IndexOf("):") > 0 && checkBoxRemoveTextBetweenParentheses.Checked)
|
|
|
|
|
newText = s.Remove(0, s.IndexOf("):") + 2);
|
|
|
|
|
else if (checkBoxRemoveTextBetweenCustomTags.Checked &&
|
|
|
|
|
s.Length > 0 && comboBoxCustomEnd.Text.Length > 0 && comboBoxCustomStart.Text.Length > 0 &&
|
|
|
|
|
s.StartsWith(comboBoxCustomStart.Text) && s.LastIndexOf(comboBoxCustomEnd.Text) > 0)
|
|
|
|
|
newText = s.Remove(0, s.LastIndexOf(comboBoxCustomEnd.Text) + comboBoxCustomEnd.Text.Length);
|
|
|
|
|
if (newText != text)
|
|
|
|
|
newText = newText.TrimStart(' ');
|
|
|
|
|
return newText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddToListView(Paragraph p, string newText)
|
|
|
|
|
{
|
|
|
|
|
var item = new ListViewItem(string.Empty) {Tag = p, Checked = true};
|
|
|
|
|
|
|
|
|
|
var subItem = new ListViewItem.ListViewSubItem(item, p.Number.ToString());
|
|
|
|
|
item.SubItems.Add(subItem);
|
|
|
|
|
subItem = new ListViewItem.ListViewSubItem(item, p.Text.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString));
|
|
|
|
|
item.SubItems.Add(subItem);
|
|
|
|
|
subItem = new ListViewItem.ListViewSubItem(item, newText.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString));
|
|
|
|
|
item.SubItems.Add(subItem);
|
|
|
|
|
|
|
|
|
|
listViewFixes.Items.Add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormRemoveTextForHearImpaired_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Escape)
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonOkClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int RemoveTextFromHearImpaired()
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (int i = _subtitle.Paragraphs.Count - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
Paragraph p = _subtitle.Paragraphs[i];
|
|
|
|
|
if (IsFixAllowed(p))
|
|
|
|
|
{
|
|
|
|
|
string newText = RemoveTextFromHearImpaired(p.Text);
|
|
|
|
|
if (string.IsNullOrEmpty(newText))
|
|
|
|
|
{
|
|
|
|
|
_subtitle.Paragraphs.RemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
p.Text = newText;
|
|
|
|
|
}
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsFixAllowed(Paragraph p)
|
|
|
|
|
{
|
|
|
|
|
foreach (ListViewItem item in listViewFixes.Items)
|
|
|
|
|
{
|
|
|
|
|
if (item.Tag.ToString() == p.ToString())
|
|
|
|
|
return item.Checked;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckBoxRemoveTextBetweenCheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Cursor = Cursors.WaitCursor;
|
|
|
|
|
GeneratePreview();
|
|
|
|
|
Cursor = Cursors.Default;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-25 13:42:08 +01:00
|
|
|
|
private void checkBoxRemoveInterjections_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Cursor = Cursors.WaitCursor;
|
|
|
|
|
GeneratePreview();
|
|
|
|
|
Cursor = Cursors.Default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonEditInterjections_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Interjections editInterjections = new Interjections();
|
|
|
|
|
editInterjections.Initialize(Configuration.Settings.Tools.Interjections);
|
|
|
|
|
if (editInterjections.ShowDialog(this) == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
Configuration.Settings.Tools.Interjections = editInterjections.GetInterjectionsSemiColonSeperatedString();
|
|
|
|
|
if (checkBoxRemoveInterjections.Checked)
|
|
|
|
|
{
|
|
|
|
|
Cursor = Cursors.WaitCursor;
|
|
|
|
|
GeneratePreview();
|
|
|
|
|
Cursor = Cursors.Default;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-02 08:19:36 +02:00
|
|
|
|
private void FormRemoveTextForHearImpaired_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBeforeColor = checkBoxRemoveTextBeforeColon.Checked;
|
|
|
|
|
Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBeforeColorOnlyIfUppercase = checkBoxRemoveTextBeforeColonOnlyUppercase.Checked;
|
|
|
|
|
Configuration.Settings.RemoveTextForHearingImpaired.RemoveInterjections = checkBoxRemoveInterjections.Checked;
|
|
|
|
|
Configuration.Settings.RemoveTextForHearingImpaired.RemoveIfContains = checkBoxRemoveWhereContains.Checked;
|
|
|
|
|
Configuration.Settings.RemoveTextForHearingImpaired.RemoveIfContainsText = comboBoxRemoveIfTextContains.Text;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 07:10:41 +02:00
|
|
|
|
private void FormRemoveTextForHearImpaired_Resize(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
int availableWidth = listViewFixes.Width - (listViewFixes.Columns[0].Width + listViewFixes.Columns[1].Width + 20);
|
|
|
|
|
listViewFixes.Columns[2].Width = availableWidth / 2;
|
|
|
|
|
listViewFixes.Columns[3].Width = availableWidth / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkBoxRemoveTextBeforeColon_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
checkBoxRemoveTextBeforeColonOnlyUppercase.Enabled = checkBoxRemoveTextBeforeColon.Checked;
|
|
|
|
|
Cursor = Cursors.WaitCursor;
|
|
|
|
|
GeneratePreview();
|
|
|
|
|
Cursor = Cursors.Default;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|