Browse Source

add TextMarkerService to preview in highlighting options

pull/26/head
Siegfried Pammer 13 years ago
parent
commit
017a874863
  1. 21
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
  2. 12
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml
  3. 22
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
  4. 57
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerService.cs
  5. 4
      src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs
  6. 6
      src/Main/Base/Project/Src/Services/Tasks/ErrorPainter.cs
  7. 2
      src/Main/Core/Project/Src/Services/PropertyService/Properties.cs

21
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs

@ -33,20 +33,11 @@ using ICSharpCode.SharpDevelop.Widgets.MyersDiff;
namespace ICSharpCode.AvalonEdit.AddIn namespace ICSharpCode.AvalonEdit.AddIn
{ {
public interface ICodeEditor
{
TextDocument Document { get; }
void Redraw(ISegment segment, DispatcherPriority priority);
event EventHandler DocumentChanged;
}
/// <summary> /// <summary>
/// Integrates AvalonEdit with SharpDevelop. /// Integrates AvalonEdit with SharpDevelop.
/// Also provides support for Split-View (showing two AvalonEdit instances using the same TextDocument) /// Also provides support for Split-View (showing two AvalonEdit instances using the same TextDocument)
/// </summary> /// </summary>
public class CodeEditor : Grid, IDisposable, ICodeEditor public class CodeEditor : Grid, IDisposable
{ {
const string contextMenuPath = "/SharpDevelop/ViewContent/AvalonEdit/ContextMenu"; const string contextMenuPath = "/SharpDevelop/ViewContent/AvalonEdit/ContextMenu";
@ -153,9 +144,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
ParserService.ParseInformationUpdated += ParserServiceParseInformationUpdated; ParserService.ParseInformationUpdated += ParserServiceParseInformationUpdated;
this.FlowDirection = FlowDirection.LeftToRight; // code editing is always left-to-right this.FlowDirection = FlowDirection.LeftToRight; // code editing is always left-to-right
this.document = new TextDocument();
this.CommandBindings.Add(new CommandBinding(SharpDevelopRoutedCommands.SplitView, OnSplitView)); this.CommandBindings.Add(new CommandBinding(SharpDevelopRoutedCommands.SplitView, OnSplitView));
textMarkerService = new TextMarkerService(document);
textMarkerService = new TextMarkerService(this);
iconBarManager = new IconBarManager(); iconBarManager = new IconBarManager();
if (CodeEditorOptions.Instance.EnableChangeMarkerMargin) { if (CodeEditorOptions.Instance.EnableChangeMarkerMargin) {
changeWatcher = new DefaultChangeWatcher(); changeWatcher = new DefaultChangeWatcher();
@ -165,9 +156,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
Debug.Assert(primaryTextEditorAdapter != null); Debug.Assert(primaryTextEditorAdapter != null);
activeTextEditor = primaryTextEditor; activeTextEditor = primaryTextEditor;
this.Document = primaryTextEditor.Document;
primaryTextEditor.SetBinding(TextEditor.DocumentProperty, new Binding("Document") { Source = this });
this.ColumnDefinitions.Add(new ColumnDefinition()); this.ColumnDefinitions.Add(new ColumnDefinition());
this.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); this.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star), MinHeight = minRowHeight }); this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star), MinHeight = minRowHeight });
@ -199,6 +187,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
CodeEditorView codeEditorView = new CodeEditorView(); CodeEditorView codeEditorView = new CodeEditorView();
CodeEditorAdapter adapter = new CodeEditorAdapter(this, codeEditorView); CodeEditorAdapter adapter = new CodeEditorAdapter(this, codeEditorView);
codeEditorView.Adapter = adapter; codeEditorView.Adapter = adapter;
codeEditorView.Document = document;
TextView textView = codeEditorView.TextArea.TextView; TextView textView = codeEditorView.TextArea.TextView;
textView.Services.AddService(typeof(ITextEditor), adapter); textView.Services.AddService(typeof(ITextEditor), adapter);
textView.Services.AddService(typeof(CodeEditor), this); textView.Services.AddService(typeof(CodeEditor), this);
@ -340,8 +329,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
secondaryTextEditorAdapter = (CodeEditorAdapter)secondaryTextEditor.TextArea.GetService(typeof(ITextEditor)); secondaryTextEditorAdapter = (CodeEditorAdapter)secondaryTextEditor.TextArea.GetService(typeof(ITextEditor));
Debug.Assert(primaryTextEditorAdapter != null); Debug.Assert(primaryTextEditorAdapter != null);
secondaryTextEditor.SetBinding(TextEditor.DocumentProperty,
new Binding(TextEditor.DocumentProperty.Name) { Source = primaryTextEditor });
secondaryTextEditor.SetBinding(TextEditor.IsReadOnlyProperty, secondaryTextEditor.SetBinding(TextEditor.IsReadOnlyProperty,
new Binding(TextEditor.IsReadOnlyProperty.Name) { Source = primaryTextEditor }); new Binding(TextEditor.IsReadOnlyProperty.Name) { Source = primaryTextEditor });
secondaryTextEditor.SyntaxHighlighting = primaryTextEditor.SyntaxHighlighting; secondaryTextEditor.SyntaxHighlighting = primaryTextEditor.SyntaxHighlighting;

