Skip to content

Commit 470aa5a

Browse files
committed
Add custom type syntax highlight
1 parent d6c6678 commit 470aa5a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Bonsai.Scripting.Expressions.Design/ExpressionScriptEditor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide
5353
var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
5454
if (editorService != null)
5555
{
56-
using var editorDialog = new ExpressionScriptEditorDialog();
56+
var itType = GetDataSource(context, provider)?.ObservableType;
57+
using var editorDialog = new ExpressionScriptEditorDialog(itType);
5758
editorDialog.Script = (string)value;
58-
editorDialog.ItType = GetDataSource(context, provider)?.ObservableType;
5959
return editorService.ShowDialog(editorDialog) == DialogResult.OK
6060
? editorDialog.Script
6161
: value;

src/Bonsai.Scripting.Expressions.Design/ExpressionScriptEditorDialog.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ internal partial class ExpressionScriptEditorDialog : Form
1616
{
1717
readonly StringBuilder autoCompleteList = new();
1818

19-
public ExpressionScriptEditorDialog()
19+
public ExpressionScriptEditorDialog(Type? itType = null)
2020
{
21+
ItType = itType;
2122
InitializeComponent();
2223
scintilla.StyleResetDefault();
2324
scintilla.Styles[Style.Default].Font = "Consolas";
@@ -35,8 +36,11 @@ public ExpressionScriptEditorDialog()
3536
scintilla.Lexer = Lexer.Cpp;
3637

3738
var typeKeywords = string.Join(" ", CaretExpressionAnalyzer.PredefinedTypeKeywords.Keys);
39+
var predefinedTypes = CaretExpressionAnalyzer.PredefinedTypes;
3840
scintilla.SetKeywords(0, "it iif new outerIt as true false null " + typeKeywords);
39-
scintilla.SetKeywords(1, string.Join(" ", CaretExpressionAnalyzer.PredefinedTypes.Select(type => type.Name)));
41+
scintilla.SetKeywords(1, string.Join(" ", Enumerable.Concat(
42+
(itType is not null ? predefinedTypes.Append(itType) : predefinedTypes).Select(type => type.Name),
43+
predefinedTypes.Select(type => type.Name.ToLowerInvariant()))));
4044

4145
scintilla.AutoCSeparator = ';';
4246
scintilla.AutoCTypeSeparator = '?';
@@ -47,7 +51,7 @@ public ExpressionScriptEditorDialog()
4751
scintilla.RegisterRgbaImage(3, Resources.TypeIcon);
4852
}
4953

50-
public Type ItType { get; set; }
54+
public Type? ItType { get; }
5155

5256
public string Script { get; set; }
5357

@@ -190,7 +194,7 @@ private void AppendMethods(Type type, BindingFlags bindingFlags, StringBuilder s
190194
private void AppendTypes(Type itType, StringBuilder sb)
191195
{
192196
foreach (var type in CaretExpressionAnalyzer.PredefinedTypes.Append(itType)
193-
.OrderBy(t => t.Name))
197+
.OrderBy(t => t.Name))
194198
{
195199
AppendMember(type.Name, 3, sb);
196200
}

0 commit comments

Comments
 (0)