Browse Source

Close InsightWindow when typing ')'.

Close code completion window after '.'-completion when deleting the dot with backspace.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5674 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
493ea45a5d
  1. 4
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs
  2. 30
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopInsightWindow.cs
  3. 15
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockDocument.cs
  4. 5
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextBuffer.cs
  5. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/XPath/RemoveXPathHighlightingCommandTestFixture.cs
  6. 4
      src/AddIns/DisplayBindings/XmlEditor/Test/XPath/XPathNodeTextMarkerTests.cs
  7. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj
  8. 17
      src/AddIns/Misc/SearchAndReplace/Test/MockDocument.cs
  9. 6
      src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj
  10. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/CompletionWindowBase.cs
  11. 11
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/ITextSource.cs
  12. 8
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextAreaDefaultInputHandlers.cs
  13. 10
      src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs
  14. 5
      src/Libraries/NRefactory/Project/Src/Lexer/ILexer.cs
  15. 3
      src/Libraries/SharpTreeView/ICSharpCode.TreeView.Demo/ICSharpCode.TreeView.Demo.csproj
  16. 2
      src/Libraries/SharpTreeView/ICSharpCode.TreeView.Demo/Window1.xaml
  17. 71
      src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditDocumentAdapter.cs
  18. 8
      src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextSourceAdapter.cs
  19. 12
      src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionBinding.cs
  20. 10
      src/Main/Base/Project/Src/Editor/CodeCompletion/IInsightWindow.cs
  21. 41
      src/Main/Base/Project/Src/Editor/CodeCompletion/NRefactoryCodeCompletionBinding.cs
  22. 3
      src/Main/Base/Project/Src/Editor/IDocument.cs
  23. 5
      src/Main/Base/Project/Src/Editor/ITextBuffer.cs
  24. 5
      src/Main/Base/Project/Src/Editor/RefactoringDocumentAdapter.cs
  25. 24
      src/Main/Base/Project/Src/Services/RefactoringService/TextEditorDocument.cs
  26. 2
      src/Main/Base/Test/Utils/MockTextMarkerService.cs
  27. 5
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/IRefactoringDocument.cs

4
src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs

@ -32,7 +32,9 @@ namespace VBNetBinding @@ -32,7 +32,9 @@ namespace VBNetBinding
public override CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
{
if(ch == '(' && EnableMethodInsight && CodeCompletionOptions.InsightEnabled) {
editor.ShowInsightWindow(new MethodInsightProvider().ProvideInsight(editor));
IInsightWindow insightWindow = editor.ShowInsightWindow(new MethodInsightProvider().ProvideInsight(editor));
if (insightWindow != null)
InitializeOpenedInsightWindow(editor, insightWindow);
return CodeCompletionKeyPressResult.Completed;
} else if(ch == ',' && CodeCompletionOptions.InsightRefreshOnComma && CodeCompletionOptions.InsightEnabled) {
if (InsightRefreshOnComma(editor, ch))

30
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopInsightWindow.cs

@ -5,15 +5,17 @@ @@ -5,15 +5,17 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using ICSharpCode.AvalonEdit.CodeCompletion;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
namespace ICSharpCode.AvalonEdit.AddIn
{
@ -94,6 +96,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -94,6 +96,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
{
this.Provider = new SDItemProvider(this);
this.Style = ICSharpCode.Core.Presentation.GlobalStyles.WindowStyle;
AttachEvents();
}
public IList<IInsightItem> Items {
@ -112,5 +115,30 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -112,5 +115,30 @@ namespace ICSharpCode.AvalonEdit.AddIn
this.Provider.SelectedIndex = items.IndexOf(value);
}
}
TextDocument document;
void AttachEvents()
{
document = this.TextArea.Document;
if (document != null)
document.Changed += document_Changed;
}
/// <inheritdoc/>
protected override void DetachEvents()
{
if (document != null)
document.Changed -= document_Changed;
base.DetachEvents();
}
void document_Changed(object sender, DocumentChangeEventArgs e)
{
if (DocumentChanged != null)
DocumentChanged(this, new TextChangeEventArgs(e.Offset, e.RemovedText, e.InsertedText));
}
public event EventHandler<TextChangeEventArgs> DocumentChanged;
}
}

15
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockDocument.cs

