Browse Source

move textmarker tooltip support to AddIn tree

newNRvisualizers
Siegfried Pammer 13 years ago
parent
commit
ae7aec8d8c
  1. 6
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.addin
  2. 1
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  3. 88
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs
  4. 115
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerToolTipProvider.cs

6
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.addin

@ -36,6 +36,12 @@ @@ -36,6 +36,12 @@
class="ICSharpCode.AvalonEdit.AddIn.AvalonEditorControlService"/>
</Path>
<Path name = "/SharpDevelop/ViewContent/TextEditor/ToolTips">
<Class id = "DefaultTextMarkerToolTips"
insertafter="DefaultDebuggerToolTips"
class = "ICSharpCode.AvalonEdit.AddIn.TextMarkerToolTipProvider"/>
</Path>
<!--
<Path name = "/SharpDevelop/ViewContent/TextEditor/ContextMenu">
<Condition name = "WindowActive" activewindow="ICSharpCode.AvalonEdit.AddIn.ICodeEditorProvider">

1
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -118,6 +118,7 @@ @@ -118,6 +118,7 @@
<Compile Include="Src\SyntaxHighlighting\MultiHighlighter.cs" />
<Compile Include="Src\Snippets\CodeSnippetComparer.cs" />
<Compile Include="Src\SyntaxHighlighting\SyntaxModeDoozer.cs" />
<Compile Include="Src\TextMarkerToolTipProvider.cs" />
<Compile Include="Src\Utils.cs" />
<Compile Include="Src\XmlDoc\DocumentationUIBuilder.cs" />
<Compile Include="Src\XmlDoc\XmlDocTooltipProvider.cs" />

88
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs

