Browse Source

Move HighlightCurrentLine from AvalonEdit.Addin to ICSharpCode.AvalonEdit

pull/289/head
Patryk Mikos 12 years ago
parent
commit
5de622f937
  1. 1
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  2. 24
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs
  3. 13
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CodeEditorOptions.cs
  4. 16
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
  5. 13
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/CustomizingHighlighter.cs
  6. 9
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs
  7. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj
  8. 86
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/CurrentLineHighlightRenderer.cs
  9. 46
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs
  10. 16
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditorOptions.cs

1
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -112,7 +112,6 @@ @@ -112,7 +112,6 @@
<Compile Include="Src\ContextActions\FindBaseClasses.cs" />
<Compile Include="Src\ContextActions\FindDerivedClassesOrOverrides.cs" />
<Compile Include="Src\ContextActions\GoToEntityAction.cs" />
<Compile Include="Src\CurrentLineHighlightRenderer.cs" />
<Compile Include="Src\EnhancedScrollBar.cs" />
<Compile Include="Src\HiddenDefinitionRenderer.cs" />
<Compile Include="Src\SyntaxHighlighting\CustomizingHighlighter.cs" />

24
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs

@ -48,7 +48,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -48,7 +48,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
public ITextEditor Adapter { get; set; }
BracketHighlightRenderer bracketRenderer;
CurrentLineHighlightRenderer currentLineRenderer;
//CaretReferencesRenderer caretReferencesRenderer;
ContextActionsRenderer contextActionsRenderer;
HiddenDefinition.HiddenDefinitionRenderer hiddenDefinitionRenderer;
@ -58,7 +57,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -58,7 +57,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Help, OnHelpExecuted));
this.bracketRenderer = new BracketHighlightRenderer(this.TextArea.TextView);
this.currentLineRenderer = new CurrentLineHighlightRenderer(this.TextArea.TextView);
//this.caretReferencesRenderer = new CaretReferencesRenderer(this);
this.contextActionsRenderer = new ContextActionsRenderer(this);
this.hiddenDefinitionRenderer = new HiddenDefinition.HiddenDefinitionRenderer(this);
@ -73,7 +71,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -73,7 +71,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
this.TextArea.TextView.MouseDown += TextViewMouseDown;
this.TextArea.TextView.MouseUp += TextViewMouseUp;
this.TextArea.Caret.PositionChanged += HighlightBrackets;
this.TextArea.Caret.PositionChanged += HighlightCurrentLine;
this.TextArea.TextView.VisualLinesChanged += CodeEditorView_VisualLinesChanged;
SetupTabSnippetHandler();
@ -107,9 +104,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -107,9 +104,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
case "HighlightBrackets":
HighlightBrackets(null, e);
break;
case "HighlightCurrentLine":
HighlightCurrentLine(null, e);
break;
case "EnableFolding":
UpdateParseInformationForFolding();
break;
@ -120,8 +114,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -120,8 +114,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
}
}
#region CaretPositionChanged - Bracket Highlighting and current line highlighting
#region CaretPositionChanged - Bracket Highlighting
/// <summary>
/// Highlights matching brackets.
/// </summary>
@ -153,20 +146,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -153,20 +146,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
}
}
/// <summary>
/// Highlights current line
/// </summary>
void HighlightCurrentLine(object sender, EventArgs e)
{
if(this.Adapter.Language != null) {
if(CodeEditorOptions.Instance.HighlightCurrentLine) {
this.currentLineRenderer.SetHighlight(this.TextArea.Caret.Line);
} else {
this.currentLineRenderer.SetHighlight(-1);
}
}
}
#endregion
#region Custom Tab command (code snippet expansion)
@ -534,7 +513,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -534,7 +513,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
var customizations = CustomizedHighlightingColor.FetchCustomizations(language);
CustomizingHighlighter.ApplyCustomizationsToDefaultElements(this, customizations);
BracketHighlightRenderer.ApplyCustomizationsToRendering(this.bracketRenderer, customizations);
CurrentLineHighlightRenderer.ApplyCustomizationsToRendering(this.currentLineRenderer, customizations);
HighlightingOptions.ApplyToRendering(this, customizations);
this.TextArea.TextView.Redraw(); // manually redraw if default elements didn't change but customized highlightings did
}

13
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CodeEditorOptions.cs