@ -144,5 +144,20 @@ namespace XmlEditor.Tests.Utils @@ -144,5 +144,20 @@ namespace XmlEditor.Tests.Utils
{
throw new NotImplementedException();
}
public event EventHandler<TextChangeEventArgs> Changing {
add { throw new NotImplementedException(); }
remove { throw new NotImplementedException(); }
}
public event EventHandler<TextChangeEventArgs> Changed {
add { throw new NotImplementedException(); }
remove { throw new NotImplementedException(); }
}
public TextReader CreateReader(int offset, int length)
{
throw new NotImplementedException();
}
}
}

5
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextBuffer.cs

@ -60,6 +60,11 @@ namespace XmlEditor.Tests.Utils @@ -60,6 +60,11 @@ namespace XmlEditor.Tests.Utils
return new StringReader(text);
}
public TextReader CreateReader(int offset, int length)
{
return new StringReader(text);
}
public char GetCharAt(int offset)
{
throw new NotImplementedException();

2
src/AddIns/DisplayBindings/XmlEditor/Test/XPath/RemoveXPathHighlightingCommandTestFixture.cs

@ -37,7 +37,7 @@ namespace XmlEditor.Tests.XPath @@ -37,7 +37,7 @@ namespace XmlEditor.Tests.XPath
container.AddService(typeof(ITextMarkerService), markerService);
// Add xpath marker to document.
AvalonEditDocumentAdapter doc = new AvalonEditDocumentAdapter(container);
AvalonEditDocumentAdapter doc = new AvalonEditDocumentAdapter(new ICSharpCode.AvalonEdit.Document.TextDocument(), container);
doc.Text = "<Test/>";
XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);
XPathNodeMatch nodeMatch = new XPathNodeMatch("Test", "<Test/>", 0, 1, XPathNodeType.Element);

4
src/AddIns/DisplayBindings/XmlEditor/Test/XPath/XPathNodeTextMarkerTests.cs

@ -34,7 +34,7 @@ namespace XmlEditor.Tests.XPath @@ -34,7 +34,7 @@ namespace XmlEditor.Tests.XPath
ServiceContainer container = new ServiceContainer();
container.AddService(typeof(MockTextMarkerService), new MockTextMarkerService());
AvalonEditDocumentAdapter doc = new AvalonEditDocumentAdapter(container);
AvalonEditDocumentAdapter doc = new AvalonEditDocumentAdapter(new ICSharpCode.AvalonEdit.Document.TextDocument(), container);
doc.Text = xml;
XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);
xpathNodeMarker.AddMarkers(nodes);
@ -64,7 +64,7 @@ namespace XmlEditor.Tests.XPath @@ -64,7 +64,7 @@ namespace XmlEditor.Tests.XPath
ServiceContainer container = new ServiceContainer();
container.AddService(typeof(MockTextMarkerService), new MockTextMarkerService());
AvalonEditDocumentAdapter doc = new AvalonEditDocumentAdapter(container);
AvalonEditDocumentAdapter doc = new AvalonEditDocumentAdapter(new ICSharpCode.AvalonEdit.Document.TextDocument(), container);
doc.Text = xml;
XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);
xpathNodeMarker.AddMarkers(nodes);

2
src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
<DebugType>Full</DebugType>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<OutputPath>..\..\..\..\..\bin\UnitTests\</OutputPath>
<Optimize>False</Optimize>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>

17
src/AddIns/Misc/SearchAndReplace/Test/MockDocument.cs

@ -120,10 +120,25 @@ namespace SearchAndReplace.Tests.Utils @@ -120,10 +120,25 @@ namespace SearchAndReplace.Tests.Utils
{
throw new NotImplementedException();
}
public ITextBuffer CreateSnapshot(int offset, int length)
{
throw new NotImplementedException();
}
public event EventHandler<TextChangeEventArgs> Changing {
add { throw new NotImplementedException(); }
remove { throw new NotImplementedException(); }
}
public event EventHandler<TextChangeEventArgs> Changed {
add { throw new NotImplementedException(); }
remove { throw new NotImplementedException(); }
}
public System.IO.TextReader CreateReader(int offset, int length)
{
throw new NotImplementedException();
}
}
}