12
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml

@ -10,7 +10,12 @@
<BooleanToVisibilityConverter x:Key="boolToVisibility" /> <BooleanToVisibilityConverter x:Key="boolToVisibility" />
</FrameworkElement.Resources> </FrameworkElement.Resources>
<DockPanel> <DockPanel>
<StackPanel DockPanel.Dock="Right" Margin="4,0,0,0" DataContext="{Binding SelectedItem, ElementName=listBox}"> <Grid DockPanel.Dock="Right" Margin="4,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel DataContext="{Binding SelectedItem, ElementName=listBox}">
<Grid Margin="0,0,8,0"> <Grid Margin="0,0,8,0">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -46,11 +51,12 @@
<core:RestrictDesiredSize Height="50" MinWidth="200"> <core:RestrictDesiredSize Height="50" MinWidth="200">
<avalonedit:TextEditor Name="textEditor" IsReadOnly="True" /> <avalonedit:TextEditor Name="textEditor" IsReadOnly="True" />
</core:RestrictDesiredSize> </core:RestrictDesiredSize>
<widgets:StackPanelWithSpacing Orientation="Vertical" SpaceBetweenItems="5" Margin="0,5"> </StackPanel>
<widgets:StackPanelWithSpacing Grid.Row="1" Orientation="Vertical" SpaceBetweenItems="5" Margin="0,5">
<Button Click="ImportButtonClick" Content="{core:Localize Dialog.HighlightingEditor.Import}" /> <Button Click="ImportButtonClick" Content="{core:Localize Dialog.HighlightingEditor.Import}" />
<Button Click="ExportButtonClick" Content="{core:Localize Dialog.HighlightingEditor.Export}" /> <Button Click="ExportButtonClick" Content="{core:Localize Dialog.HighlightingEditor.Export}" />
</widgets:StackPanelWithSpacing> </widgets:StackPanelWithSpacing>
</StackPanel> </Grid>
<ComboBox Name="languageComboBox" DockPanel.Dock="Top" SelectionChanged="LanguageComboBox_SelectionChanged"> <ComboBox Name="languageComboBox" DockPanel.Dock="Top" SelectionChanged="LanguageComboBox_SelectionChanged">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>

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

