This commit is contained in:
Nikolaj Olsson 2021-04-25 05:41:32 +02:00
parent 79bd38df11
commit 292d03c03f
2 changed files with 50 additions and 25 deletions

View File

@ -306,7 +306,7 @@ namespace Nikse.SubtitleEdit.Core
return subtitleFormat;
}
public void MakeHistoryForUndo(string description, SubtitleFormat subtitleFormat, DateTime fileModified, Subtitle original, string originalSubtitleFileName, int lineNumber, int linePosition, int linePositionOriginal)
public void MakeHistoryForUndo(string description, string subtitleFormatFriendlyName, DateTime fileModified, Subtitle original, string originalSubtitleFileName, int lineNumber, int linePosition, int linePositionOriginal)
{
// don't fill memory with history - use a max rollback points
if (HistoryItems.Count > MaximumHistoryItems)
@ -314,7 +314,7 @@ namespace Nikse.SubtitleEdit.Core
HistoryItems.RemoveAt(0);
}
HistoryItems.Add(new HistoryItem(HistoryItems.Count, this, description, FileName, fileModified, subtitleFormat.FriendlyName, original, originalSubtitleFileName, lineNumber, linePosition, linePositionOriginal));
HistoryItems.Add(new HistoryItem(HistoryItems.Count, this, description, FileName, fileModified, subtitleFormatFriendlyName, original, originalSubtitleFileName, lineNumber, linePosition, linePositionOriginal));
}
public string UndoHistory(int index, out string subtitleFormatFriendlyName, out DateTime fileModified, out Subtitle originalSubtitle, out string originalSubtitleFileName)

View File

