Remove a few unneeded NULL cheks - thx XhmikosR :)

This commit is contained in:
niksedk 2014-09-13 15:14:28 +02:00
parent f900a48488
commit addc5f7151
8 changed files with 57 additions and 71 deletions

View File

@ -195,28 +195,25 @@ namespace Nikse.SubtitleEdit.Controls
}
set
{
if (value.TotalMilliseconds >= TimeCode.MaxTime.TotalMilliseconds - 0.1)
if (value.TotalMilliseconds >= TimeCode.MaxTime.TotalMilliseconds - 0.1 || value == null)
{
maskedTextBox1.Text = string.Empty;
return;
}
if (Mode == TimeMode.HHMMSSMS && value != null && value.TotalMilliseconds < 0)
maskedTextBox1.Mask = "-00:00:00.000";
else if (Mode == TimeMode.HHMMSSMS)
maskedTextBox1.Mask = "00:00:00.000";
else
maskedTextBox1.Mask = "00:00:00:00";
if (value != null)
if (Mode == TimeMode.HHMMSSMS)
{
if (Mode == TimeMode.HHMMSSMS)
maskedTextBox1.Text = value.ToString();
else
maskedTextBox1.Text = value.ToHHMMSSFF();
if (value.TotalMilliseconds < 0)
maskedTextBox1.Mask = "-00:00:00.000";
else
maskedTextBox1.Mask = "00:00:00.000";
maskedTextBox1.Text = value.ToString();
}
else
{
maskedTextBox1.Text = new TimeCode(0).ToString();
maskedTextBox1.Mask = "00:00:00:00";
maskedTextBox1.Text = value.ToHHMMSSFF();
}
}
}

View File

