Browse Source

SD-1592: color used for bracket highlighting is now customisable

pull/14/head
Siegfried Pammer 15 years ago
parent
commit
f5a56a05bd
  1. 36
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/BracketHighlightRenderer.cs
  2. 5
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs
  3. 30
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs

36
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/BracketHighlightRenderer.cs

@ -2,8 +2,10 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Windows.Media; using System.Windows.Media;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Rendering; using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
@ -17,6 +19,12 @@ namespace ICSharpCode.AvalonEdit.AddIn
Brush backgroundBrush; Brush backgroundBrush;
TextView textView; TextView textView;
// 255 - x is needed to produce the inverse Alpha value for subtraction.
static readonly Color transparencyBack = Color.FromArgb(255 - 22, 0, 0, 0);
static readonly Color transparencyFore = Color.FromArgb(255 - 52, 0, 0, 0);
public const string BracketHighlight = "Bracket highlight";
public void SetHighlight(BracketSearchResult result) public void SetHighlight(BracketSearchResult result)
{ {
if (this.result != result) { if (this.result != result) {
@ -30,16 +38,22 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (textView == null) if (textView == null)
throw new ArgumentNullException("textView"); throw new ArgumentNullException("textView");
this.borderPen = new Pen(new SolidColorBrush(Color.FromArgb(52, 0, 0, 255)), 1);
this.borderPen.Freeze();
this.backgroundBrush = new SolidColorBrush(Color.FromArgb(22, 0, 0, 255));
this.backgroundBrush.Freeze();
this.textView = textView; this.textView = textView;
this.textView.BackgroundRenderers.Add(this); this.textView.BackgroundRenderers.Add(this);
} }
void UpdateColors(Color background, Color foreground)
{
Color border = Color.Subtract(foreground, transparencyFore);
Color back = Color.Subtract(background, transparencyBack);
this.borderPen = new Pen(new SolidColorBrush(border), 1);
this.borderPen.Freeze();
this.backgroundBrush = new SolidColorBrush(back);
this.backgroundBrush.Freeze();
}
public KnownLayer Layer { public KnownLayer Layer {
get { get {
@ -66,5 +80,15 @@ namespace ICSharpCode.AvalonEdit.AddIn
drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry); drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
} }
} }
public static void ApplyCustomizationsToRendering(BracketHighlightRenderer renderer, IEnumerable<CustomizedHighlightingColor> customizations)
{
renderer.UpdateColors(Colors.Blue, Colors.Blue);
foreach (CustomizedHighlightingColor color in customizations) {
if (color.Name == BracketHighlight) {
renderer.UpdateColors(color.Background ?? Colors.Blue, color.Foreground ?? Colors.Blue);
}
}
}
} }
} }

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

@ -46,12 +46,12 @@ namespace ICSharpCode.AvalonEdit.AddIn
{ {
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Help, OnHelpExecuted)); this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Help, OnHelpExecuted));
UpdateCustomizedHighlighting();
this.bracketRenderer = new BracketHighlightRenderer(this.TextArea.TextView); this.bracketRenderer = new BracketHighlightRenderer(this.TextArea.TextView);
this.caretReferencesRenderer = new CaretReferencesRenderer(this); this.caretReferencesRenderer = new CaretReferencesRenderer(this);
this.contextActionsRenderer = new ContextActionsRenderer(this); this.contextActionsRenderer = new ContextActionsRenderer(this);
UpdateCustomizedHighlighting();
this.MouseHover += TextEditorMouseHover; this.MouseHover += TextEditorMouseHover;
this.MouseHoverStopped += TextEditorMouseHoverStopped; this.MouseHoverStopped += TextEditorMouseHoverStopped;
this.MouseLeave += TextEditorMouseLeave; this.MouseLeave += TextEditorMouseLeave;
@ -501,6 +501,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
{ {
string language = this.SyntaxHighlighting != null ? this.SyntaxHighlighting.Name : null; string language = this.SyntaxHighlighting != null ? this.SyntaxHighlighting.Name : null;
CustomizableHighlightingColorizer.ApplyCustomizationsToDefaultElements(this, FetchCustomizations(language)); CustomizableHighlightingColorizer.ApplyCustomizationsToDefaultElements(this, FetchCustomizations(language));
BracketHighlightRenderer.ApplyCustomizationsToRendering(this.bracketRenderer, FetchCustomizations(language));
this.TextArea.TextView.Redraw(); // manually redraw if default elements didn't change but customized highlightings did this.TextArea.TextView.Redraw(); // manually redraw if default elements didn't change but customized highlightings did
} }

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

@ -10,11 +10,13 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Xml; using System.Xml;
using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd; using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using ICSharpCode.AvalonEdit.Rendering; using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.SharpDevelop.Bookmarks;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.AvalonEdit.AddIn.Options namespace ICSharpCode.AvalonEdit.AddIn.Options
@ -29,9 +31,13 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
InitializeComponent(); InitializeComponent();
textEditor.Document.UndoStack.SizeLimit = 0; textEditor.Document.UndoStack.SizeLimit = 0;
textEditor.Options = CodeEditorOptions.Instance; textEditor.Options = CodeEditorOptions.Instance;
bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView);
CodeEditorOptions.Instance.BindToTextEditor(textEditor); CodeEditorOptions.Instance.BindToTextEditor(textEditor);
} }
BracketHighlightRenderer bracketHighlighter;
List<CustomizedHighlightingColor> customizationList; List<CustomizedHighlightingColor> customizationList;
XshdSyntaxDefinition LoadBuiltinXshd(string name) XshdSyntaxDefinition LoadBuiltinXshd(string name)
@ -132,6 +138,28 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
selectedText = new CustomizedHighlightingItem(customizationList, selectedText, language, canSetFont: false); selectedText = new CustomizedHighlightingItem(customizationList, selectedText, language, canSetFont: false);
selectedText.PropertyChanged += item_PropertyChanged; selectedText.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(selectedText); listBox.Items.Add(selectedText);
// Create entry for "Bracket highlight"
IHighlightingItem bracketHighlight = new SimpleHighlightingItem(
BracketHighlightRenderer.BracketHighlight,
ta => {
ta.Document.Text = "(simple) example";
XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem;
if (xshd == null)
return;
var customizationsForCurrentLanguage = customizationList.Where(c => c.Language == null || c.Language == xshd.Name);
BracketHighlightRenderer.ApplyCustomizationsToRendering(bracketHighlighter, customizationsForCurrentLanguage);
bracketHighlighter.SetHighlight(new BracketSearchResult(0, 1, 7, 1));
})
{
Foreground = Colors.Blue,
Background = Colors.Blue
};
bracketHighlight = new CustomizedHighlightingItem(customizationList, bracketHighlight, null, canSetFont: false);
if (language != null)
selectedText = new CustomizedHighlightingItem(customizationList, bracketHighlight, language, canSetFont: false);
bracketHighlight.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(bracketHighlight);
} }
void item_PropertyChanged(object sender, PropertyChangedEventArgs e) void item_PropertyChanged(object sender, PropertyChangedEventArgs e)

Loading…
Cancel
Save