Merge pull request #546 from ivandrofly/fix/refactOnly

Refact only
This commit is contained in:
Nikolaj Olsson 2015-02-19 12:45:55 +01:00
commit e5791b91a1

View File

@ -6190,12 +6190,13 @@ namespace Nikse.SubtitleEdit.Forms
{ {
var format = GetCurrentSubtitleFormat(); var format = GetCurrentSubtitleFormat();
bool useExtraForStyle = format.HasStyleSupport; bool useExtraForStyle = format.HasStyleSupport;
var formatType = format.GetType();
var styles = new List<string>(); var styles = new List<string>();
if (format.GetType() == typeof(AdvancedSubStationAlpha) || format.GetType() == typeof(SubStationAlpha)) if (formatType == typeof(AdvancedSubStationAlpha) || formatType == typeof(SubStationAlpha))
styles = AdvancedSubStationAlpha.GetStylesFromHeader(_subtitle.Header); styles = AdvancedSubStationAlpha.GetStylesFromHeader(_subtitle.Header);
else if (format.GetType() == typeof(TimedText10) || format.GetType() == typeof(ItunesTimedText)) else if (formatType == typeof(TimedText10) || formatType == typeof(ItunesTimedText))
styles = TimedText10.GetStylesFromHeader(_subtitle.Header); styles = TimedText10.GetStylesFromHeader(_subtitle.Header);
else if (format.GetType() == typeof(Sami) || format.GetType() == typeof(SamiModern)) else if (formatType == typeof(Sami) || formatType == typeof(SamiModern))
styles = Sami.GetStylesFromHeader(_subtitle.Header); styles = Sami.GetStylesFromHeader(_subtitle.Header);
string style = "Default"; string style = "Default";
if (styles.Count > 0) if (styles.Count > 0)
@ -6483,33 +6484,26 @@ namespace Nikse.SubtitleEdit.Forms
private void ButtonNextClick(object sender, EventArgs e) private void ButtonNextClick(object sender, EventArgs e)
{ {
if (_subtitle.Paragraphs.Count > 0) MoveNextPrevious(0);
{
int firstSelectedIndex = 0;
if (SubtitleListview1.SelectedItems.Count > 0)
firstSelectedIndex = SubtitleListview1.SelectedItems[0].Index;
firstSelectedIndex++;
Paragraph p = _subtitle.GetParagraphOrDefault(firstSelectedIndex);
if (p != null)
SubtitleListview1.SelectIndexAndEnsureVisible(firstSelectedIndex);
}
} }
private void ButtonPreviousClick(object sender, EventArgs e) private void ButtonPreviousClick(object sender, EventArgs e)
{ {
if (_subtitle.Paragraphs.Count > 0) MoveNextPrevious(1);
}
private void MoveNextPrevious(int firstSelectedIndex)
{ {
int firstSelectedIndex = 1; if (_subtitle.Paragraphs.Count == 0)
return;
var temp = firstSelectedIndex;
if (SubtitleListview1.SelectedItems.Count > 0) if (SubtitleListview1.SelectedItems.Count > 0)
firstSelectedIndex = SubtitleListview1.SelectedItems[0].Index; firstSelectedIndex = SubtitleListview1.SelectedItems[0].Index;
firstSelectedIndex = temp == 0 ? firstSelectedIndex + 1 : firstSelectedIndex - 1;
firstSelectedIndex--;
Paragraph p = _subtitle.GetParagraphOrDefault(firstSelectedIndex); Paragraph p = _subtitle.GetParagraphOrDefault(firstSelectedIndex);
if (p != null) if (p != null)
SubtitleListview1.SelectIndexAndEnsureVisible(firstSelectedIndex); SubtitleListview1.SelectIndexAndEnsureVisible(firstSelectedIndex);
} }
}
private static string RemoveSsaStyle(string text) private static string RemoveSsaStyle(string text)
{ {
@ -6570,8 +6564,7 @@ namespace Nikse.SubtitleEdit.Forms
IList<char> uCharList = new List<char>() { '♫', '♪', '☺', '☹', '♥', '©', '☮', '☯', 'Σ', '∞', '≡', '⇒', 'π' }; IList<char> uCharList = new List<char>() { '♫', '♪', '☺', '☹', '♥', '©', '☮', '☯', 'Σ', '∞', '≡', '⇒', 'π' };
foreach (char uChar in uCharList) foreach (char uChar in uCharList)
{ {
var idx = text.IndexOf(uChar); if (text.IndexOf(uChar) >= 0)
if (idx >= 0)
text = text.Replace(uChar, ' '); text = text.Replace(uChar, ' ');
} }
text = text.Trim(); text = text.Trim();
@ -6625,11 +6618,7 @@ namespace Nikse.SubtitleEdit.Forms
private static void FixVerticalScrollBars(TextBox tb) private static void FixVerticalScrollBars(TextBox tb)
{ {
var lineCount = Utilities.CountTagInText(tb.Text, Environment.NewLine) + 1; tb.ScrollBars = Utilities.GetNumberOfLines(tb.Text) + 1 > 3 ? ScrollBars.Vertical : ScrollBars.None;
if (lineCount > 3)
tb.ScrollBars = ScrollBars.Vertical;
else
tb.ScrollBars = ScrollBars.None;
} }
private void TextBoxListViewTextTextChanged(object sender, EventArgs e) private void TextBoxListViewTextTextChanged(object sender, EventArgs e)
@ -6717,7 +6706,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
if (textBoxListViewText.SelectionLength == 0) if (textBoxListViewText.SelectionLength == 0)
{ {
if (textBoxListViewText.Text.Contains("<i>")) if (textBoxListViewText.Text.Contains("<i>", StringComparison.Ordinal))
{ {
textBoxListViewText.Text = HtmlUtil.RemoveOpenCloseTags(textBoxListViewText.Text, HtmlUtil.TagItalic); textBoxListViewText.Text = HtmlUtil.RemoveOpenCloseTags(textBoxListViewText.Text, HtmlUtil.TagItalic);
} }
@ -6751,9 +6740,7 @@ namespace Nikse.SubtitleEdit.Forms
GoToNextSynaxError(); GoToNextSynaxError();
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
} }
else if (_mainTextBoxSelectionToLower == e.KeyData) // selection to lowercase else if (_mainTextBoxSelectionToLower == e.KeyData && textBoxListViewText.SelectionLength > 0) // selection to lowercase
{
if (textBoxListViewText.SelectionLength > 0)
{ {
int start = textBoxListViewText.SelectionStart; int start = textBoxListViewText.SelectionStart;
int length = textBoxListViewText.SelectionLength; int length = textBoxListViewText.SelectionLength;
@ -6762,10 +6749,7 @@ namespace Nikse.SubtitleEdit.Forms
textBoxListViewText.SelectionLength = length; textBoxListViewText.SelectionLength = length;
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
} }
} else if (_mainTextBoxSelectionToUpper == e.KeyData && textBoxListViewText.SelectionLength > 0) // selection to uppercase
else if (_mainTextBoxSelectionToUpper == e.KeyData) // selection to uppercase
{
if (textBoxListViewText.SelectionLength > 0)
{ {
int start = textBoxListViewText.SelectionStart; int start = textBoxListViewText.SelectionStart;
int length = textBoxListViewText.SelectionLength; int length = textBoxListViewText.SelectionLength;
@ -6774,7 +6758,6 @@ namespace Nikse.SubtitleEdit.Forms
textBoxListViewText.SelectionLength = length; textBoxListViewText.SelectionLength = length;
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
} }
}
else if (_mainTextBoxToggleAutoDuration == e.KeyData) // toggle auto-duration else if (_mainTextBoxToggleAutoDuration == e.KeyData) // toggle auto-duration
{ {
if (timerAutoDuration.Enabled) if (timerAutoDuration.Enabled)
@ -6884,13 +6867,13 @@ namespace Nikse.SubtitleEdit.Forms
if (firstWord.StartsWith('-')) if (firstWord.StartsWith('-'))
{ {
// Save the dialog marker ("-" or "- "). // Save the dialog marker ("-" or "- ").
dialogMarker = (firstWord.StartsWith("- ") ? "- " : "-"); dialogMarker = (firstWord.StartsWith("- ", StringComparison.Ordinal) ? "- " : "-");
// Remove the dialog marker from the first word. // Remove the dialog marker from the first word.
firstWord = firstWord.Remove(0, dialogMarker.Length); firstWord = firstWord.Remove(0, dialogMarker.Length);
} }
// If the second subtitle starts with "...": // If the second subtitle starts with "...":
Boolean nextSubtitleStartsWithEllipsis = firstWord.StartsWith("..."); Boolean nextSubtitleStartsWithEllipsis = firstWord.StartsWith("...", StringComparison.Ordinal);
if (nextSubtitleStartsWithEllipsis) if (nextSubtitleStartsWithEllipsis)
{ {
// Remove "..." from the beginning of first word. // Remove "..." from the beginning of first word.
@ -6994,7 +6977,7 @@ namespace Nikse.SubtitleEdit.Forms
if (next.Text.StartsWith('-')) if (next.Text.StartsWith('-'))
{ {
// Save the dialog marker ("-" or "- "). // Save the dialog marker ("-" or "- ").
dialogMarker = (next.Text.StartsWith("- ") ? "- " : "-"); dialogMarker = (next.Text.StartsWith("- ", StringComparison.Ordinal) ? "- " : "-");
// Remove the dialog marker from the next subtitle. // Remove the dialog marker from the next subtitle.
next.Text = next.Text.Remove(0, dialogMarker.Length); next.Text = next.Text.Remove(0, dialogMarker.Length);
} }
@ -18184,7 +18167,7 @@ namespace Nikse.SubtitleEdit.Forms
string fname = saveFileDialog1.FileName; string fname = saveFileDialog1.FileName;
if (string.IsNullOrEmpty(fname)) if (string.IsNullOrEmpty(fname))
fname = "ATS"; fname = "ATS";
if (!fname.EndsWith(".txt")) if (!fname.EndsWith(".txt", StringComparison.Ordinal))
fname += ".txt"; fname += ".txt";
string fileNameTimeCode = fname.Insert(fname.Length - 4, "_timecode"); string fileNameTimeCode = fname.Insert(fname.Length - 4, "_timecode");
string fileNameText = fname.Insert(fname.Length - 4, "_text"); string fileNameText = fname.Insert(fname.Length - 4, "_text");
@ -18257,7 +18240,7 @@ namespace Nikse.SubtitleEdit.Forms
if (!extOk) if (!extOk)
{ {
if (fileName.EndsWith('.')) if (fileName.EndsWith('.'))
fileName = fileName.Substring(0, _fileName.Length - 1); fileName = fileName.TrimEnd('.');
fileName += format.Extension; fileName += format.Extension;
} }
@ -18360,7 +18343,7 @@ namespace Nikse.SubtitleEdit.Forms
var tmp = new Subtitle(); var tmp = new Subtitle();
var format = new SubRip(); var format = new SubRip();
var list = new List<string>(); var list = new List<string>();
foreach (string line in text.Replace(Environment.NewLine, "\n").Split('\n')) foreach (string line in text.SplitToLines())
list.Add(line); list.Add(line);
format.LoadSubtitle(tmp, list, null); format.LoadSubtitle(tmp, list, null);
@ -18373,7 +18356,7 @@ namespace Nikse.SubtitleEdit.Forms
if (tmp.Paragraphs.Count == 0) if (tmp.Paragraphs.Count == 0)
{ {
foreach (string line in text.Replace(Environment.NewLine, "\n").Split('\n')) foreach (string line in text.SplitToLines())
tmp.Paragraphs.Add(new Paragraph(0, 0, line)); tmp.Paragraphs.Add(new Paragraph(0, 0, line));
} }