Browse Source

SD-1592: color of line numbers is now customisable

pull/14/head
Siegfried Pammer 15 years ago
parent
commit
ef888b4c22
  1. 14
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs
  2. 18
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
  3. 6
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs
  4. 32
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs
  5. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/themes/generic.xaml

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

@ -6,8 +6,8 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting;
@ -23,18 +23,22 @@ namespace ICSharpCode.AvalonEdit.AddIn
public const string DefaultTextAndBackground = "Default text/background"; public const string DefaultTextAndBackground = "Default text/background";
public const string SelectedText = "Selected text"; public const string SelectedText = "Selected text";
public const string NonPrintableCharacters = "Non-printable characters"; public const string NonPrintableCharacters = "Non-printable characters";
public const string LineNumbers = "Line numbers";
public static void ApplyCustomizationsToDefaultElements(TextEditor textEditor, IEnumerable<CustomizedHighlightingColor> customizations) public static void ApplyCustomizationsToDefaultElements(TextEditor textEditor, IEnumerable<CustomizedHighlightingColor> customizations)
{ {
textEditor.ClearValue(TextEditor.BackgroundProperty); textEditor.ClearValue(TextEditor.BackgroundProperty);
textEditor.ClearValue(TextEditor.ForegroundProperty); textEditor.ClearValue(TextEditor.ForegroundProperty);
textEditor.ClearValue(TextEditor.LineNumbersForegroundProperty);
textEditor.TextArea.ClearValue(TextArea.SelectionBorderProperty); textEditor.TextArea.ClearValue(TextArea.SelectionBorderProperty);
textEditor.TextArea.ClearValue(TextArea.SelectionBrushProperty); textEditor.TextArea.ClearValue(TextArea.SelectionBrushProperty);
textEditor.TextArea.ClearValue(TextArea.SelectionForegroundProperty); textEditor.TextArea.ClearValue(TextArea.SelectionForegroundProperty);
textEditor.TextArea.TextView.ClearValue(TextView.NonPrintableCharacterBrushProperty); textEditor.TextArea.TextView.ClearValue(TextView.NonPrintableCharacterBrushProperty);
bool assignedDefaultText = false; bool assignedDefaultText = false;
bool assignedSelectedText = false; bool assignedSelectedText = false;
bool assignedNonPrintableCharacter = false; bool assignedNonPrintableCharacter = false;
bool assignedLineNumbers = false;
foreach (CustomizedHighlightingColor color in customizations) { foreach (CustomizedHighlightingColor color in customizations) {
switch (color.Name) { switch (color.Name) {
case DefaultTextAndBackground: case DefaultTextAndBackground:
@ -73,6 +77,14 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (color.Foreground != null) if (color.Foreground != null)
textEditor.TextArea.TextView.NonPrintableCharacterBrush = CreateFrozenBrush(color.Foreground.Value); textEditor.TextArea.TextView.NonPrintableCharacterBrush = CreateFrozenBrush(color.Foreground.Value);
break; break;
case LineNumbers:
if (assignedLineNumbers)
continue;
assignedLineNumbers = true;
if (color.Foreground != null)
textEditor.LineNumbersForeground = CreateFrozenBrush(color.Foreground.Value);
break;
} }
} }
} }

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

