Add toggle quotes and HI tags shortcuts

This commit is contained in:
OmrSi 2021-05-06 21:15:42 +03:00
parent df0128de45
commit 4b9b9b8186
8 changed files with 187 additions and 83 deletions

View File

@ -2231,6 +2231,8 @@ can edit in same subtitle file (collaboration)</Information>
<ToggleFocus>Toggle focus between list view and subtitle text box</ToggleFocus>
<ToggleFocusWaveform>Toggle focus between list view and waveform/spectrogram</ToggleFocusWaveform>
<ToggleDialogDashes>Toggle dialog dashes</ToggleDialogDashes>
<ToggleQuotes>Toggle quotes</ToggleQuotes>
<ToggleHiTags>Toggle HI tags</ToggleHiTags>
<ToggleMusicSymbols>Toggle music symbols</ToggleMusicSymbols>
<Alignment>Alignment (selected lines)</Alignment>
<AlignmentN1>Alignment bottom left - {\an1}</AlignmentN1>

View File

@ -1934,6 +1934,8 @@ $HorzAlign = Center
public string MainListViewBold { get; set; }
public string MainListViewUnderline { get; set; }
public string MainListViewBox { get; set; }
public string MainListViewToggleQuotes { get; set; }
public string MainListViewToggleHiTags { get; set; }
public string MainListViewSplit { get; set; }
public string MainListViewToggleDashes { get; set; }
public string MainListViewToggleMusicSymbols { get; set; }
@ -7183,6 +7185,18 @@ $HorzAlign = Center
shortcuts.MainListViewBox = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainListViewToggleQuotes");
if (subNode != null)
{
shortcuts.MainListViewToggleQuotes = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainListViewToggleHiTags");
if (subNode != null)
{
shortcuts.MainListViewToggleHiTags = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainListViewSplit");
if (subNode != null)
{
@ -8938,6 +8952,8 @@ $HorzAlign = Center
textWriter.WriteElementString("MainListViewBold", shortcuts.MainListViewBold);
textWriter.WriteElementString("MainListViewUnderline", shortcuts.MainListViewUnderline);
textWriter.WriteElementString("MainListViewBox", shortcuts.MainListViewBox);
textWriter.WriteElementString("MainListViewToggleQuotes", shortcuts.MainListViewToggleQuotes);
textWriter.WriteElementString("MainListViewToggleHiTags", shortcuts.MainListViewToggleHiTags);
textWriter.WriteElementString("MainListViewSplit", shortcuts.MainListViewSplit);
textWriter.WriteElementString("MainListViewToggleDashes", shortcuts.MainListViewToggleDashes);
textWriter.WriteElementString("MainListViewToggleMusicSymbols", shortcuts.MainListViewToggleMusicSymbols);

View File

@ -9868,7 +9868,8 @@ namespace Nikse.SubtitleEdit.Forms
}
else if (e.KeyData == _shortcuts.MainListViewToggleMusicSymbols)
{
textBoxListViewText.Text = ToggleMusicSymbols("♪", textBoxListViewText.Text);
SurroundWithTag(Configuration.Settings.Tools.MusicSymbol, selectedTextOnly: true);
e.SuppressKeyPress = true;
}
else if (e.KeyData == _shortcuts.MainInsertBefore)
{
@ -12531,7 +12532,6 @@ namespace Nikse.SubtitleEdit.Forms
}
int selectionStart = tb.SelectionStart;
int selectionLength = tb.SelectionLength;
bool done = false;
string pre = string.Empty;
if (selectionStart == 0 && text.StartsWith("{\\", StringComparison.Ordinal) && text.IndexOf('}') >= 0)
@ -14660,6 +14660,32 @@ namespace Nikse.SubtitleEdit.Forms
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainListViewToggleQuotes == e.KeyData && InListView)
{
if (textBoxListViewText.Focused || textBoxListViewTextOriginal.Focused)
{
SurroundWithTag("\"", selectedTextOnly: true);
}
else
{
SurroundWithTag("\"");
}
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainListViewToggleHiTags == e.KeyData && InListView)
{
if (textBoxListViewText.Focused || textBoxListViewTextOriginal.Focused)
{
SurroundWithTag("[", "]", true);
}
else
{
SurroundWithTag("[", "]");
}
e.SuppressKeyPress = true;
}
else if (!toolStripMenuItemRtlUnicodeControlChars.Visible && _shortcuts.MainEditFixRTLViaUnicodeChars == e.KeyData && InListView)
{
toolStripMenuItemRtlUnicodeControlChars_Click(null, null);
@ -18014,6 +18040,45 @@ namespace Nikse.SubtitleEdit.Forms
return s;
}
private static string SplitEndTags(string line, ref string post)
{
var s = line;
if (s.EndsWith("{\\r}", StringComparison.Ordinal))
{
post = s.Substring(s.Length - 4, 4);
s = s.Remove(s.Length - 4, 4);
}
bool updated = true;
while (updated)
{
updated = false;
if (s.EndsWith(' '))
{
post += ' ';
s = s.Remove(s.Length - 1, 1);
updated = true;
}
else if (s.EndsWith("</i>", StringComparison.OrdinalIgnoreCase) ||
s.EndsWith("</b>", StringComparison.OrdinalIgnoreCase) ||
s.EndsWith("</u>", StringComparison.OrdinalIgnoreCase))
{
post += s.Substring(s.Length - 4, 4);
s = s.Remove(s.Length - 4, 4);
updated = true;
}
else if (s.EndsWith("</font>", StringComparison.OrdinalIgnoreCase))
{
var endFontTag = "</font>";
post += endFontTag;
s = s.Remove(s.Length - endFontTag.Length, endFontTag.Length);
updated = true;
}
}
return s;
}
private void SetTitle()
{
var text = "Untitled";
@ -26781,101 +26846,106 @@ namespace Nikse.SubtitleEdit.Forms
private void ToolStripMenuItemSurroundWithMusicSymbolsClick(object sender, EventArgs e)
{
string tag = Configuration.Settings.Tools.MusicSymbol;
if (string.IsNullOrWhiteSpace(tag))
{
return;
}
if (_subtitle.Paragraphs.Count > 0 && SubtitleListview1.SelectedItems.Count > 0)
{
SubtitleListview1.SelectedIndexChanged -= SubtitleListview1_SelectedIndexChanged;
MakeHistoryForUndo(string.Format(_language.BeforeAddingTagX, tag));
var indices = new List<int>();
foreach (ListViewItem item in SubtitleListview1.SelectedItems)
{
indices.Add(item.Index);
}
SubtitleListview1.BeginUpdate();
foreach (int i in indices)
{
if (_subtitleOriginal != null && Configuration.Settings.General.AllowEditOfOriginalSubtitle)
{
var original = Utilities.GetOriginalParagraph(i, _subtitle.Paragraphs[i], _subtitleOriginal.Paragraphs);
if (original != null)
{
original.Text = ToggleMusicSymbols(tag, original.Text);
SubtitleListview1.SetOriginalText(i, original.Text);
}
}
_subtitle.Paragraphs[i].Text = ToggleMusicSymbols(tag, _subtitle.Paragraphs[i].Text);
SubtitleListview1.SetText(i, _subtitle.Paragraphs[i].Text);
}
SubtitleListview1.EndUpdate();
ShowStatus(string.Format(_language.TagXAdded, tag));
UpdateSourceView();
RefreshSelectedParagraph();
SubtitleListview1.SelectedIndexChanged += SubtitleListview1_SelectedIndexChanged;
}
SurroundWithTag(tag);
}
private string ToggleMusicSymbols(string tag, string text)
private void SurroundWithTag(string tag, string endTag = "", bool selectedTextOnly = false)
{
string pre = string.Empty;
string post = string.Empty;
var indexOfEndBracket = text.IndexOf('}');
if (text.StartsWith("{\\", StringComparison.Ordinal) && indexOfEndBracket > 1)
if (selectedTextOnly)
{
pre = text.Substring(0, indexOfEndBracket + 1);
text = text.Remove(0, indexOfEndBracket + 1);
}
bool updated = true;
while (updated)
{
updated = false;
if (text.StartsWith(' '))
var tb = GetFocusedTextBox();
var text = tb.SelectedText;
if (string.IsNullOrEmpty(text) && tb.Text.Length > 0)
{
pre += ' ';
text = text.Remove(0, 1);
updated = true;
text = tb.Text;
tb.SelectAll();
}
else if (text.StartsWith("<font", StringComparison.OrdinalIgnoreCase))
{
int endFont = text.IndexOf('>');
if (endFont > 0)
{
pre += text.Substring(0, endFont + 1);
text = text.Remove(0, endFont + 1);
updated = true;
}
if (text.EndsWith("</font>", StringComparison.OrdinalIgnoreCase))
{
var endTag = "</font>";
post += endTag;
text = text.Remove(text.Length - endTag.Length, endTag.Length);
}
}
}
if (text.Contains(tag))
{
text = pre + text.Replace(tag, string.Empty).Replace(Environment.NewLine + " ", Environment.NewLine).Replace(" " + Environment.NewLine, Environment.NewLine).Trim() + post;
int selectionStart = tb.SelectionStart;
text = ToggleSymbols(tag, text, endTag);
tb.SelectedText = text;
tb.SelectionStart = selectionStart;
tb.SelectionLength = text.Length;
}
else
{
if (Configuration.Settings.Tools.MusicSymbolStyle.Equals("single", StringComparison.OrdinalIgnoreCase))
if (string.IsNullOrWhiteSpace(tag))
{
text = string.Format("{0}{1} {2}{3}", pre, tag, text.Replace(Environment.NewLine, Environment.NewLine + tag + " "), post);
return;
}
if (_subtitle.Paragraphs.Count > 0 && SubtitleListview1.SelectedItems.Count > 0)
{
SubtitleListview1.SelectedIndexChanged -= SubtitleListview1_SelectedIndexChanged;
MakeHistoryForUndo(string.Format(_language.BeforeAddingTagX, tag));
var indices = new List<int>();
foreach (ListViewItem item in SubtitleListview1.SelectedItems)
{
indices.Add(item.Index);
}
SubtitleListview1.BeginUpdate();
foreach (int i in indices)
{
if (_subtitleOriginal != null && Configuration.Settings.General.AllowEditOfOriginalSubtitle)
{
var original = Utilities.GetOriginalParagraph(i, _subtitle.Paragraphs[i], _subtitleOriginal.Paragraphs);
if (original != null)
{
original.Text = ToggleSymbols(tag, original.Text, endTag);
SubtitleListview1.SetOriginalText(i, original.Text);
}
}
_subtitle.Paragraphs[i].Text = ToggleSymbols(tag, _subtitle.Paragraphs[i].Text, endTag);
SubtitleListview1.SetText(i, _subtitle.Paragraphs[i].Text);
}
SubtitleListview1.EndUpdate();
ShowStatus(string.Format(_language.TagXAdded, tag));
UpdateSourceView();
RefreshSelectedParagraph();
SubtitleListview1.SelectedIndexChanged += SubtitleListview1_SelectedIndexChanged;
}
}
}
private string ToggleSymbols(string tag, string text, string endTag = "")
{
string pre = string.Empty;
string post = string.Empty;
text = SplitStartTags(text, ref pre);
text = SplitEndTags(text, ref post);
if (text.Contains(tag))
{
if (string.IsNullOrEmpty(endTag))
{
text = pre + text.Replace(tag, string.Empty).Replace(Environment.NewLine + " ", Environment.NewLine).Replace(" " + Environment.NewLine, Environment.NewLine).Trim() + post;
}
else
{
text = string.Format("{0}{1} {2} {1}{3}", pre, tag, text.Replace(Environment.NewLine, " " + tag + Environment.NewLine + tag + " "), post);
text = pre + text.Replace(tag, string.Empty).Replace(endTag, string.Empty).Replace(Environment.NewLine + " ", Environment.NewLine).Replace(" " + Environment.NewLine, Environment.NewLine).Trim() + post;
}
}
else
{
if (tag == Configuration.Settings.Tools.MusicSymbol)
{
if (Configuration.Settings.Tools.MusicSymbolStyle.Equals("single", StringComparison.OrdinalIgnoreCase))
{
text = string.Format("{0}{1} {2}{3}", pre, tag, text.Replace(Environment.NewLine, Environment.NewLine + tag + " "), post);
}
else
{
text = string.Format("{0}{1} {2} {1}{3}", pre, tag, text.Replace(Environment.NewLine, " " + tag + Environment.NewLine + tag + " "), post);
}
}
else
{
text = string.Format("{0}{1}{2}{3}{4}", pre, tag, text, string.IsNullOrEmpty(endTag) ? tag : endTag, post);
}
}

View File

@ -1406,6 +1406,8 @@ namespace Nikse.SubtitleEdit.Forms.Options
AddNode(listViewAndTextBoxNode, LanguageSettings.Current.General.Bold, nameof(Configuration.Settings.Shortcuts.MainListViewBold), true);
AddNode(listViewAndTextBoxNode, LanguageSettings.Current.General.Underline, nameof(Configuration.Settings.Shortcuts.MainListViewUnderline), true);
AddNode(listViewAndTextBoxNode, LanguageSettings.Current.Main.Menu.ContextMenu.Box, nameof(Configuration.Settings.Shortcuts.MainListViewBox), true);
AddNode(listViewAndTextBoxNode, language.ToggleQuotes, nameof(Configuration.Settings.Shortcuts.MainListViewToggleQuotes), true);
AddNode(listViewAndTextBoxNode, language.ToggleHiTags, nameof(Configuration.Settings.Shortcuts.MainListViewToggleHiTags), true);
AddNode(listViewAndTextBoxNode, LanguageSettings.Current.General.SplitLine.Replace("!", string.Empty), nameof(Configuration.Settings.Shortcuts.MainListViewSplit), true);
AddNode(listViewAndTextBoxNode, language.ToggleMusicSymbols, nameof(Configuration.Settings.Shortcuts.MainListViewToggleMusicSymbols), true);
AddNode(listViewAndTextBoxNode, language.AlignmentN1, nameof(Configuration.Settings.Shortcuts.MainListViewAlignmentN1));

View File

@ -2542,6 +2542,8 @@ can edit in same subtitle file (collaboration)",
ToggleFocus = "Toggle focus between list view and subtitle text box",
ToggleFocusWaveform = "Toggle focus between list view and waveform/spectrogram",
ToggleDialogDashes = "Toggle dialog dashes",
ToggleQuotes = "Toggle quotes",
ToggleHiTags = "Toggle HI tags",
ToggleMusicSymbols = "Toggle music symbols",
Alignment = "Alignment (selected lines)",
AlignmentN1 = "Alignment bottom left - {\\an1}",

View File

@ -6103,6 +6103,12 @@ namespace Nikse.SubtitleEdit.Logic
case "Settings/ToggleDialogDashes":
language.Settings.ToggleDialogDashes = reader.Value;
break;
case "Settings/ToggleQuotes":
language.Settings.ToggleQuotes = reader.Value;
break;
case "Settings/ToggleHiTags":
language.Settings.ToggleHiTags = reader.Value;
break;
case "Settings/ToggleMusicSymbols":
language.Settings.ToggleMusicSymbols = reader.Value;
break;

View File

@ -2403,6 +2403,8 @@
public string ToggleFocus { get; set; }
public string ToggleFocusWaveform { get; set; }
public string ToggleDialogDashes { get; set; }
public string ToggleQuotes { get; set; }
public string ToggleHiTags { get; set; }
public string ToggleMusicSymbols { get; set; }
public string Alignment { get; set; }
public string AlignmentN1 { get; set; }

View File

@ -153,6 +153,8 @@ namespace Nikse.SubtitleEdit.Logic
public Keys MainToggleFocusWaveform { get; set; }
public Keys MainWaveformAdd { get; set; }
public Keys MainListViewToggleDashes { get; set; }
public Keys MainListViewToggleQuotes { get; set; }
public Keys MainListViewToggleHiTags { get; set; }
public Keys MainListViewToggleMusicSymbols { get; set; }
public Keys MainListViewAutoDuration { get; set; }
public Keys MainListViewAlignmentN1 { get; set; }
@ -276,6 +278,8 @@ namespace Nikse.SubtitleEdit.Logic
MainToolsAutoDuration = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainToolsAutoDuration);
MainToolsBeamer = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainToolsBeamer);
MainListViewToggleDashes = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewToggleDashes);
MainListViewToggleQuotes = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewToggleQuotes);
MainListViewToggleHiTags = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewToggleHiTags);
MainListViewToggleMusicSymbols = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewToggleMusicSymbols);
MainListViewAutoDuration = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewAutoDuration);
MainListViewAlignmentN1 = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewAlignmentN1);