Browse Source

Make ColumnRulerRenderer internal; expose pen instead of brush.

pull/26/merge
Daniel Grunwald 13 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 @@ -30,6 +30,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
public const string LinkText = "Link text";
public const string BreakpointMarker = "Breakpoint";
public const string InstructionPointerMarker = "Current statement";
public const string ColumnRuler = "Column ruler";
public static void ApplyCustomizationsToDefaultElements(TextEditor textEditor, IEnumerable<CustomizedHighlightingColor> customizations)
{
@ -42,7 +43,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -42,7 +43,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);
textEditor.TextArea.TextView.ClearValue(TextView.ColumnRulerPenProperty);
// 'assigned' flags are used so that the first matching customization wins.
// This is necessary because more specific customizations come first in the list
@ -109,12 +110,12 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -109,12 +110,12 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (color.Background != null)
textEditor.TextArea.TextView.LinkTextBackgroundBrush = CreateFrozenBrush(color.Background.Value);
break;
case ColumnRulerRenderer.Name:
case ColumnRuler:
if (assignedColumnRulerColor)
continue;
assignedColumnRulerColor = true;
if (color.Foreground != null)
textEditor.TextArea.TextView.ColumnRulerBrush = CreateFrozenBrush(color.Foreground.Value);
textEditor.TextArea.TextView.ColumnRulerPen = CreateFrozenPen(color.Foreground.Value);
break;
}
}
@ -224,5 +225,12 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -224,5 +225,12 @@ namespace ICSharpCode.AvalonEdit.AddIn
brush.Freeze();
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 @@ -431,14 +431,14 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
items.Add(currentStatementMarker);
IHighlightingItem columnRuler = new SimpleHighlightingItem(
ColumnRulerRenderer.Name,
CustomizableHighlightingColorizer.ColumnRuler,
ta => {
ta.Document.Text = "some line with a lot of text";
ta.TextView.Options.ColumnRulerPosition = 15;
ta.TextView.Options.ShowColumnRuler = true;
})
{
Foreground = ColumnRulerRenderer.DefaultForeground
Foreground = Colors.LightGray
};
columnRuler = new CustomizedHighlightingItem(customizationList, columnRuler, language, canSetFont: false, canSetBackground: false);
columnRuler.PropertyChanged += item_PropertyChanged;

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

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

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

@ -54,7 +54,7 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -54,7 +54,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
backgroundRenderers = new ObserveAddRemoveCollection<IBackgroundRenderer>(BackgroundRenderer_Added, BackgroundRenderer_Removed);
columnRulerRenderer = new ColumnRulerRenderer(this);
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
@ -204,13 +204,10 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -204,13 +204,10 @@ namespace ICSharpCode.AvalonEdit.Rendering
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);
}
if (Options.ShowColumnRuler)
columnRulerRenderer.SetRuler(Options.ColumnRulerPosition, ColumnRulerPen);
else
columnRulerRenderer.SetRuler(-1, ColumnRulerPen);
UpdateBuiltinElementGeneratorsFromOptions();
Redraw();
@ -1942,24 +1939,33 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -1942,24 +1939,33 @@ namespace ICSharpCode.AvalonEdit.Rendering
InvalidateDefaultTextMetrics();
Redraw();
}
if (e.Property == ColumnRulerPenProperty) {
columnRulerRenderer.SetRuler(this.Options.ColumnRulerPosition, this.ColumnRulerPen);
}
}
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); }
}
/// <summary>
/// The pen used to draw the column ruler.
/// <seealso cref="TextEditorOptions.ShowColumnRuler"/>
/// </summary>
public static readonly DependencyProperty ColumnRulerPenProperty =
DependencyProperty.Register("ColumnRulerBrush", typeof(Pen), typeof(TextView),
new FrameworkPropertyMetadata(CreateFrozenPen(Brushes.LightGray)));
public static void OnUpdateBrushes(DependencyObject d, DependencyPropertyChangedEventArgs e)
static Pen CreateFrozenPen(SolidColorBrush brush)
{
TextView view = d as TextView;
if (view == null) return;
if (e.Property == ColumnRulerBrushProperty)
view.columnRulerRenderer.SetRuler(view.Options.ColumnRulerPosition, (Brush)e.NewValue);
Pen pen = new Pen(brush, 1);
pen.Freeze();
return pen;
}
/// <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