mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Toggle music symbols, now toggles via first text - thx Leon :)
Related to #7386
This commit is contained in:
parent
a2e9519725
commit
3e4bfbb9cd
@ -41,6 +41,7 @@
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stbl/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tahoma/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tesseract/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ukranian/@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>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Vanc/@EntryIndexedValue">True</s:Boolean>
|
||||
|
@ -3124,7 +3124,55 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
}
|
||||
}
|
||||
|
||||
public static string ToggleSymbols(string tag, string text, string endTag = null)
|
||||
public static string ToggleSymbols(string tag, string text, string endTag, out bool added)
|
||||
{
|
||||
var pre = string.Empty;
|
||||
var post = string.Empty;
|
||||
text = SplitStartTags(text, ref pre);
|
||||
text = SplitEndTags(text, ref post);
|
||||
|
||||
if (!string.IsNullOrEmpty(tag) && text.Contains(tag) || string.IsNullOrEmpty(tag) && !string.IsNullOrEmpty(endTag) && text.Contains(endTag))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(endTag) && !string.IsNullOrEmpty(tag))
|
||||
{
|
||||
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 (string.IsNullOrEmpty(endTag) && !string.IsNullOrEmpty(tag))
|
||||
{
|
||||
text = pre + text.Replace(tag, string.Empty).Replace(Environment.NewLine + " ", Environment.NewLine).Replace(" " + Environment.NewLine, Environment.NewLine).Trim() + post;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(endTag))
|
||||
{
|
||||
text = pre + text.Replace(endTag, string.Empty).Replace(Environment.NewLine + " ", Environment.NewLine).Replace(" " + Environment.NewLine, Environment.NewLine).Trim() + post;
|
||||
}
|
||||
|
||||
added = false;
|
||||
}
|
||||
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, endTag ?? tag, post);
|
||||
}
|
||||
|
||||
added = true;
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public static string RemoveSymbols(string tag, string text, string endTag)
|
||||
{
|
||||
var pre = string.Empty;
|
||||
var post = string.Empty;
|
||||
@ -3146,8 +3194,20 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
text = pre + text.Replace(endTag, string.Empty).Replace(Environment.NewLine + " ", Environment.NewLine).Replace(" " + Environment.NewLine, Environment.NewLine).Trim() + post;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
public static string AddSymbols(string tag, string text, string endTag)
|
||||
{
|
||||
text = RemoveSymbols(tag, text, endTag);
|
||||
|
||||
var pre = string.Empty;
|
||||
var post = string.Empty;
|
||||
text = SplitStartTags(text, ref pre);
|
||||
text = SplitEndTags(text, ref post);
|
||||
|
||||
if (tag == Configuration.Settings.Tools.MusicSymbol)
|
||||
{
|
||||
if (Configuration.Settings.Tools.MusicSymbolStyle.Equals("single", StringComparison.OrdinalIgnoreCase))
|
||||
@ -3163,7 +3223,6 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
{
|
||||
text = string.Format("{0}{1}{2}{3}{4}", pre, tag, text, endTag ?? tag, post);
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
@ -31230,7 +31230,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
|
||||
int selectionStart = tb.SelectionStart;
|
||||
text = Utilities.ToggleSymbols(tag, text, endTag);
|
||||
text = Utilities.ToggleSymbols(tag, text, endTag, out var _);
|
||||
tb.SelectedText = text;
|
||||
tb.SelectionStart = selectionStart;
|
||||
tb.SelectionLength = text.Length;
|
||||
@ -31254,20 +31254,46 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
|
||||
SubtitleListview1.BeginUpdate();
|
||||
var first = true;
|
||||
var addTags = true;
|
||||
foreach (int i in indices)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
_subtitle.Paragraphs[i].Text = Utilities.ToggleSymbols(tag, _subtitle.Paragraphs[i].Text, endTag, out var added);
|
||||
addTags = added;
|
||||
first = false;
|
||||
}
|
||||
|
||||
|
||||
if (addTags)
|
||||
{
|
||||
_subtitle.Paragraphs[i].Text = Utilities.AddSymbols(tag, _subtitle.Paragraphs[i].Text, endTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
_subtitle.Paragraphs[i].Text = Utilities.RemoveSymbols(tag, _subtitle.Paragraphs[i].Text, endTag);
|
||||
}
|
||||
|
||||
SubtitleListview1.SetText(i, _subtitle.Paragraphs[i].Text);
|
||||
|
||||
if (IsOriginalEditable)
|
||||
{
|
||||
var original = Utilities.GetOriginalParagraph(i, _subtitle.Paragraphs[i], _subtitleOriginal.Paragraphs);
|
||||
if (original != null)
|
||||
{
|
||||
original.Text = Utilities.ToggleSymbols(tag, original.Text, endTag);
|
||||
if (addTags)
|
||||
{
|
||||
original.Text = Utilities.AddSymbols(tag, original.Text, endTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
original.Text = Utilities.RemoveSymbols(tag, original.Text, endTag);
|
||||
}
|
||||
|
||||
SubtitleListview1.SetOriginalText(i, original.Text);
|
||||
}
|
||||
}
|
||||
|
||||
_subtitle.Paragraphs[i].Text = Utilities.ToggleSymbols(tag, _subtitle.Paragraphs[i].Text, endTag);
|
||||
SubtitleListview1.SetText(i, _subtitle.Paragraphs[i].Text);
|
||||
}
|
||||
|
||||
SubtitleListview1.EndUpdate();
|
||||
|
Loading…
Reference in New Issue
Block a user