@ -154,6 +154,24 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
nonPrintChars.PropertyChanged += item_PropertyChanged; nonPrintChars.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(nonPrintChars); listBox.Items.Add(nonPrintChars);
// Create entry for "Line numbers"
IHighlightingItem lineNumbers = new SimpleHighlightingItem(
CustomizableHighlightingColorizer.LineNumbers,
ta => {
ta.Document.Text = "These are just" + Environment.NewLine +
"multiple" + Environment.NewLine +
"lines of" + Environment.NewLine +
"text";
})
{
Foreground = Colors.Gray
};
lineNumbers = new CustomizedHighlightingItem(customizationList, lineNumbers, null, canSetFont: false, canSetBackground: false);
if (language != null)
lineNumbers = new CustomizedHighlightingItem(customizationList, lineNumbers, language, canSetFont: false);
lineNumbers.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(lineNumbers);
// Create entry for "Bracket highlight" // Create entry for "Bracket highlight"
IHighlightingItem bracketHighlight = new SimpleHighlightingItem( IHighlightingItem bracketHighlight = new SimpleHighlightingItem(
BracketHighlightRenderer.BracketHighlight, BracketHighlightRenderer.BracketHighlight,

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

@ -367,10 +367,16 @@ namespace ICSharpCode.AvalonEdit.Rendering
#endregion #endregion
#region Brushes #region Brushes
/// <summary>
/// NonPrintableCharacterBrush dependency property.
/// </summary>
public static readonly DependencyProperty NonPrintableCharacterBrushProperty = public static readonly DependencyProperty NonPrintableCharacterBrushProperty =
DependencyProperty.Register("NonPrintableCharacterBrush", typeof(Brush), typeof(TextView), DependencyProperty.Register("NonPrintableCharacterBrush", typeof(Brush), typeof(TextView),
new FrameworkPropertyMetadata(Brushes.LightGray)); new FrameworkPropertyMetadata(Brushes.LightGray));
/// <summary>
/// Gets/sets the Brush used for displaying non-printable characters.
/// </summary>
public Brush NonPrintableCharacterBrush { public Brush NonPrintableCharacterBrush {
get { return (Brush)GetValue(NonPrintableCharacterBrushProperty); } get { return (Brush)GetValue(NonPrintableCharacterBrushProperty); }
set { SetValue(NonPrintableCharacterBrushProperty, value); } set { SetValue(NonPrintableCharacterBrushProperty, value); }

32
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs

@ -4,6 +4,7 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@ -11,6 +12,7 @@ using System.Windows.Controls.Primitives;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Markup; using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Threading; using System.Windows.Threading;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Editing;
@ -449,7 +451,7 @@ namespace ICSharpCode.AvalonEdit
#region ShowLineNumbers #region ShowLineNumbers
/// <summary> /// <summary>
/// IsReadOnly dependency property. /// ShowLineNumbers dependency property.
/// </summary> /// </summary>
public static readonly DependencyProperty ShowLineNumbersProperty = public static readonly DependencyProperty ShowLineNumbersProperty =
DependencyProperty.Register("ShowLineNumbers", typeof(bool), typeof(TextEditor), DependencyProperty.Register("ShowLineNumbers", typeof(bool), typeof(TextEditor),
@ -470,6 +472,7 @@ namespace ICSharpCode.AvalonEdit
if ((bool)e.NewValue) { if ((bool)e.NewValue) {
leftMargins.Insert(0, new LineNumberMargin()); leftMargins.Insert(0, new LineNumberMargin());
leftMargins.Insert(1, DottedLineMargin.Create()); leftMargins.Insert(1, DottedLineMargin.Create());
leftMargins[0].SetValue(Control.ForegroundProperty, editor.LineNumbersForeground);
} else { } else {
for (int i = 0; i < leftMargins.Count; i++) { for (int i = 0; i < leftMargins.Count; i++) {
if (leftMargins[i] is LineNumberMargin) { if (leftMargins[i] is LineNumberMargin) {
@ -484,6 +487,33 @@ namespace ICSharpCode.AvalonEdit
} }
#endregion #endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly DependencyProperty LineNumbersForegroundProperty =
DependencyProperty.Register("LineNumbersForeground", typeof(Brush), typeof(TextEditor),
new FrameworkPropertyMetadata(Brushes.Gray, OnLineNumbersForegroundChanged));
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public Brush LineNumbersForeground {
get { return (Brush)GetValue(LineNumbersForegroundProperty); }
set { SetValue(LineNumbersForegroundProperty, value); }
}
static void OnLineNumbersForegroundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
TextEditor editor = (TextEditor)d;
var lineNumberMargin = editor.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;;
if (lineNumberMargin != null) {
lineNumberMargin.SetValue(Control.ForegroundProperty, e.NewValue);
}
}
#endregion
#region TextBoxBase-like methods #region TextBoxBase-like methods
/// <summary> /// <summary>
/// Appends text to the end of the document. /// Appends text to the end of the document.

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/themes/generic.xaml

@ -9,7 +9,6 @@
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type editing:LineNumberMargin}"> <Style TargetType="{x:Type editing:LineNumberMargin}">
<Setter Property="TextBlock.Foreground" Value="Gray"/>
<Setter Property="Control.Cursor" Value="/ICSharpCode.AvalonEdit;component/themes/RightArrow.cur"/> <Setter Property="Control.Cursor" Value="/ICSharpCode.AvalonEdit;component/themes/RightArrow.cur"/>
</Style> </Style>
</ResourceDictionary> </ResourceDictionary>

Loading…
Cancel
Save