Merge remote-tracking branch 'origin/master' into newNR.
This commit is contained in:
Коммит
b92e72f15b
|
@ -51,6 +51,7 @@ namespace ICSharpCode.AvalonEdit.Editing
|
|||
if (textArea != null) {
|
||||
textArea.GotKeyboardFocus -= TextAreaGotKeyboardFocus;
|
||||
textArea.LostKeyboardFocus -= TextAreaLostKeyboardFocus;
|
||||
textArea.OptionChanged -= TextAreaOptionChanged;
|
||||
textArea = null;
|
||||
}
|
||||
ClearContext();
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.TextFormatting;
|
||||
|
||||
using ICSharpCode.AvalonEdit.Editing;
|
||||
using ICSharpCode.AvalonEdit.Rendering;
|
||||
using ICSharpCode.AvalonEdit.Utils;
|
||||
|
@ -92,10 +92,16 @@ namespace ICSharpCode.AvalonEdit.Folding
|
|||
|
||||
static void OnUpdateBrushes(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
FoldingMargin m = null;
|
||||
if (d is FoldingMargin)
|
||||
m = (FoldingMargin)d;
|
||||
else if (d is TextEditor)
|
||||
m = ((TextEditor)d).TextArea.LeftMargins.FirstOrDefault(c => c is FoldingMargin) as FoldingMargin;
|
||||
if (m == null) return;
|
||||
if (e.Property.Name == FoldingMarkerBrushProperty.Name)
|
||||
foldingControlPen = MakeFrozenPen((Brush)e.NewValue);
|
||||
m.foldingControlPen = MakeFrozenPen((Brush)e.NewValue);
|
||||
if (e.Property.Name == SelectedFoldingMarkerBrushProperty.Name)
|
||||
selectedFoldingControlPen = MakeFrozenPen((Brush)e.NewValue);
|
||||
m.selectedFoldingControlPen = MakeFrozenPen((Brush)e.NewValue);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -181,8 +187,8 @@ namespace ICSharpCode.AvalonEdit.Folding
|
|||
return markers[index];
|
||||
}
|
||||
|
||||
static Pen foldingControlPen = MakeFrozenPen((Brush)FoldingMarkerBrushProperty.DefaultMetadata.DefaultValue);
|
||||
static Pen selectedFoldingControlPen = MakeFrozenPen((Brush)SelectedFoldingMarkerBrushProperty.DefaultMetadata.DefaultValue);
|
||||
Pen foldingControlPen = MakeFrozenPen((Brush)FoldingMarkerBrushProperty.DefaultMetadata.DefaultValue);
|
||||
Pen selectedFoldingControlPen = MakeFrozenPen((Brush)SelectedFoldingMarkerBrushProperty.DefaultMetadata.DefaultValue);
|
||||
|
||||
static Pen MakeFrozenPen(Brush brush)
|
||||
{
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<Span color="Preprocessor">
|
||||
<Begin>\#</Begin>
|
||||
<RuleSet name="PreprocessorSet">
|
||||
<Span> <!-- preprocessor directives that allow comments -->
|
||||
<Span> <!-- preprocessor directives that allows comments -->
|
||||
<Begin fontWeight="bold">
|
||||
(define|undef|if|elif|else|endif|line)\b
|
||||
</Begin>
|
||||
|
@ -97,7 +97,7 @@
|
|||
</Span>
|
||||
|
||||
<Span color="String" multiline="true">
|
||||
<Begin color="String">@"</Begin>
|
||||
<Begin>@"</Begin>
|
||||
<End>"</End>
|
||||
<RuleSet>
|
||||
<!-- span for escape sequences -->
|
||||
|
|
|
@ -232,6 +232,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,65 @@
|
|||
// 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>
|
||||
/// 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(new SolidColorBrush(DefaultForeground), 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;
|
||||
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>
|
||||
|
@ -50,7 +52,10 @@ namespace ICSharpCode.AvalonEdit.Rendering
|
|||
elementGenerators = new ObserveAddRemoveCollection<VisualLineElementGenerator>(ElementGenerator_Added, ElementGenerator_Removed);
|
||||
lineTransformers = new ObserveAddRemoveCollection<IVisualLineTransformer>(LineTransformer_Added, LineTransformer_Removed);
|
||||
backgroundRenderers = new ObserveAddRemoveCollection<IBackgroundRenderer>(BackgroundRenderer_Added, BackgroundRenderer_Removed);
|
||||
columnRulerRenderer = new ColumnRulerRenderer(this);
|
||||
this.Options = new TextEditorOptions();
|
||||
this.columnRulerRenderer.SetRuler(Options.ColumnRulerPosition, ColumnRulerBrush);
|
||||
|
||||
Debug.Assert(singleCharacterElementGenerator != null); // assert that the option change created the builtin element generators
|
||||
|
||||
layers = new LayerCollection(this);
|
||||
|
@ -178,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); }
|
||||
|
@ -198,6 +203,15 @@ namespace ICSharpCode.AvalonEdit.Rendering
|
|||
if (OptionChanged != null) {
|
||||
OptionChanged(this, e);
|
||||
}
|
||||
|
||||
// PropertyName == null means all properties are changed
|
||||
if (e.PropertyName == null || e.PropertyName == "ColumnRulerPosition" || e.PropertyName == "ShowColumnRuler") {
|
||||
if (Options.ShowColumnRuler)
|
||||
columnRulerRenderer.SetRuler(Options.ColumnRulerPosition, ColumnRulerBrush);
|
||||
else
|
||||
columnRulerRenderer.SetRuler(-1, ColumnRulerBrush);
|
||||
}
|
||||
|
||||
UpdateBuiltinElementGeneratorsFromOptions();
|
||||
Redraw();
|
||||
}
|
||||
|
@ -538,6 +552,36 @@ namespace ICSharpCode.AvalonEdit.Rendering
|
|||
get { return (Brush)GetValue(NonPrintableCharacterBrushProperty); }
|
||||
set { SetValue(NonPrintableCharacterBrushProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LinkTextForegroundBrush dependency property.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty LinkTextForegroundBrushProperty =
|
||||
DependencyProperty.Register("LinkTextForegroundBrush", typeof(Brush), typeof(TextView),
|
||||
new FrameworkPropertyMetadata(Brushes.Blue));
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the Brush used for displaying link texts.
|
||||
/// </summary>
|
||||
public Brush LinkTextForegroundBrush {
|
||||
get { return (Brush)GetValue(LinkTextForegroundBrushProperty); }
|
||||
set { SetValue(LinkTextForegroundBrushProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LinkTextBackgroundBrush dependency property.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty LinkTextBackgroundBrushProperty =
|
||||
DependencyProperty.Register("LinkTextBackgroundBrush", typeof(Brush), typeof(TextView),
|
||||
new FrameworkPropertyMetadata(Brushes.Transparent));
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the Brush used for the background of link texts.
|
||||
/// </summary>
|
||||
public Brush LinkTextBackgroundBrush {
|
||||
get { return (Brush)GetValue(LinkTextBackgroundBrushProperty); }
|
||||
set { SetValue(LinkTextBackgroundBrushProperty, value); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Redraw methods / VisualLine invalidation
|
||||
|
@ -899,7 +943,8 @@ namespace ICSharpCode.AvalonEdit.Rendering
|
|||
|
||||
// number of pixels clipped from the first visual line(s)
|
||||
clippedPixelsOnTop = scrollOffset.Y - heightTree.GetVisualPosition(firstLineInView);
|
||||
Debug.Assert(clippedPixelsOnTop >= 0);
|
||||
// clippedPixelsOnTop should be >= 0, except for floating point inaccurracy.
|
||||
Debug.Assert(clippedPixelsOnTop >= -ExtensionMethods.Epsilon);
|
||||
|
||||
newVisualLines = new List<VisualLine>();
|
||||
|
||||
|
@ -1886,7 +1931,9 @@ namespace ICSharpCode.AvalonEdit.Rendering
|
|||
// and we need to re-measure the font metrics:
|
||||
InvalidateDefaultTextMetrics();
|
||||
} else if (e.Property == Control.ForegroundProperty
|
||||
|| e.Property == TextView.NonPrintableCharacterBrushProperty)
|
||||
|| e.Property == TextView.NonPrintableCharacterBrushProperty
|
||||
|| e.Property == TextView.LinkTextBackgroundBrushProperty
|
||||
|| e.Property == TextView.LinkTextForegroundBrushProperty)
|
||||
{
|
||||
// changing brushes requires recreating the cached elements
|
||||
RecreateCachedElements();
|
||||
|
@ -1905,5 +1952,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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
|
@ -46,7 +47,8 @@ namespace ICSharpCode.AvalonEdit.Rendering
|
|||
/// <inheritdoc/>
|
||||
public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructionContext context)
|
||||
{
|
||||
this.TextRunProperties.SetForegroundBrush(Brushes.Blue);
|
||||
this.TextRunProperties.SetForegroundBrush(context.TextView.LinkTextForegroundBrush);
|
||||
this.TextRunProperties.SetBackgroundBrush(context.TextView.LinkTextBackgroundBrush);
|
||||
this.TextRunProperties.SetTextDecorations(TextDecorations.Underline);
|
||||
return base.CreateTextRun(startVisualColumn, context);
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче