Browse Source

Remove CustomizableHighlightingColorizer.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
c9cc2ff077
  1. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  2. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs
  3. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs
  4. 274
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizingHighlighter.cs
  5. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DiffControl.xaml.cs
  6. 26
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -157,7 +157,7 @@ @@ -157,7 +157,7 @@
<Compile Include="Src\Commands\SortSelectionCommand.cs" />
<Compile Include="Src\Commands\SurroundWithCommand.cs" />
<Compile Include="Src\CustomCommands.cs" />
<Compile Include="Src\CustomizableHighlightingColorizer.cs" />
<Compile Include="Src\CustomizingHighlighter.cs" />
<Compile Include="Src\CustomizedHighlightingColor.cs" />
<Compile Include="Src\DocumentPrinter.cs" />
<Compile Include="Src\InlineUIElementGenerator.cs" />

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -52,7 +52,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
// add additional highlighters
highlighters.AddRange(SD.AddInTree.BuildItems<IHighlighter>(HighlighterDoozer.AddInPath, document, false));
var multiHighlighter = new MultiHighlighter(document, highlighters.ToArray());
return new CustomizableHighlightingColorizer.CustomizingHighlighter(
return new CustomizingHighlighter(
document, CustomizedHighlightingColor.FetchCustomizations(def.Name),
multiHighlighter);
}

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

