Moved the ColumnRulerRenderer from the AddIn to the Library and changed the line pointed out by Daniel

This commit is contained in:
Tobias Ibounig 2012-06-04 00:09:26 +02:00 коммит произвёл Siegfried Pammer
Родитель e7cabe18bf
Коммит fa9dd44841
4 изменённых файлов: 129 добавлений и 0 удалений

Просмотреть файл

@ -233,6 +233,7 @@
<Compile Include="Rendering\ColorizingTransformer.cs">
<DependentUpon>IVisualLineTransformer.cs</DependentUpon>
</Compile>
<Compile Include="Rendering\ColumnRulerRenderer.cs" />
<Compile Include="Rendering\DocumentColorizingTransformer.cs">
<DependentUpon>IVisualLineTransformer.cs</DependentUpon>
</Compile>

Просмотреть файл

@ -0,0 +1,66 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
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
/// </summary>
public class ColumnRulerRenderer : IBackgroundRenderer
{
Pen pen;
int column;
TextView textView;
public ColumnRulerRenderer(TextView textView)
{
if (textView == null)
throw new ArgumentNullException("textView");
this.pen = new Pen(Brushes.LightGray, 1);
this.pen.Freeze();
this.textView = textView;
this.textView.BackgroundRenderers.Add(this);
}
public KnownLayer Layer {
get {
return KnownLayer.Background;
}
}
public void SetRuler(int column, Brush brush)
{
if (this.column != column) {
this.column = column;
textView.InvalidateLayer(this.Layer);
}
if (pen.Brush != brush) {
this.pen = new Pen(brush, 1);
this.pen.Freeze();
textView.InvalidateLayer(this.Layer);
}
}
public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext)
{
if(column < 1)
return;
double offset = textView.WideSpaceWidth * column;
System.Windows.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));
drawingContext.DrawLine(pen, start, end);
}
}
}

Просмотреть файл

@ -40,6 +40,8 @@ namespace ICSharpCode.AvalonEdit.Rendering
FocusableProperty.OverrideMetadata(typeof(TextView), new FrameworkPropertyMetadata(Boxes.False));
}
ColumnRulerRenderer columnRulerRenderer;
/// <summary>
/// Creates a new TextView instance.
/// </summary>
@ -59,6 +61,8 @@ namespace ICSharpCode.AvalonEdit.Rendering
this.hoverLogic = new MouseHoverLogic(this);
this.hoverLogic.MouseHover += (sender, e) => RaiseHoverEventPair(e, PreviewMouseHoverEvent, MouseHoverEvent);
this.hoverLogic.MouseHoverStopped += (sender, e) => RaiseHoverEventPair(e, PreviewMouseHoverStoppedEvent, MouseHoverStoppedEvent);
this.columnRulerRenderer = new ColumnRulerRenderer(this);
this.columnRulerRenderer.SetRuler(Options.ColumnRulerPosition, ColumnRulerBrush);
}
#endregion
@ -198,6 +202,14 @@ namespace ICSharpCode.AvalonEdit.Rendering
if (OptionChanged != null) {
OptionChanged(this, e);
}
if (e.PropertyName == "ColumRulerPosition" || e.PropertyName == "ShowColumnRuler") {
if (Options.ShowColumnRuler)
columnRulerRenderer.SetRuler(Options.ColumnRulerPosition, ColumnRulerBrush);
else
columnRulerRenderer.SetRuler(-1, ColumnRulerBrush);
}
UpdateBuiltinElementGeneratorsFromOptions();
Redraw();
}
@ -1928,5 +1940,23 @@ namespace ICSharpCode.AvalonEdit.Rendering
Redraw();
}
}
public static readonly DependencyProperty ColumnRulerBrushProperty =
DependencyProperty.Register("ColumnRulerBrush", typeof(Brush), typeof(TextView),
new FrameworkPropertyMetadata(Brushes.LightGray, OnUpdateBrushes));
public Brush ColumnRulerBrush {
get { return (Brush)GetValue(ColumnRulerBrushProperty); }
set { SetValue(ColumnRulerBrushProperty, value); }
}
public static void OnUpdateBrushes(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
TextView view = d as TextView;
if (view == null) return;
if (e.Property == ColumnRulerBrushProperty)
view.columnRulerRenderer.SetRuler(view.Options.ColumnRulerPosition, (Brush)e.NewValue);
}
}
}

Просмотреть файл

@ -398,5 +398,37 @@ namespace ICSharpCode.AvalonEdit
}
}
}
bool showColumnRuler = false;
/// <summary>
/// Gets/Sets whether the column ruler should be shown.
/// </summary>
[DefaultValue(false)]
public virtual bool ShowColumnRuler {
get { return showColumnRuler; }
set {
if (showColumnRuler != value) {
showColumnRuler = value;
OnPropertyChanged("ShowColumnRuler");
}
}
}
int columnRulerPosition = 80;
/// <summary>
/// Gets/Sets where the column ruler should be shown.
/// </summary>
[DefaultValue(80)]
public virtual int ColumnRulerPosition {
get { return columnRulerPosition; }
set {
if (columnRulerPosition != value) {
columnRulerPosition = value;
OnPropertyChanged("ColumnRulerPosition");
}
}
}
}
}