aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.Editors
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-07-23 22:07:44 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-07-23 22:07:44 +0300
commit84b3861addbb2f60c8b45e74d2748d4de5c39d86 (patch)
tree006a6575c226df5437dc3f0d48a2715cd1885f7b /Software/Visual_Studio/Scripting/Tango.Scripting.Editors
parent449cc62b5bd91e5233edc5c0042d5792c8aa2972 (diff)
downloadTango-84b3861addbb2f60c8b45e74d2748d4de5c39d86.tar.gz
Tango-84b3861addbb2f60c8b45e74d2748d4de5c39d86.zip
Implemented find & replace.
Improved symbols loading and highlighting. Implemented font +/-.
Diffstat (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors')
-rw-r--r--Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Highlighting/OffsetColorizer.cs2
-rw-r--r--Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs218
2 files changed, 217 insertions, 3 deletions
diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Highlighting/OffsetColorizer.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Highlighting/OffsetColorizer.cs
index a05d1fc75..72c27f9a9 100644
--- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Highlighting/OffsetColorizer.cs
+++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Highlighting/OffsetColorizer.cs
@@ -30,7 +30,7 @@ namespace Tango.Scripting.Editors.Highlighting
{
try
{
- ChangeLinePart(StartOffset, EndOffset, element => element.TextRunProperties.SetForegroundBrush(Brush));
+ ChangeLinePart(StartOffset, EndOffset, element => element.TextRunProperties.SetBackgroundBrush(Brush));
}
catch { }
}
diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs
index 71a455f86..7b5c38a2b 100644
--- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs
+++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs
@@ -69,6 +69,7 @@ namespace Tango.Scripting.Editors
public static event EventHandler<TangoProgressChangedEventArgs<int>> LoadingSymbolsProgress;
public static event EventHandler LoadingSymbolsStarted;
public static event EventHandler LoadingSymbolsCompleted;
+ private static event EventHandler KnownTypesAvailable;
#region Mini Classes
@@ -161,6 +162,14 @@ namespace Tango.Scripting.Editors
public static readonly DependencyProperty AdditionalScriptsProperty =
DependencyProperty.Register("AdditionalScripts", typeof(ObservableCollection<IScriptSource>), typeof(ScriptEditor), new PropertyMetadata(null));
+ public Brush ColorizeBrush
+ {
+ get { return (Brush)GetValue(ColorizeBrushProperty); }
+ set { SetValue(ColorizeBrushProperty, value); }
+ }
+ public static readonly DependencyProperty ColorizeBrushProperty =
+ DependencyProperty.Register("ColorizeBrush", typeof(Brush), typeof(ScriptEditor), new PropertyMetadata(new SolidColorBrush(Colors.YellowGreen) { Opacity = 0.5 }));
+
#endregion
#region Constructors
@@ -266,6 +275,8 @@ namespace Tango.Scripting.Editors
_knownTypes = new List<KnownType>();
_parser = new ScriptParser();
+ KnownTypesAvailable += ScriptEditor_KnownTypesAvailable;
+
TextArea.IndentationStrategy = new Indentation.CSharp.CSharpIndentationStrategy(Options);
foldingStrategy = new BraceFoldingStrategy();
@@ -287,6 +298,14 @@ namespace Tango.Scripting.Editors
TextChanged += ScriptEditor_TextChanged;
}
+ private void ScriptEditor_KnownTypesAvailable(object sender, EventArgs e)
+ {
+ if (sender != this)
+ {
+ InvalidateHighlightingPartial();
+ }
+ }
+
private bool preventCodeUpdate;
private void ScriptEditor_TextChanged(object sender, EventArgs e)
{
@@ -1357,7 +1376,7 @@ namespace Tango.Scripting.Editors
return popup;
}
- public static void LoadUsingsSymbols(List<Assembly> assemblies, List<String> usings)
+ public void LoadUsingsSymbols(List<Assembly> assemblies, List<String> usings)
{
lock (_loadUsingsLock)
{
@@ -1390,6 +1409,9 @@ namespace Tango.Scripting.Editors
_knownTypesCache.Add(knownType.Type, knownType);
}
+ KnownTypesAvailable?.Invoke(this, new EventArgs());
+ InvalidateHighlightingPartial();
+
continue;
}
@@ -1575,6 +1597,100 @@ namespace Tango.Scripting.Editors
// _isLoadingCachedAssemblies = false;
//}
+ private void InvalidateHighlightingPartial()
+ {
+ List<Assembly> assemblies = new List<Assembly>();
+ Dispatcher.Invoke(() =>
+ {
+ assemblies = ReferenceAssemblies.ToList();
+ });
+
+ var usings = _current_usings.ToList();
+
+ _knownTypes.Clear();
+
+ foreach (var knownType in _knownTypesCache.ToList().Select(x => x.Value).ToList())
+ {
+ if (usings.Exists(x => knownType.Type.Namespace == x) && assemblies.Exists(x => x == knownType.Type.Assembly))
+ {
+ lock (_knownTypes)
+ {
+ _knownTypes.Add(knownType);
+ }
+ }
+ }
+
+ if (_knownTypes.Count > 0 || _declaredTypes.Count > 0)
+ {
+ String text = String.Empty;
+
+ Stream xshd_stream = typeof(ScriptEditor).Assembly.GetManifestResourceStream("Tango.Scripting.Editors.Highlighting.Resources.CSharp-Mode.xshd");
+
+ using (StreamReader reader = new StreamReader(xshd_stream))
+ {
+ text = reader.ReadToEnd();
+ }
+
+ List<String> referenceTypes = new List<string>();
+ List<String> interfaceTypes = new List<string>();
+
+ lock (_knownTypes)
+ {
+ foreach (var type in _knownTypes.ToList().Where(x => x != null))
+ {
+ String name = type.Name;
+
+ if (type.Type.ContainsGenericParameters)
+ {
+ name = new String(name.TakeWhile(x => x != '`').ToArray());
+ }
+
+ if (type.Type.IsInterface || type.Type.IsEnum)
+ {
+ interfaceTypes.Add(String.Format("<Word>{0}</Word>", name));
+ }
+ else if (type.Type.IsClass || (type.Type.IsValueType))
+ {
+ referenceTypes.Add(String.Format("<Word>{0}</Word>", name));
+ }
+ }
+ }
+
+ foreach (var type in _declaredTypes)
+ {
+ if (type.Kind == TypeKind.Interface || type.Kind == TypeKind.Enum)
+ {
+ interfaceTypes.Add(String.Format("<Word>{0}</Word>", type.Name));
+ }
+ else if (type.Kind == TypeKind.Class)
+ {
+ referenceTypes.Add(String.Format("<Word>{0}</Word>", type.Name));
+ }
+ }
+
+ if (referenceTypes.Count > 0)
+ {
+ text = text.Replace("<Word>@ReferenceTypes@</Word>", String.Join(Environment.NewLine, referenceTypes.Distinct()));
+ }
+
+ if (interfaceTypes.Count > 0)
+ {
+ text = text.Replace("<Word>@InterfaceTypes@</Word>", String.Join(Environment.NewLine, interfaceTypes.Distinct()));
+ }
+
+ MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text));
+
+ XmlTextReader xshd_reader = new XmlTextReader(ms);
+
+ Dispatcher.Invoke(new Action(() =>
+ {
+ SyntaxHighlighting = HighlightingLoader.Load(xshd_reader, HighlightingManager.Instance);
+ xshd_reader.Close();
+ ms.Dispose();
+ }));
+ }
+ }
+
public void InvalidateHighlighting(bool loadKnownTypes = true)
{
if (!_isLoadingTypes)
@@ -1964,7 +2080,7 @@ namespace Tango.Scripting.Editors
{
int parameterIndex = expression.Count(x => x == ',');
-
+
expression = new string(expression.TakeWhile(x => x != '(').ToArray());
var tree = expression.Split('.').Select(x => x.Remove(@"\n|\r|\s|\t|\(|\)|\[|\]|<.*>")).ToList();
@@ -2209,6 +2325,104 @@ namespace Tango.Scripting.Editors
Document.Insert(TextArea.Caret.Offset, code);
}
+ public int Find(String text)
+ {
+ if (String.IsNullOrEmpty(text)) return -1;
+
+ string txt = Document.Text;
+ int index = txt.IndexOf(text, TextArea.Caret.Offset);
+
+ if (index > -1)
+ {
+ Select(index, text.Length);
+ ScrollToLine(TextArea.Selection.StartPosition.Line);
+ }
+ else
+ {
+ index = txt.IndexOf(text, 0);
+
+ if (index > -1)
+ {
+ Select(index, text.Length);
+ ScrollToLine(TextArea.Selection.StartPosition.Line);
+ }
+ else
+ {
+ Select(0, 0);
+ System.Media.SystemSounds.Beep.Play();
+ }
+ }
+
+ return index;
+ }
+
+ public int ReplaceNext(String text, String replace)
+ {
+ if (String.IsNullOrEmpty(text)) return -1;
+
+ String selectedText = TextArea.Selection.GetText();
+
+ if (selectedText == text)
+ {
+ TextArea.Selection.ReplaceSelectionWithText(replace);
+ }
+
+ return Find(text);
+ }
+
+ public int ReplaceAll(String text, String replace)
+ {
+ int counter = 0;
+
+ Select(0, 0);
+
+ while (ReplaceNext(text, replace) > -1)
+ {
+ counter++;
+ };
+
+ return counter;
+ }
+
+ public void ColorizeByKeyword(String text)
+ {
+ ResetColorizationByKeyword();
+
+ if (String.IsNullOrEmpty(text)) return;
+
+ var txt = Document.Text;
+
+ var indexes = txt.AllIndexesOf(text).ToList();
+
+ foreach (var index in indexes)
+ {
+ Document.BeginUpdate();
+
+ var line = Document.GetLineByOffset(index);
+
+ OffsetColorizer colorizer = new OffsetColorizer(line, index, index + text.Length, ColorizeBrush);
+ TextArea.TextView.LineTransformers.Add(colorizer);
+
+ Document.EndUpdate();
+ }
+ }
+
+ public void ResetColorizationByKeyword()
+ {
+ Document.BeginUpdate();
+
+ for (int i = 0; i < TextArea.TextView.LineTransformers.Count; i++)
+ {
+ if (TextArea.TextView.LineTransformers[i] is OffsetColorizer)
+ {
+ TextArea.TextView.LineTransformers.RemoveAt(i);
+ i--;
+ }
+ }
+
+ Document.EndUpdate();
+ }
+
#endregion
}
}