From 5d5715aeac12a5f2c719fbd1990f2ae84c50efe9 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Tue, 4 Sep 2018 19:56:41 +0200 Subject: [PATCH] Fix for multiple replace result count - thx OmrSi :) --- src/Forms/MultipleReplace.cs | 37 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Forms/MultipleReplace.cs b/src/Forms/MultipleReplace.cs index bd85d5f60..330d87358 100644 --- a/src/Forms/MultipleReplace.cs +++ b/src/Forms/MultipleReplace.cs @@ -26,11 +26,11 @@ namespace Nikse.SubtitleEdit.Forms private readonly List _oldMultipleSearchAndReplaceGroups = new List(); private readonly Dictionary _compiledRegExList = new Dictionary(); private Subtitle _subtitle; + private Subtitle _original; public List DeleteIndices { get; private set; } public Subtitle FixedSubtitle { get; private set; } - public int FixCount => _fixedTotalLines.Count; - private readonly List _fixedTotalLines; - private List _fixedLines; + public int FixCount { get; private set; } + private MultipleSearchAndReplaceGroup _currentGroup; public MultipleReplace() @@ -99,13 +99,12 @@ namespace Nikse.SubtitleEdit.Forms radioButtonCaseSensitive.Left = radioButtonNormal.Left + radioButtonNormal.Width + 40; radioButtonRegEx.Left = radioButtonCaseSensitive.Left + radioButtonCaseSensitive.Width + 40; - _fixedLines = new List(); - _fixedTotalLines = new List(); } public void Initialize(Subtitle subtitle) { _subtitle = subtitle ?? throw new ArgumentNullException(nameof(subtitle)); + _original = new Subtitle(_subtitle); _oldMultipleSearchAndReplaceGroups.Clear(); if (Configuration.Settings.MultipleSearchAndReplaceGroups.Count == 0) @@ -209,7 +208,7 @@ namespace Nikse.SubtitleEdit.Forms Cursor = Cursors.WaitCursor; FixedSubtitle = new Subtitle(_subtitle); DeleteIndices = new List(); - _fixedLines = new List(); + int fixedLines = 0; listViewFixes.BeginUpdate(); listViewFixes.Items.Clear(); var replaceExpressions = new HashSet(); @@ -281,7 +280,7 @@ namespace Nikse.SubtitleEdit.Forms if (hit && newText != p.Text) { - _fixedLines.Add(i); + fixedLines++; fixes.Add(MakePreviewListItem(p, newText)); int index = _subtitle.GetIndex(p); FixedSubtitle.Paragraphs[index].Text = newText; @@ -294,7 +293,7 @@ namespace Nikse.SubtitleEdit.Forms listViewFixes.Items.AddRange(fixes.ToArray()); listViewFixes.EndUpdate(); - groupBoxLinesFound.Text = string.Format(Configuration.Settings.Language.MultipleReplace.LinesFoundX, _fixedLines.Count); + groupBoxLinesFound.Text = string.Format(Configuration.Settings.Language.MultipleReplace.LinesFoundX, fixedLines); Cursor = Cursors.Default; DeleteIndices.Reverse(); } @@ -338,16 +337,23 @@ namespace Nikse.SubtitleEdit.Forms private void buttonOK_Click(object sender, EventArgs e) { - foreach (var fixedLine in _fixedLines) - { - if (!_fixedTotalLines.Contains(fixedLine)) - _fixedTotalLines.Add(fixedLine); - } ResetUncheckLines(); + SetFixCount(); SaveReplaceList(true); DialogResult = DialogResult.OK; } + public void SetFixCount() + { + for (var index = 0; index < _original.Paragraphs.Count; index++) + { + var p = _original.Paragraphs[index]; + var f = FixedSubtitle.GetParagraphOrDefault(index); + if (f != null && f.Text != p.Text) + FixCount++; + } + } + private void SaveReplaceList(bool saveToDisk) { if (saveToDisk) @@ -1057,11 +1063,6 @@ namespace Nikse.SubtitleEdit.Forms private void buttonApply_Click(object sender, EventArgs e) { - foreach (var fixedLine in _fixedLines) - { - if (!_fixedTotalLines.Contains(fixedLine)) - _fixedTotalLines.Add(fixedLine); - } ResetUncheckLines(); _subtitle = new Subtitle(FixedSubtitle); GeneratePreview();