Save settings from selected lines unbreak/break - thx David :)

This commit is contained in:
niksedk 2023-09-18 19:18:50 +02:00
parent 124bbdb00b
commit bb99ddacde
4 changed files with 100 additions and 39 deletions

View File

@ -32,4 +32,5 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nikse/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Purfview/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tahoma/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unbreak/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Undocked/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -462,6 +462,8 @@ namespace Nikse.SubtitleEdit.Core.Common
public int AudioToTextLineMaxChars { get; set; }
public int AudioToTextLineMaxCharsJp { get; set; }
public int AudioToTextLineMaxCharsCn { get; set; }
public int BreakLinesLongerThan { get; set; }
public int UnbreakLinesLongerThan { get; set; }
public ToolsSettings()
{
@ -6855,6 +6857,17 @@ $HorzAlign = Center
settings.Tools.AudioToTextLineMaxCharsCn = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("BreakLinesLongerThan");
if (subNode != null)
{
settings.Tools.BreakLinesLongerThan = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("UnbreakLinesLongerThan");
if (subNode != null)
{
settings.Tools.UnbreakLinesLongerThan = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("FindHistory");
if (subNode != null)
@ -11588,6 +11601,8 @@ $HorzAlign = Center
textWriter.WriteElementString("AudioToTextLineMaxChars", settings.Tools.AudioToTextLineMaxChars.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("AudioToTextLineMaxCharsJp", settings.Tools.AudioToTextLineMaxCharsJp.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("AudioToTextLineMaxCharsCn", settings.Tools.AudioToTextLineMaxCharsCn.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("UnbreakLinesLongerThan", settings.Tools.UnbreakLinesLongerThan.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("BreakLinesLongerThan", settings.Tools.BreakLinesLongerThan.ToString(CultureInfo.InvariantCulture));
if (settings.Tools.FindHistory != null && settings.Tools.FindHistory.Count > 0)
{

View File

@ -34,16 +34,16 @@
this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader8 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItemSelectAll = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemInverseSelection = new System.Windows.Forms.ToolStripMenuItem();
this.groupBoxLinesFound = new System.Windows.Forms.GroupBox();
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.comboBoxConditions = new Nikse.SubtitleEdit.Controls.NikseComboBox();
this.labelCondition = new System.Windows.Forms.Label();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItemSelectAll = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemInverseSelection = new System.Windows.Forms.ToolStripMenuItem();
this.groupBoxLinesFound.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
this.groupBoxLinesFound.SuspendLayout();
this.SuspendLayout();
//
// listViewFixes
@ -88,6 +88,28 @@
this.columnHeader8.Text = "After";
this.columnHeader8.Width = 292;
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemSelectAll,
this.toolStripMenuItemInverseSelection});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(162, 48);
//
// toolStripMenuItemSelectAll
//
this.toolStripMenuItemSelectAll.Name = "toolStripMenuItemSelectAll";
this.toolStripMenuItemSelectAll.Size = new System.Drawing.Size(161, 22);
this.toolStripMenuItemSelectAll.Text = "Select all";
this.toolStripMenuItemSelectAll.Click += new System.EventHandler(this.toolStripMenuItemSelectAll_Click);
//
// toolStripMenuItemInverseSelection
//
this.toolStripMenuItemInverseSelection.Name = "toolStripMenuItemInverseSelection";
this.toolStripMenuItemInverseSelection.Size = new System.Drawing.Size(161, 22);
this.toolStripMenuItemInverseSelection.Text = "Inverse selection";
this.toolStripMenuItemInverseSelection.Click += new System.EventHandler(this.toolStripMenuItemInverseSelection_Click);
//
// groupBoxLinesFound
//
this.groupBoxLinesFound.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -125,12 +147,26 @@
//
// comboBoxConditions
//
this.comboBoxConditions.BackColor = System.Drawing.SystemColors.Window;
this.comboBoxConditions.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
this.comboBoxConditions.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179)))));
this.comboBoxConditions.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120)))));
this.comboBoxConditions.ButtonForeColor = System.Drawing.SystemColors.ControlText;
this.comboBoxConditions.ButtonForeColorDown = System.Drawing.Color.Orange;
this.comboBoxConditions.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215)))));
this.comboBoxConditions.DropDownHeight = 400;
this.comboBoxConditions.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxConditions.DropDownWidth = 150;
this.comboBoxConditions.FormattingEnabled = true;
this.comboBoxConditions.Location = new System.Drawing.Point(12, 30);
this.comboBoxConditions.MaxLength = 32767;
this.comboBoxConditions.Name = "comboBoxConditions";
this.comboBoxConditions.SelectedIndex = -1;
this.comboBoxConditions.SelectedItem = null;
this.comboBoxConditions.SelectedText = "";
this.comboBoxConditions.Size = new System.Drawing.Size(150, 21);
this.comboBoxConditions.TabIndex = 8;
this.comboBoxConditions.UsePopupWindow = false;
//
// labelCondition
//
@ -141,28 +177,6 @@
this.labelCondition.TabIndex = 9;
this.labelCondition.Text = "Only break lines longer than";
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemSelectAll,
this.toolStripMenuItemInverseSelection});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(181, 70);
//
// toolStripMenuItemSelectAll
//
this.toolStripMenuItemSelectAll.Name = "toolStripMenuItemSelectAll";
this.toolStripMenuItemSelectAll.Size = new System.Drawing.Size(180, 22);
this.toolStripMenuItemSelectAll.Text = "Select all";
this.toolStripMenuItemSelectAll.Click += new System.EventHandler(this.toolStripMenuItemSelectAll_Click);
//
// toolStripMenuItemInverseSelection
//
this.toolStripMenuItemInverseSelection.Name = "toolStripMenuItemInverseSelection";
this.toolStripMenuItemInverseSelection.Size = new System.Drawing.Size(180, 22);
this.toolStripMenuItemInverseSelection.Text = "Inverse selection";
this.toolStripMenuItemInverseSelection.Click += new System.EventHandler(this.toolStripMenuItemInverseSelection_Click);
//
// AutoBreakUnbreakLines
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -183,11 +197,12 @@
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "AutoBreakUnbreakLines";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.AutoBreakUnbreakLinesKeyDown);
this.ResizeEnd += new System.EventHandler(this.AutoBreakUnbreakLines_ResizeEnd);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AutoBreakUnbreakLines_FormClosing);
this.Shown += new System.EventHandler(this.AutoBreakUnbreakLines_Shown);
this.groupBoxLinesFound.ResumeLayout(false);
this.ResizeEnd += new System.EventHandler(this.AutoBreakUnbreakLines_ResizeEnd);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.AutoBreakUnbreakLinesKeyDown);
this.contextMenuStrip1.ResumeLayout(false);
this.groupBoxLinesFound.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();

