1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Windows.Controls.Primitives;
6
using ICSharpCode.Core.Presentation;
7
using ICSharpCode.SharpDevelop.Editor;
8
using ICSharpCode.SharpDevelop.Gui;
10
namespace ICSharpCode.AvalonEdit.AddIn.HiddenDefinition
12
public class HiddenDefinitionRenderer : IDisposable
14
private CodeEditorView editor;
15
private ExtendedPopup popup = new ExtendedPopup();
16
private HiddenDefinitionControl control;
18
public HiddenDefinitionRenderer(CodeEditorView editorView)
20
this.editor = editorView;
21
control = new HiddenDefinitionControl();
22
WorkbenchSingleton.Workbench.ActiveContentChanged += WorkbenchSingleton_Workbench_ActiveContentChanged;
25
public BracketSearchResult BracketSearchResult { get; set; }
29
WorkbenchSingleton.Workbench.ActiveContentChanged -= WorkbenchSingleton_Workbench_ActiveContentChanged;
34
public void ClosePopup()
44
if (BracketSearchResult == null) return;
46
// verify if we have a open bracket
47
if (this.editor.Document.GetCharAt(BracketSearchResult.OpeningBracketOffset) != '{')
50
var line = GetLineText(BracketSearchResult.OpeningBracketOffset);
51
if(line == null) return;
53
control.DefinitionText = line;
54
popup.Child = control;
55
popup.HorizontalOffset = 70;
56
popup.Placement = PlacementMode.Relative;
57
popup.PlacementTarget = editor.TextArea;
62
/// Gets the line text near the offset.
64
/// <param name="offset">Offset.</param>
65
/// <returns></returns>
66
private string GetLineText(int offset)
68
if (!editor.TextArea.TextView.VisualLinesValid)
72
var documentLine = editor.Document.GetLineByOffset(offset);
73
string documentText = editor.Document.Text;
74
string lineText = string.Empty;
78
if (documentLine == null || documentLine.IsDeleted) return null;
79
off = documentLine.Offset;
80
length = documentLine.Length;
81
lineText = documentText.Substring(off, length).Trim();
83
documentLine = documentLine.PreviousLine;
85
while (lineText == "{" || string.IsNullOrEmpty(lineText) ||
86
lineText.StartsWith("//") || lineText.StartsWith("/*") ||
87
lineText.StartsWith("*") || lineText.StartsWith("'"));
89
// check whether the line is visible
90
if (editor.TextArea.TextView.VisualLines[0].StartOffset > off) {
91
return this.editor.TextArea.TextView.Document.GetText(off, length);
97
private void WorkbenchSingleton_Workbench_ActiveContentChanged(object sender, EventArgs e)
b'\\ No newline at end of file'