@ -43,10 +43,16 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView); bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView);
foldingManager = FoldingManager.Install(textEditor.TextArea); foldingManager = FoldingManager.Install(textEditor.TextArea);
CodeEditorOptions.Instance.BindToTextEditor(textEditor); CodeEditorOptions.Instance.BindToTextEditor(textEditor);
textMarkerService = new TextMarkerService(textEditor.Document);
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
textEditor.TextArea.TextView.Services.AddService(typeof(ITextMarkerService), textMarkerService);
} }
BracketHighlightRenderer bracketHighlighter; BracketHighlightRenderer bracketHighlighter;
FoldingManager foldingManager; FoldingManager foldingManager;
TextMarkerService textMarkerService;
ITextMarker marker;
List<CustomizedHighlightingColor> customizationList; List<CustomizedHighlightingColor> customizationList;
public const string FoldingControls = "Folding controls"; public const string FoldingControls = "Folding controls";
@ -361,7 +367,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
ErrorPainter.ErrorColorName, ErrorPainter.ErrorColorName,
ta => { ta => {
ta.Document.Text = "some error"; ta.Document.Text = "some error";
// TODO : attach error painter/text marker service marker = textMarkerService.Create(0, 5);
}) })
{ {
Foreground = Colors.Red Foreground = Colors.Red
@ -374,7 +380,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
ErrorPainter.WarningColorName, ErrorPainter.WarningColorName,
ta => { ta => {
ta.Document.Text = "some warning"; ta.Document.Text = "some warning";
// TODO : attach error painter/text marker service marker = textMarkerService.Create(0, 5);
}) })
{ {
Foreground = Colors.Orange Foreground = Colors.Orange
@ -387,7 +393,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
ErrorPainter.MessageColorName, ErrorPainter.MessageColorName,
ta => { ta => {
ta.Document.Text = "some message"; ta.Document.Text = "some message";
// TODO : attach error painter/text marker service marker = textMarkerService.Create(0, 5);
}) })
{ {
Foreground = Colors.Blue Foreground = Colors.Blue
@ -432,6 +438,8 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
var item = (IHighlightingItem)listBox.SelectedItem; var item = (IHighlightingItem)listBox.SelectedItem;
TextView textView = textEditor.TextArea.TextView; TextView textView = textEditor.TextArea.TextView;
foldingManager.Clear(); foldingManager.Clear();
textMarkerService.RemoveAll(m => true);
marker = null;
textView.LineTransformers.Remove(colorizer); textView.LineTransformers.Remove(colorizer);
colorizer = null; colorizer = null;
if (item != null) { if (item != null) {
@ -442,6 +450,10 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
textEditor.Select(0, 0); textEditor.Select(0, 0);
bracketHighlighter.SetHighlight(null); bracketHighlighter.SetHighlight(null);
item.ShowExample(textEditor.TextArea); item.ShowExample(textEditor.TextArea);
if (marker != null) {
marker.MarkerType = TextMarkerType.SquigglyUnderline;
marker.MarkerColor = item.Foreground;
}
} }
} }
} }
@ -687,7 +699,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
void LoadSDSettings(XDocument document) void LoadSDSettings(XDocument document)
{ {
var version = document.Root.Attribute("version"); var version = document.Root.Attribute("version");
if (version != null && version.Value != Properties.Version1.ToString()) { if (version != null && version.Value != Properties.CurrentVersion.ToString()) {
Core.MessageService.ShowError("Settings version not supported!"); Core.MessageService.ShowError("Settings version not supported!");
return; return;
} }
@ -714,7 +726,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
using (XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8)) { using (XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8)) {
writer.Formatting = Formatting.Indented; writer.Formatting = Formatting.Indented;
writer.WriteStartElement("Properties"); writer.WriteStartElement("Properties");
writer.WriteAttributeString("version", Properties.Version1.ToString()); writer.WriteAttributeString("version", Properties.CurrentVersion.ToString());
p.WriteProperties(writer); p.WriteProperties(writer);
writer.WriteEndElement(); writer.WriteEndElement();
} }

