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

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

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

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

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

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

@ -79,7 +79,7 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -79,7 +79,7 @@ namespace ICSharpCode.AvalonEdit.Editing
newTextView.VisualLinesChanged += TextViewVisualLinesChanged;
// 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 {
textArea = null;
}

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

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

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

@ -1757,6 +1757,11 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -1757,6 +1757,11 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// <summary>
/// Gets a service container used to associate services with the text view.
/// </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 {
get { return services; }
}
@ -1766,7 +1771,7 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -1766,7 +1771,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// 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.
/// </summary>
public object GetService(Type serviceType)
public virtual object GetService(Type serviceType)
{
object instance = services.GetService(serviceType);
if (instance == null && document != null) {

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

@ -124,6 +124,7 @@ namespace ICSharpCode.SharpDevelop @@ -124,6 +124,7 @@ namespace ICSharpCode.SharpDevelop
if (view == null)
throw new ArgumentNullException("view");
bool success = false;
try {
if (currentView != view) {
if (currentView == null) {
@ -139,9 +140,14 @@ namespace ICSharpCode.SharpDevelop @@ -139,9 +140,14 @@ namespace ICSharpCode.SharpDevelop
}
}
}
} catch (Exception) {
view.Dispose();
throw;
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();
}
}
}

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

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

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

@ -36,11 +36,19 @@ namespace ICSharpCode.Core @@ -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
{
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
{
object service = provider.GetService(typeof(T));

Loading…
Cancel
Save