@ -247,30 +247,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -247,30 +247,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
args.LogicalPosition = pos.Value.Location;
}
if (args.InDocument) {
int offset = args.Editor.Document.GetOffset(args.LogicalPosition);
FoldingManager foldings = this.Adapter.GetService(typeof(FoldingManager)) as FoldingManager;
if (foldings != null) {
var foldingsAtOffset = foldings.GetFoldingsAt(offset);
FoldingSection collapsedSection = foldingsAtOffset.FirstOrDefault(section => section.IsFolded);
if (collapsedSection != null) {
args.SetToolTip(GetTooltipTextForCollapsedSection(collapsedSection));
}
}
TextMarkerService textMarkerService = this.Adapter.GetService(typeof(ITextMarkerService)) as TextMarkerService;
if (textMarkerService != null) {
var markersAtOffset = textMarkerService.GetMarkersAtOffset(offset);
ITextMarker markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null);
if (markerWithToolTip != null) {
args.SetToolTip(markerWithToolTip.ToolTip);
}
}
}
if (!args.Handled) {
// if request wasn't handled by a marker, pass it to the ToolTipRequestService
ToolTipRequestService.RequestToolTip(args);
@ -366,70 +342,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -366,70 +342,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
{
toolTip = null;
}
#region GetTooltipTextForCollapsedSection
string GetTooltipTextForCollapsedSection(FoldingSection foldingSection)
{
// This fixes SD-1394:
// Each line is checked for leading indentation whitespaces. If
// a line has the same or more indentation than the first line,
// it is reduced. If a line is less indented than the first line
// the indentation is removed completely.
//
// See the following example:
// line 1
// line 2
// line 3
// line 4
//
// is reduced to:
// line 1
// line 2
// line 3
// line 4
const int maxLineCount = 15;
TextDocument document = this.Document;
int startOffset = foldingSection.StartOffset;
int endOffset = foldingSection.EndOffset;
DocumentLine startLine = document.GetLineByOffset(startOffset);
DocumentLine endLine = document.GetLineByOffset(endOffset);
StringBuilder builder = new StringBuilder();
DocumentLine current = startLine;
ISegment startIndent = TextUtilities.GetLeadingWhitespace(document, startLine);
int lineCount = 0;
while (current != endLine.NextLine && lineCount < maxLineCount) {
ISegment currentIndent = TextUtilities.GetLeadingWhitespace(document, current);
if (current == startLine && current == endLine)
builder.Append(document.GetText(startOffset, endOffset - startOffset));
else if (current == startLine) {
if (current.EndOffset - startOffset > 0)
builder.AppendLine(document.GetText(startOffset, current.EndOffset - startOffset).TrimStart());
} else if (current == endLine) {
if (startIndent.Length <= currentIndent.Length)
builder.Append(document.GetText(current.Offset + startIndent.Length, endOffset - current.Offset - startIndent.Length));
else
builder.Append(document.GetText(current.Offset + currentIndent.Length, endOffset - current.Offset - currentIndent.Length));
} else {
if (startIndent.Length <= currentIndent.Length)
builder.AppendLine(document.GetText(current.Offset + startIndent.Length, current.Length - startIndent.Length));
else
builder.AppendLine(document.GetText(current.Offset + currentIndent.Length, current.Length - currentIndent.Length));
}
current = current.NextLine;
lineCount++;
}
if (current != endLine.NextLine)
builder.Append("...");
return builder.ToString();
}
#endregion
#endregion
#region Ctrl+Click Go To Definition

115
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerToolTipProvider.cs

@ -0,0 +1,115 @@ @@ -0,0 +1,115 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.AvalonEdit.AddIn
{
/// <summary>
/// Description of TextMarkerToolTipProvider.
/// </summary>
public class TextMarkerToolTipProvider : ITextAreaToolTipProvider
{
public void HandleToolTipRequest(ToolTipRequestEventArgs args)
{
if (args.InDocument) {
int offset = args.Editor.Document.GetOffset(args.LogicalPosition);
FoldingManager foldings = args.Editor.GetService(typeof(FoldingManager)) as FoldingManager;
if (foldings != null) {
var foldingsAtOffset = foldings.GetFoldingsAt(offset);
FoldingSection collapsedSection = foldingsAtOffset.FirstOrDefault(section => section.IsFolded);
if (collapsedSection != null) {
args.SetToolTip(GetTooltipTextForCollapsedSection(args, collapsedSection));
}
}
TextMarkerService textMarkerService = args.Editor.GetService(typeof(ITextMarkerService)) as TextMarkerService;
if (textMarkerService != null) {
var markersAtOffset = textMarkerService.GetMarkersAtOffset(offset);
ITextMarker markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null);
if (markerWithToolTip != null) {
args.SetToolTip(markerWithToolTip.ToolTip);
}
}
}
}
string GetTooltipTextForCollapsedSection(ToolTipRequestEventArgs args, FoldingSection foldingSection)
{
// This fixes SD-1394:
// Each line is checked for leading indentation whitespaces. If
// a line has the same or more indentation than the first line,
// it is reduced. If a line is less indented than the first line
// the indentation is removed completely.
//
// See the following example:
// line 1
// line 2
// line 3
// line 4
//
// is reduced to:
// line 1
// line 2
// line 3
// line 4
const int maxLineCount = 15;
TextDocument document = (TextDocument)args.Editor.Document;
int startOffset = foldingSection.StartOffset;
int endOffset = foldingSection.EndOffset;
DocumentLine startLine = document.GetLineByOffset(startOffset);
DocumentLine endLine = document.GetLineByOffset(endOffset);
StringBuilder builder = new StringBuilder();
DocumentLine current = startLine;
ISegment startIndent = TextUtilities.GetLeadingWhitespace(document, startLine);
int lineCount = 0;
while (current != endLine.NextLine && lineCount < maxLineCount) {
ISegment currentIndent = TextUtilities.GetLeadingWhitespace(document, current);
if (current == startLine && current == endLine)
builder.Append(document.GetText(startOffset, endOffset - startOffset));
else if (current == startLine) {
if (current.EndOffset - startOffset > 0)
builder.AppendLine(document.GetText(startOffset, current.EndOffset - startOffset).TrimStart());
} else if (current == endLine) {
if (startIndent.Length <= currentIndent.Length)
builder.Append(document.GetText(current.Offset + startIndent.Length, endOffset - current.Offset - startIndent.Length));
else
builder.Append(document.GetText(current.Offset + currentIndent.Length, endOffset - current.Offset - currentIndent.Length));
} else {
if (startIndent.Length <= currentIndent.Length)
builder.AppendLine(document.GetText(current.Offset + startIndent.Length, current.Length - startIndent.Length));
else
builder.AppendLine(document.GetText(current.Offset + currentIndent.Length, current.Length - currentIndent.Length));
}
current = current.NextLine;
lineCount++;
}
if (current != endLine.NextLine)
builder.Append("...");
return builder.ToString();
}
}
}
Loading…
Cancel
Save