@ -2024,7 +2024,7 @@ namespace Nikse.SubtitleEdit.Forms
}
_lastAutoSave = DateTime.UtcNow.Ticks + 1009000;
var currentSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
var currentSubtitleHash = GetFastSubtitleHash();
if (_changeSubtitleHash != currentSubtitleHash && _lastDoNotPrompt != currentSubtitleHash && _subtitle?.Paragraphs.Count > 0)
{
if (string.IsNullOrEmpty(_fileName) || _converted)
@ -2046,7 +2046,7 @@ namespace Nikse.SubtitleEdit.Forms
private bool ContinueNewOrExit()
{
AutoSave(true);
var currentSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
var currentSubtitleHash = GetFastSubtitleHash();
if (_changeSubtitleHash != currentSubtitleHash && _lastDoNotPrompt != currentSubtitleHash && _subtitle?.Paragraphs.Count > 0)
{
string promptText = _language.SaveChangesToUntitled;
@ -2141,7 +2141,7 @@ namespace Nikse.SubtitleEdit.Forms
}
}
_lastDoNotPrompt = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
_lastDoNotPrompt = GetFastSubtitleHash();
return true;
}
@ -2194,7 +2194,7 @@ namespace Nikse.SubtitleEdit.Forms
}
_subtitle.FileName = _fileName;
_subtitle.MakeHistoryForUndo(description, GetCurrentSubtitleFormat(), _fileDateTime, _subtitleOriginal, _subtitleOriginalFileName, _subtitleListViewIndex, textBoxListViewText.SelectionStart, textBoxListViewTextOriginal.SelectionStart);
_subtitle.MakeHistoryForUndo(description, GetCurrentSubtitleFormat().FriendlyName, _fileDateTime, _subtitleOriginal, _subtitleOriginalFileName, _subtitleListViewIndex, textBoxListViewText.SelectionStart, textBoxListViewTextOriginal.SelectionStart);
_undoIndex++;
if (_undoIndex > Subtitle.MaximumHistoryItems)
@ -2549,7 +2549,7 @@ namespace Nikse.SubtitleEdit.Forms
SetTitle();
ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName));
_sourceViewChange = false;
_changeSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
_changeSubtitleHash = GetFastSubtitleHash();
ResetHistory();
SetUndockedWindowsTitle();
_converted = true;
@ -2653,7 +2653,7 @@ namespace Nikse.SubtitleEdit.Forms
MakeHistoryForUndo(string.Format(_language.BeforeLoadOf, Path.GetFileName(fileName)));
}
var subtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
var subtitleHash = GetFastSubtitleHash();
bool hasChanged = (_changeSubtitleHash != subtitleHash) && (_lastDoNotPrompt != subtitleHash);
SubtitleFormat format = _subtitle.LoadSubtitle(fileName, out encoding, encoding);
@ -2664,7 +2664,7 @@ namespace Nikse.SubtitleEdit.Forms
if (!hasChanged)
{
_changeSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
_changeSubtitleHash = GetFastSubtitleHash();
}
ShowHideTextBasedFeatures(format);
@ -3424,7 +3424,7 @@ namespace Nikse.SubtitleEdit.Forms
SetEncoding(encoding);
}
_changeSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
_changeSubtitleHash = GetFastSubtitleHash();
_converted = false;
ResetHistory();
SetListViewStateImages();
@ -3942,7 +3942,7 @@ namespace Nikse.SubtitleEdit.Forms
if (rfe.VideoOffsetInMs != 0)
{
_subtitle.AddTimeToAllParagraphs(TimeSpan.FromMilliseconds(-Configuration.Settings.General.CurrentVideoOffsetInMs));
_changeSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
_changeSubtitleHash = GetFastSubtitleHash();
if (_subtitleOriginal != null && _subtitleOriginal.Paragraphs.Count > 0)
{
_subtitleOriginal.AddTimeToAllParagraphs(TimeSpan.FromMilliseconds(-Configuration.Settings.General.CurrentVideoOffsetInMs));
@ -4125,7 +4125,7 @@ namespace Nikse.SubtitleEdit.Forms
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, VideoFileName, _subtitleOriginalFileName, Configuration.Settings.General.CurrentVideoOffsetInMs);
Configuration.Settings.Save();
UpdateRecentFilesUI();
_changeSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
_changeSubtitleHash = GetFastSubtitleHash();
}
break;
@ -4163,7 +4163,7 @@ namespace Nikse.SubtitleEdit.Forms
if (ebu.Save(_fileName, sub, !_saveAsCalled, header))
{
_changeSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
_changeSubtitleHash = GetFastSubtitleHash();
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, VideoFileName, _subtitleOriginalFileName, Configuration.Settings.General.CurrentVideoOffsetInMs);
Configuration.Settings.Save();
}
@ -4347,7 +4347,7 @@ namespace Nikse.SubtitleEdit.Forms
NetflixGlyphCheck(true);
}
_changeSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
_changeSubtitleHash = GetFastSubtitleHash();
return DialogResult.OK;
}
catch (Exception exception)
@ -4576,7 +4576,7 @@ namespace Nikse.SubtitleEdit.Forms
_listViewOriginalTextUndoLast = null;
_listViewTextUndoIndex = -1;
_changeSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
_changeSubtitleHash = GetFastSubtitleHash();
_converted = false;
SetTitle();
@ -4639,6 +4639,9 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private string _lastChangedToFormat;
private void ComboBoxSubtitleFormatsSelectedIndexChanged(object sender, EventArgs e)
{
if (IsMenuOpen)
@ -4654,16 +4657,26 @@ namespace Nikse.SubtitleEdit.Forms
}
var formatType = format.GetType();
if (_oldSubtitleFormat == null)
{
if (!_loading)
if (!_loading && _lastChangedToFormat != format.FriendlyName)
{
MakeHistoryForUndo(string.Format(_language.BeforeConvertingToX, format.FriendlyName));
}
}
else
{
_subtitle.MakeHistoryForUndo(string.Format(_language.BeforeConvertingToX, format.FriendlyName), _oldSubtitleFormat, _fileDateTime, _subtitleOriginal, _subtitleOriginalFileName, _subtitleListViewIndex, textBoxListViewText.SelectionStart, textBoxListViewTextOriginal.SelectionStart);
if (!_makeHistoryPaused && _lastChangedToFormat != format.FriendlyName)
{
_subtitle.MakeHistoryForUndo(string.Format(_language.BeforeConvertingToX, format.FriendlyName), _lastChangedToFormat, _fileDateTime, _subtitleOriginal, _subtitleOriginalFileName, _subtitleListViewIndex, textBoxListViewText.SelectionStart, textBoxListViewTextOriginal.SelectionStart);
_undoIndex++;
if (_undoIndex > Subtitle.MaximumHistoryItems)
{
_undoIndex--;
}
}
if (_oldSubtitleFormat?.GetType() != format.GetType())
{
_oldSubtitleFormat.RemoveNativeFormatting(_subtitle, format);
@ -4693,6 +4706,7 @@ namespace Nikse.SubtitleEdit.Forms
}
}
_lastChangedToFormat = format.FriendlyName;
UpdateSourceView();
if (_converted)
{
@ -7347,9 +7361,15 @@ namespace Nikse.SubtitleEdit.Forms
_fileDateTime = oldFileDateTime; // undo will not give overwrite-newer-file warning
}
comboBoxSubtitleFormats.SelectedIndexChanged -= ComboBoxSubtitleFormatsSelectedIndexChanged;
SetCurrentFormat(subtitleFormatFriendlyName);
comboBoxSubtitleFormats.SelectedIndexChanged += ComboBoxSubtitleFormatsSelectedIndexChanged;
if (GetCurrentSubtitleFormat().FriendlyName != subtitleFormatFriendlyName)
{
var oldPaused = _makeHistoryPaused;
_makeHistoryPaused = true;
comboBoxSubtitleFormats.SelectedIndexChanged -= ComboBoxSubtitleFormatsSelectedIndexChanged;
SetCurrentFormat(subtitleFormatFriendlyName);
comboBoxSubtitleFormats.SelectedIndexChanged += ComboBoxSubtitleFormatsSelectedIndexChanged;
_makeHistoryPaused = oldPaused;
}
UpdateSourceView();
SubtitleListview1.Fill(_subtitle, _subtitleOriginal);
@ -19855,7 +19875,7 @@ namespace Nikse.SubtitleEdit.Forms
}
}
var currentChanged = _changeSubtitleHash != _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
var currentChanged = _changeSubtitleHash != GetFastSubtitleHash();
var originalActive = Configuration.Settings.General.AllowEditOfOriginalSubtitle &&
_subtitleOriginal != null &&
_subtitleOriginal.Paragraphs.Count > 0;
@ -21789,7 +21809,7 @@ namespace Nikse.SubtitleEdit.Forms
if (string.IsNullOrEmpty(_fileName) && (_subtitle == null || _subtitle.Paragraphs.Count == 0))
{
_changeSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
_changeSubtitleHash = GetFastSubtitleHash();
}
comboBoxSubtitleFormats.AutoCompleteSource = AutoCompleteSource.ListItems;
@ -28812,7 +28832,7 @@ namespace Nikse.SubtitleEdit.Forms
var oldVideoOffset = Configuration.Settings.General.CurrentVideoOffsetInMs;
if (form.ShowDialog(this) == DialogResult.OK)
{
var change = _changeSubtitleHash != _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
var change = _changeSubtitleHash != GetFastSubtitleHash();
if (form.FromCurrentVideoPosition && mediaPlayer.VideoPlayer != null)
{
Configuration.Settings.General.CurrentVideoOffsetInMs = (long)(Math.Round((form.VideoOffset.TotalSeconds - mediaPlayer.VideoPlayer.CurrentPosition) * 1000.0));
@ -28843,9 +28863,9 @@ namespace Nikse.SubtitleEdit.Forms
if (!change)
{
_changeSubtitleHash = _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName);
_changeSubtitleHash = GetFastSubtitleHash();
}
else if (change && _changeSubtitleHash == _subtitle.GetFastHashCode(GetCurrentEncoding().BodyName))
else if (change && _changeSubtitleHash == GetFastSubtitleHash())
{
_changeSubtitleHash = -1;
}
@ -30294,5 +30314,10 @@ namespace Nikse.SubtitleEdit.Forms
return ProcessCmdKey(ref messageCopy, keyData);
}
private int GetFastSubtitleHash()
{
return _subtitle.GetFastHashCode(_fileName + GetCurrentEncoding().BodyName);
}
}
}