@ -153,19 +153,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -153,19 +153,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
}
}
bool highlightCurrentLine = true;
[DefaultValueAttribute(true)]
public bool HighlightCurrentLine {
get { return highlightCurrentLine; }
set {
if(highlightCurrentLine != value) {
highlightCurrentLine = value;
OnPropertyChanged("HighlightCurrentLine");
}
}
}
bool highlightSymbol = true;
[DefaultValue(true)]

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

@ -40,7 +40,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -40,7 +40,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
CodeEditorOptions.Instance.BindToTextEditor(textEditor);
textEditor.Options = new TextEditorOptions(CodeEditorOptions.Instance);
bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView);
currentLineHighlighter = new CurrentLineHighlightRenderer(textEditor.TextArea.TextView);
foldingManager = FoldingManager.Install(textEditor.TextArea);
textMarkerService = new TextMarkerService(textEditor.Document);
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
@ -49,7 +48,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -49,7 +48,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
}
BracketHighlightRenderer bracketHighlighter;
CurrentLineHighlightRenderer currentLineHighlighter;
FoldingManager foldingManager;
TextMarkerService textMarkerService;
List<CustomizedHighlightingColor> customizationList;
@ -355,19 +353,14 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -355,19 +353,14 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
// Create entry for "Current Line highlight"
IHighlightingItem currentLineHighlight = new SimpleHighlightingItem(
CurrentLineHighlightRenderer.CurrentLineHighlight,
CustomizingHighlighter.CurrentLineHighlighter,
ta => {
ta.Document.Text = "example text line";
XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem;
if (xshd == null)
return;
var customizationsForCurrentLanguage = customizationList.Where(c => c.Language == null || c.Language == xshd.Name);
CurrentLineHighlightRenderer.ApplyCustomizationsToRendering(currentLineHighlighter, customizationsForCurrentLanguage);
currentLineHighlighter.SetHighlight(1);
ta.TextView.Options.HighlightCurrentLine = true;
})
{
Foreground = CurrentLineHighlightRenderer.DefaultBorder,
Background = CurrentLineHighlightRenderer.DefaultBackground
Foreground = Colors.Red,//CurrentLineHighlightRenderer.DefaultBorder,
Background = Colors.Yellow//CurrentLineHighlightRenderer.DefaultBackground
};
currentLineHighlight = new CustomizedHighlightingItem(customizationList, currentLineHighlight, language, canSetFont: false);
currentLineHighlight.PropertyChanged += item_PropertyChanged;
@ -587,7 +580,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -587,7 +580,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
}
textEditor.Select(0, 0);
bracketHighlighter.SetHighlight(null);
currentLineHighlighter.SetHighlight(0);
item.ShowExample(textEditor.TextArea);
ITextMarker m = textMarkerService.TextMarkers.SingleOrDefault();
if (m != null && m.Tag != null) {

13
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/CustomizingHighlighter.cs

@ -29,6 +29,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -29,6 +29,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
public const string BreakpointMarker = "Breakpoint";
public const string InstructionPointerMarker = "Current statement";
public const string ColumnRuler = "Column ruler";
public const string CurrentLineHighlighter = "Current line highlighting";
public static void ApplyCustomizationsToDefaultElements(TextEditor textEditor, IEnumerable<CustomizedHighlightingColor> customizations)
{
@ -42,6 +43,8 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -42,6 +43,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
textEditor.TextArea.TextView.ClearValue(TextView.LinkTextForegroundBrushProperty);
textEditor.TextArea.TextView.ClearValue(TextView.LinkTextBackgroundBrushProperty);
textEditor.TextArea.TextView.ClearValue(TextView.ColumnRulerPenProperty);
textEditor.TextArea.TextView.ClearValue(TextView.CurrentLineBorderProperty);
textEditor.TextArea.TextView.ClearValue(TextView.CurrentLineBackgroundProperty);
// 'assigned' flags are used so that the first matching customization wins.
// This is necessary because more specific customizations come first in the list
@ -52,6 +55,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -52,6 +55,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
bool assignedLineNumbers = false;
bool assignedLinkText = false;
bool assignedColumnRulerColor = false;
bool assignedCurrentLineHighlighter = false;
foreach (CustomizedHighlightingColor color in customizations) {
switch (color.Name) {
@ -115,6 +119,15 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -115,6 +119,15 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (color.Foreground != null)
textEditor.TextArea.TextView.ColumnRulerPen = CreateFrozenPen(color.Foreground.Value);
break;
case CurrentLineHighlighter:
if (assignedCurrentLineHighlighter)
continue;
assignedCurrentLineHighlighter = true;
if (color.Background != null)
textEditor.TextArea.TextView.CurrentLineBackground = CreateFrozenBrush(color.Background.Value);
if (color.Foreground != null)
textEditor.TextArea.TextView.CurrentLineBorder = CreateFrozenPen(color.Foreground.Value);
break;
}
}
}

9
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs

@ -69,6 +69,7 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -69,6 +69,7 @@ namespace ICSharpCode.AvalonEdit.Editing
caret = new Caret(this);
caret.PositionChanged += (sender, e) => RequestSelectionValidation();
caret.PositionChanged += CaretPositionChanged;
ime = new ImeSupport(this);
leftMargins.CollectionChanged += leftMargins_CollectionChanged;
@ -559,6 +560,14 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -559,6 +560,14 @@ namespace ICSharpCode.AvalonEdit.Editing
get { return caret; }
}
void CaretPositionChanged(object sender, EventArgs e)
{
if (textView == null)
return;
this.textView.HighlightedLine = this.Caret.Line;
}
ObservableCollection<UIElement> leftMargins = new ObservableCollection<UIElement>();
/// <summary>

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj

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

