Browse Source

Make ColumnRulerRenderer internal; expose pen instead of brush.

pull/26/merge
Daniel Grunwald 14 years ago
parent
commit
94585060eb
  1. 14
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs
  2. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
  3. 12
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/ColumnRulerRenderer.cs
  4. 48
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs

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

@ -30,6 +30,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
public const string LinkText = "Link text"; public const string LinkText = "Link text";
public const string BreakpointMarker = "Breakpoint"; public const string BreakpointMarker = "Breakpoint";
public const string InstructionPointerMarker = "Current statement"; public const string InstructionPointerMarker = "Current statement";
public const string ColumnRuler = "Column ruler";
public static void ApplyCustomizationsToDefaultElements(TextEditor textEditor, IEnumerable<CustomizedHighlightingColor> customizations) public static void ApplyCustomizationsToDefaultElements(TextEditor textEditor, IEnumerable<CustomizedHighlightingColor> customizations)
{ {
@ -42,7 +43,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); textEditor.TextArea.TextView.ClearValue(TextView.ColumnRulerPenProperty);
// '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
@ -109,12 +110,12 @@ 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: case ColumnRuler:
if (assignedColumnRulerColor) if (assignedColumnRulerColor)
continue; continue;
assignedColumnRulerColor = true; assignedColumnRulerColor = true;
if (color.Foreground != null) if (color.Foreground != null)
textEditor.TextArea.TextView.ColumnRulerBrush = CreateFrozenBrush(color.Foreground.Value); textEditor.TextArea.TextView.ColumnRulerPen = CreateFrozenPen(color.Foreground.Value);
break; break;
} }
} }
@ -224,5 +225,12 @@ namespace ICSharpCode.AvalonEdit.AddIn
brush.Freeze(); brush.Freeze();
return brush; return brush;
} }
static Pen CreateFrozenPen(Color color)
{
Pen pen = new Pen(CreateFrozenBrush(color), 1);
pen.Freeze();
return pen;
}
} }
} }

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

@ -431,14 +431,14 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
items.Add(currentStatementMarker); items.Add(currentStatementMarker);
IHighlightingItem columnRuler = new SimpleHighlightingItem( IHighlightingItem columnRuler = new SimpleHighlightingItem(
ColumnRulerRenderer.Name, CustomizableHighlightingColorizer.ColumnRuler,
ta => { ta => {
ta.Document.Text = "some line with a lot of text"; ta.Document.Text = "some line with a lot of text";
ta.TextView.Options.ColumnRulerPosition = 15; ta.TextView.Options.ColumnRulerPosition = 15;
ta.TextView.Options.ShowColumnRuler = true; ta.TextView.Options.ShowColumnRuler = true;
}) })
{ {
Foreground = ColumnRulerRenderer.DefaultForeground Foreground = Colors.LightGray
}; };
columnRuler = new CustomizedHighlightingItem(customizationList, columnRuler, language, canSetFont: false, canSetBackground: false); columnRuler = new CustomizedHighlightingItem(customizationList, columnRuler, language, canSetFont: false, canSetBackground: false);
columnRuler.PropertyChanged += item_PropertyChanged; columnRuler.PropertyChanged += item_PropertyChanged;

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

@ -8,18 +8,17 @@ 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.Rendering
{ {
/// <summary> /// <summary>
/// Renders a ruler at a certain column. /// Renders a ruler at a certain column.
/// </summary> /// </summary>
public class ColumnRulerRenderer : IBackgroundRenderer sealed 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 static readonly Color DefaultForeground = Colors.LightGray;
public ColumnRulerRenderer(TextView textView) public ColumnRulerRenderer(TextView textView)
@ -37,15 +36,14 @@ namespace ICSharpCode.AvalonEdit
get { return KnownLayer.Background; } get { return KnownLayer.Background; }
} }
public void SetRuler(int column, Brush brush) public void SetRuler(int column, Pen pen)
{ {
if (this.column != column) { if (this.column != column) {
this.column = column; this.column = column;
textView.InvalidateLayer(this.Layer); textView.InvalidateLayer(this.Layer);
} }
if (pen.Brush != brush) { if (this.pen != pen) {
this.pen = new Pen(brush, 1); this.pen = pen;
this.pen.Freeze();
textView.InvalidateLayer(this.Layer); textView.InvalidateLayer(this.Layer);
} }
} }

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

