Minor refact + minor update of text

This commit is contained in:
niksedk 2015-09-25 21:34:58 +02:00
parent 117e92ab0b
commit 9fba87b9bc
3 changed files with 25 additions and 28 deletions

View File

@ -666,5 +666,27 @@ namespace Nikse.SubtitleEdit.Core
return text;
}
public static string ToogleTag(string text, string tag)
{
if (text.Contains("<" + tag + ">"))
{
text = text.Replace("<" + tag + ">", string.Empty);
text = text.Replace("</" + tag + ">", string.Empty);
}
else
{
int indexOfEndBracket = text.IndexOf('}');
if (text.StartsWith("{\\", StringComparison.Ordinal) && indexOfEndBracket > 1 && indexOfEndBracket < 6)
{
text = string.Format("{2}<{0}>{1}</{0}>", tag, text.Remove(0, indexOfEndBracket + 1), text.Substring(0, indexOfEndBracket + 1));
}
else
{
text = string.Format("<{0}>{1}</{0}>", tag, text);
}
}
return text;
}
}
}

View File

@ -1440,7 +1440,7 @@ namespace Nikse.SubtitleEdit.Core
MergeSelectedLinesAsDialog = "Merge selected lines as dialog",
MergeWithLineBefore = "Merge with line before",
MergeWithLineAfter = "Merge with line after",
Normal = "Normal",
Normal = "Normal (remove formatting)",
Underline = "Underline",
Color = "Color...",
FontName = "Font name...",

View File

@ -6082,36 +6082,11 @@ namespace Nikse.SubtitleEdit.Forms
var original = Utilities.GetOriginalParagraph(i, _subtitle.Paragraphs[i], _subtitleAlternate.Paragraphs);
if (original != null)
{
if (original.Text.Contains("<" + tag + ">"))
{
original.Text = original.Text.Replace("<" + tag + ">", string.Empty);
original.Text = original.Text.Replace("</" + tag + ">", string.Empty);
}
else
{
int indexOfEndBracket = original.Text.IndexOf('}');
if (original.Text.StartsWith("{\\", StringComparison.Ordinal) && indexOfEndBracket > 1 && indexOfEndBracket < 6)
original.Text = string.Format("{2}<{0}>{1}</{0}>", tag, original.Text.Remove(0, indexOfEndBracket + 1), original.Text.Substring(0, indexOfEndBracket + 1));
else
original.Text = string.Format("<{0}>{1}</{0}>", tag, original.Text);
}
original.Text = HtmlUtil.ToogleTag(original.Text, tag);
SubtitleListview1.SetAlternateText(i, original.Text);
}
}
if (_subtitle.Paragraphs[i].Text.Contains("<" + tag + ">"))
{
_subtitle.Paragraphs[i].Text = _subtitle.Paragraphs[i].Text.Replace("<" + tag + ">", string.Empty);
_subtitle.Paragraphs[i].Text = _subtitle.Paragraphs[i].Text.Replace("</" + tag + ">", string.Empty);
}
else
{
int indexOfEndBracket = _subtitle.Paragraphs[i].Text.IndexOf('}');
if (_subtitle.Paragraphs[i].Text.StartsWith("{\\", StringComparison.Ordinal) && indexOfEndBracket > 1 && indexOfEndBracket < 6)
_subtitle.Paragraphs[i].Text = string.Format("{2}<{0}>{1}</{0}>", tag, _subtitle.Paragraphs[i].Text.Remove(0, indexOfEndBracket + 1), _subtitle.Paragraphs[i].Text.Substring(0, indexOfEndBracket + 1));
else
_subtitle.Paragraphs[i].Text = string.Format("<{0}>{1}</{0}>", tag, _subtitle.Paragraphs[i].Text);
}
_subtitle.Paragraphs[i].Text = HtmlUtil.ToogleTag(_subtitle.Paragraphs[i].Text, tag);
SubtitleListview1.SetText(i, _subtitle.Paragraphs[i].Text);
}
SubtitleListview1.EndUpdate();