From 560f8feef9d6f760db9c116a631b2e519ee4abdd Mon Sep 17 00:00:00 2001 From: niksedk Date: Tue, 7 Mar 2023 21:51:24 +0100 Subject: [PATCH] Add new shortcut for split + auto-br - thx oep42 :) Work on #6673 --- LanguageBaseEnglish.xml | 1 + src/libse/Common/Settings.cs | 8 ++++++++ src/ui/Forms/Main.cs | 30 ++++++++++++++++++++++++---- src/ui/Forms/Options/Settings.cs | 1 + src/ui/Logic/Language.cs | 1 + src/ui/Logic/LanguageDeserializer.cs | 3 +++ src/ui/Logic/LanguageStructure.cs | 1 + src/ui/Logic/MainShortcuts.cs | 2 ++ 8 files changed, 43 insertions(+), 4 deletions(-) diff --git a/LanguageBaseEnglish.xml b/LanguageBaseEnglish.xml index 3f8d20241..b003f9eac 100644 --- a/LanguageBaseEnglish.xml +++ b/LanguageBaseEnglish.xml @@ -1369,6 +1369,7 @@ To use an API key, go to "Options -> Settings -> Tools" to enter your Goog Paste Delete Split line at cursor position + Split line at cursor position and auto-break Split line at cursor/video position Auto duration (current line) Select all diff --git a/src/libse/Common/Settings.cs b/src/libse/Common/Settings.cs index 181ccfd8c..4bcb7c421 100644 --- a/src/libse/Common/Settings.cs +++ b/src/libse/Common/Settings.cs @@ -2438,6 +2438,7 @@ $HorzAlign = Center public string MainListViewSortByStyle { get; set; } public string MainListViewRemoveTimeCodes { get; set; } public string MainTextBoxSplitAtCursor { get; set; } + public string MainTextBoxSplitAtCursorAndAutoBr { get; set; } public string MainTextBoxSplitAtCursorAndVideoPos { get; set; } public string MainTextBoxSplitSelectedLineBilingual { get; set; } public string MainTextBoxMoveLastWordDown { get; set; } @@ -9304,6 +9305,12 @@ $HorzAlign = Center shortcuts.MainTextBoxSplitAtCursor = subNode.InnerText; } + subNode = node.SelectSingleNode("MainTextBoxSplitAtCursorAndAutoBr"); + if (subNode != null) + { + shortcuts.MainTextBoxSplitAtCursorAndAutoBr = subNode.InnerText; + } + subNode = node.SelectSingleNode("MainTextBoxSplitAtCursorAndVideoPos"); if (subNode != null) { @@ -11260,6 +11267,7 @@ $HorzAlign = Center textWriter.WriteElementString("MainEditReverseStartAndEndingForRTL", shortcuts.MainEditReverseStartAndEndingForRTL); textWriter.WriteElementString("MainVideoToggleControls", shortcuts.MainVideoToggleControls); textWriter.WriteElementString("MainTextBoxSplitAtCursor", shortcuts.MainTextBoxSplitAtCursor); + textWriter.WriteElementString("MainTextBoxSplitAtCursorAndAutoBr", shortcuts.MainTextBoxSplitAtCursorAndAutoBr); textWriter.WriteElementString("MainTextBoxSplitAtCursorAndVideoPos", shortcuts.MainTextBoxSplitAtCursorAndVideoPos); textWriter.WriteElementString("MainTextBoxSplitSelectedLineBilingual", shortcuts.MainTextBoxSplitSelectedLineBilingual); textWriter.WriteElementString("MainTextBoxMoveLastWordDown", shortcuts.MainTextBoxMoveLastWordDown); diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index a852cab9a..d860fef5d 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -10651,7 +10651,12 @@ namespace Nikse.SubtitleEdit.Forms } else if (_shortcuts.MainTextBoxSplitAtCursor == e.KeyData) { - ToolStripMenuItemSplitTextAtCursorClick(null, null); + SplitTextAtCursor(false); + e.SuppressKeyPress = true; + } + else if (_shortcuts.MainTextBoxSplitAtCursorAndAutoBr == e.KeyData) + { + SplitTextAtCursor(true); e.SuppressKeyPress = true; } else if (_shortcuts.MainTextBoxSplitAtCursorAndVideoPos == e.KeyData) @@ -11108,7 +11113,7 @@ namespace Nikse.SubtitleEdit.Forms SplitSelectedParagraph(null, null); } - private void SplitSelectedParagraph(double? splitSeconds, int? textIndex) + private void SplitSelectedParagraph(double? splitSeconds, int? textIndex, bool autoBreak = false) { int maxSingleLineLength = Configuration.Settings.General.SubtitleLineMaximumLength; var language = LanguageAutoDetect.AutoDetectGoogleLanguage(_subtitle); @@ -11337,6 +11342,12 @@ namespace Nikse.SubtitleEdit.Forms FixSplitBoxTag(currentParagraph, newParagraph); SetSplitTime(splitSeconds, currentParagraph, newParagraph, oldText); + if (autoBreak) + { + currentParagraph.Text = Utilities.AutoBreakLine(currentParagraph.Text); + newParagraph.Text = Utilities.AutoBreakLine(newParagraph.Text); + } + if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleOriginal != null && _subtitleOriginal.Paragraphs.Count > 0) { var originalCurrent = Utilities.GetOriginalParagraph(firstSelectedIndex, currentParagraph, _subtitleOriginal.Paragraphs); @@ -11522,7 +11533,13 @@ namespace Nikse.SubtitleEdit.Forms _subtitleOriginal.Renumber(); FixSplitItalicTagAndAssa(originalCurrent, originalNew); FixSplitFontTag(originalCurrent, originalNew); - FixSplitBoxTag(currentParagraph, newParagraph); + FixSplitBoxTag(originalCurrent, originalNew); + + if (autoBreak) + { + originalCurrent.Text = Utilities.AutoBreakLine(originalCurrent.Text); + originalNew.Text = Utilities.AutoBreakLine(originalNew.Text); + } } } @@ -28638,6 +28655,11 @@ namespace Nikse.SubtitleEdit.Forms } private void ToolStripMenuItemSplitTextAtCursorClick(object sender, EventArgs e) + { + SplitTextAtCursor(false); + } + + private void SplitTextAtCursor(bool autoBreak) { var tb = GetFocusedTextBox(); @@ -28647,7 +28669,7 @@ namespace Nikse.SubtitleEdit.Forms pos = tb.SelectionStart; } - SplitSelectedParagraph(null, pos); + SplitSelectedParagraph(null, pos, autoBreak); tb.Focus(); tb.SelectionStart = tb.Text.Length; } diff --git a/src/ui/Forms/Options/Settings.cs b/src/ui/Forms/Options/Settings.cs index b1024599b..d50d27bdc 100644 --- a/src/ui/Forms/Options/Settings.cs +++ b/src/ui/Forms/Options/Settings.cs @@ -1516,6 +1516,7 @@ namespace Nikse.SubtitleEdit.Forms.Options var textBoxNode = new ShortcutNode(language.TextBox); AddNode(textBoxNode, LanguageSettings.Current.Main.Menu.ContextMenu.SplitLineAtCursorPosition, nameof(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursor)); + AddNode(textBoxNode, LanguageSettings.Current.Main.Menu.ContextMenu.SplitLineAtCursorPositionAndAutoBr, nameof(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursorAndAutoBr)); AddNode(textBoxNode, LanguageSettings.Current.Main.Menu.ContextMenu.SplitLineAtCursorAndWaveformPosition, nameof(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursorAndVideoPos)); AddNode(textBoxNode, language.SplitSelectedLineBilingual, nameof(Configuration.Settings.Shortcuts.MainTextBoxSplitSelectedLineBilingual)); AddNode(textBoxNode, language.MainTextBoxMoveLastWordDown, nameof(Configuration.Settings.Shortcuts.MainTextBoxMoveLastWordDown)); diff --git a/src/ui/Logic/Language.cs b/src/ui/Logic/Language.cs index 3244a2ce5..78c2a890c 100644 --- a/src/ui/Logic/Language.cs +++ b/src/ui/Logic/Language.cs @@ -1930,6 +1930,7 @@ namespace Nikse.SubtitleEdit.Logic Paste = "Paste", Delete = "Delete", SplitLineAtCursorPosition = "Split line at cursor position", + SplitLineAtCursorPositionAndAutoBr = "Split line at cursor position and auto-break", SplitLineAtCursorAndWaveformPosition = "Split line at cursor/video position", AutoDurationCurrentLine = "Auto duration (current line)", SelectAll = "Select all", diff --git a/src/ui/Logic/LanguageDeserializer.cs b/src/ui/Logic/LanguageDeserializer.cs index 65c135854..ca7863e34 100644 --- a/src/ui/Logic/LanguageDeserializer.cs +++ b/src/ui/Logic/LanguageDeserializer.cs @@ -4480,6 +4480,9 @@ namespace Nikse.SubtitleEdit.Logic case "Main/Menu/ContextMenu/SplitLineAtCursorPosition": language.Main.Menu.ContextMenu.SplitLineAtCursorPosition = reader.Value; break; + case "Main/Menu/ContextMenu/SplitLineAtCursorPositionAndAutoBr": + language.Main.Menu.ContextMenu.SplitLineAtCursorPositionAndAutoBr = reader.Value; + break; case "Main/Menu/ContextMenu/SplitLineAtCursorAndWaveformPosition": language.Main.Menu.ContextMenu.SplitLineAtCursorAndWaveformPosition = reader.Value; break; diff --git a/src/ui/Logic/LanguageStructure.cs b/src/ui/Logic/LanguageStructure.cs index e2c8bf735..24e14d15c 100644 --- a/src/ui/Logic/LanguageStructure.cs +++ b/src/ui/Logic/LanguageStructure.cs @@ -1775,6 +1775,7 @@ namespace Nikse.SubtitleEdit.Logic public string Paste { get; set; } public string Delete { get; set; } public string SplitLineAtCursorPosition { get; set; } + public string SplitLineAtCursorPositionAndAutoBr { get; set; } public string SplitLineAtCursorAndWaveformPosition { get; set; } public string AutoDurationCurrentLine { get; set; } public string SelectAll { get; set; } diff --git a/src/ui/Logic/MainShortcuts.cs b/src/ui/Logic/MainShortcuts.cs index 69352e28a..dc5fcbd0a 100644 --- a/src/ui/Logic/MainShortcuts.cs +++ b/src/ui/Logic/MainShortcuts.cs @@ -103,6 +103,7 @@ namespace Nikse.SubtitleEdit.Logic public Keys MainGeneralToggleMode { get; set; } public Keys MainGeneralTogglePreviewOnVideo { get; set; } public Keys MainTextBoxSplitAtCursor { get; set; } + public Keys MainTextBoxSplitAtCursorAndAutoBr { get; set; } public Keys MainTextBoxSplitAtCursorAndVideoPos { get; set; } public Keys MainTextBoxSplitSelectedLineBilingual { get; set; } public Keys MainTextBoxMoveLastWordDown { get; set; } @@ -373,6 +374,7 @@ namespace Nikse.SubtitleEdit.Logic MainListViewCopyText = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewCopyText); MainListViewCopyPlainText = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewCopyPlainText); MainTextBoxSplitAtCursor = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursor); + MainTextBoxSplitAtCursorAndAutoBr = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursorAndAutoBr); MainTextBoxSplitAtCursorAndVideoPos = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursorAndVideoPos); MainTextBoxSplitSelectedLineBilingual = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxSplitSelectedLineBilingual); MainTextBoxMoveLastWordDown = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxMoveLastWordDown);