Browse Source

Fixed document service retrieval.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
6436a028bb
  1. 9
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs
  2. 11
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
  3. 8
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/IconBarMargin.cs
  4. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/LineNumberMargin.cs
  5. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs
  6. 7
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs
  7. 10
      src/Main/Base/Project/Src/Services/File/OpenedFile.cs
  8. 5
      src/Main/Base/Project/Src/Services/Tasks/ErrorPainter.cs
  9. 8
      src/Main/Core/Project/Src/Services/ServiceSingleton.cs

9
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs

@ -13,6 +13,7 @@ using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Rendering; using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Widgets.MyersDiff; using ICSharpCode.SharpDevelop.Widgets.MyersDiff;
@ -114,13 +115,13 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (oldTextView != null) { if (oldTextView != null) {
oldTextView.VisualLinesChanged -= VisualLinesChanged; oldTextView.VisualLinesChanged -= VisualLinesChanged;
oldTextView.ScrollOffsetChanged -= ScrollOffsetChanged; oldTextView.ScrollOffsetChanged -= ScrollOffsetChanged;
((TextArea)oldTextView.Services.GetService(typeof(TextArea))).KeyDown -= TextViewKeyDown; oldTextView.GetRequiredService<TextArea>().KeyDown -= TextViewKeyDown;
} }
base.OnTextViewChanged(oldTextView, newTextView); base.OnTextViewChanged(oldTextView, newTextView);
if (newTextView != null) { if (newTextView != null) {
newTextView.VisualLinesChanged += VisualLinesChanged; newTextView.VisualLinesChanged += VisualLinesChanged;
newTextView.ScrollOffsetChanged += ScrollOffsetChanged; newTextView.ScrollOffsetChanged += ScrollOffsetChanged;
((TextArea)newTextView.Services.GetService(typeof(TextArea))).KeyDown += TextViewKeyDown; newTextView.GetRequiredService<TextArea>().KeyDown += TextViewKeyDown;
} }
} }
@ -169,8 +170,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
bool added; bool added;
string oldText = changeWatcher.GetOldVersionFromLine(line, out startLine, out added); string oldText = changeWatcher.GetOldVersionFromLine(line, out startLine, out added);
TextEditor editor = this.TextView.Services.GetService(typeof(TextEditor)) as TextEditor; TextEditor editor = this.TextView.GetService<TextEditor>();
markerService = this.TextView.Services.GetService(typeof(ITextMarkerService)) as ITextMarkerService; markerService = this.TextView.GetService<ITextMarkerService>();
LineChangeInfo zeroLineInfo = changeWatcher.GetChange(0); LineChangeInfo zeroLineInfo = changeWatcher.GetChange(0);

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

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel.Design;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -145,9 +146,15 @@ namespace ICSharpCode.AvalonEdit.AddIn
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.document = new TextDocument();
var documentServiceContainer = document.GetRequiredService<IServiceContainer>();
this.CommandBindings.Add(new CommandBinding(SharpDevelopRoutedCommands.SplitView, OnSplitView)); this.CommandBindings.Add(new CommandBinding(SharpDevelopRoutedCommands.SplitView, OnSplitView));
textMarkerService = new TextMarkerService(document); textMarkerService = new TextMarkerService(document);
documentServiceContainer.AddService(typeof(ITextMarkerService), textMarkerService);
iconBarManager = new IconBarManager(); iconBarManager = new IconBarManager();
documentServiceContainer.AddService(typeof(IBookmarkMargin), iconBarManager);
if (CodeEditorOptions.Instance.EnableChangeMarkerMargin) { if (CodeEditorOptions.Instance.EnableChangeMarkerMargin) {
changeWatcher = new DefaultChangeWatcher(); changeWatcher = new DefaultChangeWatcher();
} }
@ -203,11 +210,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
textView.BackgroundRenderers.Add(textMarkerService); textView.BackgroundRenderers.Add(textMarkerService);
textView.LineTransformers.Add(textMarkerService); textView.LineTransformers.Add(textMarkerService);
textView.Services.AddService(typeof(ITextMarkerService), textMarkerService);
textView.Services.AddService(typeof(IEditorUIService), new AvalonEditEditorUIService(textView)); textView.Services.AddService(typeof(IEditorUIService), new AvalonEditEditorUIService(textView));
textView.Services.AddService(typeof(IBookmarkMargin), iconBarManager);
codeEditorView.TextArea.LeftMargins.Insert(0, new IconBarMargin(iconBarManager)); codeEditorView.TextArea.LeftMargins.Insert(0, new IconBarMargin(iconBarManager));
if (changeWatcher != null) { if (changeWatcher != null) {
@ -235,7 +240,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
{ {
foreach (var d in textEditor.TextArea.LeftMargins.OfType<IDisposable>()) foreach (var d in textEditor.TextArea.LeftMargins.OfType<IDisposable>())
d.Dispose(); d.Dispose();
((EnhancedScrollBar)textEditor.TextArea.GetService(typeof(EnhancedScrollBar))).Dispose(); textEditor.TextArea.GetRequiredService<EnhancedScrollBar>().Dispose();
textEditor.Dispose(); textEditor.Dispose();
} }

8
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/IconBarMargin.cs

@ -166,7 +166,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
dragDropBookmark = bm; dragDropBookmark = bm;
dragDropStartPoint = dragDropCurrentPoint = e.GetPosition(this).Y; dragDropStartPoint = dragDropCurrentPoint = e.GetPosition(this).Y;
if (TextView != null) { if (TextView != null) {
TextArea area = TextView.Services.GetService(typeof(TextArea)) as TextArea; TextArea area = TextView.GetService(typeof(TextArea)) as TextArea;
if (area != null) if (area != null)
area.PreviewKeyDown += TextArea_PreviewKeyDown; area.PreviewKeyDown += TextArea_PreviewKeyDown;
} }
@ -178,7 +178,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
dragDropBookmark = null; dragDropBookmark = null;
dragStarted = false; dragStarted = false;
if (TextView != null) { if (TextView != null) {
TextArea area = TextView.Services.GetService(typeof(TextArea)) as TextArea; TextArea area = TextView.GetService(typeof(TextArea)) as TextArea;
if (area != null) if (area != null)
area.PreviewKeyDown -= TextArea_PreviewKeyDown; area.PreviewKeyDown -= TextArea_PreviewKeyDown;
} }
@ -238,7 +238,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
} }
if (e.ChangedButton == MouseButton.Left && TextView != null) { if (e.ChangedButton == MouseButton.Left && TextView != null) {
// no bookmark on the line: create a new breakpoint // no bookmark on the line: create a new breakpoint
ITextEditor textEditor = TextView.Services.GetService(typeof(ITextEditor)) as ITextEditor; ITextEditor textEditor = TextView.GetService(typeof(ITextEditor)) as ITextEditor;
if (textEditor != null) { if (textEditor != null) {
DebuggerService.ToggleBreakpointAt(textEditor, line, typeof(BreakpointBookmark)); DebuggerService.ToggleBreakpointAt(textEditor, line, typeof(BreakpointBookmark));
return; return;
@ -247,7 +247,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
// create breakpoint for the other posible active contents // create breakpoint for the other posible active contents
var viewContent = WorkbenchSingleton.Workbench.ActiveContent as AbstractViewContentWithoutFile; var viewContent = WorkbenchSingleton.Workbench.ActiveContent as AbstractViewContentWithoutFile;
if (viewContent != null) { if (viewContent != null) {
textEditor = viewContent.Services.GetService(typeof(ITextEditor)) as ITextEditor; textEditor = viewContent.GetService(typeof(ITextEditor)) as ITextEditor;
if (textEditor != null) { if (textEditor != null) {
DebuggerService.ToggleBreakpointAt(textEditor, line, typeof(DecompiledBreakpointBookmark)); DebuggerService.ToggleBreakpointAt(textEditor, line, typeof(DecompiledBreakpointBookmark));
return; return;

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/LineNumberMargin.cs

@ -79,7 +79,7 @@ namespace ICSharpCode.AvalonEdit.Editing
newTextView.VisualLinesChanged += TextViewVisualLinesChanged; newTextView.VisualLinesChanged += TextViewVisualLinesChanged;
// find the text area belonging to the new text view // find the text area belonging to the new text view
textArea = newTextView.Services.GetService(typeof(TextArea)) as TextArea; textArea = newTextView.GetService(typeof(TextArea)) as TextArea;
} else { } else {
textArea = null; textArea = null;
} }

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs

@ -995,7 +995,7 @@ namespace ICSharpCode.AvalonEdit.Editing
/// <returns>Returns the requested service instance, or null if the service cannot be found.</returns> /// <returns>Returns the requested service instance, or null if the service cannot be found.</returns>
public virtual object GetService(Type serviceType) public virtual object GetService(Type serviceType)
{ {
return textView.Services.GetService(serviceType); return textView.GetService(serviceType);
} }
/// <summary> /// <summary>

7
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs

@ -1757,6 +1757,11 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// <summary> /// <summary>
/// Gets a service container used to associate services with the text view. /// Gets a service container used to associate services with the text view.
/// </summary> /// </summary>
/// <remarks>
/// This container does not provide document services -
/// use <c>TextView.GetService()</c> instead of <c>TextView.Services.GetService()</c> to ensure
/// that document services can be found as well.
/// </remarks>
public ServiceContainer Services { public ServiceContainer Services {
get { return services; } get { return services; }
} }
@ -1766,7 +1771,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// If the service is not found in the <see cref="Services"/> container, /// If the service is not found in the <see cref="Services"/> container,
/// this method will also look for it in the current document's service provider. /// this method will also look for it in the current document's service provider.
/// </summary> /// </summary>
public object GetService(Type serviceType) public virtual object GetService(Type serviceType)
{ {
object instance = services.GetService(serviceType); object instance = services.GetService(serviceType);
if (instance == null && document != null) { if (instance == null && document != null) {

10
src/Main/Base/Project/Src/Services/File/OpenedFile.cs

@ -124,6 +124,7 @@ namespace ICSharpCode.SharpDevelop
if (view == null) if (view == null)
throw new ArgumentNullException("view"); throw new ArgumentNullException("view");
bool success = false;
try { try {
if (currentView != view) { if (currentView != view) {
if (currentView == null) { if (currentView == null) {
@ -139,9 +140,14 @@ namespace ICSharpCode.SharpDevelop
} }
} }
} }
} catch (Exception) { success = true;
} finally {
// Only in case of exceptions:
// (try-finally with bool is better than try-catch-rethrow because it causes the debugger to stop
// at the original error location, not at the rethrow)
if (!success) {
view.Dispose(); view.Dispose();
throw; }
} }
} }

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

@ -24,10 +24,7 @@ namespace ICSharpCode.SharpDevelop
{ {
instances.Add(this); instances.Add(this);
this.textEditor = textEditor; this.textEditor = textEditor;
this.markerService = this.textEditor.GetService(typeof(ITextMarkerService)) as ITextMarkerService; this.markerService = this.textEditor.GetRequiredService<ITextMarkerService>();
if (this.markerService == null)
throw new InvalidOperationException("this ITextEditor has no text marker service!");
TaskService.Added += OnAdded; TaskService.Added += OnAdded;
TaskService.Removed += OnRemoved; TaskService.Removed += OnRemoved;

8
src/Main/Core/Project/Src/Services/ServiceSingleton.cs

@ -36,11 +36,19 @@ namespace ICSharpCode.Core
} }
} }
/// <summary>
/// Retrieves the service of type <c>T</c> from the provider.
/// If the service cannot be found, this method returns <c>null</c>.
/// </summary>
public static T GetService<T>(this IServiceProvider provider) where T : class public static T GetService<T>(this IServiceProvider provider) where T : class
{ {
return (T)provider.GetService(typeof(T)); return (T)provider.GetService(typeof(T));
} }
/// <summary>
/// Retrieves the service of type <c>T</c> from the provider.
/// If the service cannot be found, a <see cref="ServiceNotFoundException"/> will be thrown.
/// </summary>
public static T GetRequiredService<T>(this IServiceProvider provider) where T : class public static T GetRequiredService<T>(this IServiceProvider provider) where T : class
{ {
object service = provider.GetService(typeof(T)); object service = provider.GetService(typeof(T));

Loading…
Cancel
Save