Browse Source

add support for customizations in combination with the semantic highlighting + fix bugs in HighlightingOptions

newNRvisualizers
Siegfried Pammer 13 years ago
parent
commit
16abd83dd1
  1. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs
  2. 32
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs
  3. 10
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizedHighlightingColor.cs
  4. 54
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
  5. 23
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs
  6. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs
  7. 3
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs

4
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs

@ -541,9 +541,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -541,9 +541,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
protected override IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
return new CustomizableHighlightingColorizer(
highlightingDefinition,
FetchCustomizations(highlightingDefinition.Name));
return null;
}
// TODO: move this into SharpDevelopTextEditor

32
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs

@ -159,7 +159,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -159,7 +159,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
readonly IHighlightingDefinition highlightingDefinition;
readonly IHighlighter baseHighlighter;
readonly IDocument document;
List<IHighlighter> additionalHighlighters = new List<IHighlighter>();
public CustomizingHighlighter(TextView textView, IEnumerable<CustomizedHighlightingColor> customizations, IHighlightingDefinition highlightingDefinition, IHighlighter baseHighlighter)
{
@ -202,25 +201,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -202,25 +201,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
public void UpdateHighlightingState(int lineNumber)
{
baseHighlighter.UpdateHighlightingState(lineNumber);
foreach (var h in additionalHighlighters) {
h.UpdateHighlightingState(lineNumber);
}
}
public void AddAdditionalHighlighter(IHighlighter highlighter)
{
if (highlighter == null)
throw new ArgumentNullException("highlighter");
if (highlighter.Document != baseHighlighter.Document)
throw new ArgumentException("Additional highlighters must use the same document as the base highlighter");
additionalHighlighters.Add(highlighter);
highlighter.HighlightingStateChanged += highlighter_HighlightingStateChanged;
}
public void RemoveAdditionalHighlighter(IHighlighter highlighter)
{
additionalHighlighters.Remove(highlighter);
highlighter.HighlightingStateChanged -= highlighter_HighlightingStateChanged;
}
void highlighter_HighlightingStateChanged(IHighlighter sender, int fromLineNumber, int toLineNumber)
@ -241,22 +221,12 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -241,22 +221,12 @@ namespace ICSharpCode.AvalonEdit.AddIn
public IEnumerable<HighlightingColor> GetColorStack(int lineNumber)
{
List<HighlightingColor> list = new List<HighlightingColor>();
for (int i = additionalHighlighters.Count - 1; i >= 0; i--) {
var s = additionalHighlighters[i].GetColorStack(lineNumber);
if (s != null)
list.AddRange(s);
}
list.AddRange(baseHighlighter.GetColorStack(lineNumber));
return list;
return baseHighlighter.GetColorStack(lineNumber);
}
public HighlightedLine HighlightLine(int lineNumber)
{
HighlightedLine line = baseHighlighter.HighlightLine(lineNumber);
foreach (IHighlighter h in additionalHighlighters) {
line.MergeWith(h.HighlightLine(lineNumber));
}
foreach (HighlightedSection section in line.Sections) {
section.Color = CustomizeColor(section.Color, customizations);
}

10
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizedHighlightingColor.cs

@ -19,15 +19,17 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -19,15 +19,17 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// <summary>
/// The language to which this customization applies. null==all languages.
/// </summary>
public string Language;
public string Language { get; set; }
/// <summary>
/// The name of the highlighting color being modified.
/// </summary>
public string Name;
public string Name { get; set; }
public bool Bold, Italic;
public Color? Foreground, Background;
public bool Bold { get; set; }
public bool Italic { get; set; }
public Color? Foreground { get; set; }
public Color? Background { get; set; }
public static IReadOnlyList<CustomizedHighlightingColor> LoadColors()
{

54
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Design;
using System.Globalization;
using System.IO;
@ -12,7 +13,6 @@ using System.Windows.Controls; @@ -12,7 +13,6 @@ using System.Windows.Controls;
using System.Windows.Media;
using System.Xml;
using System.Xml.Linq;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.AvalonEdit.Highlighting;
@ -50,7 +50,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -50,7 +50,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
BracketHighlightRenderer bracketHighlighter;
FoldingManager foldingManager;
TextMarkerService textMarkerService;
ITextMarker marker;
List<CustomizedHighlightingColor> customizationList;
public const string FoldingControls = "Folding controls";
@ -196,7 +195,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -196,7 +195,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem;
if (xshd != null) {
IHighlightingItem defaultText;
List<IHighlightingItem> list = new List<IHighlightingItem>();
ObservableCollection<IHighlightingItem> list = new ObservableCollection<IHighlightingItem>();
CreateDefaultEntries(languageComboBox.SelectedIndex == 0 ? null : xshd.Name, out defaultText, list);
listBox.ItemsSource = list;
@ -213,7 +212,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -213,7 +212,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
if (namedColor.ExampleText != null) {
IHighlightingItem item = new NamedColorHighlightingItem(defaultText, namedColor) { ParentDefinition = def };
item = new CustomizedHighlightingItem(customizationList, item, xshd.Name);
listBox.Items.Add(item);
list.Add(item);
item.PropertyChanged += item_PropertyChanged;
}
}
@ -420,7 +419,11 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -420,7 +419,11 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
ErrorPainter.ErrorColorName,
ta => {
ta.Document.Text = "some error";
marker = textMarkerService.Create(0, 5);
ITextMarker marker = textMarkerService.Create(0, 5);
marker.Tag = (Action<IHighlightingItem, ITextMarker>)delegate(IHighlightingItem item, ITextMarker m) {
m.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
m.MarkerColor = item.Foreground;
};
})
{
Foreground = Colors.Red
@ -433,7 +436,11 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -433,7 +436,11 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
ErrorPainter.WarningColorName,
ta => {
ta.Document.Text = "some warning";
marker = textMarkerService.Create(0, 5);
ITextMarker marker = textMarkerService.Create(0, 5);
marker.Tag = (Action<IHighlightingItem, ITextMarker>)delegate(IHighlightingItem item, ITextMarker m) {
m.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
m.MarkerColor = item.Foreground;
};
})
{
Foreground = Colors.Orange
@ -446,7 +453,11 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -446,7 +453,11 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
ErrorPainter.MessageColorName,
ta => {
ta.Document.Text = "some message";
marker = textMarkerService.Create(0, 5);
ITextMarker marker = textMarkerService.Create(0, 5);
marker.Tag = (Action<IHighlightingItem, ITextMarker>)delegate(IHighlightingItem item, ITextMarker m) {
m.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
m.MarkerColor = item.Foreground;
};
})
{
Foreground = Colors.Blue
@ -459,7 +470,11 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -459,7 +470,11 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
BreakpointBookmark.BreakpointMarker,
ta => {
ta.Document.Text = "some code with a breakpoint";
marker = textMarkerService.Create(0, ta.Document.TextLength);
ITextMarker marker = textMarkerService.Create(0, ta.Document.TextLength);
marker.Tag = (Action<IHighlightingItem, ITextMarker>)delegate(IHighlightingItem item, ITextMarker m) {
m.BackgroundColor = item.Background;
m.ForegroundColor = item.Foreground;
};
})
{
Background = BreakpointBookmark.DefaultBackground,
@ -473,7 +488,11 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -473,7 +488,11 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
CurrentLineBookmark.Name,
ta => {
ta.Document.Text = "current statement line";
marker = textMarkerService.Create(0, ta.Document.TextLength);
ITextMarker marker = textMarkerService.Create(0, ta.Document.TextLength);
marker.Tag = (Action<IHighlightingItem, ITextMarker>)delegate(IHighlightingItem item, ITextMarker m) {
m.BackgroundColor = item.Background;
m.ForegroundColor = item.Foreground;
};
})
{
Background = CurrentLineBookmark.DefaultBackground,
@ -534,7 +553,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -534,7 +553,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
TextView textView = textEditor.TextArea.TextView;
foldingManager.Clear();
textMarkerService.RemoveAll(m => true);
marker = null;
textView.LineTransformers.Remove(colorizer);
colorizer = null;
if (item != null) {
@ -545,19 +563,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -545,19 +563,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
textEditor.Select(0, 0);
bracketHighlighter.SetHighlight(null);
item.ShowExample(textEditor.TextArea);
if (marker != null) {
switch (item.Name) {
case ErrorPainter.ErrorColorName:
case ErrorPainter.WarningColorName:
case ErrorPainter.MessageColorName:
marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
marker.MarkerColor = item.Foreground;
break;
default:
marker.MarkerTypes = TextMarkerTypes.None;
marker.MarkerColor = Colors.Transparent;
break;
}
ITextMarker m = textMarkerService.TextMarkers.SingleOrDefault();
if (m != null && m.Tag != null) {
((Action<IHighlightingItem, ITextMarker>)m.Tag)(item, m);
}
}
}

23
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs

@ -11,6 +11,7 @@ using ICSharpCode.AvalonEdit.Editing; @@ -11,6 +11,7 @@ using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.AvalonEdit.AddIn.Options
{
@ -129,7 +130,27 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -129,7 +130,27 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
public void ShowExample(TextArea exampleTextArea)
{
exampleTextArea.Document.Text = StringParser.Parse(color.ExampleText, GetXshdProperties().ToArray());
string exampleText = StringParser.Parse(color.ExampleText, GetXshdProperties().ToArray());
int semanticHighlightStart = exampleText.IndexOf("#{#", StringComparison.OrdinalIgnoreCase);
int semanticHighlightEnd = exampleText.IndexOf("#}#", StringComparison.OrdinalIgnoreCase);
if (semanticHighlightStart > -1 && semanticHighlightEnd >= semanticHighlightStart + 3) {
semanticHighlightEnd -= 3;
exampleText = exampleText.Remove(semanticHighlightStart, 3).Remove(semanticHighlightEnd, 3);
ITextMarkerService svc = exampleTextArea.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
exampleTextArea.Document.Text = exampleText;
if (svc != null) {
ITextMarker m = svc.Create(semanticHighlightStart, semanticHighlightEnd - semanticHighlightStart);
m.Tag = (Action<IHighlightingItem, ITextMarker>)(
(IHighlightingItem item, ITextMarker marker) => {
marker.BackgroundColor = item.Background;
marker.ForegroundColor = item.Foreground;
marker.FontStyle = item.Italic ? FontStyles.Italic : FontStyles.Normal;
marker.FontWeight = item.Bold ? FontWeights.Bold : FontWeights.Normal;
});
}
} else {
exampleTextArea.Document.Text = exampleText;
}
}
IEnumerable<StringTagPair> GetXshdProperties()

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs

@ -30,7 +30,6 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -30,7 +30,6 @@ namespace ICSharpCode.AvalonEdit.Highlighting
if (definition == null)
throw new ArgumentNullException("definition");
this.definition = definition;
this.highlighter = highlighter;
}
/// <summary>

3
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs

@ -331,7 +331,8 @@ namespace ICSharpCode.AvalonEdit @@ -331,7 +331,8 @@ namespace ICSharpCode.AvalonEdit
}
if (newValue != null) {
colorizer = CreateColorizer(newValue);
this.TextArea.TextView.LineTransformers.Insert(0, colorizer);
if (colorizer != null)
this.TextArea.TextView.LineTransformers.Insert(0, colorizer);
}
}

Loading…
Cancel
Save