From 337218e0c4f44d4aa53e623d2c1d3e0b0278e259 Mon Sep 17 00:00:00 2001 From: niksedk Date: Thu, 28 Feb 2013 14:47:40 +0000 Subject: [PATCH] Added "auto balance lines" to batch converter - thx hacker :) git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1686 99eadd0c-20b8-1223-b5c4-2a2b2df33de2 --- src/Forms/BatchConvert.Designer.cs | 125 ++++++++++++++++------------- src/Forms/BatchConvert.cs | 20 ++++- src/Logic/Language.cs | 1 + src/Logic/LanguageStructure.cs | 1 + src/Logic/Settings.cs | 5 ++ 5 files changed, 94 insertions(+), 58 deletions(-) diff --git a/src/Forms/BatchConvert.Designer.cs b/src/Forms/BatchConvert.Designer.cs index 69fe59fdb..c58bccce1 100644 --- a/src/Forms/BatchConvert.Designer.cs +++ b/src/Forms/BatchConvert.Designer.cs @@ -32,6 +32,8 @@ this.buttonConvert = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.groupBoxConvertOptions = new System.Windows.Forms.GroupBox(); + this.buttonMultipleReplaceSettings = new System.Windows.Forms.Button(); + this.checkBoxMultipleReplace = new System.Windows.Forms.CheckBox(); this.checkBoxFixCommonErrors = new System.Windows.Forms.CheckBox(); this.buttonFixCommonErrorSettings = new System.Windows.Forms.Button(); this.groupBoxChangeFrameRate = new System.Windows.Forms.GroupBox(); @@ -40,6 +42,9 @@ this.comboBoxFrameRateFrom = new System.Windows.Forms.ComboBox(); this.labelFromFrameRate = new System.Windows.Forms.Label(); this.groupBoxOffsetTimeCodes = new System.Windows.Forms.GroupBox(); + this.radioButtonShowLater = new System.Windows.Forms.RadioButton(); + this.radioButtonShowEarlier = new System.Windows.Forms.RadioButton(); + this.timeUpDownAdjust = new Nikse.SubtitleEdit.Controls.TimeUpDown(); this.labelHoursMinSecsMilliSecs = new System.Windows.Forms.Label(); this.checkBoxFixCasing = new System.Windows.Forms.CheckBox(); this.checkBoxRemoveTextForHI = new System.Windows.Forms.CheckBox(); @@ -70,11 +75,7 @@ this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.labelStatus = new System.Windows.Forms.Label(); - this.radioButtonShowLater = new System.Windows.Forms.RadioButton(); - this.radioButtonShowEarlier = new System.Windows.Forms.RadioButton(); - this.checkBoxMultipleReplace = new System.Windows.Forms.CheckBox(); - this.buttonMultipleReplaceSettings = new System.Windows.Forms.Button(); - this.timeUpDownAdjust = new Nikse.SubtitleEdit.Controls.TimeUpDown(); + this.checkBoxAutoBalance = new System.Windows.Forms.CheckBox(); this.groupBoxConvertOptions.SuspendLayout(); this.groupBoxChangeFrameRate.SuspendLayout(); this.groupBoxOffsetTimeCodes.SuspendLayout(); @@ -111,6 +112,7 @@ // this.groupBoxConvertOptions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.groupBoxConvertOptions.Controls.Add(this.checkBoxAutoBalance); this.groupBoxConvertOptions.Controls.Add(this.buttonMultipleReplaceSettings); this.groupBoxConvertOptions.Controls.Add(this.checkBoxMultipleReplace); this.groupBoxConvertOptions.Controls.Add(this.checkBoxFixCommonErrors); @@ -127,6 +129,27 @@ this.groupBoxConvertOptions.TabStop = false; this.groupBoxConvertOptions.Text = "Convert options"; // + // buttonMultipleReplaceSettings + // + this.buttonMultipleReplaceSettings.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.buttonMultipleReplaceSettings.Location = new System.Drawing.Point(149, 119); + this.buttonMultipleReplaceSettings.Name = "buttonMultipleReplaceSettings"; + this.buttonMultipleReplaceSettings.Size = new System.Drawing.Size(87, 21); + this.buttonMultipleReplaceSettings.TabIndex = 6; + this.buttonMultipleReplaceSettings.Text = "Settings..."; + this.buttonMultipleReplaceSettings.UseVisualStyleBackColor = true; + this.buttonMultipleReplaceSettings.Click += new System.EventHandler(this.buttonMultipleReplaceSettings_Click); + // + // checkBoxMultipleReplace + // + this.checkBoxMultipleReplace.AutoSize = true; + this.checkBoxMultipleReplace.Location = new System.Drawing.Point(16, 122); + this.checkBoxMultipleReplace.Name = "checkBoxMultipleReplace"; + this.checkBoxMultipleReplace.Size = new System.Drawing.Size(100, 17); + this.checkBoxMultipleReplace.TabIndex = 5; + this.checkBoxMultipleReplace.Text = "Multiple replace"; + this.checkBoxMultipleReplace.UseVisualStyleBackColor = true; + // // checkBoxFixCommonErrors // this.checkBoxFixCommonErrors.AutoSize = true; @@ -208,6 +231,38 @@ this.groupBoxOffsetTimeCodes.TabStop = false; this.groupBoxOffsetTimeCodes.Text = "Offset time codes"; // + // radioButtonShowLater + // + this.radioButtonShowLater.AutoSize = true; + this.radioButtonShowLater.Checked = true; + this.radioButtonShowLater.Location = new System.Drawing.Point(108, 61); + this.radioButtonShowLater.Name = "radioButtonShowLater"; + this.radioButtonShowLater.Size = new System.Drawing.Size(75, 17); + this.radioButtonShowLater.TabIndex = 3; + this.radioButtonShowLater.TabStop = true; + this.radioButtonShowLater.Text = "Show later"; + this.radioButtonShowLater.UseVisualStyleBackColor = true; + // + // radioButtonShowEarlier + // + this.radioButtonShowEarlier.AutoSize = true; + this.radioButtonShowEarlier.Location = new System.Drawing.Point(108, 38); + this.radioButtonShowEarlier.Name = "radioButtonShowEarlier"; + this.radioButtonShowEarlier.Size = new System.Drawing.Size(83, 17); + this.radioButtonShowEarlier.TabIndex = 2; + this.radioButtonShowEarlier.Text = "Show earlier"; + this.radioButtonShowEarlier.UseVisualStyleBackColor = true; + // + // timeUpDownAdjust + // + this.timeUpDownAdjust.AutoSize = true; + this.timeUpDownAdjust.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.timeUpDownAdjust.Location = new System.Drawing.Point(7, 37); + this.timeUpDownAdjust.Margin = new System.Windows.Forms.Padding(4); + this.timeUpDownAdjust.Name = "timeUpDownAdjust"; + this.timeUpDownAdjust.Size = new System.Drawing.Size(92, 24); + this.timeUpDownAdjust.TabIndex = 1; + // // labelHoursMinSecsMilliSecs // this.labelHoursMinSecsMilliSecs.AutoSize = true; @@ -489,58 +544,15 @@ this.labelStatus.TabIndex = 9; this.labelStatus.Text = "labelStatus"; // - // radioButtonShowLater + // checkBoxAutoBalance // - this.radioButtonShowLater.AutoSize = true; - this.radioButtonShowLater.Checked = true; - this.radioButtonShowLater.Location = new System.Drawing.Point(108, 61); - this.radioButtonShowLater.Name = "radioButtonShowLater"; - this.radioButtonShowLater.Size = new System.Drawing.Size(75, 17); - this.radioButtonShowLater.TabIndex = 3; - this.radioButtonShowLater.TabStop = true; - this.radioButtonShowLater.Text = "Show later"; - this.radioButtonShowLater.UseVisualStyleBackColor = true; - // - // radioButtonShowEarlier - // - this.radioButtonShowEarlier.AutoSize = true; - this.radioButtonShowEarlier.Location = new System.Drawing.Point(108, 38); - this.radioButtonShowEarlier.Name = "radioButtonShowEarlier"; - this.radioButtonShowEarlier.Size = new System.Drawing.Size(83, 17); - this.radioButtonShowEarlier.TabIndex = 2; - this.radioButtonShowEarlier.Text = "Show earlier"; - this.radioButtonShowEarlier.UseVisualStyleBackColor = true; - // - // checkBoxMultipleReplace - // - this.checkBoxMultipleReplace.AutoSize = true; - this.checkBoxMultipleReplace.Location = new System.Drawing.Point(16, 122); - this.checkBoxMultipleReplace.Name = "checkBoxMultipleReplace"; - this.checkBoxMultipleReplace.Size = new System.Drawing.Size(100, 17); - this.checkBoxMultipleReplace.TabIndex = 5; - this.checkBoxMultipleReplace.Text = "Multiple replace"; - this.checkBoxMultipleReplace.UseVisualStyleBackColor = true; - // - // buttonMultipleReplaceSettings - // - this.buttonMultipleReplaceSettings.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonMultipleReplaceSettings.Location = new System.Drawing.Point(149, 119); - this.buttonMultipleReplaceSettings.Name = "buttonMultipleReplaceSettings"; - this.buttonMultipleReplaceSettings.Size = new System.Drawing.Size(87, 21); - this.buttonMultipleReplaceSettings.TabIndex = 6; - this.buttonMultipleReplaceSettings.Text = "Settings..."; - this.buttonMultipleReplaceSettings.UseVisualStyleBackColor = true; - this.buttonMultipleReplaceSettings.Click += new System.EventHandler(this.buttonMultipleReplaceSettings_Click); - // - // timeUpDownAdjust - // - this.timeUpDownAdjust.AutoSize = true; - this.timeUpDownAdjust.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.timeUpDownAdjust.Location = new System.Drawing.Point(7, 37); - this.timeUpDownAdjust.Margin = new System.Windows.Forms.Padding(4); - this.timeUpDownAdjust.Name = "timeUpDownAdjust"; - this.timeUpDownAdjust.Size = new System.Drawing.Size(92, 24); - this.timeUpDownAdjust.TabIndex = 1; + this.checkBoxAutoBalance.AutoSize = true; + this.checkBoxAutoBalance.Location = new System.Drawing.Point(16, 145); + this.checkBoxAutoBalance.Name = "checkBoxAutoBalance"; + this.checkBoxAutoBalance.Size = new System.Drawing.Size(113, 17); + this.checkBoxAutoBalance.TabIndex = 9; + this.checkBoxAutoBalance.Text = "Auto balance lines"; + this.checkBoxAutoBalance.UseVisualStyleBackColor = true; // // BatchConvert // @@ -624,6 +636,7 @@ private System.Windows.Forms.RadioButton radioButtonShowEarlier; private System.Windows.Forms.Button buttonMultipleReplaceSettings; private System.Windows.Forms.CheckBox checkBoxMultipleReplace; + private System.Windows.Forms.CheckBox checkBoxAutoBalance; } } \ No newline at end of file diff --git a/src/Forms/BatchConvert.cs b/src/Forms/BatchConvert.cs index 26bd83d03..d8a914c30 100644 --- a/src/Forms/BatchConvert.cs +++ b/src/Forms/BatchConvert.cs @@ -17,6 +17,7 @@ namespace Nikse.SubtitleEdit.Forms { public bool FixCommonErrors { get; set; } public bool MultipleReplaceActive { get; set; } + public bool AutoBalanceActive { get; set; } public ListViewItem Item { get; set; } public Subtitle Subtitle { get; set; } public SubtitleFormat Format { get; set; } @@ -27,10 +28,11 @@ namespace Nikse.SubtitleEdit.Forms public string ToFormat { get; set; } public SubtitleFormat SourceFormat { get; set; } - public ThreadDoWorkParameter(bool fixCommonErrors, bool multipleReplace, ListViewItem item, Subtitle subtitle, SubtitleFormat format, Encoding encoding, string language, string fileName, string toFormat, SubtitleFormat sourceFormat) + public ThreadDoWorkParameter(bool fixCommonErrors, bool multipleReplace, bool autoBalance, ListViewItem item, Subtitle subtitle, SubtitleFormat format, Encoding encoding, string language, string fileName, string toFormat, SubtitleFormat sourceFormat) { FixCommonErrors = fixCommonErrors; MultipleReplaceActive = multipleReplace; + AutoBalanceActive = autoBalance; Item = item; Subtitle = subtitle; Format = format; @@ -146,12 +148,14 @@ namespace Nikse.SubtitleEdit.Forms checkBoxFixCasing.Checked = Configuration.Settings.Tools.BatchConvertFixCasing; checkBoxFixCommonErrors.Checked = Configuration.Settings.Tools.BatchConvertFixCommonErrors; checkBoxMultipleReplace.Checked = Configuration.Settings.Tools.BatchConvertMultipleReplace; + checkBoxAutoBalance.Checked = Configuration.Settings.Tools.BatchConvertAutoBalance; checkBoxRemoveFormatting.Checked = Configuration.Settings.Tools.BatchConvertRemoveFormatting; checkBoxRemoveTextForHI.Checked = Configuration.Settings.Tools.BatchConvertRemoveTextForHI; if (!string.IsNullOrEmpty(Configuration.Settings.Language.BatchConvert.Settings)) buttonFixCommonErrorSettings.Text = Configuration.Settings.Language.BatchConvert.Settings; checkBoxFixCommonErrors.Text = Configuration.Settings.Language.FixCommonErrors.Title; checkBoxMultipleReplace.Text = Configuration.Settings.Language.MultipleReplace.Title; + checkBoxAutoBalance.Text = Configuration.Settings.Language.BatchConvert.AutoBalance; radioButtonShowEarlier.Text = Configuration.Settings.Language.ShowEarlierLater.ShowEarlier; radioButtonShowLater.Text = Configuration.Settings.Language.ShowEarlierLater.ShowLater; } @@ -635,7 +639,7 @@ namespace Nikse.SubtitleEdit.Forms System.Threading.Thread.Sleep(100); } - ThreadDoWorkParameter parameter = new ThreadDoWorkParameter(checkBoxFixCommonErrors.Checked, checkBoxMultipleReplace.Checked, item, sub, GetCurrentSubtitleFormat(), GetCurrentEncoding(), Configuration.Settings.Tools.BatchConvertLanguage, fileName, toFormat, format); + ThreadDoWorkParameter parameter = new ThreadDoWorkParameter(checkBoxFixCommonErrors.Checked, checkBoxMultipleReplace.Checked, checkBoxAutoBalance.Checked, item, sub, GetCurrentSubtitleFormat(), GetCurrentEncoding(), Configuration.Settings.Tools.BatchConvertLanguage, fileName, toFormat, format); if (!worker1.IsBusy) worker1.RunWorkerAsync(parameter); else if (!worker2.IsBusy) @@ -703,6 +707,18 @@ namespace Nikse.SubtitleEdit.Forms p.Error = "MultipleReplace error: " + exception.Message; } } + if (p.AutoBalanceActive) + { + try + { + foreach (Paragraph paragraph in p.Subtitle.Paragraphs) + paragraph.Text = Utilities.AutoBreakLine(paragraph.Text); + } + catch (Exception exception) + { + p.Error = "AutoBalance error: " + exception.Message; + } + } e.Result = p; } diff --git a/src/Logic/Language.cs b/src/Logic/Language.cs index 883aa82da..3b2220dd8 100644 --- a/src/Logic/Language.cs +++ b/src/Logic/Language.cs @@ -263,6 +263,7 @@ namespace Nikse.SubtitleEdit.Logic Converted = "Converted", ConvertedX = "Converted ({0})", Settings = "Settings", + AutoBalance = "Auto balance lines", }; Beamer = new LanguageStructure.Beamer diff --git a/src/Logic/LanguageStructure.cs b/src/Logic/LanguageStructure.cs index 07fc898e2..d39a61e0a 100644 --- a/src/Logic/LanguageStructure.cs +++ b/src/Logic/LanguageStructure.cs @@ -165,6 +165,7 @@ public string Converted { get; set; } public string ConvertedX { get; set; } public string Settings { get; set; } + public string AutoBalance { get; set; } } public class Beamer diff --git a/src/Logic/Settings.cs b/src/Logic/Settings.cs index 805a02aac..086480df1 100644 --- a/src/Logic/Settings.cs +++ b/src/Logic/Settings.cs @@ -108,6 +108,7 @@ namespace Nikse.SubtitleEdit.Logic public bool BatchConvertRemoveTextForHI { get; set; } public bool BatchConvertFixCommonErrors { get; set; } public bool BatchConvertMultipleReplace { get; set; } + public bool BatchConvertAutoBalance { get; set; } public string BatchConvertLanguage { get; set; } public string ModifySelectionText { get; set; } public string ModifySelectionRule { get; set; } @@ -1337,6 +1338,9 @@ namespace Nikse.SubtitleEdit.Logic subNode = node.SelectSingleNode("BatchConvertMultipleReplace"); if (subNode != null) settings.Tools.BatchConvertMultipleReplace = Convert.ToBoolean(subNode.InnerText); + subNode = node.SelectSingleNode("BatchConvertAutoBalance"); + if (subNode != null) + settings.Tools.BatchConvertAutoBalance = Convert.ToBoolean(subNode.InnerText); subNode = node.SelectSingleNode("BatchConvertLanguage"); if (subNode != null) settings.Tools.BatchConvertLanguage = subNode.InnerText; @@ -2201,6 +2205,7 @@ namespace Nikse.SubtitleEdit.Logic textWriter.WriteElementString("BatchConvertRemoveTextForHI", settings.Tools.BatchConvertRemoveTextForHI.ToString()); textWriter.WriteElementString("BatchConvertFixCommonErrors", settings.Tools.BatchConvertFixCommonErrors.ToString()); textWriter.WriteElementString("BatchConvertMultipleReplace", settings.Tools.BatchConvertMultipleReplace.ToString()); + textWriter.WriteElementString("BatchConvertAutoBalance", settings.Tools.BatchConvertAutoBalance.ToString()); textWriter.WriteElementString("BatchConvertLanguage", settings.Tools.BatchConvertLanguage); textWriter.WriteElementString("ModifySelectionRule", settings.Tools.ModifySelectionRule); textWriter.WriteElementString("ModifySelectionText", settings.Tools.ModifySelectionText);