mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 19:22:53 +01:00
Fix #581 - thx Ivandrofly (also fixed double run for autobr/unbr due to combobox event)... hopefully bug free...
This commit is contained in:
parent
f31140af15
commit
143d4034c0
1
src/Forms/AutoBreakUnbreakLines.Designer.cs
generated
1
src/Forms/AutoBreakUnbreakLines.Designer.cs
generated
@ -123,7 +123,6 @@
|
||||
this.comboBoxConditions.Name = "comboBoxConditions";
|
||||
this.comboBoxConditions.Size = new System.Drawing.Size(150, 21);
|
||||
this.comboBoxConditions.TabIndex = 8;
|
||||
this.comboBoxConditions.SelectedIndexChanged += new System.EventHandler(this.ComboBoxConditionsSelectedIndexChanged);
|
||||
//
|
||||
// labelCondition
|
||||
//
|
||||
|
@ -12,20 +12,19 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
private List<Paragraph> _paragraphs;
|
||||
private int _changes;
|
||||
private bool _modeAutoBalance;
|
||||
private HashSet<string> _notAllowedFixes = new HashSet<string>();
|
||||
|
||||
private Dictionary<string, string> _fixedText = new Dictionary<string, string>();
|
||||
public Dictionary<string, string> FixedText
|
||||
{
|
||||
get { return _fixedText; }
|
||||
}
|
||||
|
||||
public int Changes
|
||||
{
|
||||
get { return _changes; }
|
||||
}
|
||||
|
||||
public List<Paragraph> FixedParagraphs
|
||||
{
|
||||
get
|
||||
{
|
||||
return _paragraphs;
|
||||
}
|
||||
}
|
||||
|
||||
public AutoBreakUnbreakLines()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -86,6 +85,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
|
||||
Unbreak();
|
||||
}
|
||||
comboBoxConditions.SelectedIndexChanged += ComboBoxConditionsSelectedIndexChanged;
|
||||
}
|
||||
|
||||
public int MinimumLength
|
||||
@ -108,10 +108,13 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
|
||||
private void AutoBalance()
|
||||
{
|
||||
listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
|
||||
_notAllowedFixes = new HashSet<string>();
|
||||
_fixedText = new Dictionary<string, string>();
|
||||
int minLength = MinimumLength;
|
||||
Text = Configuration.Settings.Language.AutoBreakUnbreakLines.TitleAutoBreak;
|
||||
|
||||
Subtitle sub = new Subtitle();
|
||||
var sub = new Subtitle();
|
||||
foreach (Paragraph p in _paragraphs)
|
||||
sub.Paragraphs.Add(p);
|
||||
string language = Utilities.AutoDetectGoogleLanguage(sub);
|
||||
@ -126,16 +129,21 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
if (text != p.Text)
|
||||
{
|
||||
AddToListView(p, text);
|
||||
_fixedText.Add(p.ID, text);
|
||||
_changes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
listViewFixes.EndUpdate();
|
||||
groupBoxLinesFound.Text = string.Format(Configuration.Settings.Language.AutoBreakUnbreakLines.LinesFoundX, listViewFixes.Items.Count);
|
||||
listViewFixes.ItemChecked += listViewFixes_ItemChecked;
|
||||
}
|
||||
|
||||
private void Unbreak()
|
||||
{
|
||||
listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
|
||||
_notAllowedFixes = new HashSet<string>();
|
||||
_fixedText = new Dictionary<string, string>();
|
||||
int minLength = int.Parse(comboBoxConditions.Items[comboBoxConditions.SelectedIndex].ToString());
|
||||
Text = Configuration.Settings.Language.AutoBreakUnbreakLines.TitleUnbreak;
|
||||
listViewFixes.BeginUpdate();
|
||||
@ -151,12 +159,14 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
if (text != p.Text)
|
||||
{
|
||||
AddToListView(p, text);
|
||||
_fixedText.Add(p.ID, text);
|
||||
_changes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
listViewFixes.EndUpdate();
|
||||
groupBoxLinesFound.Text = string.Format(Configuration.Settings.Language.AutoBreakUnbreakLines.LinesFoundX, listViewFixes.Items.Count);
|
||||
listViewFixes.ItemChecked += listViewFixes_ItemChecked;
|
||||
}
|
||||
|
||||
private void AutoBreakUnbreakLinesKeyDown(object sender, KeyEventArgs e)
|
||||
@ -179,23 +189,15 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
listViewFixes.Items.Add(item);
|
||||
}
|
||||
|
||||
private bool IsFixAllowed(Paragraph p)
|
||||
{
|
||||
foreach (ListViewItem item in listViewFixes.Items)
|
||||
{
|
||||
if (item.Tag.ToString() == p.ToString())
|
||||
return item.Checked;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ButtonOkClick(object sender, EventArgs e)
|
||||
{
|
||||
for (int i = _paragraphs.Count - 1; i > 0; i--)
|
||||
for (int i = _paragraphs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Paragraph p = _paragraphs[i];
|
||||
if (!IsFixAllowed(p))
|
||||
_paragraphs.Remove(p);
|
||||
if (_notAllowedFixes.Contains(p.ID))
|
||||
{
|
||||
_fixedText.Remove(p.ID);
|
||||
}
|
||||
}
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
@ -207,5 +209,21 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
else
|
||||
Unbreak();
|
||||
}
|
||||
|
||||
private void listViewFixes_ItemChecked(object sender, ItemCheckedEventArgs e)
|
||||
{
|
||||
if (e.Item == null)
|
||||
return;
|
||||
|
||||
var p = e.Item.Tag as Paragraph;
|
||||
if (p == null)
|
||||
return;
|
||||
|
||||
if (e.Item.Checked)
|
||||
_notAllowedFixes.Remove(p.ID);
|
||||
else
|
||||
_notAllowedFixes.Add(p.ID);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11652,7 +11652,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
selectedLines.Paragraphs.Add(_subtitle.Paragraphs[index]);
|
||||
autoBreakUnbreakLines.Initialize(selectedLines, true);
|
||||
|
||||
if (autoBreakUnbreakLines.ShowDialog() == DialogResult.OK && autoBreakUnbreakLines.FixedParagraphs.Count > 0)
|
||||
if (autoBreakUnbreakLines.ShowDialog() == DialogResult.OK && autoBreakUnbreakLines.FixedText.Count > 0)
|
||||
{
|
||||
MakeHistoryForUndo(_language.BeforeAutoBalanceSelectedLines);
|
||||
string language = Utilities.AutoDetectGoogleLanguage(_subtitle);
|
||||
@ -11660,18 +11660,16 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
foreach (int index in SubtitleListview1.SelectedIndices)
|
||||
{
|
||||
Paragraph p = _subtitle.GetParagraphOrDefault(index);
|
||||
|
||||
int indexFixed = autoBreakUnbreakLines.FixedParagraphs.IndexOf(p);
|
||||
if (indexFixed >= 0)
|
||||
if (autoBreakUnbreakLines.FixedText.ContainsKey(p.ID))
|
||||
{
|
||||
p.Text = Utilities.AutoBreakLine(p.Text, 5, autoBreakUnbreakLines.MergeLinesShorterThan, language);
|
||||
p.Text = autoBreakUnbreakLines.FixedText[p.ID];
|
||||
SubtitleListview1.SetText(index, p.Text);
|
||||
SubtitleListview1.SyntaxColorLine(_subtitle.Paragraphs, index, p);
|
||||
}
|
||||
}
|
||||
SubtitleListview1.EndUpdate();
|
||||
RefreshSelectedParagraph();
|
||||
ShowStatus(string.Format(_language.NumberOfLinesAutoBalancedX, autoBreakUnbreakLines.FixedParagraphs.Count));
|
||||
ShowStatus(string.Format(_language.NumberOfLinesAutoBalancedX, autoBreakUnbreakLines.FixedText.Count));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11692,7 +11690,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
selectedLines.Paragraphs.Add(_subtitle.Paragraphs[index]);
|
||||
autoBreakUnbreakLines.Initialize(selectedLines, false);
|
||||
|
||||
if (autoBreakUnbreakLines.ShowDialog() == DialogResult.OK && autoBreakUnbreakLines.FixedParagraphs.Count > 0)
|
||||
if (autoBreakUnbreakLines.ShowDialog() == DialogResult.OK && autoBreakUnbreakLines.FixedText.Count > 0)
|
||||
{
|
||||
MakeHistoryForUndo(_language.BeforeRemoveLineBreaksInSelectedLines);
|
||||
|
||||
@ -11700,18 +11698,17 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
foreach (int index in SubtitleListview1.SelectedIndices)
|
||||
{
|
||||
Paragraph p = _subtitle.GetParagraphOrDefault(index);
|
||||
|
||||
int indexFixed = autoBreakUnbreakLines.FixedParagraphs.IndexOf(p);
|
||||
if (indexFixed >= 0)
|
||||
if (autoBreakUnbreakLines.FixedText.ContainsKey(p.ID))
|
||||
{
|
||||
p.Text = Utilities.UnbreakLine(p.Text);
|
||||
p.Text = autoBreakUnbreakLines.FixedText[p.ID];
|
||||
SubtitleListview1.SetText(index, p.Text);
|
||||
SubtitleListview1.SyntaxColorLine(_subtitle.Paragraphs, index, p);
|
||||
}
|
||||
|
||||
}
|
||||
SubtitleListview1.EndUpdate();
|
||||
RefreshSelectedParagraph();
|
||||
ShowStatus(string.Format(_language.NumberOfWithRemovedLineBreakX, autoBreakUnbreakLines.FixedParagraphs.Count));
|
||||
ShowStatus(string.Format(_language.NumberOfWithRemovedLineBreakX, autoBreakUnbreakLines.FixedText.Count));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user