From 7b655b68cca79b863633f90e62c5ff1bc26077f8 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sun, 6 Jun 2021 07:52:27 +0200 Subject: [PATCH] Improve assa intellisence/color-highlight --- src/ui/Controls/AdvancedTextBox.cs | 7 ++- src/ui/Logic/AssaIntellisense.cs | 76 +++++++++++++++++++++++++----- 2 files changed, 71 insertions(+), 12 deletions(-) diff --git a/src/ui/Controls/AdvancedTextBox.cs b/src/ui/Controls/AdvancedTextBox.cs index 14b55d10a..a2fe197be 100644 --- a/src/ui/Controls/AdvancedTextBox.cs +++ b/src/ui/Controls/AdvancedTextBox.cs @@ -519,12 +519,17 @@ namespace Nikse.SubtitleEdit.Controls colorStart++; } - int colorEnd = text.IndexOf('&', colorStart + 1); + int colorEnd = text.IndexOfAny(new char[] {'}', '\\', '&'}, colorStart + 1); if (colorEnd > 0) { var color = text.Substring(colorStart, colorEnd - colorStart); try { + if (color.Length > 0 && color.Length < 6) + { + color = color.PadLeft(6, '0'); + } + if (color.Length == 6) { var rgbColor = string.Concat("#", color[4], color[5], color[2], color[3], color[0], color[1]); var c = ColorTranslator.FromHtml(rgbColor); diff --git a/src/ui/Logic/AssaIntellisense.cs b/src/ui/Logic/AssaIntellisense.cs index 862f6dd62..256b624fd 100644 --- a/src/ui/Logic/AssaIntellisense.cs +++ b/src/ui/Logic/AssaIntellisense.cs @@ -1,9 +1,10 @@ -using System; +using Nikse.SubtitleEdit.Controls; +using Nikse.SubtitleEdit.Core.Common; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; -using Nikse.SubtitleEdit.Controls; namespace Nikse.SubtitleEdit.Logic { @@ -41,7 +42,7 @@ namespace Nikse.SubtitleEdit.Logic } } - private static readonly List DictionaryList = new List(new[] + private static readonly List Keywords = new List { new IntellisenseItem("{\\b}", "Bold"), new IntellisenseItem("{\\b0}", "Bold off"), @@ -81,10 +82,10 @@ namespace Nikse.SubtitleEdit.Logic new IntellisenseItem("{\\2c&H}", "Color for outline"), new IntellisenseItem("{\\3c&H}", "Color for opaque box"), new IntellisenseItem("{\\4c&H}", "Color for shadow"), - new IntellisenseItem("{\\alpha&H&}", "Alpha (00=fully visible, ff=fully transparent)"), - new IntellisenseItem("{\\a2&H&}", "Alpha for outline (00=fully visible, ff=fully transparent)"), - new IntellisenseItem("{\\a3&H&}", "Alpha for opaque box (00=fully visible, ff=fully transparent)"), - new IntellisenseItem("{\\a4&H&}", "Alpha for shadow (00=fully visible, ff=fully transparent)"), + new IntellisenseItem("{\\alpha&H&}", "Alpha (00=fully visible, ff=transparent)"), + new IntellisenseItem("{\\a2&H&}", "Alpha for outline (00=fully visible, ff=transparent)"), + new IntellisenseItem("{\\a3&H&}", "Alpha for opaque box (00=fully visible, ff=transparent)"), + new IntellisenseItem("{\\a4&H&}", "Alpha for shadow (00=fully visible, ff=transparent)"), new IntellisenseItem("{\\an7}", "Align top left"), new IntellisenseItem("{\\an8}", "Align top center"), new IntellisenseItem("{\\an9}", "Align top right"), @@ -107,7 +108,40 @@ namespace Nikse.SubtitleEdit.Logic new IntellisenseItem("{\\t()}", "Animated transform"), new IntellisenseItem("{\\t()}", "Animated transform"), new IntellisenseItem("{\\t()}", "Animated transform"), - }.ToList()); + }; + + private static readonly List TransformKeywords = new List + { + new IntellisenseItem("\\fs", "Font size"), + new IntellisenseItem("\\fscx", "Scale X percentage"), + new IntellisenseItem("\\fscy", "Scale Y percentage"), + new IntellisenseItem("\\fsp", "Spacing between letters in pixels"), + new IntellisenseItem("\\fr", "Angle (z axis for text rotation)"), + new IntellisenseItem("\\frx", "Angle (x axis for text rotation)"), + new IntellisenseItem("\\fry", "Angle (y axis for text rotation)"), + new IntellisenseItem("\\frz", "Angle (z axis for text rotation)"), + new IntellisenseItem("\\bord", "Border"), + new IntellisenseItem("\\xbord", "Border width"), + new IntellisenseItem("\\ybord", "Border height"), + new IntellisenseItem("\\shad", "Shadow"), + new IntellisenseItem("\\xshad", "Shadow width"), + new IntellisenseItem("\\yshad", "Shadow height"), + new IntellisenseItem("\\c&H", "Color"), + new IntellisenseItem("\\2c&H", "Color for outline"), + new IntellisenseItem("\\3c&H", "Color for opaque box"), + new IntellisenseItem("\\4c&H", "Color for shadow"), + new IntellisenseItem("\\alpha&H&", "Alpha (00=fully visible, ff=transparent)"), + new IntellisenseItem("\\a2&H&", "Alpha for outline (00=fully visible, ff=transparent)"), + new IntellisenseItem("\\a3&H&", "Alpha for opaque box (00=fully visible, ff=transparent)"), + new IntellisenseItem("\\a4&H&", "Alpha for shadow (00=fully visible, ff=transparent)"), + new IntellisenseItem("\\be", "Blur edges"), + new IntellisenseItem("\\be0", "Blur edges off"), + new IntellisenseItem("\\be1", "Blur edges on"), + new IntellisenseItem("\\fax", "Shearing transformation (x axis)"), + new IntellisenseItem("\\fay", "Shearing transformation (y axis)"), + new IntellisenseItem("\\clip(x1,y1,x2,y2)", "Clips (hides) any drawing outside the rectangle defined by the parameters."), + new IntellisenseItem("\\iclip(x1,y1,x2,y2)", "Clips (hides) any drawing inside the rectangle defined by the parameters."), + }; private static readonly List LastAddedTags = new List(); @@ -120,10 +154,30 @@ namespace Nikse.SubtitleEdit.Logic { var text = string.IsNullOrEmpty(textBox.Text) ? string.Empty : textBox.Text.Substring(0, textBox.SelectionStart); var lastWord = GetLastString(text) ?? string.Empty; - var filteredList = DictionaryList + var keywords = Keywords; + + if (text.EndsWith("\\t(", StringComparison.Ordinal)) + { + // use smaller list inside transformation + keywords = TransformKeywords; + lastWord = string.Empty; + } + + var filteredList = keywords .Where(n => string.IsNullOrEmpty(lastWord) || n.Value.StartsWith(GetLastString(lastWord), StringComparison.OrdinalIgnoreCase)) .OrderBy(p => p.Value) .ToList(); + + if (filteredList.Count == 0 && lastWord.EndsWith("\\")) + { + // continuing ass tag, remove "{\" + "}" + lastWord = string.Empty; + filteredList = keywords + .OrderBy(p => p.Value) + .Select(p => new IntellisenseItem(p.Value.Replace("{\\", string.Empty).RemoveChar('}'), p.Hint)) + .ToList(); + } + listBox.Items.Clear(); listBox.Width = 480; listBox.Height = 200; @@ -227,14 +281,14 @@ namespace Nikse.SubtitleEdit.Logic if (lastSeparatorIndex >= 0) { s = s.Remove(0, lastSeparatorIndex - 1); - if (DictionaryList.Any(p => p.Value.StartsWith(s, StringComparison.OrdinalIgnoreCase))) + if (Keywords.Any(p => p.Value.StartsWith(s, StringComparison.OrdinalIgnoreCase))) { return s; } } else { - if (DictionaryList.Any(p => p.Value.StartsWith(s, StringComparison.OrdinalIgnoreCase))) + if (Keywords.Any(p => p.Value.StartsWith(s, StringComparison.OrdinalIgnoreCase))) { return s; }