6
src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>UnitTesting.Tests</RootNamespace>
@ -11,14 +12,13 @@ @@ -11,14 +12,13 @@
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<FileAlignment>4096</FileAlignment>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
<IntermediateOutputPath>obj\Debug\</IntermediateOutputPath>
<OutputPath>..\..\..\..\..\bin\UnitTests\</OutputPath>
<Optimize>False</Optimize>

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/CompletionWindowBase.cs

@ -340,6 +340,10 @@ namespace ICSharpCode.AvalonEdit.CodeCompletion @@ -340,6 +340,10 @@ namespace ICSharpCode.AvalonEdit.CodeCompletion
void textArea_Document_Changing(object sender, DocumentChangeEventArgs e)
{
if (e.Offset + e.RemovalLength == this.StartOffset && e.RemovalLength > 0) {
Close(); // removal immediately in front of completion segment: close the window
// this is necessary when pressing backspace after dot-completion
}
if (e.Offset == startOffset && e.RemovalLength == 0 && ExpectInsertionBeforeStart) {
startOffset = e.GetNewOffset(startOffset, AnchorMovementType.AfterInsertion);
this.ExpectInsertionBeforeStart = false;

11
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/ITextSource.cs

@ -57,14 +57,20 @@ namespace ICSharpCode.AvalonEdit.Document @@ -57,14 +57,20 @@ namespace ICSharpCode.AvalonEdit.Document
/// <summary>
/// Creates a snapshot of the current text.
/// This method is generally not thread-safe when called on a mutable text buffer, but the resulting text buffer is immutable and thread-safe.
/// </summary>
/// <remarks>
/// This method is generally not thread-safe when called on a mutable text buffer, but the resulting text buffer is immutable and thread-safe.
/// However, some implementing classes may provide additional thread-safety guarantees, see <see cref="TextDocument.CreateSnapshot()">TextDocument.CreateSnapshot</see>.
/// </remarks>
ITextSource CreateSnapshot();
/// <summary>
/// Creates a snapshot of a part of the current text.
/// This method is not thread-safe when called on a mutable text buffer, but the resulting text buffer is immutable and thread-safe.
/// </summary>
/// <remarks>
/// This method is generally not thread-safe when called on a mutable text buffer, but the resulting text buffer is immutable and thread-safe.
/// However, some implementing classes may provide additional thread-safety guarantees, see <see cref="TextDocument.CreateSnapshot()">TextDocument.CreateSnapshot</see>.
/// </remarks>
ITextSource CreateSnapshot(int offset, int length);
/// <summary>
@ -276,6 +282,7 @@ namespace ICSharpCode.AvalonEdit.Document @@ -276,6 +282,7 @@ namespace ICSharpCode.AvalonEdit.Document
/// <inheritdoc/>
public ITextSource CreateSnapshot()
{
// we clone the underlying rope because the creator of the RopeTextSource might be modifying it
return new RopeTextSource(rope.Clone());
}

8
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextAreaDefaultInputHandlers.cs

@ -71,8 +71,10 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -71,8 +71,10 @@ namespace ICSharpCode.AvalonEdit.Editing
{
var undoStack = GetUndoStack();
if (undoStack != null) {
if (undoStack.CanUndo)
if (undoStack.CanUndo) {
undoStack.Undo();
this.TextArea.Caret.BringCaretToView();
}
e.Handled = true;
}
}
@ -90,8 +92,10 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -90,8 +92,10 @@ namespace ICSharpCode.AvalonEdit.Editing
{
var undoStack = GetUndoStack();
if (undoStack != null) {
if (undoStack.CanRedo)
if (undoStack.CanRedo) {
undoStack.Redo();
this.TextArea.Caret.BringCaretToView();
}
e.Handled = true;
}
}

10
src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs

@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.Parser
/// This is the base class for the C# and VB.NET lexer
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1708:IdentifiersShouldDifferByMoreThanCase")]
public abstract class AbstractLexer : ILexer
internal abstract class AbstractLexer : ILexer
{
TextReader reader;
int col = 1;
@ -95,6 +95,14 @@ namespace ICSharpCode.NRefactory.Parser @@ -95,6 +95,14 @@ namespace ICSharpCode.NRefactory.Parser
return reader.Peek();
}
public void SetInitialLocation(Location location)
{
if (lastToken != null || curToken != null || peekToken != null)
throw new InvalidOperationException();
this.line = location.Line;
this.col = location.Column;
}
public Errors Errors {
get {
return errors;

5
src/Libraries/NRefactory/Project/Src/Lexer/ILexer.cs

@ -15,6 +15,11 @@ namespace ICSharpCode.NRefactory.Parser @@ -15,6 +15,11 @@ namespace ICSharpCode.NRefactory.Parser
/// </summary>
public interface ILexer : IDisposable
{
/// <summary>
/// Sets the start line/column number. This method can be called only before the first token is read.
/// </summary>
void SetInitialLocation(Location location);
Errors Errors {
get;
}

3
src/Libraries/SharpTreeView/ICSharpCode.TreeView.Demo/ICSharpCode.TreeView.Demo.csproj

@ -37,6 +37,9 @@ @@ -37,6 +37,9 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>

2
src/Libraries/SharpTreeView/ICSharpCode.TreeView.Demo/Window1.xaml

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<Window x:Class="ICSharpCode.TreeView.Demo.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sd="http://sharpdevelop.net"
xmlns:sd="http://icsharpcode.net/sharpdevelop/treeview"
Title="SharpTreeView Demo"
SnapsToDevicePixels="True"
Background="{x:Static SystemColors.ControlBrush}">

71
src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditDocumentAdapter.cs

@ -44,15 +44,6 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit @@ -44,15 +44,6 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
this.document = new TextDocument();
}
/// <summary>
/// Creates a new document.
/// </summary>
public AvalonEditDocumentAdapter(IServiceProvider parentServiceProvider)
{
this.document = new TextDocument();
this.parentServiceProvider = parentServiceProvider;
}
sealed class LineAdapter : IDocumentLine
{
readonly TextDocument document;
@ -173,6 +164,11 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit @@ -173,6 +164,11 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
return document.CreateSnapshot().CreateReader();
}
public System.IO.TextReader CreateReader(int offset, int length)
{
return document.CreateSnapshot(offset, length).CreateReader();
}
#region Snapshots and ITextBufferVersion
public ITextBuffer CreateSnapshot()
{
@ -379,5 +375,62 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit @@ -379,5 +375,62 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
}
}
#endregion
#region Changing/Changed events
EventHandler<TextChangeEventArgs> changing, changed;
bool eventsAreAttached;
void AttachEvents()
{
if (!eventsAreAttached && (changing != null || changed != null)) {
eventsAreAttached = true;
document.Changing += document_Changing;
document.Changed += document_Changed;
}
}
void DetachEvents()
{
if (eventsAreAttached && changing == null && changed == null) {
eventsAreAttached = false;
document.Changing -= document_Changing;
document.Changed -= document_Changed;
}
}
void document_Changing(object sender, DocumentChangeEventArgs e)
{
if (changing != null)
changing(this, new TextChangeEventArgs(e.Offset, e.RemovedText, e.InsertedText));
}
void document_Changed(object sender, DocumentChangeEventArgs e)
{
if (changed != null)
changed(this, new TextChangeEventArgs(e.Offset, e.RemovedText, e.InsertedText));
}
public event EventHandler<TextChangeEventArgs> Changing {
add {
changing += value;
AttachEvents();
}
remove {
changing -= value;
DetachEvents();
}
}
public event EventHandler<TextChangeEventArgs> Changed {
add {
changed += value;
AttachEvents();
}
remove {
changed -= value;
DetachEvents();
}
}
#endregion
}
}

8
src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextSourceAdapter.cs

@ -50,6 +50,14 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit @@ -50,6 +50,14 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
return textSource.CreateReader();
}
/// <summary>
/// Creates a new TextReader to read from this text buffer.
/// </summary>
public System.IO.TextReader CreateReader(int offset, int length)
{
return textSource.CreateSnapshot(offset, length).CreateReader();
}
public int TextLength {
get { return textSource.TextLength; }
}

