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; @@ -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;
}
/// <summary>
/// Integrates AvalonEdit with SharpDevelop.
/// Also provides support for Split-View (showing two AvalonEdit instances using the same TextDocument)
/// </summary>
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 @@ -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 @@ -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 @@ -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 @@ -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;

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

@ -10,7 +10,12 @@ @@ -10,7 +10,12 @@
<BooleanToVisibilityConverter x:Key="boolToVisibility" />
</FrameworkElement.Resources>
<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.RowDefinitions>
<RowDefinition Height="Auto" />
@ -46,11 +51,12 @@ @@ -46,11 +51,12 @@
<core:RestrictDesiredSize Height="50" MinWidth="200">
<avalonedit:TextEditor Name="textEditor" IsReadOnly="True" />
</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="ExportButtonClick" Content="{core:Localize Dialog.HighlightingEditor.Export}" />
</widgets:StackPanelWithSpacing>
</StackPanel>
</Grid>
<ComboBox Name="languageComboBox" DockPanel.Dock="Top" SelectionChanged="LanguageComboBox_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>

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

@ -43,10 +43,16 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -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<CustomizedHighlightingColor> customizationList;
public const string FoldingControls = "Folding controls";
@ -361,7 +367,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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();
}

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

@ -3,6 +3,7 @@ @@ -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 @@ -18,42 +19,26 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// <summary>
/// Handles the text markers for a code editor.
/// </summary>
public sealed class TextMarkerService : DocumentColorizingTransformer, IBackgroundRenderer, ITextMarkerService
public sealed class TextMarkerService : DocumentColorizingTransformer, IBackgroundRenderer, ITextMarkerService, ITextViewConnect
{
readonly ICodeEditor codeEditor;
TextSegmentCollection<TextMarker> 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<TextMarker>(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<TextMarker>(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 @@ -105,7 +90,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// </summary>
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 @@ -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<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

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

@ -36,7 +36,7 @@ namespace ICSharpCode.ILSpyAddIn.ViewContent @@ -36,7 +36,7 @@ namespace ICSharpCode.ILSpyAddIn.ViewContent
/// <summary>
/// Equivalent to AE.AddIn CodeEditor, but without editing capabilities.
/// </summary>
class CodeView : Grid, IDisposable, ICodeEditor, IPositionable
class CodeView : Grid, IDisposable, IPositionable
{
public event EventHandler DocumentChanged;
@ -59,7 +59,7 @@ namespace ICSharpCode.ILSpyAddIn.ViewContent @@ -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);

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

@ -73,9 +73,9 @@ namespace ICSharpCode.SharpDevelop @@ -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;

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

@ -37,7 +37,7 @@ namespace ICSharpCode.Core @@ -37,7 +37,7 @@ namespace ICSharpCode.Core
/// </summary>
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>
class SerializedValue {

Loading…
Cancel
Save