View File

@ -13,11 +13,9 @@ namespace Nikse.SubtitleEdit.Forms
private bool _modeAutoBalance;
private HashSet<string> _notAllowedFixes = new HashSet<string>();
private Dictionary<string, string> _fixedText = new Dictionary<string, string>();
private string _language;
public Dictionary<string, string> FixedText => _fixedText;
public Dictionary<string, string> FixedText { get; private set; } = new Dictionary<string, string>();
public AutoBreakUnbreakLines()
{
@ -50,7 +48,7 @@ namespace Nikse.SubtitleEdit.Forms
_paragraphs.Add(p);
}
if (autoBalance)
if (_modeAutoBalance)
{
labelCondition.Text = LanguageSettings.Current.AutoBreakUnbreakLines.OnlyBreakLinesLongerThan;
const int start = 10;
@ -69,6 +67,13 @@ namespace Nikse.SubtitleEdit.Forms
comboBoxConditions.SelectedIndex = 30;
}
if (Configuration.Settings.Tools.BreakLinesLongerThan >= 10 &&
Configuration.Settings.Tools.BreakLinesLongerThan < 200)
{
comboBoxConditions.Text = Configuration.Settings.Tools.BreakLinesLongerThan.ToString(CultureInfo.InvariantCulture);
}
AutoBalance();
}
else
@ -86,6 +91,13 @@ namespace Nikse.SubtitleEdit.Forms
{
comboBoxConditions.SelectedIndex = 5;
}
if (Configuration.Settings.Tools.BreakLinesLongerThan >= 10 &&
Configuration.Settings.Tools.BreakLinesLongerThan < 200)
{
comboBoxConditions.Text = Configuration.Settings.Tools.UnbreakLinesLongerThan.ToString(CultureInfo.InvariantCulture);
}
Unbreak();
}
@ -111,7 +123,7 @@ namespace Nikse.SubtitleEdit.Forms
{
listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
_notAllowedFixes = new HashSet<string>();
_fixedText = new Dictionary<string, string>();
FixedText = new Dictionary<string, string>();
var minLength = MinimumLength;
Text = LanguageSettings.Current.AutoBreakUnbreakLines.TitleAutoBreak;
@ -126,7 +138,7 @@ namespace Nikse.SubtitleEdit.Forms
if (text != p.Text)
{
AddToListView(p, text);
_fixedText.Add(p.Id, text);
FixedText.Add(p.Id, text);
}
}
}
@ -140,8 +152,8 @@ namespace Nikse.SubtitleEdit.Forms
{
listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
_notAllowedFixes = new HashSet<string>();
_fixedText = new Dictionary<string, string>();
int minLength = int.Parse(comboBoxConditions.Items[comboBoxConditions.SelectedIndex].ToString());
FixedText = new Dictionary<string, string>();
var minLength = int.Parse(comboBoxConditions.Items[comboBoxConditions.SelectedIndex].ToString());
Text = LanguageSettings.Current.AutoBreakUnbreakLines.TitleUnbreak;
listViewFixes.BeginUpdate();
listViewFixes.Items.Clear();
@ -153,7 +165,7 @@ namespace Nikse.SubtitleEdit.Forms
if (text != p.Text)
{
AddToListView(p, text);
_fixedText.Add(p.Id, text);
FixedText.Add(p.Id, text);
}
}
}
@ -196,7 +208,7 @@ namespace Nikse.SubtitleEdit.Forms
var p = _paragraphs[i];
if (_notAllowedFixes.Contains(p.Id))
{
_fixedText.Remove(p.Id);
FixedText.Remove(p.Id);
}
}
DialogResult = DialogResult.OK;
@ -252,5 +264,23 @@ namespace Nikse.SubtitleEdit.Forms
item.Checked = !item.Checked;
}
}
private void AutoBreakUnbreakLines_FormClosing(object sender, FormClosingEventArgs e)
{
if (_modeAutoBalance)
{
if (int.TryParse(comboBoxConditions.Text, out var number))
{
Configuration.Settings.Tools.BreakLinesLongerThan = number;
}
}
else
{
if (int.TryParse(comboBoxConditions.Text, out var number))
{
Configuration.Settings.Tools.UnbreakLinesLongerThan = number;
}
}
}
}
}