@ -675,9 +675,7 @@ namespace Nikse.SubtitleEdit.Forms
{
Paragraph p = _subtitle.Paragraphs[i];
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1);
Paragraph target = p; // subtitle to display when clicking on fix in top list view
if (prev != null)
target = prev;
Paragraph target = prev;
string oldCurrent = p.ToString();
string oldPrevious = prev.ToString();
double prevWantedDisplayTime = Utilities.GetOptimalDisplayMilliseconds(prev.Text, Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds);
@ -689,7 +687,7 @@ namespace Nikse.SubtitleEdit.Forms
canBeEqual = Configuration.Settings.Tools.FixCommonErrorsFixOverlapAllowEqualEndStart;
double diff = prev.EndTime.TotalMilliseconds - p.StartTime.TotalMilliseconds;
if (prev != null && !prev.StartTime.IsMaxTime && !p.StartTime.IsMaxTime && diff >= 0 && !(canBeEqual && diff == 0))
if (!prev.StartTime.IsMaxTime && !p.StartTime.IsMaxTime && diff >= 0 && !(canBeEqual && diff == 0))
{
int diffHalf = (int)(diff / 2);

View File

@ -122,10 +122,7 @@ namespace Nikse.SubtitleEdit.Forms
private void TimerRefreshProgressbarTick(object sender, EventArgs e)
{
if (mediaPlayer != null)
{
mediaPlayer.RefreshProgressBar();
}
mediaPlayer.RefreshProgressBar();
}
private void numericUpDownPixelsBottom_ValueChanged(object sender, EventArgs e)

View File

@ -3736,8 +3736,7 @@ namespace Nikse.SubtitleEdit.Forms
_converted = false;
SetUndockedWindowsTitle();
if (mediaPlayer != null)
mediaPlayer.SubtitleText = string.Empty;
mediaPlayer.SubtitleText = string.Empty;
ShowStatus(_language.New);
}
@ -8618,6 +8617,8 @@ namespace Nikse.SubtitleEdit.Forms
private void ButtonUnBreakClick(object sender, EventArgs e)
{
timeUpDownStartTime.TimeCode = null;
if (SubtitleListview1.SelectedItems.Count > 1)
{
MakeHistoryForUndo(_language.BeforeRemoveLineBreaksInSelectedLines);
@ -10938,7 +10939,7 @@ namespace Nikse.SubtitleEdit.Forms
{
if (!textBoxListViewText.Focused && !textBoxListViewTextAlternate.Focused && !textBoxSource.Focused && mediaPlayer.VideoPlayer != null)
{
if (audioVisualizer != null && audioVisualizer.Focused || mediaPlayer != null && mediaPlayer.Focused || SubtitleListview1.Focused && mediaPlayer != null)
if (audioVisualizer != null && audioVisualizer.Focused || mediaPlayer.Focused || SubtitleListview1.Focused)
{
_endSeconds = -1;
mediaPlayer.TogglePlayPause();
@ -11144,42 +11145,42 @@ namespace Nikse.SubtitleEdit.Forms
else
UndockVideoControlsToolStripMenuItemClick(null, null);
}
else if (mediaPlayer != null && mediaPlayer.VideoPlayer != null && e.KeyData == _video1FrameLeft)
else if (mediaPlayer.VideoPlayer != null && e.KeyData == _video1FrameLeft)
{
MoveVideoSeconds(-1.0 / Configuration.Settings.General.CurrentFrameRate);
e.SuppressKeyPress = true;
}
else if (mediaPlayer != null && mediaPlayer.VideoPlayer != null && e.KeyData == _video1FrameRight)
else if (mediaPlayer.VideoPlayer != null && e.KeyData == _video1FrameRight)
{
MoveVideoSeconds(1.0 / Configuration.Settings.General.CurrentFrameRate);
e.SuppressKeyPress = true;
}
else if (mediaPlayer != null && mediaPlayer.VideoPlayer != null && e.KeyData == _video100MsLeft)
else if (mediaPlayer.VideoPlayer != null && e.KeyData == _video100MsLeft)
{
MoveVideoSeconds(-0.1);
e.SuppressKeyPress = true;
}
else if (mediaPlayer != null && mediaPlayer.VideoPlayer != null && e.KeyData == _video100MsRight)
else if (mediaPlayer.VideoPlayer != null && e.KeyData == _video100MsRight)
{
MoveVideoSeconds(0.1);
e.SuppressKeyPress = true;
}
else if (mediaPlayer != null && mediaPlayer.VideoPlayer != null && e.KeyData == _video500MsLeft)
else if (mediaPlayer.VideoPlayer != null && e.KeyData == _video500MsLeft)
{
MoveVideoSeconds(-0.5);
e.SuppressKeyPress = true;
}
else if (mediaPlayer != null && mediaPlayer.VideoPlayer != null && e.KeyData == _video500MsRight)
else if (mediaPlayer.VideoPlayer != null && e.KeyData == _video500MsRight)
{
MoveVideoSeconds(0.5);
e.SuppressKeyPress = true;
}
else if (mediaPlayer != null && mediaPlayer.VideoPlayer != null && e.KeyData == _video1000MsLeft)
else if (mediaPlayer.VideoPlayer != null && e.KeyData == _video1000MsLeft)
{
MoveVideoSeconds(-1.0);
e.SuppressKeyPress = true;
}
else if (mediaPlayer != null && mediaPlayer.VideoPlayer != null && e.KeyData == _video1000MsRight)
else if (mediaPlayer.VideoPlayer != null && e.KeyData == _video1000MsRight)
{
MoveVideoSeconds(1.0);
e.SuppressKeyPress = true;
@ -11546,7 +11547,7 @@ namespace Nikse.SubtitleEdit.Forms
private void PlayFirstSelectedSubtitle()
{
if (_subtitleListViewIndex >= 0 && mediaPlayer != null && mediaPlayer.VideoPlayer != null)
if (_subtitleListViewIndex >= 0 && mediaPlayer.VideoPlayer != null)
{
GotoSubtitleIndex(_subtitleListViewIndex);
var paragraph = _subtitle.Paragraphs[_subtitleListViewIndex];
@ -11657,7 +11658,7 @@ namespace Nikse.SubtitleEdit.Forms
private void GoFullscreen()
{
if (mediaPlayer == null || mediaPlayer.VideoPlayer == null)
if (mediaPlayer.VideoPlayer == null)
return;
mediaPlayer.ShowFullScreenControls();
@ -13285,14 +13286,11 @@ namespace Nikse.SubtitleEdit.Forms
internal void GoBackSeconds(double seconds)
{
if (mediaPlayer != null)
{
if (mediaPlayer.CurrentPosition > seconds)
mediaPlayer.CurrentPosition -= seconds;
else
mediaPlayer.CurrentPosition = 0;
ShowSubtitle();
}
if (mediaPlayer.CurrentPosition > seconds)
mediaPlayer.CurrentPosition -= seconds;
else
mediaPlayer.CurrentPosition = 0;
ShowSubtitle();
}
private void ButtonStartHalfASecondBackClick(object sender, EventArgs e)
@ -13371,8 +13369,7 @@ namespace Nikse.SubtitleEdit.Forms
private void HideVideoPlayer()
{
if (mediaPlayer != null)
mediaPlayer.Pause();
mediaPlayer.Pause();
int textHeight = splitContainerListViewAndText.Height - splitContainerListViewAndText.SplitterDistance;
@ -13660,7 +13657,7 @@ namespace Nikse.SubtitleEdit.Forms
private void GotoSubtitleIndex(int index)
{
if (mediaPlayer != null && mediaPlayer.VideoPlayer != null && mediaPlayer.Duration > 0)
if (mediaPlayer.VideoPlayer != null && mediaPlayer.Duration > 0)
{
mediaPlayer.CurrentPosition = _subtitle.Paragraphs[index].StartTime.TotalSeconds;
}
@ -13668,7 +13665,7 @@ namespace Nikse.SubtitleEdit.Forms
private void PlayPart(Paragraph paragraph)
{
if (mediaPlayer != null && mediaPlayer.VideoPlayer != null)
if (mediaPlayer.VideoPlayer != null)
{
double startSeconds = paragraph.StartTime.TotalSeconds;
if (startSeconds > 0.2)
@ -14132,7 +14129,7 @@ namespace Nikse.SubtitleEdit.Forms
private void timer1_Tick(object sender, EventArgs e)
{
if (mediaPlayer != null && mediaPlayer.VideoPlayer != null)
if (mediaPlayer.VideoPlayer != null)
{
if (!mediaPlayer.IsPaused)
{
@ -15165,9 +15162,10 @@ namespace Nikse.SubtitleEdit.Forms
private void TimerAutoSaveTick(object sender, EventArgs e)
{
string currentText = _subtitle.ToText(GetCurrentSubtitleFormat());
string currentText = string.Empty;
if (_subtitle != null && _subtitle.Paragraphs.Count > 0)
{
currentText = _subtitle.ToText(GetCurrentSubtitleFormat());
if (_textAutoSave == null)
_textAutoSave = _changeSubtitleToString;
if (!string.IsNullOrEmpty(_textAutoSave) && currentText.Trim() != _textAutoSave.Trim() && currentText.Trim().Length > 0)
@ -15349,8 +15347,7 @@ namespace Nikse.SubtitleEdit.Forms
return;
}
if (mediaPlayer != null)
mediaPlayer.Pause();
mediaPlayer.Pause();
var addWaveForm = new AddWaveForm();
string peakWaveFileName = GetPeakWaveFileName(_videoFileName);
string spectrogramFolder = GetSpectrogramFolder(_videoFileName);
@ -15555,7 +15552,7 @@ namespace Nikse.SubtitleEdit.Forms
private void toolStripMenuItemWaveFormPlaySelection_Click(object sender, EventArgs e)
{
if (mediaPlayer != null && mediaPlayer.VideoPlayer != null)
if (mediaPlayer.VideoPlayer != null)
{
Paragraph p = audioVisualizer.NewSelectionParagraph;
if (p == null)
@ -16860,8 +16857,7 @@ namespace Nikse.SubtitleEdit.Forms
if (!Configuration.Settings.General.Undocked)
return;
if (mediaPlayer != null)
mediaPlayer.ShowNonFullScreenControls();
mediaPlayer.ShowNonFullScreenControls();
SaveUndockedPositions();
@ -16895,8 +16891,7 @@ namespace Nikse.SubtitleEdit.Forms
ReDockVideoPlayer(control);
_videoPlayerUnDocked.Close();
_videoPlayerUnDocked = null;
if (mediaPlayer != null)
mediaPlayer.ShowFullscreenButton = Configuration.Settings.General.VideoPlayerShowFullscreenButton;
mediaPlayer.ShowFullscreenButton = Configuration.Settings.General.VideoPlayerShowFullscreenButton;
}
_isVideoControlsUnDocked = false;
@ -17021,7 +17016,7 @@ namespace Nikse.SubtitleEdit.Forms
private void CloseVideoToolStripMenuItemClick(object sender, EventArgs e)
{
timer1.Stop();
if (mediaPlayer != null && mediaPlayer.VideoPlayer != null)
if (mediaPlayer.VideoPlayer != null)
{
mediaPlayer.SubtitleText = string.Empty;
mediaPlayer.VideoPlayer.DisposeVideoPlayer();
@ -18406,16 +18401,14 @@ namespace Nikse.SubtitleEdit.Forms
textBoxListViewText.RightToLeft = RightToLeft.No;
SubtitleListview1.RightToLeft = RightToLeft.No;
textBoxSource.RightToLeft = RightToLeft.No;
if (mediaPlayer != null)
mediaPlayer.TextRightToLeft = RightToLeft.No;
mediaPlayer.TextRightToLeft = RightToLeft.No;
}
else
{
textBoxListViewText.RightToLeft = RightToLeft.Yes;
SubtitleListview1.RightToLeft = RightToLeft.Yes;
textBoxSource.RightToLeft = RightToLeft.Yes;
if (mediaPlayer != null)
mediaPlayer.TextRightToLeft = RightToLeft.Yes;
mediaPlayer.TextRightToLeft = RightToLeft.Yes;
}
}

View File

@ -80,8 +80,10 @@ namespace Nikse.SubtitleEdit.Forms
public void Initialize(Subtitle subtitle)
{
_subtitle = subtitle;
if (subtitle == null)
throw new ArgumentNullException("subtitle");
_subtitle = subtitle;
foreach (var item in Configuration.Settings.MultipleSearchAndReplaceList)
{
AddToReplaceListView(item.Enabled, item.FindWhat, item.ReplaceWith, EnglishSearchTypeToLocal(item.SearchType));
@ -89,7 +91,7 @@ namespace Nikse.SubtitleEdit.Forms
}
GeneratePreview();
if (subtitle == null || subtitle.Paragraphs == null || subtitle.Paragraphs.Count == 0)
if (subtitle.Paragraphs == null || subtitle.Paragraphs.Count == 0)
groupBoxLinesFound.Enabled = false;
}

View File

@ -3688,6 +3688,11 @@ namespace Nikse.SubtitleEdit.Forms
}
string name = pos.ToString(CultureInfo.InvariantCulture);
if (_compareDoc == null)
{
_compareDoc = new XmlDocument();
_compareDoc.LoadXml("<OcrBitmaps></OcrBitmaps>");
}
if (_compareBitmaps == null)
_compareBitmaps = new List<CompareItem>();
_compareBitmaps.Add(new CompareItem(new ManagedBitmap(newTarget), name, isItalic, expandCount, text));
@ -3709,12 +3714,6 @@ namespace Nikse.SubtitleEdit.Forms
element.Attributes.Append(italic);
}
element.InnerText = pos.ToString(CultureInfo.InvariantCulture);
if (_compareDoc == null)
{
_compareDoc = new XmlDocument();
_compareDoc.LoadXml("<OcrBitmaps></OcrBitmaps>");
}
_compareDoc.DocumentElement.AppendChild(element);
_compareDoc.Save(path + "Images.xml");
return name;

View File

@ -294,7 +294,7 @@ namespace Nikse.SubtitleEdit.Logic.DetectEncoding
// get unmanaged arrays
IntPtr pPrefEncs = Marshal.AllocCoTaskMem(sizeof(uint) * preferredEncodings.Length);
IntPtr pDetectedEncs = preferredEncodings == null ? IntPtr.Zero : Marshal.AllocCoTaskMem(sizeof(uint) * resultCodePages.Length);
IntPtr pDetectedEncs = Marshal.AllocCoTaskMem(sizeof(uint) * resultCodePages.Length);
try
{

View File

@ -507,7 +507,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var tti = new EbuTextTimingInformation();
int rows;
if (header == null || !int.TryParse(header.MaximumNumberOfDisplayableRows, out rows))
if (!int.TryParse(header.MaximumNumberOfDisplayableRows, out rows))
rows = 23;
if (header != null && header.DisplayStandardCode == "1" || header.DisplayStandardCode == "2") // teletext
@ -1076,7 +1076,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
tti.TextField = sb.ToString().Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine).TrimEnd() + endTags;
int rows;
if (header == null || !int.TryParse(header.MaximumNumberOfDisplayableRows, out rows))
if (!int.TryParse(header.MaximumNumberOfDisplayableRows, out rows))
rows = 23;
if (tti.VerticalPosition < 3)
{