12
src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionBinding.cs

@ -168,18 +168,26 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -168,18 +168,26 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
}
}
protected virtual void InitializeOpenedInsightWindow(ITextEditor editor, IInsightWindow insightWindow)
{
}
public virtual CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
{
switch (ch) {
case '(':
if (enableMethodInsight && CodeCompletionOptions.InsightEnabled) {
editor.ShowInsightWindow(new MethodInsightProvider().ProvideInsight(editor));
IInsightWindow insightWindow = editor.ShowInsightWindow(new MethodInsightProvider().ProvideInsight(editor));
if (insightWindow != null)
InitializeOpenedInsightWindow(editor, insightWindow);
return CodeCompletionKeyPressResult.Completed;
}
break;
case '[':
if (enableIndexerInsight && CodeCompletionOptions.InsightEnabled) {
editor.ShowInsightWindow(new IndexerInsightProvider().ProvideInsight(editor));
IInsightWindow insightWindow = editor.ShowInsightWindow(new IndexerInsightProvider().ProvideInsight(editor));
if (insightWindow != null)
InitializeOpenedInsightWindow(editor, insightWindow);
return CodeCompletionKeyPressResult.Completed;
}
break;

10
src/Main/Base/Project/Src/Editor/CodeCompletion/IInsightWindow.cs

@ -24,5 +24,15 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -24,5 +24,15 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
/// Gets/Sets the item that is currently selected.
/// </summary>
IInsightItem SelectedItem { get; set; }
/// <summary>
/// Occurs when the document is changed while the insight window is open.
/// Use this event to close the insight window or adjust <see cref="EndOffset"/>.
/// </summary>
/// <remarks>
/// Unlike directly attaching to <see cref="IDocument.TextChanged"/>, using the event does not require handlers to unsubscribe
/// when the insight window is closed. This makes it easier to avoid memory leaks.
/// </remarks>
event EventHandler<TextChangeEventArgs> DocumentChanged;
}
}

