|
|
|
@ -3,6 +3,7 @@
@@ -3,6 +3,7 @@
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Collections.Specialized; |
|
|
|
|
using System.ComponentModel; |
|
|
|
|
using System.IO; |
|
|
|
|
using System.Linq; |
|
|
|
@ -10,7 +11,9 @@ using System.Windows;
@@ -10,7 +11,9 @@ using System.Windows;
|
|
|
|
|
using System.Windows.Controls; |
|
|
|
|
using System.Windows.Media; |
|
|
|
|
using System.Xml; |
|
|
|
|
|
|
|
|
|
using ICSharpCode.AvalonEdit.Editing; |
|
|
|
|
using ICSharpCode.AvalonEdit.Folding; |
|
|
|
|
using ICSharpCode.AvalonEdit.Highlighting; |
|
|
|
|
using ICSharpCode.AvalonEdit.Highlighting.Xshd; |
|
|
|
|
using ICSharpCode.AvalonEdit.Rendering; |
|
|
|
@ -32,14 +35,70 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -32,14 +35,70 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
|
|
|
|
|
textEditor.Document.UndoStack.SizeLimit = 0; |
|
|
|
|
textEditor.Options = CodeEditorOptions.Instance; |
|
|
|
|
bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView); |
|
|
|
|
|
|
|
|
|
foldingManager = FoldingManager.Install(textEditor.TextArea); |
|
|
|
|
CodeEditorOptions.Instance.BindToTextEditor(textEditor); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BracketHighlightRenderer bracketHighlighter; |
|
|
|
|
|
|
|
|
|
FoldingManager foldingManager; |
|
|
|
|
List<CustomizedHighlightingColor> customizationList; |
|
|
|
|
|
|
|
|
|
#region Folding
|
|
|
|
|
// TODO : probably move this to a separate class!
|
|
|
|
|
public const string FoldingControls = "Folding controls"; |
|
|
|
|
public const string FoldingSelectedControls = "Selected folding controls"; |
|
|
|
|
public const string FoldingTextMarkers = "Folding markers"; |
|
|
|
|
|
|
|
|
|
static SolidColorBrush CreateFrozenBrush(Color color) |
|
|
|
|
{ |
|
|
|
|
SolidColorBrush brush = new SolidColorBrush(color); |
|
|
|
|
brush.Freeze(); |
|
|
|
|
return brush; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void ApplyToFolding(TextEditor editor, IEnumerable<CustomizedHighlightingColor> customisations) |
|
|
|
|
{ |
|
|
|
|
bool assignedFoldingMarker = false, assignedSelectedFoldingControls = false, assignedFoldingTextMarkers = false; |
|
|
|
|
|
|
|
|
|
editor.ClearValue(FoldingMargin.FoldingMarkerBrushProperty); |
|
|
|
|
editor.ClearValue(FoldingMargin.FoldingMarkerBackgroundBrushProperty); |
|
|
|
|
editor.ClearValue(FoldingMargin.SelectedFoldingMarkerBrushProperty); |
|
|
|
|
editor.ClearValue(FoldingMargin.SelectedFoldingMarkerBackgroundBrushProperty); |
|
|
|
|
|
|
|
|
|
FoldingElementGenerator.TextBrush = FoldingElementGenerator.DefaultTextBrush; |
|
|
|
|
|
|
|
|
|
foreach (CustomizedHighlightingColor color in customisations) { |
|
|
|
|
switch (color.Name) { |
|
|
|
|
case FoldingControls: |
|
|
|
|
if (assignedFoldingMarker) |
|
|
|
|
continue; |
|
|
|
|
assignedFoldingMarker = true; |
|
|
|
|
if (color.Foreground != null) |
|
|
|
|
editor.SetValue(FoldingMargin.FoldingMarkerBrushProperty, CreateFrozenBrush(color.Foreground.Value)); |
|
|
|
|
if (color.Background != null) |
|
|
|
|
editor.SetValue(FoldingMargin.FoldingMarkerBackgroundBrushProperty, CreateFrozenBrush(color.Background.Value)); |
|
|
|
|
break; |
|
|
|
|
case FoldingSelectedControls: |
|
|
|
|
if (assignedSelectedFoldingControls) |
|
|
|
|
continue; |
|
|
|
|
assignedSelectedFoldingControls = true; |
|
|
|
|
if (color.Foreground != null) |
|
|
|
|
editor.SetValue(FoldingMargin.SelectedFoldingMarkerBrushProperty, CreateFrozenBrush(color.Foreground.Value)); |
|
|
|
|
if (color.Background != null) |
|
|
|
|
editor.SetValue(FoldingMargin.SelectedFoldingMarkerBackgroundBrushProperty, CreateFrozenBrush(color.Background.Value)); |
|
|
|
|
break; |
|
|
|
|
case FoldingTextMarkers: |
|
|
|
|
if (assignedFoldingTextMarkers) |
|
|
|
|
continue; |
|
|
|
|
assignedFoldingTextMarkers = true; |
|
|
|
|
if (color.Foreground != null) |
|
|
|
|
FoldingElementGenerator.TextBrush = CreateFrozenBrush(color.Foreground.Value); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
XshdSyntaxDefinition LoadBuiltinXshd(string name) |
|
|
|
|
{ |
|
|
|
|
using (Stream s = typeof(HighlightingManager).Assembly.GetManifestResourceStream(name)) { |
|
|
|
@ -193,6 +252,62 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -193,6 +252,62 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
|
|
|
|
|
bracketHighlight = new CustomizedHighlightingItem(customizationList, bracketHighlight, language, canSetFont: false); |
|
|
|
|
bracketHighlight.PropertyChanged += item_PropertyChanged; |
|
|
|
|
listBox.Items.Add(bracketHighlight); |
|
|
|
|
|
|
|
|
|
// Create entry for "Folding controls"
|
|
|
|
|
IHighlightingItem foldingControls = new SimpleHighlightingItem( |
|
|
|
|
FoldingControls, |
|
|
|
|
ta => { |
|
|
|
|
ta.Document.Text = "This" + Environment.NewLine + |
|
|
|
|
"is a folding" + Environment.NewLine + |
|
|
|
|
"example"; |
|
|
|
|
foldingManager.CreateFolding(0, 10); |
|
|
|
|
}) |
|
|
|
|
{ |
|
|
|
|
Foreground = Colors.Gray, |
|
|
|
|
Background = Colors.White |
|
|
|
|
}; |
|
|
|
|
foldingControls = new CustomizedHighlightingItem(customizationList, foldingControls, null, canSetFont: false); |
|
|
|
|
if (language != null) |
|
|
|
|
foldingControls = new CustomizedHighlightingItem(customizationList, foldingControls, language, canSetFont: false); |
|
|
|
|
foldingControls.PropertyChanged += item_PropertyChanged; |
|
|
|
|
listBox.Items.Add(foldingControls); |
|
|
|
|
|
|
|
|
|
// Create entry for "Selected folding controls"
|
|
|
|
|
IHighlightingItem selectedFoldingControls = new SimpleHighlightingItem( |
|
|
|
|
FoldingSelectedControls, |
|
|
|
|
ta => { |
|
|
|
|
ta.Document.Text = "This" + Environment.NewLine + |
|
|
|
|
"is a folding" + Environment.NewLine + |
|
|
|
|
"example"; |
|
|
|
|
foldingManager.CreateFolding(0, 10); |
|
|
|
|
}) |
|
|
|
|
{ |
|
|
|
|
Foreground = Colors.Black, |
|
|
|
|
Background = Colors.White |
|
|
|
|
}; |
|
|
|
|
selectedFoldingControls = new CustomizedHighlightingItem(customizationList, selectedFoldingControls, null, canSetFont: false); |
|
|
|
|
if (language != null) |
|
|
|
|
selectedFoldingControls = new CustomizedHighlightingItem(customizationList, selectedFoldingControls, language, canSetFont: false); |
|
|
|
|
selectedFoldingControls.PropertyChanged += item_PropertyChanged; |
|
|
|
|
listBox.Items.Add(selectedFoldingControls); |
|
|
|
|
|
|
|
|
|
// Create entry for "Folding text markers"
|
|
|
|
|
IHighlightingItem foldingTextMarker = new SimpleHighlightingItem( |
|
|
|
|
FoldingTextMarkers, |
|
|
|
|
ta => { |
|
|
|
|
ta.Document.Text = "This" + Environment.NewLine + |
|
|
|
|
"is a folding" + Environment.NewLine + |
|
|
|
|
"example"; |
|
|
|
|
foldingManager.CreateFolding(0, 10).IsFolded = true; |
|
|
|
|
}) |
|
|
|
|
{ |
|
|
|
|
Foreground = Colors.Gray |
|
|
|
|
}; |
|
|
|
|
foldingTextMarker = new CustomizedHighlightingItem(customizationList, foldingTextMarker, null, canSetFont: false, canSetBackground: false); |
|
|
|
|
if (language != null) |
|
|
|
|
foldingControls = new CustomizedHighlightingItem(customizationList, foldingTextMarker, language, canSetFont: false, canSetBackground: false); |
|
|
|
|
foldingTextMarker.PropertyChanged += item_PropertyChanged; |
|
|
|
|
listBox.Items.Add(foldingTextMarker); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void item_PropertyChanged(object sender, PropertyChangedEventArgs e) |
|
|
|
@ -226,8 +341,10 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -226,8 +341,10 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
|
|
|
|
|
if (xshd != null) { |
|
|
|
|
var customizationsForCurrentLanguage = customizationList.Where(c => c.Language == null || c.Language == xshd.Name); |
|
|
|
|
CustomizableHighlightingColorizer.ApplyCustomizationsToDefaultElements(textEditor, customizationsForCurrentLanguage); |
|
|
|
|
ApplyToFolding(textEditor, customizationsForCurrentLanguage); |
|
|
|
|
var item = (IHighlightingItem)listBox.SelectedItem; |
|
|
|
|
TextView textView = textEditor.TextArea.TextView; |
|
|
|
|
foldingManager.Clear(); |
|
|
|
|
textView.LineTransformers.Remove(colorizer); |
|
|
|
|
colorizer = null; |
|
|
|
|
if (item != null) { |
|
|
|
|