@ -54,7 +54,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
backgroundRenderers = new ObserveAddRemoveCollection<IBackgroundRenderer>(BackgroundRenderer_Added, BackgroundRenderer_Removed); backgroundRenderers = new ObserveAddRemoveCollection<IBackgroundRenderer>(BackgroundRenderer_Added, BackgroundRenderer_Removed);
columnRulerRenderer = new ColumnRulerRenderer(this); columnRulerRenderer = new ColumnRulerRenderer(this);
this.Options = new TextEditorOptions(); this.Options = new TextEditorOptions();
this.columnRulerRenderer.SetRuler(Options.ColumnRulerPosition, ColumnRulerBrush); this.columnRulerRenderer.SetRuler(Options.ColumnRulerPosition, ColumnRulerPen);
Debug.Assert(singleCharacterElementGenerator != null); // assert that the option change created the builtin element generators Debug.Assert(singleCharacterElementGenerator != null); // assert that the option change created the builtin element generators
@ -204,13 +204,10 @@ namespace ICSharpCode.AvalonEdit.Rendering
OptionChanged(this, e); OptionChanged(this, e);
} }
// PropertyName == null means all properties are changed if (Options.ShowColumnRuler)
if (e.PropertyName == null || e.PropertyName == "ColumnRulerPosition" || e.PropertyName == "ShowColumnRuler") { columnRulerRenderer.SetRuler(Options.ColumnRulerPosition, ColumnRulerPen);
if (Options.ShowColumnRuler) else
columnRulerRenderer.SetRuler(Options.ColumnRulerPosition, ColumnRulerBrush); columnRulerRenderer.SetRuler(-1, ColumnRulerPen);
else
columnRulerRenderer.SetRuler(-1, ColumnRulerBrush);
}
UpdateBuiltinElementGeneratorsFromOptions(); UpdateBuiltinElementGeneratorsFromOptions();
Redraw(); Redraw();
@ -1942,24 +1939,33 @@ namespace ICSharpCode.AvalonEdit.Rendering
InvalidateDefaultTextMetrics(); InvalidateDefaultTextMetrics();
Redraw(); Redraw();
} }
if (e.Property == ColumnRulerPenProperty) {
columnRulerRenderer.SetRuler(this.Options.ColumnRulerPosition, this.ColumnRulerPen);
}
} }
public static readonly DependencyProperty ColumnRulerBrushProperty = /// <summary>
DependencyProperty.Register("ColumnRulerBrush", typeof(Brush), typeof(TextView), /// The pen used to draw the column ruler.
new FrameworkPropertyMetadata(Brushes.LightGray, OnUpdateBrushes)); /// <seealso cref="TextEditorOptions.ShowColumnRuler"/>
/// </summary>
public Brush ColumnRulerBrush { public static readonly DependencyProperty ColumnRulerPenProperty =
get { return (Brush)GetValue(ColumnRulerBrushProperty); } DependencyProperty.Register("ColumnRulerBrush", typeof(Pen), typeof(TextView),
set { SetValue(ColumnRulerBrushProperty, value); } new FrameworkPropertyMetadata(CreateFrozenPen(Brushes.LightGray)));
}
public static void OnUpdateBrushes(DependencyObject d, DependencyPropertyChangedEventArgs e) static Pen CreateFrozenPen(SolidColorBrush brush)
{ {
TextView view = d as TextView; Pen pen = new Pen(brush, 1);
if (view == null) return; pen.Freeze();
if (e.Property == ColumnRulerBrushProperty) return pen;
view.columnRulerRenderer.SetRuler(view.Options.ColumnRulerPosition, (Brush)e.NewValue);
} }
/// <summary>
/// Gets/Sets the pen used to draw the column ruler.
/// <seealso cref="TextEditorOptions.ShowColumnRuler"/>
/// </summary>
public Pen ColumnRulerPen {
get { return (Pen)GetValue(ColumnRulerPenProperty); }
set { SetValue(ColumnRulerPenProperty, value); }
}
} }
} }

Loading…
Cancel
Save