41
src/Main/Base/Project/Src/Editor/CodeCompletion/NRefactoryCodeCompletionBinding.cs

@ -27,7 +27,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -27,7 +27,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
public abstract class NRefactoryCodeCompletionBinding : DefaultCodeCompletionBinding
{
readonly SupportedLanguage language;
readonly int eofToken, commaToken, openParensToken, closeParensToken, openBracketToken, closeBracketToken, openBracesToken, closeBracesToken;
readonly int eofToken, commaToken, openParensToken, closeParensToken, openBracketToken, closeBracketToken, openBracesToken, closeBracesToken, statementEndToken;
readonly LanguageProperties languageProperties;
protected NRefactoryCodeCompletionBinding(SupportedLanguage language)
@ -42,6 +42,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -42,6 +42,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
closeBracketToken = CSTokens.CloseSquareBracket;
openBracesToken = CSTokens.OpenCurlyBrace;
closeBracesToken = CSTokens.CloseCurlyBrace;
statementEndToken = CSTokens.Semicolon;
languageProperties = LanguageProperties.CSharp;
} else {
@ -53,6 +54,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -53,6 +54,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
closeBracketToken = -1;
openBracesToken = VBTokens.OpenCurlyBrace;
closeBracesToken = VBTokens.CloseCurlyBrace;
statementEndToken = VBTokens.EOL;
languageProperties = LanguageProperties.VBNet;
}
@ -225,6 +227,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -225,6 +227,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
}
IInsightWindow insightWindow = editor.ShowInsightWindow(insightItems);
if (insightWindow != null) {
InitializeOpenedInsightWindow(editor, insightWindow);
insightWindow.SelectedItem = insightItems[defaultIndex];
}
if (overloadIsSure) {
@ -264,5 +267,41 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -264,5 +267,41 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
return null;
}
}
protected override void InitializeOpenedInsightWindow(ITextEditor editor, IInsightWindow insightWindow)
{
EventHandler<TextChangeEventArgs> onDocumentChanged = delegate {
// whenever the document is changed, recalculate EndOffset
var remainingDocument = editor.Document.CreateReader(insightWindow.StartOffset, editor.Document.TextLength - insightWindow.StartOffset);
using (ILexer lexer = ParserFactory.CreateLexer(language, remainingDocument)) {
lexer.SetInitialLocation(editor.Document.OffsetToPosition(insightWindow.StartOffset));
Token token;
int bracketCount = 0;
while ((token = lexer.NextToken()) != null && token.Kind != eofToken) {
if (token.Kind == openParensToken || token.Kind == openBracketToken || token.Kind == openBracketToken) {
bracketCount++;
} else if (token.Kind == closeParensToken || token.Kind == closeBracketToken || token.Kind == closeBracesToken) {
bracketCount--;
if (bracketCount <= 0) {
MarkInsightWindowEndOffset(insightWindow, editor, token.Location);
break;
}
} else if (token.Kind == statementEndToken) {
MarkInsightWindowEndOffset(insightWindow, editor, token.Location);
break;
}
}
}
};
insightWindow.DocumentChanged += onDocumentChanged;
onDocumentChanged(null, null);
}
void MarkInsightWindowEndOffset(IInsightWindow insightWindow, ITextEditor editor, Location endLocation)
{
insightWindow.EndOffset = editor.Document.PositionToOffset(endLocation.Line, endLocation.Column);
if (editor.Caret.Offset > insightWindow.EndOffset)
insightWindow.Close();
}
}
}