57
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerService.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
@ -18,42 +19,26 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// <summary> /// <summary>
/// Handles the text markers for a code editor. /// Handles the text markers for a code editor.
/// </summary> /// </summary>
public sealed class TextMarkerService : DocumentColorizingTransformer, IBackgroundRenderer, ITextMarkerService public sealed class TextMarkerService : DocumentColorizingTransformer, IBackgroundRenderer, ITextMarkerService, ITextViewConnect
{ {
readonly ICodeEditor codeEditor;
TextSegmentCollection<TextMarker> markers; TextSegmentCollection<TextMarker> markers;
TextDocument document;
public TextMarkerService(ICodeEditor codeEditor) public TextMarkerService(TextDocument document)
{ {
if (codeEditor == null) if (document == null)
throw new ArgumentNullException("codeEditor"); throw new ArgumentNullException("document");
this.codeEditor = codeEditor; this.document = document;
codeEditor.DocumentChanged += codeEditor_DocumentChanged; this.markers = new TextSegmentCollection<TextMarker>(document);
codeEditor_DocumentChanged(null, null);
} }
#region Document Changed - recreate marker collection
void codeEditor_DocumentChanged(object sender, EventArgs e)
{
if (markers != null) {
foreach (TextMarker m in markers.ToArray()) {
m.Delete();
}
}
if (codeEditor.Document == null)
markers = null;
else
markers = new TextSegmentCollection<TextMarker>(codeEditor.Document);
}
#endregion
#region ITextMarkerService #region ITextMarkerService
public ITextMarker Create(int startOffset, int length) public ITextMarker Create(int startOffset, int length)
{ {
if (markers == null) if (markers == null)
throw new InvalidOperationException("Cannot create a marker when not attached to a document"); throw new InvalidOperationException("Cannot create a marker when not attached to a document");
int textLength = codeEditor.Document.TextLength; int textLength = document.TextLength;
if (startOffset < 0 || startOffset > textLength) if (startOffset < 0 || startOffset > textLength)
throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be between 0 and " + textLength); throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be between 0 and " + textLength);
if (length < 0 || startOffset + length > textLength) if (length < 0 || startOffset + length > textLength)
@ -105,7 +90,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// </summary> /// </summary>
internal void Redraw(ISegment segment) internal void Redraw(ISegment segment)
{ {
codeEditor.Redraw(segment, DispatcherPriority.Normal); foreach (var view in textViews) {
view.Redraw(segment, DispatcherPriority.Normal);
}
} }
#endregion #endregion
@ -206,6 +193,26 @@ namespace ICSharpCode.AvalonEdit.AddIn
yield return new Point(start.X + i * offset, start.Y - ((i + 1) % 2 == 0 ? offset : 0)); yield return new Point(start.X + i * offset, start.Y - ((i + 1) % 2 == 0 ? offset : 0));
} }
#endregion #endregion
#region ITextViewConnect
readonly List<TextView> textViews = new List<TextView>();
void ITextViewConnect.AddToTextView(TextView textView)
{
if (textView != null && !textViews.Contains(textView)) {
Debug.Assert(textView.Document == document);
textViews.Add(textView);
}
}
void ITextViewConnect.RemoveFromTextView(TextView textView)
{
if (textView != null) {
Debug.Assert(textView.Document == document);
textViews.Remove(textView);
}
}
#endregion
} }
public sealed class TextMarker : TextSegment, ITextMarker public sealed class TextMarker : TextSegment, ITextMarker

4
src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.ILSpyAddIn.ViewContent
/// <summary> /// <summary>
/// Equivalent to AE.AddIn CodeEditor, but without editing capabilities. /// Equivalent to AE.AddIn CodeEditor, but without editing capabilities.
/// </summary> /// </summary>
class CodeView : Grid, IDisposable, ICodeEditor, IPositionable class CodeView : Grid, IDisposable, IPositionable
{ {
public event EventHandler DocumentChanged; public event EventHandler DocumentChanged;
@ -59,7 +59,7 @@ namespace ICSharpCode.ILSpyAddIn.ViewContent
this.adapter.TextEditor.TextArea.TextView.VisualLinesChanged += delegate { iconMargin.InvalidateVisual(); }; this.adapter.TextEditor.TextArea.TextView.VisualLinesChanged += delegate { iconMargin.InvalidateVisual(); };
// add marker service // add marker service
this.textMarkerService = new TextMarkerService(this); this.textMarkerService = new TextMarkerService(adapter.TextEditor.Document);
this.adapter.TextEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); this.adapter.TextEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
this.adapter.TextEditor.TextArea.TextView.LineTransformers.Add(textMarkerService); this.adapter.TextEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
this.adapter.TextEditor.TextArea.TextView.Services.AddService(typeof(ITextMarkerService), textMarkerService); this.adapter.TextEditor.TextArea.TextView.Services.AddService(typeof(ITextMarkerService), textMarkerService);

6
src/Main/Base/Project/Src/Services/Tasks/ErrorPainter.cs

@ -73,9 +73,9 @@ namespace ICSharpCode.SharpDevelop
} }
} }
public const string ErrorColorName = "Error Marker"; public const string ErrorColorName = "Error marker";
public const string WarningColorName = "Warning Marker"; public const string WarningColorName = "Warning marker";
public const string MessageColorName = "Message Marker"; public const string MessageColorName = "Message marker";
Color errorColor; Color errorColor;

2
src/Main/Core/Project/Src/Services/PropertyService/Properties.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.Core
/// </summary> /// </summary>
public class Properties public class Properties
{ {
public static readonly Version Version1 = new Version(1, 0, 0, 0); public static readonly Version CurrentVersion = new Version(1, 0, 0, 0);
/// <summary> Needed for support of late deserialization </summary> /// <summary> Needed for support of late deserialization </summary>
class SerializedValue { class SerializedValue {

Loading…
Cancel
Save