Merge pull request #1840 from ivandrofly/fce-3

[FCE] - Call subtitle its GetParagraphOrDefault.
This commit is contained in:
Nikolaj Olsson 2016-07-11 19:53:12 +02:00 committed by GitHub
commit a0b094f435

View File

@ -1027,8 +1027,7 @@ namespace Nikse.SubtitleEdit.Forms
int firstSelectedIndex = 0; int firstSelectedIndex = 0;
if (subtitleListView1.SelectedItems.Count > 0) if (subtitleListView1.SelectedItems.Count > 0)
firstSelectedIndex = subtitleListView1.SelectedItems[0].Index; firstSelectedIndex = subtitleListView1.SelectedItems[0].Index;
Paragraph p = _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex);
Paragraph p = GetParagraphOrDefault(firstSelectedIndex);
if (p != null) if (p != null)
{ {
InitializeListViewEditBox(p); InitializeListViewEditBox(p);
@ -1064,14 +1063,6 @@ namespace Nikse.SubtitleEdit.Forms
} }
} }
private Paragraph GetParagraphOrDefault(int index)
{
if (_originalSubtitle.Paragraphs == null || _originalSubtitle.Paragraphs.Count <= index || index < 0)
return null;
return _originalSubtitle.Paragraphs[index];
}
private void InitializeListViewEditBox(Paragraph p) private void InitializeListViewEditBox(Paragraph p)
{ {
textBoxListViewText.TextChanged -= TextBoxListViewTextTextChanged; textBoxListViewText.TextChanged -= TextBoxListViewTextTextChanged;
@ -1093,7 +1084,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
int firstSelectedIndex = subtitleListView1.SelectedItems[0].Index; int firstSelectedIndex = subtitleListView1.SelectedItems[0].Index;
Paragraph currentParagraph = GetParagraphOrDefault(firstSelectedIndex); Paragraph currentParagraph = _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex);
if (currentParagraph != null) if (currentParagraph != null)
{ {
UpdateOverlapErrors(); UpdateOverlapErrors();
@ -1115,11 +1106,11 @@ namespace Nikse.SubtitleEdit.Forms
{ {
int firstSelectedIndex = subtitleListView1.SelectedItems[0].Index; int firstSelectedIndex = subtitleListView1.SelectedItems[0].Index;
Paragraph prevParagraph = GetParagraphOrDefault(firstSelectedIndex - 1); Paragraph prevParagraph = _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex - 1);
if (prevParagraph != null && prevParagraph.EndTime.TotalMilliseconds > startTime.TotalMilliseconds) if (prevParagraph != null && prevParagraph.EndTime.TotalMilliseconds > startTime.TotalMilliseconds)
labelStartTimeWarning.Text = string.Format(_languageGeneral.OverlapPreviousLineX, (prevParagraph.EndTime.TotalMilliseconds - startTime.TotalMilliseconds) / TimeCode.BaseUnit); labelStartTimeWarning.Text = string.Format(_languageGeneral.OverlapPreviousLineX, (prevParagraph.EndTime.TotalMilliseconds - startTime.TotalMilliseconds) / TimeCode.BaseUnit);
Paragraph nextParagraph = GetParagraphOrDefault(firstSelectedIndex + 1); Paragraph nextParagraph = _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex + 1);
if (nextParagraph != null) if (nextParagraph != null)
{ {
double durationMilliSeconds = (double)numericUpDownDuration.Value * TimeCode.BaseUnit; double durationMilliSeconds = (double)numericUpDownDuration.Value * TimeCode.BaseUnit;