3
src/Main/Base/Project/Src/Editor/IDocument.cs

@ -66,5 +66,8 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -66,5 +66,8 @@ namespace ICSharpCode.SharpDevelop.Editor
/// Creates a new text anchor at the specified position.
/// </summary>
ITextAnchor CreateAnchor(int offset);
event EventHandler<TextChangeEventArgs> Changing;
event EventHandler<TextChangeEventArgs> Changed;
}
}

5
src/Main/Base/Project/Src/Editor/ITextBuffer.cs

@ -43,6 +43,11 @@ namespace ICSharpCode.SharpDevelop @@ -43,6 +43,11 @@ namespace ICSharpCode.SharpDevelop
/// </summary>
TextReader CreateReader();
/// <summary>
/// Creates a new TextReader to read from this text buffer.
/// </summary>
TextReader CreateReader(int offset, int length);
/// <summary>
/// Gets the total text length.
/// </summary>

5
src/Main/Base/Project/Src/Editor/RefactoringDocumentAdapter.cs

@ -60,11 +60,6 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -60,11 +60,6 @@ namespace ICSharpCode.SharpDevelop.Editor
}
}
public event EventHandler TextChanged {
add { document.TextChanged += value; }
remove { document.TextChanged -= value; }
}
public int TextLength {
get { return document.TextLength; }
}

24
src/Main/Base/Project/Src/Services/RefactoringService/TextEditorDocument.cs

@ -20,6 +20,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -20,6 +20,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
/// <summary>
/// Use this class to pass a text editor document to the refactoring API.
/// </summary>
[Obsolete]
public sealed class TextEditorDocument : ICSharpCode.SharpDevelop.Editor.IDocument
{
ICSharpCode.TextEditor.Document.IDocument doc;
@ -190,6 +191,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -190,6 +191,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring
return CreateSnapshot().CreateReader();
}
public System.IO.TextReader CreateReader(int offset, int length)
{
return CreateSnapshot(offset, length).CreateReader();
}
public ITextBuffer CreateSnapshot()
{
return new StringTextBuffer(Gui.WorkbenchSingleton.SafeThreadFunction<string>(() => this.Text));
@ -300,5 +306,23 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -300,5 +306,23 @@ namespace ICSharpCode.SharpDevelop.Refactoring
get { return anchor.ColumnNumber + 1; }
}
}
event EventHandler<TextChangeEventArgs> ICSharpCode.SharpDevelop.Editor.IDocument.Changing {
add {
throw new NotImplementedException();
}
remove {
throw new NotImplementedException();
}
}
event EventHandler<TextChangeEventArgs> ICSharpCode.SharpDevelop.Editor.IDocument.Changed {
add {
throw new NotImplementedException();
}
remove {
throw new NotImplementedException();
}
}
}
}

2
src/Main/Base/Test/Utils/MockTextMarkerService.cs

@ -24,7 +24,7 @@ namespace ICSharpCode.SharpDevelop.Tests.Utils @@ -24,7 +24,7 @@ namespace ICSharpCode.SharpDevelop.Tests.Utils
ServiceContainer container = new ServiceContainer();
container.AddService(typeof(ITextMarkerService), new MockTextMarkerService());
return new AvalonEditDocumentAdapter(container);
return new AvalonEditDocumentAdapter(new ICSharpCode.AvalonEdit.Document.TextDocument(), container);
}
List<ITextMarker> markers;

5
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/IRefactoringDocument.cs

@ -35,11 +35,6 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring @@ -35,11 +35,6 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
/// </summary>
string Text { get; set; }
/// <summary>
/// Is raised when the Text property changes.
/// </summary>
event EventHandler TextChanged;
/// <summary>
/// Gets the document line with the specified number.
/// </summary>

Loading…
Cancel
Save