diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
index bbe07412da..b743be62ba 100644
--- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
+++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
@@ -33,20 +33,11 @@ using ICSharpCode.SharpDevelop.Widgets.MyersDiff;
namespace ICSharpCode.AvalonEdit.AddIn
{
- public interface ICodeEditor
- {
- TextDocument Document { get; }
-
- void Redraw(ISegment segment, DispatcherPriority priority);
-
- event EventHandler DocumentChanged;
- }
-
///
/// Integrates AvalonEdit with SharpDevelop.
/// Also provides support for Split-View (showing two AvalonEdit instances using the same TextDocument)
///
- public class CodeEditor : Grid, IDisposable, ICodeEditor
+ public class CodeEditor : Grid, IDisposable
{
const string contextMenuPath = "/SharpDevelop/ViewContent/AvalonEdit/ContextMenu";
@@ -153,9 +144,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
ParserService.ParseInformationUpdated += ParserServiceParseInformationUpdated;
this.FlowDirection = FlowDirection.LeftToRight; // code editing is always left-to-right
+ this.document = new TextDocument();
this.CommandBindings.Add(new CommandBinding(SharpDevelopRoutedCommands.SplitView, OnSplitView));
-
- textMarkerService = new TextMarkerService(this);
+ textMarkerService = new TextMarkerService(document);
iconBarManager = new IconBarManager();
if (CodeEditorOptions.Instance.EnableChangeMarkerMargin) {
changeWatcher = new DefaultChangeWatcher();
@@ -165,9 +156,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
Debug.Assert(primaryTextEditorAdapter != null);
activeTextEditor = primaryTextEditor;
- this.Document = primaryTextEditor.Document;
- primaryTextEditor.SetBinding(TextEditor.DocumentProperty, new Binding("Document") { Source = this });
-
this.ColumnDefinitions.Add(new ColumnDefinition());
this.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
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();
CodeEditorAdapter adapter = new CodeEditorAdapter(this, codeEditorView);
codeEditorView.Adapter = adapter;
+ codeEditorView.Document = document;
TextView textView = codeEditorView.TextArea.TextView;
textView.Services.AddService(typeof(ITextEditor), adapter);
textView.Services.AddService(typeof(CodeEditor), this);
@@ -340,8 +329,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
secondaryTextEditorAdapter = (CodeEditorAdapter)secondaryTextEditor.TextArea.GetService(typeof(ITextEditor));
Debug.Assert(primaryTextEditorAdapter != null);
- secondaryTextEditor.SetBinding(TextEditor.DocumentProperty,
- new Binding(TextEditor.DocumentProperty.Name) { Source = primaryTextEditor });
secondaryTextEditor.SetBinding(TextEditor.IsReadOnlyProperty,
new Binding(TextEditor.IsReadOnlyProperty.Name) { Source = primaryTextEditor });
secondaryTextEditor.SyntaxHighlighting = primaryTextEditor.SyntaxHighlighting;
diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml
index 6820ef027d..0fec4ce0d4 100644
--- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml
+++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml
@@ -10,47 +10,53 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
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 2851a70ed1..93d2ebe6d8 100644
--- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
+++ b/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);
foldingManager = FoldingManager.Install(textEditor.TextArea);
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;
FoldingManager foldingManager;
+ TextMarkerService textMarkerService;
+ ITextMarker marker;
List customizationList;
public const string FoldingControls = "Folding controls";
@@ -361,7 +367,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
ErrorPainter.ErrorColorName,
ta => {
ta.Document.Text = "some error";
- // TODO : attach error painter/text marker service
+ marker = textMarkerService.Create(0, 5);
})
{
Foreground = Colors.Red
@@ -374,7 +380,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
ErrorPainter.WarningColorName,
ta => {
ta.Document.Text = "some warning";
- // TODO : attach error painter/text marker service
+ marker = textMarkerService.Create(0, 5);
})
{
Foreground = Colors.Orange
@@ -387,7 +393,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
ErrorPainter.MessageColorName,
ta => {
ta.Document.Text = "some message";
- // TODO : attach error painter/text marker service
+ marker = textMarkerService.Create(0, 5);
})
{
Foreground = Colors.Blue
@@ -432,6 +438,8 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
var item = (IHighlightingItem)listBox.SelectedItem;
TextView textView = textEditor.TextArea.TextView;
foldingManager.Clear();
+ textMarkerService.RemoveAll(m => true);
+ marker = null;
textView.LineTransformers.Remove(colorizer);
colorizer = null;
if (item != null) {
@@ -442,6 +450,10 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
textEditor.Select(0, 0);
bracketHighlighter.SetHighlight(null);
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)
{
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!");
return;
}
@@ -714,7 +726,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
using (XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8)) {
writer.Formatting = Formatting.Indented;
writer.WriteStartElement("Properties");
- writer.WriteAttributeString("version", Properties.Version1.ToString());
+ writer.WriteAttributeString("version", Properties.CurrentVersion.ToString());
p.WriteProperties(writer);
writer.WriteEndElement();
}
diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerService.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerService.cs
index 8a4c5bb7a7..e53a62bef7 100644
--- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerService.cs
+++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerService.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Media;
@@ -18,42 +19,26 @@ namespace ICSharpCode.AvalonEdit.AddIn
///
/// Handles the text markers for a code editor.
///
- public sealed class TextMarkerService : DocumentColorizingTransformer, IBackgroundRenderer, ITextMarkerService
+ public sealed class TextMarkerService : DocumentColorizingTransformer, IBackgroundRenderer, ITextMarkerService, ITextViewConnect
{
- readonly ICodeEditor codeEditor;
TextSegmentCollection markers;
+ TextDocument document;
- public TextMarkerService(ICodeEditor codeEditor)
+ public TextMarkerService(TextDocument document)
{
- if (codeEditor == null)
- throw new ArgumentNullException("codeEditor");
- this.codeEditor = codeEditor;
- codeEditor.DocumentChanged += codeEditor_DocumentChanged;
- codeEditor_DocumentChanged(null, null);
+ if (document == null)
+ throw new ArgumentNullException("document");
+ this.document = document;
+ this.markers = new TextSegmentCollection(document);
}
- #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(codeEditor.Document);
- }
- #endregion
-
#region ITextMarkerService
public ITextMarker Create(int startOffset, int length)
{
if (markers == null)
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)
throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be between 0 and " + textLength);
if (length < 0 || startOffset + length > textLength)
@@ -105,7 +90,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
///
internal void Redraw(ISegment segment)
{
- codeEditor.Redraw(segment, DispatcherPriority.Normal);
+ foreach (var view in textViews) {
+ view.Redraw(segment, DispatcherPriority.Normal);
+ }
}
#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));
}
#endregion
+
+ #region ITextViewConnect
+ readonly List textViews = new List();
+
+ 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
diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs
index 2c8534419c..aab1ac03d0 100644
--- a/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs
+++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs
@@ -36,7 +36,7 @@ namespace ICSharpCode.ILSpyAddIn.ViewContent
///
/// Equivalent to AE.AddIn CodeEditor, but without editing capabilities.
///
- class CodeView : Grid, IDisposable, ICodeEditor, IPositionable
+ class CodeView : Grid, IDisposable, IPositionable
{
public event EventHandler DocumentChanged;
@@ -59,7 +59,7 @@ namespace ICSharpCode.ILSpyAddIn.ViewContent
this.adapter.TextEditor.TextArea.TextView.VisualLinesChanged += delegate { iconMargin.InvalidateVisual(); };
// 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.LineTransformers.Add(textMarkerService);
this.adapter.TextEditor.TextArea.TextView.Services.AddService(typeof(ITextMarkerService), textMarkerService);
diff --git a/src/Main/Base/Project/Src/Services/Tasks/ErrorPainter.cs b/src/Main/Base/Project/Src/Services/Tasks/ErrorPainter.cs
index ca4a672f05..1bb67e9fa7 100644
--- a/src/Main/Base/Project/Src/Services/Tasks/ErrorPainter.cs
+++ b/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 WarningColorName = "Warning Marker";
- public const string MessageColorName = "Message Marker";
+ public const string ErrorColorName = "Error marker";
+ public const string WarningColorName = "Warning marker";
+ public const string MessageColorName = "Message marker";
Color errorColor;
diff --git a/src/Main/Core/Project/Src/Services/PropertyService/Properties.cs b/src/Main/Core/Project/Src/Services/PropertyService/Properties.cs
index 72d2e93f71..4aea17e0c0 100644
--- a/src/Main/Core/Project/Src/Services/PropertyService/Properties.cs
+++ b/src/Main/Core/Project/Src/Services/PropertyService/Properties.cs
@@ -37,7 +37,7 @@ namespace ICSharpCode.Core
///
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);
/// Needed for support of late deserialization
class SerializedValue {