Merge pull request #2587 from ivandrofly/autobreak

[AutoBreakUnbreakLines] - Update
This commit is contained in:
Nikolaj Olsson 2017-10-01 18:12:16 +02:00 committed by GitHub
commit d244d25304

View File

@ -10,22 +10,18 @@ namespace Nikse.SubtitleEdit.Forms
public partial class AutoBreakUnbreakLines : PositionAndSizeForm public partial class AutoBreakUnbreakLines : PositionAndSizeForm
{ {
private List<Paragraph> _paragraphs; private List<Paragraph> _paragraphs;
private int _changes;
private bool _modeAutoBalance; private bool _modeAutoBalance;
private HashSet<string> _notAllowedFixes = new HashSet<string>(); private HashSet<string> _notAllowedFixes = new HashSet<string>();
private Dictionary<string, string> _fixedText = new Dictionary<string, string>(); private Dictionary<string, string> _fixedText = new Dictionary<string, string>();
private string _language;
public Dictionary<string, string> FixedText public Dictionary<string, string> FixedText
{ {
get { return _fixedText; } get { return _fixedText; }
} }
public int Changes
{
get { return _changes; }
}
public AutoBreakUnbreakLines() public AutoBreakUnbreakLines()
{ {
UiUtil.PreInitialize(this); UiUtil.PreInitialize(this);
@ -46,6 +42,7 @@ namespace Nikse.SubtitleEdit.Forms
public void Initialize(Subtitle subtitle, bool autoBalance) public void Initialize(Subtitle subtitle, bool autoBalance)
{ {
_language = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle);
_modeAutoBalance = autoBalance; _modeAutoBalance = autoBalance;
_paragraphs = new List<Paragraph>(); _paragraphs = new List<Paragraph>();
@ -106,10 +103,6 @@ namespace Nikse.SubtitleEdit.Forms
int minLength = MinimumLength; int minLength = MinimumLength;
Text = Configuration.Settings.Language.AutoBreakUnbreakLines.TitleAutoBreak; Text = Configuration.Settings.Language.AutoBreakUnbreakLines.TitleAutoBreak;
var sub = new Subtitle();
foreach (Paragraph p in _paragraphs)
sub.Paragraphs.Add(p);
var language = LanguageAutoDetect.AutoDetectGoogleLanguage(sub);
listViewFixes.BeginUpdate(); listViewFixes.BeginUpdate();
listViewFixes.Items.Clear(); listViewFixes.Items.Clear();
@ -117,12 +110,11 @@ namespace Nikse.SubtitleEdit.Forms
{ {
if (HtmlUtil.RemoveHtmlTags(p.Text, true).Length > minLength || p.Text.Contains(Environment.NewLine)) if (HtmlUtil.RemoveHtmlTags(p.Text, true).Length > minLength || p.Text.Contains(Environment.NewLine))
{ {
var text = Utilities.AutoBreakLine(p.Text, 5, MergeLinesShorterThan, language); var text = Utilities.AutoBreakLine(p.Text, 5, MergeLinesShorterThan, _language);
if (text != p.Text) if (text != p.Text)
{ {
AddToListView(p, text); AddToListView(p, text);
_fixedText.Add(p.ID, text); _fixedText.Add(p.ID, text);
_changes++;
} }
} }
} }
@ -142,14 +134,13 @@ namespace Nikse.SubtitleEdit.Forms
listViewFixes.Items.Clear(); listViewFixes.Items.Clear();
foreach (Paragraph p in _paragraphs) foreach (Paragraph p in _paragraphs)
{ {
if (p.Text != null && p.Text.Contains(Environment.NewLine) && HtmlUtil.RemoveHtmlTags(p.Text, true).Length > minLength) if (p.Text.Contains(Environment.NewLine) && HtmlUtil.RemoveHtmlTags(p.Text, true).Length > minLength)
{ {
var text = Utilities.UnbreakLine(p.Text); var text = Utilities.UnbreakLine(p.Text);
if (text != p.Text) if (text != p.Text)
{ {
AddToListView(p, text); AddToListView(p, text);
_fixedText.Add(p.ID, text); _fixedText.Add(p.ID, text);
_changes++;
} }
} }
} }