diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/BracketHighlightRenderer.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/BracketHighlightRenderer.cs index 3e2778e723..2eca94cf29 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/BracketHighlightRenderer.cs +++ b/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) using System; +using System.Collections.Generic; using System.Diagnostics; using System.Windows.Media; + using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Rendering; using ICSharpCode.SharpDevelop.Editor; @@ -17,6 +19,12 @@ namespace ICSharpCode.AvalonEdit.AddIn Brush backgroundBrush; 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) { if (this.result != result) { @@ -30,16 +38,22 @@ namespace ICSharpCode.AvalonEdit.AddIn if (textView == null) 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.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 { get { @@ -66,5 +80,15 @@ namespace ICSharpCode.AvalonEdit.AddIn drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry); } } + + public static void ApplyCustomizationsToRendering(BracketHighlightRenderer renderer, IEnumerable 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); + } + } + } } } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs index e584003e66..6e2528ccb4 100755 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs @@ -46,12 +46,12 @@ namespace ICSharpCode.AvalonEdit.AddIn { this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Help, OnHelpExecuted)); - UpdateCustomizedHighlighting(); - this.bracketRenderer = new BracketHighlightRenderer(this.TextArea.TextView); this.caretReferencesRenderer = new CaretReferencesRenderer(this); this.contextActionsRenderer = new ContextActionsRenderer(this); + UpdateCustomizedHighlighting(); + this.MouseHover += TextEditorMouseHover; this.MouseHoverStopped += TextEditorMouseHoverStopped; this.MouseLeave += TextEditorMouseLeave; @@ -501,6 +501,7 @@ namespace ICSharpCode.AvalonEdit.AddIn { string language = this.SyntaxHighlighting != null ? this.SyntaxHighlighting.Name : null; 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 } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs index 35331c84a5..a915a03283 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs @@ -10,11 +10,13 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Xml; - using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting.Xshd; using ICSharpCode.AvalonEdit.Rendering; +using ICSharpCode.SharpDevelop.Bookmarks; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.SharpDevelop.Editor.AvalonEdit; using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -29,9 +31,13 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options InitializeComponent(); textEditor.Document.UndoStack.SizeLimit = 0; textEditor.Options = CodeEditorOptions.Instance; + bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView); + CodeEditorOptions.Instance.BindToTextEditor(textEditor); } + BracketHighlightRenderer bracketHighlighter; + List customizationList; XshdSyntaxDefinition LoadBuiltinXshd(string name) @@ -132,6 +138,28 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options selectedText = new CustomizedHighlightingItem(customizationList, selectedText, language, canSetFont: false); selectedText.PropertyChanged += item_PropertyChanged; 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)