From a2fa661448d832be081e4a77e72171276b60d943 Mon Sep 17 00:00:00 2001 From: niksedk Date: Mon, 2 May 2011 14:18:31 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20crash=20when=20entering=20invalid=20text?= =?UTF-8?q?=20in=20source=20view=20(thx=20Fr=C3=A9d=C3=A9ric)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@416 99eadd0c-20b8-1223-b5c4-2a2b2df33de2 --- src/Forms/Main.Designer.cs | 1 + src/Forms/Main.cs | 26 +++++++++++++++++++++----- src/Forms/Main.resx | 5 ++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Forms/Main.Designer.cs b/src/Forms/Main.Designer.cs index afeba5ecf..29aeec848 100644 --- a/src/Forms/Main.Designer.cs +++ b/src/Forms/Main.Designer.cs @@ -2868,6 +2868,7 @@ this.tabControlSubtitle.Size = new System.Drawing.Size(945, 280); this.tabControlSubtitle.TabIndex = 0; this.tabControlSubtitle.SelectedIndexChanged += new System.EventHandler(this.TabControlSubtitleSelectedIndexChanged); + this.tabControlSubtitle.Selecting += new System.Windows.Forms.TabControlCancelEventHandler(this.tabControlSubtitle_Selecting); // // tabPage1 // diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index f8974a852..2438d9fcb 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -2643,20 +2643,23 @@ namespace Nikse.SubtitleEdit.Forms { if (_sourceViewChange) { - MakeHistoryForUndo(_language.BeforeChangesMadeInSourceView); SaveSubtitleListviewIndexes(); if (textBoxSource.Text.Trim().Length > 0) { - SubtitleFormat format = _subtitle.ReloadLoadSubtitle(new List(textBoxSource.Lines), null); - if (format.IsFrameBased) - _subtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate); - _sourceViewChange = false; + Subtitle temp = new Subtitle(_subtitle); + SubtitleFormat format = temp.ReloadLoadSubtitle(new List(textBoxSource.Lines), null); if (format == null) { MessageBox.Show(_language.UnableToParseSourceView); + return; } else { + _sourceViewChange = false; + MakeHistoryForUndo(_language.BeforeChangesMadeInSourceView); + _subtitle.ReloadLoadSubtitle(new List(textBoxSource.Lines), null); + if (format.IsFrameBased) + _subtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate); int index = 0; foreach (object obj in comboBoxSubtitleFormats.Items) { @@ -2668,6 +2671,8 @@ namespace Nikse.SubtitleEdit.Forms } else { + _sourceViewChange = false; + MakeHistoryForUndo(_language.BeforeChangesMadeInSourceView); _sourceViewChange = false; _subtitle.Paragraphs.Clear(); } @@ -9856,5 +9861,16 @@ namespace Nikse.SubtitleEdit.Forms exportBdnXmlPng.ShowDialog(this); } + private void tabControlSubtitle_Selecting(object sender, TabControlCancelEventArgs e) + { + if (tabControlSubtitle.SelectedIndex != TabControlSourceView && textBoxSource.Text.Trim().Length > 1) + { + Subtitle temp = new Subtitle(_subtitle); + SubtitleFormat format = temp.ReloadLoadSubtitle(new List(textBoxSource.Lines), null); + if (format == null) + e.Cancel = true; + } + } + } } \ No newline at end of file diff --git a/src/Forms/Main.resx b/src/Forms/Main.resx index 3a2ade696..f34c85b21 100644 --- a/src/Forms/Main.resx +++ b/src/Forms/Main.resx @@ -577,6 +577,9 @@ 208, 56 + + 208, 56 + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 @@ -684,7 +687,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD2 - CAAAAk1TRnQBSQFMAgEBAgEAAYABBAGAAQQBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + CAAAAk1TRnQBSQFMAgEBAgEAAYgBBAGIAQQBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA