private void AddHilight(int start, int length, Color color) { ExplicitDecoration ed = new ExplicitDecoration(); ed.Start = start; ed.Length = length; ed.Brush = new SolidColorBrush(color); ed.DecorationType = EDecorationType.Hilight; ContentTextBox.Decorations.Add(ed); }
private void PresentColoredTokens(IEnumerable <Token> tokens, IEnumerable <Error> errors) { SourceTextBox.Decorations.Clear(); SourceTextBox.InvalidateVisual(); foreach (var token in tokens) { if (_colorMap.ContainsKey(token.Type)) { ExplicitDecoration ed = new ExplicitDecoration(); ed.Start = token.Position.Value.Offset; ed.Length = token.Value.Length; ed.Brush = _colorMap[token.Type]; ed.DecorationType = EDecorationType.TextColor; SourceTextBox.Decorations.Add(ed); } } foreach (var error in errors) { if (error.Token != null) { if (error.Kind == ErrorKind.Syntax) { ExplicitDecoration ed = new ExplicitDecoration(); ExplicitDecoration ed2 = new ExplicitDecoration(); ed.Start = ed2.Start = error.Token.Position.Value.Offset; ed.Length = ed2.Length = error.Token.Value.Length; ed.DecorationType = EDecorationType.Hilight; ed.Brush = new SolidColorBrush(Color.FromArgb(200, 255, 0, 0)); ed2.DecorationType = EDecorationType.TextColor; ed2.Brush = new SolidColorBrush(Colors.White); SourceTextBox.Decorations.Add(ed); SourceTextBox.Decorations.Add(ed2); } else if (error.Kind == ErrorKind.Lexical) { ExplicitDecoration ed = new ExplicitDecoration(); ed.Start = error.Token.Position.Value.Offset; ed.Length = error.Token.Value.Length; ed.DecorationType = EDecorationType.Underline; ed.Brush = Brushes.Red; SourceTextBox.Decorations.Add(ed); } else if (error.Kind == ErrorKind.Semantic) { ExplicitDecoration ed = new ExplicitDecoration(); ed.Start = error.Token.Position.Value.Offset; ed.Length = error.Token.Value.Length; ed.DecorationType = EDecorationType.Hilight; ed.Brush = new SolidColorBrush(Color.FromArgb(200, 0, 255, 0)); SourceTextBox.Decorations.Add(ed); } } } SourceTextBox.InvalidateVisual(); }