Prompt when cancelling OCR window - thx Zwulf :)

This commit is contained in:
niksedk 2015-05-31 19:25:02 +02:00
parent bf74a59321
commit 3b19c51073
5 changed files with 63 additions and 0 deletions

View File

@ -2032,6 +2032,8 @@ Keep changes?</KeepChangesMessage>
<InspectCompareMatchesForCurrentImage>Inspect compare matches for current image...</InspectCompareMatchesForCurrentImage>
<EditLastAdditions>Edit last image compare additions...</EditLastAdditions>
<SetUnitalicFactor>Set un-italic factor...</SetUnitalicFactor>
<DiscardTitle>Discard changes made in OCR?</DiscardTitle>
<DiscardText>Do you want to discard changes made in current OCR session?</DiscardText>
</VobSubOcr>
<VobSubOcrCharacter>
<Title>VobSub - Manual image to text</Title>

View File

@ -291,6 +291,9 @@ namespace Nikse.SubtitleEdit.Forms
private int _tesseractAsyncIndex;
private BackgroundWorker _tesseractThread;
private DateTime _windowStartTime = DateTime.Now;
private int _linesOcred = 0;
public static void SetDoubleBuffered(Control c)
{
//Taxes: Remote Desktop Connection and painting http://blogs.msdn.com/oldnewthing/archive/2006/01/03/508694.aspx
@ -1275,6 +1278,19 @@ namespace Nikse.SubtitleEdit.Forms
foreach (string fn in fileNames)
{
string fullFileName = Path.Combine(Path.GetDirectoryName(_bdnFileName), fn);
if (!File.Exists(fullFileName))
{
// fix AVISubDetector lines
int idxOfIEquals = fn.IndexOf("i=", StringComparison.OrdinalIgnoreCase);
if (idxOfIEquals >= 0)
{
int idxOfSpace = fn.IndexOf(' ', idxOfIEquals);
if (idxOfSpace > 0)
{
fullFileName = Path.Combine(Path.GetDirectoryName(_bdnFileName), fn.Remove(0, idxOfSpace).Trim());
}
}
}
if (File.Exists(fullFileName))
{
try
@ -4950,6 +4966,7 @@ namespace Nikse.SubtitleEdit.Forms
private void ButtonOkClick(object sender, EventArgs e)
{
_linesOcred = 0; // don't ask about discard changes
if (_dvbSubtitles != null && checkBoxTransportStreamGetColorAndSplit.Checked)
MergeDvbForEachSubImage();
@ -5538,6 +5555,8 @@ namespace Nikse.SubtitleEdit.Forms
text = "<font color=\"" + ColorTranslator.ToHtml(_dvbSubColor) + "\">" + text + "</font>";
}
_linesOcred++;
if (_abort)
{
textBoxCurrentText.Text = text;
@ -7788,8 +7807,40 @@ namespace Nikse.SubtitleEdit.Forms
subtitleListView1.SelectIndexAndEnsureVisible(0);
}
private bool HasChangesBeenMade()
{
var secondsSinceOcrWindowOpened = DateTime.Now.Subtract(_windowStartTime).TotalSeconds;
if (_subtitle != null && _subtitle.Paragraphs.Count > 10 && secondsSinceOcrWindowOpened > 10)
{
int numberOfLinesWithText = 0;
foreach (var p in _subtitle.Paragraphs)
{
if (p != null && !string.IsNullOrWhiteSpace(p.Text))
{
numberOfLinesWithText++;
}
}
// ocr'ed more than 10 lines - or perhaps manually translated more than 10 lines in at least 30 seconds
if (_linesOcred > 10 || (numberOfLinesWithText > 10 && secondsSinceOcrWindowOpened > 30))
{
return true;
}
}
return false;
}
private void VobSubOcr_FormClosing(object sender, FormClosingEventArgs e)
{
if (HasChangesBeenMade())
{
if (MessageBox.Show(Configuration.Settings.Language.VobSubOcr.DiscardText, Configuration.Settings.Language.VobSubOcr.DiscardTitle, MessageBoxButtons.YesNo) == DialogResult.No)
{
e.Cancel = true;
return;
}
}
_icThreadsStop = true;
_abort = true;
_nocrThreadsStop = true;

View File

@ -2345,6 +2345,8 @@ Keep changes?",
InspectCompareMatchesForCurrentImage = "Inspect compare matches for current image...",
EditLastAdditions = "Edit last image compare additions...",
SetUnitalicFactor = "Set un-italic factor...",
DiscardTitle = "Discard changes made in OCR?",
DiscardText = "Do you want to discard changes made in current OCR session?",
};
VobSubOcrCharacter = new LanguageStructure.VobSubOcrCharacter

View File

@ -5454,6 +5454,12 @@ namespace Nikse.SubtitleEdit.Logic
case "VobSubOcr/SetUnitalicFactor":
language.VobSubOcr.SetUnitalicFactor = reader.Value;
break;
case "VobSubOcr/DiscardTitle":
language.VobSubOcr.DiscardTitle = reader.Value;
break;
case "VobSubOcr/DiscardText":
language.VobSubOcr.DiscardText = reader.Value;
break;
case "VobSubOcrCharacter/Title":
language.VobSubOcrCharacter.Title = reader.Value;
break;

View File

@ -2227,6 +2227,8 @@
public string InspectCompareMatchesForCurrentImage { get; set; }
public string EditLastAdditions { get; set; }
public string SetUnitalicFactor { get; set; }
public string DiscardTitle { get; set; }
public string DiscardText { get; set; }
}
public class VobSubOcrCharacter