@ -538,7 +538,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -538,7 +538,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
public void UpdateCustomizedHighlighting()
{
string language = this.SyntaxHighlighting != null ? this.SyntaxHighlighting.Name : null;
CustomizableHighlightingColorizer.ApplyCustomizationsToDefaultElements(this, FetchCustomizations(language));
CustomizingHighlighter.ApplyCustomizationsToDefaultElements(this, FetchCustomizations(language));
BracketHighlightRenderer.ApplyCustomizationsToRendering(this.bracketRenderer, FetchCustomizations(language));
HighlightingOptions.ApplyToRendering(this, FetchCustomizations(language));
this.TextArea.TextView.Redraw(); // manually redraw if default elements didn't change but customized highlightings did

274
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs → src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizingHighlighter.cs

@ -3,25 +3,23 @@ @@ -3,25 +3,23 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.AvalonEdit.AddIn
{
/// <summary>
/// Applies a set of customizations to syntax highlighting.
/// Wraps another <see cref="IHighlighter"/> and applies customizations
/// to the highlighting.
/// </summary>
public class CustomizableHighlightingColorizer : HighlightingColorizer
public class CustomizingHighlighter : IHighlighter, IDisposable
{
#region ApplyCustomizationsToDefaultElements
public const string DefaultTextAndBackground = "Default text/background";
@ -123,178 +121,152 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -123,178 +121,152 @@ namespace ICSharpCode.AvalonEdit.AddIn
}
#endregion
readonly IHighlightingDefinition highlightingDefinition;
readonly TextView textView;
readonly IEnumerable<CustomizedHighlightingColor> customizations;
readonly IHighlighter baseHighlighter;
readonly IDocument document;
[ObsoleteAttribute("Use a normal HighlightingColorizer with a CustomizingHighlighter instead")]
public CustomizableHighlightingColorizer(IHighlightingDefinition highlightingDefinition, IEnumerable<CustomizedHighlightingColor> customizations)
: base(highlightingDefinition)
public CustomizingHighlighter(TextView textView, IEnumerable<CustomizedHighlightingColor> customizations, IHighlighter baseHighlighter)
{
if (textView == null)
throw new ArgumentNullException("textView");
if (customizations == null)
throw new ArgumentNullException("customizations");
this.highlightingDefinition = highlightingDefinition;
if (baseHighlighter == null)
throw new ArgumentNullException("baseHighlighter");
this.textView = textView;
this.document = textView.Document;
this.customizations = customizations;
this.baseHighlighter = baseHighlighter;
baseHighlighter.HighlightingStateChanged += highlighter_HighlightingStateChanged;
}
protected override void DeregisterServices(TextView textView)
public CustomizingHighlighter(IDocument document, IEnumerable<CustomizedHighlightingColor> customizations, IHighlighter baseHighlighter)
{
textView.Services.RemoveService(typeof(IHighlighter));
base.DeregisterServices(textView);
if (document == null)
throw new ArgumentNullException("document");
if (customizations == null)
throw new ArgumentNullException("customizations");
if (baseHighlighter == null)
throw new ArgumentNullException("baseHighlighter");
this.document = document;
this.customizations = customizations;
this.baseHighlighter = baseHighlighter;
baseHighlighter.HighlightingStateChanged += highlighter_HighlightingStateChanged;
}
public IDocument Document {
get { return baseHighlighter.Document; }
}
public event HighlightingStateChangedEventHandler HighlightingStateChanged;
protected override void RegisterServices(TextView textView)
public void UpdateHighlightingState(int lineNumber)
{
base.RegisterServices(textView);
// textView.Services.AddService(typeof(IHighlighter), (CustomizingHighlighter)textView.GetService(typeof(IHighlighter)));
baseHighlighter.UpdateHighlightingState(lineNumber);
}
protected override IHighlighter CreateHighlighter(TextView textView, TextDocument document)
void highlighter_HighlightingStateChanged(IHighlighter sender, int fromLineNumber, int toLineNumber)
{
return new CustomizingHighlighter(textView, customizations, base.CreateHighlighter(textView, document));
if (HighlightingStateChanged != null)
HighlightingStateChanged(this, fromLineNumber, toLineNumber);
}
internal sealed class CustomizingHighlighter : IHighlighter, IDisposable
public IEnumerable<string> GetSpanColorNamesFromLineStart(int lineNumber)
{
readonly TextView textView;
readonly IEnumerable<CustomizedHighlightingColor> customizations;
readonly IHighlighter baseHighlighter;
readonly IDocument document;
public CustomizingHighlighter(TextView textView, IEnumerable<CustomizedHighlightingColor> customizations, IHighlighter baseHighlighter)
{
Debug.Assert(textView != null);
Debug.Assert(customizations != null);
Debug.Assert(baseHighlighter != null);
this.textView = textView;
this.document = textView.Document;
this.customizations = customizations;
this.baseHighlighter = baseHighlighter;
baseHighlighter.HighlightingStateChanged += highlighter_HighlightingStateChanged;
}
public CustomizingHighlighter(IDocument document, IEnumerable<CustomizedHighlightingColor> customizations, IHighlighter baseHighlighter)
{
Debug.Assert(customizations != null);
Debug.Assert(baseHighlighter != null);
this.document = document;
this.customizations = customizations;
this.baseHighlighter = baseHighlighter;
baseHighlighter.HighlightingStateChanged += highlighter_HighlightingStateChanged;
}
public IDocument Document {
get { return baseHighlighter.Document; }
}
public event HighlightingStateChangedEventHandler HighlightingStateChanged;
public void UpdateHighlightingState(int lineNumber)
{
baseHighlighter.UpdateHighlightingState(lineNumber);
}
void highlighter_HighlightingStateChanged(IHighlighter sender, int fromLineNumber, int toLineNumber)
{
if (HighlightingStateChanged != null)
HighlightingStateChanged(this, fromLineNumber, toLineNumber);
}
public IEnumerable<string> GetSpanColorNamesFromLineStart(int lineNumber)
{
// delayed evaluation doesn't cause a problem here: GetColorStack is called immediately,
// only the where/select portion is evaluated later. But that won't be a problem because the
// HighlightingColor instance shouldn't change once it's in use.
return from color in GetColorStack(lineNumber - 1)
where color.Name != null
select color.Name;
}
public IEnumerable<HighlightingColor> GetColorStack(int lineNumber)
{
return baseHighlighter.GetColorStack(lineNumber);
}
public HighlightedLine HighlightLine(int lineNumber)
{
HighlightedLine line = baseHighlighter.HighlightLine(lineNumber);
foreach (HighlightedSection section in line.Sections) {
section.Color = CustomizeColor(section.Color, customizations);
}
return line;
// delayed evaluation doesn't cause a problem here: GetColorStack is called immediately,
// only the where/select portion is evaluated later. But that won't be a problem because the
// HighlightingColor instance shouldn't change once it's in use.
return from color in GetColorStack(lineNumber - 1)
where color.Name != null
select color.Name;
}
public IEnumerable<HighlightingColor> GetColorStack(int lineNumber)
{
return baseHighlighter.GetColorStack(lineNumber);
}
public HighlightedLine HighlightLine(int lineNumber)
{
HighlightedLine line = baseHighlighter.HighlightLine(lineNumber);
foreach (HighlightedSection section in line.Sections) {
section.Color = CustomizeColor(section.Color, customizations);
}
return line;
}
public void InvalidateLine(IDocumentLine line)
{
if (textView == null)
throw new InvalidOperationException("IHighlighter has no TextView assigned!");
textView.Redraw(line, DispatcherPriority.Background);
}
public void InvalidateAll()
{
if (textView == null)
throw new InvalidOperationException("IHighlighter has no TextView assigned!");
textView.Redraw(DispatcherPriority.Background);
}
public event EventHandler VisibleDocumentLinesChanged {
add { textView.VisualLinesChanged += value; }
remove { textView.VisualLinesChanged -= value; }
}
public IEnumerable<IDocumentLine> GetVisibleDocumentLines()
{
if (textView == null)
throw new InvalidOperationException("IHighlighter has no TextView assigned!");
List<IDocumentLine> result = new List<IDocumentLine>();
foreach (VisualLine line in textView.VisualLines) {
if (line.FirstDocumentLine == line.LastDocumentLine) {
result.Add(line.FirstDocumentLine);
} else {
int firstLineStart = line.FirstDocumentLine.Offset;
int lineEndOffset = firstLineStart + line.FirstDocumentLine.TotalLength;
foreach (VisualLineElement e in line.Elements) {
int elementOffset = firstLineStart + e.RelativeTextOffset;
if (elementOffset >= lineEndOffset) {
var currentLine = this.Document.GetLineByOffset(elementOffset);
lineEndOffset = currentLine.Offset + currentLine.TotalLength;
result.Add(currentLine);
}
public void InvalidateLine(IDocumentLine line)
{
if (textView == null)
throw new InvalidOperationException("IHighlighter has no TextView assigned!");
textView.Redraw(line, DispatcherPriority.Background);
}
public void InvalidateAll()
{
if (textView == null)
throw new InvalidOperationException("IHighlighter has no TextView assigned!");
textView.Redraw(DispatcherPriority.Background);
}
public event EventHandler VisibleDocumentLinesChanged {
add { textView.VisualLinesChanged += value; }
remove { textView.VisualLinesChanged -= value; }
}
public IEnumerable<IDocumentLine> GetVisibleDocumentLines()
{
if (textView == null)
throw new InvalidOperationException("IHighlighter has no TextView assigned!");
List<IDocumentLine> result = new List<IDocumentLine>();
foreach (VisualLine line in textView.VisualLines) {
if (line.FirstDocumentLine == line.LastDocumentLine) {
result.Add(line.FirstDocumentLine);
} else {
int firstLineStart = line.FirstDocumentLine.Offset;
int lineEndOffset = firstLineStart + line.FirstDocumentLine.TotalLength;
foreach (VisualLineElement e in line.Elements) {
int elementOffset = firstLineStart + e.RelativeTextOffset;
if (elementOffset >= lineEndOffset) {
var currentLine = this.Document.GetLineByOffset(elementOffset);
lineEndOffset = currentLine.Offset + currentLine.TotalLength;
result.Add(currentLine);
}
}
}
return result;
}
public HighlightingColor GetNamedColor(string name)
{
return CustomizeColor(name, customizations);
}
public HighlightingColor DefaultTextColor {
get {
return GetNamedColor(CustomizableHighlightingColorizer.DefaultTextAndBackground);
}
}
public void BeginHighlighting()
{
baseHighlighter.BeginHighlighting();
}
public void EndHighlighting()
{
baseHighlighter.EndHighlighting();
}
public void Dispose()
{
baseHighlighter.Dispose();
return result;
}
public HighlightingColor GetNamedColor(string name)
{
return CustomizeColor(name, customizations);
}
public HighlightingColor DefaultTextColor {
get {
return GetNamedColor(CustomizingHighlighter.DefaultTextAndBackground);
}
}
public void BeginHighlighting()
{
baseHighlighter.BeginHighlighting();
}
public void EndHighlighting()
{
baseHighlighter.EndHighlighting();
}
public void Dispose()
{
baseHighlighter.Dispose();
}
internal static HighlightingColor CustomizeColor(HighlightingColor color, IEnumerable<CustomizedHighlightingColor> customizations)
{
if (color == null || color.Name == null)

4
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DiffControl.xaml.cs

@ -48,13 +48,13 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -48,13 +48,13 @@ namespace ICSharpCode.AvalonEdit.AddIn
{
string language = source.SyntaxHighlighting != null ? source.SyntaxHighlighting.Name : null;
editor.TextArea.TextView.LineTransformers.RemoveAll(x => x is HighlightingColorizer);
var customizedHighlighter = new CustomizableHighlightingColorizer.CustomizingHighlighter(
var customizedHighlighter = new CustomizingHighlighter(
editor.TextArea.TextView,
CustomizedHighlightingColor.FetchCustomizations(language),
new DocumentHighlighter(editor.Document, source.SyntaxHighlighting)
);
editor.TextArea.TextView.LineTransformers.Insert(0, new HighlightingColorizer(customizedHighlighter));
CustomizableHighlightingColorizer.ApplyCustomizationsToDefaultElements(editor, CustomizedHighlightingColor.FetchCustomizations(language));
CustomizingHighlighter.ApplyCustomizationsToDefaultElements(editor, CustomizedHighlightingColor.FetchCustomizations(language));
HighlightingOptions.ApplyToRendering(editor, CustomizedHighlightingColor.FetchCustomizations(language));
editor.TextArea.TextView.Redraw(); // manually redraw if default elements didn't change but customized highlightings did
}

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

@ -279,7 +279,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -279,7 +279,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
void CreateDefaultEntries(string language, out IHighlightingItem defaultText, IList<IHighlightingItem> items)
{
// Create entry for "default text/background"
defaultText = new SimpleHighlightingItem(CustomizableHighlightingColorizer.DefaultTextAndBackground, ta => ta.Document.Text = "Normal text") {
defaultText = new SimpleHighlightingItem(CustomizingHighlighter.DefaultTextAndBackground, ta => ta.Document.Text = "Normal text") {
Foreground = SystemColors.WindowTextColor,
Background = SystemColors.WindowColor
};
@ -289,7 +289,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -289,7 +289,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
// Create entry for "Selected text"
IHighlightingItem selectedText = new SimpleHighlightingItem(
CustomizableHighlightingColorizer.SelectedText,
CustomizingHighlighter.SelectedText,
ta => {
ta.Document.Text = "Selected text";
ta.Selection = Selection.Create(ta, 0, 13);
@ -304,7 +304,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -304,7 +304,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
// Create entry for "Non-printable characters"
IHighlightingItem nonPrintChars = new SimpleHighlightingItem(
CustomizableHighlightingColorizer.NonPrintableCharacters,
CustomizingHighlighter.NonPrintableCharacters,
ta => {
ta.Document.Text = " \r \r\n \n";
})
@ -317,7 +317,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -317,7 +317,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
// Create entry for "Line numbers"
IHighlightingItem lineNumbers = new SimpleHighlightingItem(
CustomizableHighlightingColorizer.LineNumbers,
CustomizingHighlighter.LineNumbers,
ta => {
ta.Document.Text = "These are just" + Environment.NewLine +
"multiple" + Environment.NewLine +
@ -402,7 +402,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -402,7 +402,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
items.Add(foldingTextMarker);
IHighlightingItem linkText = new SimpleHighlightingItem(
CustomizableHighlightingColorizer.LinkText,
CustomizingHighlighter.LinkText,
ta => {
ta.Document.Text = "http://icsharpcode.net" + Environment.NewLine + "me@example.com";
})
@ -502,7 +502,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -502,7 +502,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
items.Add(currentStatementMarker);
IHighlightingItem columnRuler = new SimpleHighlightingItem(
CustomizableHighlightingColorizer.ColumnRuler,
CustomizingHighlighter.ColumnRuler,
ta => {
ta.Document.Text = "some line with a lot of text";
ta.TextView.Options.ColumnRulerPosition = 15;
@ -546,7 +546,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -546,7 +546,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem;
if (xshd != null) {
var customizationsForCurrentLanguage = customizationList.Where(c => c.Language == null || c.Language == xshd.Name);
CustomizableHighlightingColorizer.ApplyCustomizationsToDefaultElements(textEditor, customizationsForCurrentLanguage);
CustomizingHighlighter.ApplyCustomizationsToDefaultElements(textEditor, customizationsForCurrentLanguage);
ApplyToRendering(textEditor, customizationsForCurrentLanguage);
var item = (IHighlightingItem)listBox.SelectedItem;
TextView textView = textEditor.TextArea.TextView;
@ -556,7 +556,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -556,7 +556,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
colorizer = null;
if (item != null) {
if (item.ParentDefinition != null) {
var highlighter = new CustomizableHighlightingColorizer.CustomizingHighlighter(
var highlighter = new CustomizingHighlighter(
textView, customizationsForCurrentLanguage,
new DocumentHighlighter(textView.Document, item.ParentDefinition)
);
@ -704,7 +704,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -704,7 +704,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{ "Keyword", "VBNET.Keywords" },
{ "Keyword", "VBNET.FunctionKeywords" },
{ "Keyword", "VBNET.ContextKeywords" },
{ "Line Numbers", CustomizableHighlightingColorizer.LineNumbers },
{ "Line Numbers", CustomizingHighlighter.LineNumbers },
{ "MarkerFormatDefinition/HighlightedReference", "" },
{ "Number", "C#.NumberLiteral" },
{ "Operator", "C#.Punctuation" },
@ -713,7 +713,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -713,7 +713,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{ "outlining.square", FoldingSelectedControls },
{ "outlining.verticalrule", "" },
{ "Plain Text", "" },
{ "Plain Text", CustomizableHighlightingColorizer.DefaultTextAndBackground },
{ "Plain Text", CustomizingHighlighter.DefaultTextAndBackground },
{ "Preprocessor Keyword", "" },
{ "Preprocessor Keyword", "C#.Preprocessor" },
{ "Razor Code", "" },
@ -724,12 +724,12 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -724,12 +724,12 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{ "Script Operator", "" },
{ "Script String", "" },
{ "Selected Text", "" },
{ "Selected Text", CustomizableHighlightingColorizer.SelectedText },
{ "Selected Text", CustomizingHighlighter.SelectedText },
{ "String", "VBNET.String" },
{ "String", "C#.String" },
{ "String(C# @ Verbatim)", "" },
{ "Syntax Error", "" },
{ "urlformat", CustomizableHighlightingColorizer.LinkText },
{ "urlformat", CustomizingHighlighter.LinkText },
{ "User Types", "" },
{ "User Types(Delegates)", "" },
{ "User Types(Enums)", "" },
@ -760,7 +760,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -760,7 +760,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{ "XML Name", "XML.XmlTag" },
{ "XML Name", "XML.XmlDeclaration" },
{ "XML Name", "XML.DocType" },
{ "XML Text", "XML." + CustomizableHighlightingColorizer.DefaultTextAndBackground },
{ "XML Text", "XML." + CustomizingHighlighter.DefaultTextAndBackground },
};
Tuple<Color?, Color?, bool> ParseEntry(XElement element)

Loading…
Cancel
Save