SubtitleEdit/src/Forms/RemoveTextFromHearImpaired.cs
2011-06-14 18:02:37 +00:00

719 lines
32 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Text.RegularExpressions;
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();
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;
_language = Configuration.Settings.Language.RemoveTextFromHearImpaired;
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;
checkBoxRemoveWhereContains.Text = _language.RemoveTextIfContains;
checkBoxRemoveInterjections.Text = _language.RemoveInterjections;
buttonEditInterjections.Text = _language.EditInterjections;
buttonEditInterjections.Left = checkBoxRemoveInterjections.Left + checkBoxRemoveInterjections.Width;
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;
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);
}
}
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('-');
return s.Trim();
}
private string RemoveTextBetweenTags(string startTag, string endTag, string text)
{
text = text.Trim();
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)
{
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;
}
public bool HasHearImpariedTagsAtStart(string text)
{
if (checkBoxOnlyIfInSeparateLine.Checked)
return StartAndEndsWithHearImpariedTags(text);
return HasHearImpairedText(text);
}
public bool HasHearImpariedTagsAtEnd(string text)
{
if (checkBoxOnlyIfInSeparateLine.Checked)
return StartAndEndsWithHearImpariedTags(text);
return HasHearImpairedText(text);
}
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
{
string unicodeFontName = Utilities.WinXp2kUnicodeFontName;
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()
{
if (_subtitle == null)
return;
listViewFixes.BeginUpdate();
listViewFixes.Items.Clear();
int count = 0;
foreach (Paragraph p in _subtitle.Paragraphs)
{
bool hit = false;
if (HasHearImpariedTagsAtStart(RemoveStartEndNoise(p.Text)))
hit = true;
if (HasHearImpariedTagsAtEnd(RemoveStartEndNoise(p.Text)))
hit = true;
if (!hit && checkBoxRemoveWhereContains.Checked && comboBoxRemoveIfTextContains.Text.Length > 0 && p.Text.Contains(comboBoxRemoveIfTextContains.Text))
hit = true;
if (!hit)
{
foreach (string s in p.Text.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
if (HasHearImpariedTagsAtStart(RemoveStartEndNoise(s)))
hit = true;
}
}
if (RemoveColon(p.Text) != p.Text.Trim())
{
hit = true;
}
if (checkBoxRemoveInterjections.Checked && RemoveInterjections(p.Text) != p.Text.Trim())
{
hit = true;
}
if (RemoveHearImpairedtagsInsideLine(p.Text) != p.Text.Trim())
{
hit = true;
}
if (!hit)
{
string[] parts = p.Text.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (string s in parts)
{
StripableText stSub = new StripableText(s, " >-\"'`´♪¿¡.", " -\"'`´♪.!?:");
string newText = stSub.StrippedText;
if (HasHearImpariedTagsAtStart(newText))
hit = true;
else if (HasHearImpariedTagsAtEnd(newText))
hit = true;
}
}
if (hit)
{
count++;
string newText = RemoveTextFromHearImpaired(p.Text);
AddToListView(p, newText);
}
}
listViewFixes.EndUpdate();
groupBoxLinesFound.Text = string.Format(_language.LinesFoundX, count);
}
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;
}
private string RemoveColon(string text)
{
if (text.IndexOf(":") < 0)
return text;
// 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;
string newText = string.Empty;
string[] parts = text.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
int noOfNames = 0;
foreach (string s in parts)
{
int indexOfColon = s.IndexOf(":");
if (indexOfColon > 0)
{
string pre = s.Substring(0, indexOfColon);
if (checkBoxRemoveTextBeforeColonOnlyUppercase.Checked && pre.Replace("<i>", string.Empty) != pre.Replace("<i>", string.Empty).ToUpper())
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
}
else
{
StripableText st = new StripableText(pre);
if (Utilities.CountTagInText(st.StrippedText, " ") < 2)
{
newText = newText + Environment.NewLine + st.Pre + s.Substring(indexOfColon + 1).Trim() + st.Post;
newText = newText.Trim();
if (!IsHIDescription(st.StrippedText))
noOfNames++;
}
string s2 = newText;
for (int k = 0; k < 2; k++)
{
if (s2.Contains(":"))
{
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 (endIndex > 0)
{
s2 = s2.Remove(endIndex + 1, colonIndex - endIndex);
}
}
}
newText = s2;
}
}
else
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
}
}
newText = newText.Trim();
if (noOfNames > 0 && Utilities.CountTagInText(newText, Environment.NewLine) == 1)
{
int indexOfDialogChar = newText.IndexOf('-');
if (indexOfDialogChar < 0 || indexOfDialogChar > 6)
{
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;
}
}
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;
}
}
return newText;
}
private string RemoveTextFromHearImpaired(string text)
{
if (checkBoxRemoveWhereContains.Checked && comboBoxRemoveIfTextContains.Text.Length > 0 && text.Contains(comboBoxRemoveIfTextContains.Text))
{
return string.Empty;
}
string oldText = text;
text = RemoveColon(text);
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);
var sb = new StringBuilder();
string[] parts = st.StrippedText.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
int lineNumber = 0;
bool removedDialogInFirstLine = false;
int noOfNamesRemoved = 0;
foreach (string s in parts)
{
StripableText stSub = new StripableText(s, pre, post);
if (!StartAndEndsWithHearImpariedTags(stSub.StrippedText))
{
if (removedDialogInFirstLine && stSub.Pre.Contains("- "))
stSub.Pre = stSub.Pre.Replace("- ", string.Empty);
string newText = stSub.StrippedText;
newText = RemoveHearImpairedTags(newText);
if (stSub.StrippedText.Length - newText.Length > 2)
{
string removedText = GetRemovedString(stSub.StrippedText, newText);
if (!IsHIDescription(removedText))
noOfNamesRemoved++;
}
sb.AppendLine(stSub.Pre + newText + stSub.Post);
}
else
{
if (!IsHIDescription(stSub.StrippedText))
noOfNamesRemoved++;
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);
}
lineNumber++;
}
text = st.Pre + sb.ToString().Trim() + st.Post;
text = RemoveColon(text);
text = RemoveHearImpairedtagsInsideLine(text);
if (checkBoxRemoveInterjections.Checked)
text = RemoveInterjections(text);
st = new StripableText(text, " >-\"'`´♪¿¡.…—", " -\"'`´♪.!?:…—");
text = st.StrippedText;
if (StartAndEndsWithHearImpariedTags(text))
{
text = RemoveStartEndTags(text);
}
if (!text.StartsWith("-") && !text.Contains(Environment.NewLine + "-") && noOfNamesRemoved >= 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1)
{
string[] arr = text.Split(Environment.NewLine.ToCharArray());
string part0 = arr[0].Trim().Replace("</i>", string.Empty).Trim();
if (!part0.EndsWith(",") && !part0.EndsWith("-"))
text = "- " + text.Replace(Environment.NewLine, Environment.NewLine + "- ");
}
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();
}
text = text.Replace(Environment.NewLine + "- <i>", Environment.NewLine + "<i>- ");
return text;
}
private bool IsHIDescription(string text)
{
text = text.ToLower();
text = text.TrimEnd(" ()[]?{}".ToCharArray());
text = text.TrimStart(" ()[]?{}".ToCharArray());
if (text == "sighing" ||
text == "laughs" ||
text == "chuckles" ||
text == "scoff" ||
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;
}
private string RemoveInterjections(string text)
{
string[] arr = Configuration.Settings.Tools.Interjections.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (string s in arr)
{
if (text.Contains(s))
{
Regex regex = new Regex(s);
Match match = regex.Match(text);
if (match.Success)
{
int index = match.Index;
string temp = text.Remove(index, s.Length);
string pre = string.Empty;
if (index > 0)
{
pre = text.Substring(0, index);
temp = temp.Remove(0, index);
}
while (temp.Length > 0 && (temp.StartsWith(" ") || temp.StartsWith(",") || temp.StartsWith(".") || temp.StartsWith("!") || temp.StartsWith("?")))
{
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());
}
temp = pre + temp;
StripableText st = new StripableText(temp);
if (st.StrippedText.Length == 0)
return string.Empty;
return temp;
}
}
}
return text;
}
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;
}
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;
}
}
}
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;
}
}
}