86
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CurrentLineHighlightRenderer.cs → src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/CurrentLineHighlightRenderer.cs

@ -9,57 +9,72 @@ using System.Windows.Media; @@ -9,57 +9,72 @@ using System.Windows.Media;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.AvalonEdit.AddIn
namespace ICSharpCode.AvalonEdit.Rendering
{
public class CurrentLineHighlightRenderer : IBackgroundRenderer
sealed class CurrentLineHighlightRenderer : IBackgroundRenderer
{
#region Fields
int line;
Pen borderPen;
Brush backgroundBrush;
TextView textView;
public static readonly Color DefaultBackground = Color.FromArgb(22, 20, 220, 224);
public static readonly Color DefaultBorder = Color.FromArgb(52, 0, 255, 110);
public const string CurrentLineHighlight = "Current line highlight";
#endregion
#region Properties
public CurrentLineHighlightRenderer(TextView textView)
{
if (textView == null)
throw new ArgumentNullException("textView");
this.textView = textView;
this.textView.BackgroundRenderers.Add(this);
this.line = -1;
public int Line {
get { return this.Line; }
set {
this.line = value;
this.textView.InvalidateLayer(this.Layer);
}
}
public void SetHighlight(int caretLine)
{
this.line = caretLine;
this.textView.InvalidateLayer(this.Layer);
public bool Enabled {
get; set;
}
void UpdateColors(Color background, Color foreground)
public KnownLayer Layer
{
this.borderPen = new Pen(new SolidColorBrush(foreground), 1);
this.borderPen.Freeze();
this.backgroundBrush = new SolidColorBrush(background);
this.backgroundBrush.Freeze();
get { return KnownLayer.Selection; }
}
public Brush BackgroundBrush {
get; set;
}
public Pen BorderPen {
get; set;
}
public KnownLayer Layer
#endregion
public CurrentLineHighlightRenderer(TextView textView)
{
get
{
return KnownLayer.Selection;
}
if (textView == null)
throw new ArgumentNullException("textView");
this.BorderPen = new Pen(new SolidColorBrush(DefaultBorder), 1);
this.BorderPen.Freeze();
this.BackgroundBrush = new SolidColorBrush(DefaultBackground);
this.BackgroundBrush.Freeze();
this.textView = textView;
this.textView.BackgroundRenderers.Add(this);
this.line = 0;
}
public void Draw(TextView textView, DrawingContext drawingContext)
{
if(!Enabled)
return;
BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();
builder.CornerRadius = 1;
@ -83,18 +98,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -83,18 +98,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
Geometry geometry = builder.CreateGeometry();
if (geometry != null) {
drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
}
}
public static void ApplyCustomizationsToRendering(CurrentLineHighlightRenderer renderer, IEnumerable<CustomizedHighlightingColor> customizations)
{
renderer.UpdateColors(DefaultBackground, DefaultBorder);
foreach (CustomizedHighlightingColor color in customizations) {
if (color.Name == CurrentLineHighlight) {
renderer.UpdateColors(color.Background ?? Colors.Pink, color.Foreground ?? Colors.Pink);
break;
}
drawingContext.DrawGeometry(this.BackgroundBrush, this.BorderPen, geometry);
}
}
}

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

@ -42,6 +42,7 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -42,6 +42,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
}
ColumnRulerRenderer columnRulerRenderer;
CurrentLineHighlightRenderer currentLineHighlighRenderer;
/// <summary>
/// Creates a new TextView instance.
@ -54,6 +55,7 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -54,6 +55,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
lineTransformers = new ObserveAddRemoveCollection<IVisualLineTransformer>(LineTransformer_Added, LineTransformer_Removed);
backgroundRenderers = new ObserveAddRemoveCollection<IBackgroundRenderer>(BackgroundRenderer_Added, BackgroundRenderer_Removed);
columnRulerRenderer = new ColumnRulerRenderer(this);
currentLineHighlighRenderer = new CurrentLineHighlightRenderer(this);
this.Options = new TextEditorOptions();
Debug.Assert(singleCharacterElementGenerator != null); // assert that the option change created the builtin element generators
@ -209,6 +211,8 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -209,6 +211,8 @@ namespace ICSharpCode.AvalonEdit.Rendering
else
columnRulerRenderer.SetRuler(-1, ColumnRulerPen);
currentLineHighlighRenderer.Enabled = Options.HighlightCurrentLine;
UpdateBuiltinElementGeneratorsFromOptions();
Redraw();
}
@ -1994,6 +1998,12 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -1994,6 +1998,12 @@ namespace ICSharpCode.AvalonEdit.Rendering
if (e.Property == ColumnRulerPenProperty) {
columnRulerRenderer.SetRuler(this.Options.ColumnRulerPosition, this.ColumnRulerPen);
}
if (e.Property == CurrentLineBorderProperty) {
currentLineHighlighRenderer.BorderPen = this.CurrentLineBorder;
}
if (e.Property == CurrentLineBackgroundProperty) {
currentLineHighlighRenderer.BackgroundBrush = this.CurrentLineBackground;
}
}
/// <summary>
@ -2019,5 +2029,41 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -2019,5 +2029,41 @@ namespace ICSharpCode.AvalonEdit.Rendering
get { return (Pen)GetValue(ColumnRulerPenProperty); }
set { SetValue(ColumnRulerPenProperty, value); }
}
/// <summary>
/// The <see cref="CurrentLineBackground"/> property.
/// </summary>
public static readonly DependencyProperty CurrentLineBackgroundProperty =
DependencyProperty.Register("CurrentLineBackground", typeof(Brush), typeof(TextView));
/// <summary>
/// Gets/Sets the background brush used by current line highlighter.
/// </summary>
public Brush CurrentLineBackground {
get { return (Brush)GetValue(CurrentLineBackgroundProperty); }
set { SetValue(CurrentLineBackgroundProperty, value); }
}
/// <summary>
/// The <see cref="CurrentLineBorder"/> property.
/// </summary>
public static readonly DependencyProperty CurrentLineBorderProperty =
DependencyProperty.Register("CurrentLineBorder", typeof(Pen), typeof(TextView));
/// <summary>
/// Gets/Sets the background brush used for the current line.
/// </summary>
public Pen CurrentLineBorder {
get { return (Pen)GetValue(CurrentLineBorderProperty); }
set { SetValue(CurrentLineBorderProperty, value); }
}
/// <summary>
/// Gets/Sets highlighted line number.
/// </summary>
public int HighlightedLine {
get { return this.currentLineHighlighRenderer.Line; }
set { this.currentLineHighlighRenderer.Line = value; }
}
}
}

16
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditorOptions.cs

@ -430,5 +430,21 @@ namespace ICSharpCode.AvalonEdit @@ -430,5 +430,21 @@ namespace ICSharpCode.AvalonEdit
}
}
}
bool highlightCurrentLine = false;
/// <summary>
/// Gets/Sets whether current line should be shown.
/// </summary>
[DefaultValue(false)]
public virtual bool HighlightCurrentLine {
get { return highlightCurrentLine; }
set {
if (highlightCurrentLine != value) {
highlightCurrentLine = value;
OnPropertyChanged("HighlightCurrentLine");
}
}
}
}
}

Loading…
Cancel
Save