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 @@ -42,6 +42,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
textEditor.TextArea.TextView.ClearValue(TextView.NonPrintableCharacterBrushProperty);
textEditor.TextArea.TextView.ClearValue(TextView.LinkTextForegroundBrushProperty);
textEditor.TextArea.TextView.ClearValue(TextView.LinkTextBackgroundBrushProperty);
textEditor.TextArea.TextView.ClearValue(TextView.ColumnRulerBrushProperty);
// 'assigned' flags are used so that the first matching customization wins.
// This is necessary because more specific customizations come first in the list
@ -51,6 +52,8 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -51,6 +52,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
bool assignedNonPrintableCharacter = false;
bool assignedLineNumbers = false;
bool assignedLinkText = false;
bool assignedColumnRulerColor = false;
foreach (CustomizedHighlightingColor color in customizations) {
switch (color.Name) {
case DefaultTextAndBackground:
@ -106,6 +109,13 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -106,6 +109,13 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (color.Background != null)
textEditor.TextArea.TextView.LinkTextBackgroundBrush = CreateFrozenBrush(color.Background.Value);
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 @@ -245,7 +245,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
}
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 @@ -39,10 +39,10 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
InitializeComponent();
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);
foldingManager = FoldingManager.Install(textEditor.TextArea);
CodeEditorOptions.Instance.BindToTextEditor(textEditor);
textMarkerService = new TextMarkerService(textEditor.Document);
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
@ -429,6 +429,20 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -429,6 +429,20 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
currentStatementMarker = new CustomizedHighlightingItem(customizationList, currentStatementMarker, language, canSetFont: false);
currentStatementMarker.PropertyChanged += item_PropertyChanged;
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)

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

@ -4,36 +4,37 @@ @@ -4,36 +4,37 @@
using System;
using System.Windows;
using System.Windows.Media;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.AvalonEdit
{
/// <summary>
/// Redners a ruler at a certain colum
/// Renders a ruler at a certain column.
/// </summary>
public class ColumnRulerRenderer : IBackgroundRenderer
{
Pen pen;
int column;
TextView textView;
public const string Name = "Column ruler";
public static readonly Color DefaultForeground = Colors.LightGray;
public ColumnRulerRenderer(TextView textView)
{
if (textView == null)
throw new ArgumentNullException("textView");
this.pen = new Pen(Brushes.LightGray, 1);
this.pen = new Pen(new SolidColorBrush(DefaultForeground), 1);
this.pen.Freeze();
this.textView = textView;
this.textView.BackgroundRenderers.Add(this);
}
public KnownLayer Layer {
get {
return KnownLayer.Background;
}
get { return KnownLayer.Background; }
}
public void SetRuler(int column, Brush brush)
@ -51,11 +52,9 @@ namespace ICSharpCode.AvalonEdit @@ -51,11 +52,9 @@ namespace ICSharpCode.AvalonEdit
public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext)
{
if(column < 1)
return;
if (column < 1) return;
double offset = textView.WideSpaceWidth * column;
System.Windows.Size pixelSize = PixelSnapHelpers.GetPixelSize(textView);
Size pixelSize = PixelSnapHelpers.GetPixelSize(textView);
double markerXPos = PixelSnapHelpers.PixelAlign(offset, pixelSize.Width);
Point start = new Point(markerXPos, 0);
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 @@ -183,7 +183,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
new FrameworkPropertyMetadata(OnOptionsChanged));
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// Gets/Sets the options used by the text editor.
/// </summary>
public TextEditorOptions Options {
get { return (TextEditorOptions)GetValue(OptionsProperty); }

Loading…
Cancel
Save