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)
6
using System.Windows.Controls;
7
using ICSharpCode.AvalonEdit.Editing;
8
using ICSharpCode.AvalonEdit.Utils;
10
namespace ICSharpCode.AvalonEdit.CodeCompletion
13
/// A popup-like window that is attached to a text segment.
15
public class InsightWindow : CompletionWindowBase
17
static InsightWindow()
19
DefaultStyleKeyProperty.OverrideMetadata(typeof(InsightWindow),
20
new FrameworkPropertyMetadata(typeof(InsightWindow)));
21
AllowsTransparencyProperty.OverrideMetadata(typeof(InsightWindow),
22
new FrameworkPropertyMetadata(Boxes.True));
26
/// Creates a new InsightWindow.
28
public InsightWindow(TextArea textArea) : base(textArea)
30
this.CloseAutomatically = true;
33
Rect caret = this.TextArea.Caret.CalculateCaretRectangle();
34
Rect workingArea = System.Windows.Forms.Screen.FromPoint(caret.Location.ToSystemDrawing()).WorkingArea.ToWpf();
36
MaxHeight = workingArea.Height;
37
MaxWidth = Math.Min(workingArea.Width, Math.Max(1000, workingArea.Width * 0.6));
41
/// Gets/Sets whether the insight window should close automatically.
42
/// The default value is true.
44
public bool CloseAutomatically { get; set; }
47
protected override bool CloseOnFocusLost {
48
get { return this.CloseAutomatically; }
53
this.TextArea.Caret.PositionChanged += CaretPositionChanged;
57
protected override void DetachEvents()
59
this.TextArea.Caret.PositionChanged -= CaretPositionChanged;
63
void CaretPositionChanged(object sender, EventArgs e)
65
if (this.CloseAutomatically) {
66
int offset = this.TextArea.Caret.Offset;
67
if (offset < this.StartOffset || offset > this.EndOffset) {
75
/// TemplateSelector for InsightWindow to replace plain string content by a TextBlock with TextWrapping.
77
internal sealed class InsightWindowTemplateSelector : DataTemplateSelector
80
public override DataTemplate SelectTemplate(object item, DependencyObject container)
83
return (DataTemplate)((FrameworkElement)container).FindResource("TextBlockTemplate");