Browse Source

make column ruler color customizable

pull/26/merge
Siegfried Pammer 14 years ago
parent
commit
97c248803a
  1. 10
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs
  2. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CodeEditorOptions.cs
  3. 18
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
  4. 19
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/ColumnRulerRenderer.cs
  5. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs

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

@ -42,6 +42,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
textEditor.TextArea.TextView.ClearValue(TextView.NonPrintableCharacterBrushProperty); textEditor.TextArea.TextView.ClearValue(TextView.NonPrintableCharacterBrushProperty);
textEditor.TextArea.TextView.ClearValue(TextView.LinkTextForegroundBrushProperty); textEditor.TextArea.TextView.ClearValue(TextView.LinkTextForegroundBrushProperty);
textEditor.TextArea.TextView.ClearValue(TextView.LinkTextBackgroundBrushProperty); textEditor.TextArea.TextView.ClearValue(TextView.LinkTextBackgroundBrushProperty);
textEditor.TextArea.TextView.ClearValue(TextView.ColumnRulerBrushProperty);
// 'assigned' flags are used so that the first matching customization wins. // 'assigned' flags are used so that the first matching customization wins.
// This is necessary because more specific customizations come first in the list // This is necessary because more specific customizations come first in the list
@ -51,6 +52,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
bool assignedNonPrintableCharacter = false; bool assignedNonPrintableCharacter = false;
bool assignedLineNumbers = false; bool assignedLineNumbers = false;
bool assignedLinkText = false; bool assignedLinkText = false;
bool assignedColumnRulerColor = false;
foreach (CustomizedHighlightingColor color in customizations) { foreach (CustomizedHighlightingColor color in customizations) {
switch (color.Name) { switch (color.Name) {
case DefaultTextAndBackground: case DefaultTextAndBackground:
@ -106,6 +109,13 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (color.Background != null) if (color.Background != null)
textEditor.TextArea.TextView.LinkTextBackgroundBrush = CreateFrozenBrush(color.Background.Value); textEditor.TextArea.TextView.LinkTextBackgroundBrush = CreateFrozenBrush(color.Background.Value);
break; break;
case ColumnRulerRenderer.Name:
if (assignedColumnRulerColor)
continue;
assignedColumnRulerColor = true;
if (color.Foreground != null)
textEditor.TextArea.TextView.ColumnRulerBrush = CreateFrozenBrush(color.Foreground.Value);
break;
} }
} }
} }

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CodeEditorOptions.cs

@ -245,7 +245,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
} }
int ITextEditorOptions.VerticalRulerColumn { int ITextEditorOptions.VerticalRulerColumn {
get { return 120; } get { return ColumnRulerPosition; }
} }
} }
} }

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

@ -39,10 +39,10 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
InitializeComponent(); InitializeComponent();
textEditor.Document.UndoStack.SizeLimit = 0; textEditor.Document.UndoStack.SizeLimit = 0;
textEditor.Options = CodeEditorOptions.Instance; CodeEditorOptions.Instance.BindToTextEditor(textEditor);
textEditor.Options = new TextEditorOptions(CodeEditorOptions.Instance);
bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView); bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView);
foldingManager = FoldingManager.Install(textEditor.TextArea); foldingManager = FoldingManager.Install(textEditor.TextArea);
CodeEditorOptions.Instance.BindToTextEditor(textEditor);
textMarkerService = new TextMarkerService(textEditor.Document); textMarkerService = new TextMarkerService(textEditor.Document);
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService); textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
@ -429,6 +429,20 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
currentStatementMarker = new CustomizedHighlightingItem(customizationList, currentStatementMarker, language, canSetFont: false); currentStatementMarker = new CustomizedHighlightingItem(customizationList, currentStatementMarker, language, canSetFont: false);
currentStatementMarker.PropertyChanged += item_PropertyChanged; currentStatementMarker.PropertyChanged += item_PropertyChanged;
items.Add(currentStatementMarker); items.Add(currentStatementMarker);
IHighlightingItem columnRuler = new SimpleHighlightingItem(
ColumnRulerRenderer.Name,
ta => {
ta.Document.Text = "some line with a lot of text";
ta.TextView.Options.ColumnRulerPosition = 15;
ta.TextView.Options.ShowColumnRuler = true;
})
{
Foreground = ColumnRulerRenderer.DefaultForeground
};
columnRuler = new CustomizedHighlightingItem(customizationList, columnRuler, language, canSetFont: false, canSetBackground: false);
columnRuler.PropertyChanged += item_PropertyChanged;
items.Add(columnRuler);
} }
void item_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) void item_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)

19
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/ColumnRulerRenderer.cs

@ -4,36 +4,37 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using ICSharpCode.AvalonEdit.Rendering; using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.AvalonEdit.Utils; using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.AvalonEdit namespace ICSharpCode.AvalonEdit
{ {
/// <summary> /// <summary>
/// Redners a ruler at a certain colum /// Renders a ruler at a certain column.
/// </summary> /// </summary>
public class ColumnRulerRenderer : IBackgroundRenderer public class ColumnRulerRenderer : IBackgroundRenderer
{ {
Pen pen; Pen pen;
int column; int column;
TextView textView; TextView textView;
public const string Name = "Column ruler";
public static readonly Color DefaultForeground = Colors.LightGray;
public ColumnRulerRenderer(TextView textView) public ColumnRulerRenderer(TextView textView)
{ {
if (textView == null) if (textView == null)
throw new ArgumentNullException("textView"); throw new ArgumentNullException("textView");
this.pen = new Pen(Brushes.LightGray, 1); this.pen = new Pen(new SolidColorBrush(DefaultForeground), 1);
this.pen.Freeze(); this.pen.Freeze();
this.textView = textView; this.textView = textView;
this.textView.BackgroundRenderers.Add(this); this.textView.BackgroundRenderers.Add(this);
} }
public KnownLayer Layer { public KnownLayer Layer {
get { get { return KnownLayer.Background; }
return KnownLayer.Background;
}
} }
public void SetRuler(int column, Brush brush) public void SetRuler(int column, Brush brush)
@ -51,11 +52,9 @@ namespace ICSharpCode.AvalonEdit
public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext) public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext)
{ {
if(column < 1) if (column < 1) return;
return;
double offset = textView.WideSpaceWidth * column; double offset = textView.WideSpaceWidth * column;
System.Windows.Size pixelSize = PixelSnapHelpers.GetPixelSize(textView); Size pixelSize = PixelSnapHelpers.GetPixelSize(textView);
double markerXPos = PixelSnapHelpers.PixelAlign(offset, pixelSize.Width); double markerXPos = PixelSnapHelpers.PixelAlign(offset, pixelSize.Width);
Point start = new Point(markerXPos, 0); Point start = new Point(markerXPos, 0);
Point end = new Point(markerXPos, Math.Max(textView.DocumentHeight, textView.ActualHeight)); Point end = new Point(markerXPos, Math.Max(textView.DocumentHeight, textView.ActualHeight));

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs

@ -183,7 +183,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
new FrameworkPropertyMetadata(OnOptionsChanged)); new FrameworkPropertyMetadata(OnOptionsChanged));
/// <summary> /// <summary>
/// Gets/Sets the document displayed by the text editor. /// Gets/Sets the options used by the text editor.
/// </summary> /// </summary>
public TextEditorOptions Options { public TextEditorOptions Options {
get { return (TextEditorOptions)GetValue(OptionsProperty); } get { return (TextEditorOptions)GetValue(OptionsProperty); }

Loading…
Cancel
Save