Work on "Multiple replace" apply button - th Sopor :)

Work on #6633
This commit is contained in:
niksedk 2023-01-31 18:58:13 +01:00
parent d074c69b4a
commit aaeff9280b
5 changed files with 29 additions and 6 deletions

View File

@ -3377,7 +3377,7 @@ namespace Nikse.SubtitleEdit.Forms
{
using (var form = new MultipleReplace())
{
form.Initialize(new Subtitle());
form.Initialize(new Subtitle(), null);
form.ShowDialog(this);
}
}

View File

@ -48,7 +48,7 @@ using static System.Windows.Forms.LinkLabel;
namespace Nikse.SubtitleEdit.Forms
{
public sealed partial class Main : Form
public sealed partial class Main : Form, IReloadSubtitle
{
private class ComboBoxZoomItem
{
@ -8800,7 +8800,7 @@ namespace Nikse.SubtitleEdit.Forms
sub.Paragraphs.Add(new Paragraph(_subtitle.Paragraphs[idx], false));
}
multipleReplace.Initialize(sub);
multipleReplace.Initialize(sub, this);
if (multipleReplace.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(_language.BeforeMultipleReplace);
@ -20984,7 +20984,7 @@ namespace Nikse.SubtitleEdit.Forms
{
using (var multipleReplace = new MultipleReplace())
{
multipleReplace.Initialize(_subtitle);
multipleReplace.Initialize(_subtitle, this);
if (multipleReplace.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(_language.BeforeMultipleReplace);
@ -34877,5 +34877,13 @@ namespace Nikse.SubtitleEdit.Forms
RefreshSelectedParagraph();
}
}
public void ReloadSubtitle(Subtitle subtitle)
{
SaveSubtitleListviewIndices();
SubtitleListview1.Fill(_subtitle, _subtitleOriginal);
RestoreSubtitleListviewIndices();
RefreshSelectedParagraph();
}
}
}

View File

@ -27,6 +27,7 @@ namespace Nikse.SubtitleEdit.Forms
private readonly List<MultipleSearchAndReplaceGroup> _oldMultipleSearchAndReplaceGroups = new List<MultipleSearchAndReplaceGroup>();
private readonly Dictionary<string, Regex> _compiledRegExList = new Dictionary<string, Regex>();
private Subtitle _subtitle;
private IReloadSubtitle _reloadSubtitle;
private Subtitle _original;
public Subtitle FixedSubtitle { get; private set; }
public int FixCount { get; private set; }
@ -120,11 +121,12 @@ namespace Nikse.SubtitleEdit.Forms
radioButtonRegEx.Left = radioButtonCaseSensitive.Left + radioButtonCaseSensitive.Width + 40;
}
public void Initialize(Subtitle subtitle)
public void Initialize(Subtitle subtitle, IReloadSubtitle reloadSubtitle)
{
_subtitle = subtitle ?? throw new ArgumentNullException(nameof(subtitle));
_original = new Subtitle(_subtitle);
_oldMultipleSearchAndReplaceGroups.Clear();
_reloadSubtitle = reloadSubtitle;
if (Configuration.Settings.MultipleSearchAndReplaceGroups.Count == 0)
{
@ -151,11 +153,12 @@ namespace Nikse.SubtitleEdit.Forms
}
UpdateViewFromModel(Configuration.Settings.MultipleSearchAndReplaceGroups, Configuration.Settings.MultipleSearchAndReplaceGroups[0]);
buttonApply.Enabled = _reloadSubtitle != null;
}
internal void RunFromBatch(Subtitle subtitle)
{
Initialize(subtitle);
Initialize(subtitle, null);
GeneratePreview();
SetDeleteIndices();
}
@ -1226,7 +1229,9 @@ namespace Nikse.SubtitleEdit.Forms
SetDeleteIndices();
ResetUncheckLines();
_subtitle = new Subtitle(FixedSubtitle);
_reloadSubtitle?.ReloadSubtitle(_subtitle);
GeneratePreview();
SaveReplaceList(true);
}
private void exportToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -0,0 +1,9 @@
using Nikse.SubtitleEdit.Core.Common;
namespace Nikse.SubtitleEdit.Logic
{
public interface IReloadSubtitle
{
void ReloadSubtitle(Subtitle subtitle);
}
}

View File

@ -1407,6 +1407,7 @@
<Compile Include="Logic\FileTypeAssociations.cs" />
<Compile Include="Logic\FindReplaceDialogHelper.cs" />
<Compile Include="Logic\FontHelper.cs" />
<Compile Include="Logic\IReloadSubtitle.cs" />
<Compile Include="Logic\Language.cs" />
<Compile Include="Logic\LanguageDeserializer.cs" />
<Compile Include="Logic\LanguageStructure.cs" />