Browse Source

AvalonEdit Insight Window

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4034 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
d83dbd9f16
  1. 1
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/QuickClassBrowser.cs
  2. 19
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/CompletionWindowBase.cs
  3. 95
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/InsightWindow.cs
  4. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj
  5. 4
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  6. 38
      src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditInsightWindow.cs
  7. 20
      src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextEditorAdapter.cs
  8. 2
      src/Main/Base/Project/Src/Editor/CodeCompletion/ICompletionItemList.cs
  9. 20
      src/Main/Base/Project/Src/Editor/CodeCompletion/IInsightItem.cs
  10. 51
      src/Main/Base/Project/Src/Editor/CodeCompletion/IInsightWindow.cs
  11. 15
      src/Main/Base/Project/Src/Editor/ITextEditor.cs
  12. 1
      src/Main/Base/Project/Src/Gui/AbstractViewContent.cs
  13. 2
      src/Main/Base/Project/Src/Services/File/OpenedFile.cs
  14. 15
      src/Main/Base/Project/Src/TextEditor/Gui/TextEditorAdapter.cs

1
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/QuickClassBrowser.cs

@ -21,6 +21,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -21,6 +21,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// </summary>
public partial class QuickClassBrowser : UserControl
{
// type codes are used for sorting entities by type
const int TYPE_CLASS = 0;
const int TYPE_CONSTRUCTOR = 1;
const int TYPE_METHOD = 2;

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

@ -82,13 +82,13 @@ namespace ICSharpCode.AvalonEdit.CodeCompletion @@ -82,13 +82,13 @@ namespace ICSharpCode.AvalonEdit.CodeCompletion
void textArea_PreviewKeyDown(object sender, KeyEventArgs e)
{
e.Handled = RaiseEventPair(this, PreviewKeyDownEvent, KeyDownEvent,
new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, e.Key));
new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, e.Key));
}
void textArea_PreviewKeyUp(object sender, KeyEventArgs e)
{
e.Handled = RaiseEventPair(this, PreviewKeyUpEvent, KeyUpEvent,
new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, e.Key));
new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, e.Key));
}
void TextViewScrollOffsetChanged(object sender, EventArgs e)
@ -162,12 +162,21 @@ namespace ICSharpCode.AvalonEdit.CodeCompletion @@ -162,12 +162,21 @@ namespace ICSharpCode.AvalonEdit.CodeCompletion
void CloseIfFocusLost()
{
Debug.WriteLine("CloseIfFocusLost: this.IsActive=" + this.IsActive + " IsTextAreaFocused=" + IsTextAreaFocused);
if (!this.IsActive && !IsTextAreaFocused) {
Close();
if (CloseOnFocusLost) {
Debug.WriteLine("CloseIfFocusLost: this.IsActive=" + this.IsActive + " IsTextAreaFocused=" + IsTextAreaFocused);
if (!this.IsActive && !IsTextAreaFocused) {
Close();
}
}
}
/// <summary>
/// Gets whether the completion window should automatically close when the text editor looses focus.
/// </summary>
protected virtual bool CloseOnFocusLost {
get { return true; }
}
bool IsTextAreaFocused {
get {
if (parentWindow != null && !parentWindow.IsActive)

95
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/InsightWindow.cs

@ -0,0 +1,95 @@ @@ -0,0 +1,95 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows;
using ICSharpCode.AvalonEdit.Document;
using System.Windows.Controls;
namespace ICSharpCode.AvalonEdit.CodeCompletion
{
/// <summary>
/// A popup-like window.
/// </summary>
public class InsightWindow : CompletionWindowBase
{
TextDocument document;
int startOffset;
int endOffset;
/// <summary>
/// Creates a new InsightWindow.
/// </summary>
public InsightWindow(TextArea textArea) : base(textArea)
{
this.SizeToContent = SizeToContent.WidthAndHeight;
// prevent user from resizing window to 0x0
this.MinHeight = 15;
this.MinWidth = 30;
startOffset = endOffset = this.TextArea.Caret.Offset;
}
/// <summary>
/// Gets/Sets whether the insight window should close automatically.
/// The default value is true.
/// </summary>
public bool CloseAutomatically { get; set; }
/// <inheritdoc/>
protected override bool CloseOnFocusLost {
get { return this.CloseAutomatically; }
}
/// <summary>
/// Gets/Sets the start of the text range in which the insight window stays open.
/// Has no effect if CloseAutomatically is false.
/// </summary>
public int StartOffset { get; set; }
/// <summary>
/// Gets/Sets the end of the text range in which the insight window stays open.
/// Has no effect if CloseAutomatically is false.
/// </summary>
public int EndOffset { get; set; }
/// <inheritdoc/>
protected override void AttachEvents()
{
base.AttachEvents();
document = this.TextArea.Document;
if (document != null) {
document.Changing += textArea_Document_Changing;
}
this.TextArea.Caret.PositionChanged += CaretPositionChanged;
}
/// <inheritdoc/>
protected override void DetachEvents()
{
if (document != null) {
document.Changing -= textArea_Document_Changing;
}
this.TextArea.Caret.PositionChanged -= CaretPositionChanged;
base.DetachEvents();
}
void textArea_Document_Changing(object sender, DocumentChangeEventArgs e)
{
startOffset = e.GetNewOffset(startOffset, AnchorMovementType.BeforeInsertion);
endOffset = e.GetNewOffset(endOffset, AnchorMovementType.AfterInsertion);
}
void CaretPositionChanged(object sender, EventArgs e)
{
int offset = this.TextArea.Caret.Offset;
if (offset < startOffset || offset > endOffset) {
Close();
}
}
}
}

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj

@ -80,6 +80,7 @@ @@ -80,6 +80,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="CodeCompletion\ICompletionData.cs" />
<Compile Include="CodeCompletion\InsightWindow.cs" />
<Compile Include="Document\DocumentChangeOperation.cs">
<DependentUpon>UndoStack.cs</DependentUpon>
</Compile>

4
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -69,6 +69,8 @@ @@ -69,6 +69,8 @@
<ItemGroup>
<Compile Include="Src\Commands\SharpDevelopRoutedCommands.cs" />
<Compile Include="Src\Editor\AvalonEdit\AvalonEditDocumentAdapter.cs" />
<Compile Include="Src\Editor\AvalonEdit\AvalonEditInsightWindow.cs">
</Compile>
<Compile Include="Src\Editor\AvalonEdit\AvalonEditTextEditorAdapter.cs" />
<Compile Include="Src\Editor\AvalonEdit\IndentationStrategyAdapter.cs" />
<Compile Include="Src\Editor\CodeCompletion\AttributesItemProvider.cs" />
@ -81,6 +83,8 @@ @@ -81,6 +83,8 @@
<Compile Include="Src\Editor\CodeCompletion\CtrlSpaceCompletionItemProvider.cs" />
<Compile Include="Src\Editor\CodeCompletion\ICompletionItem.cs" />
<Compile Include="Src\Editor\CodeCompletion\ICompletionItemList.cs" />
<Compile Include="Src\Editor\CodeCompletion\IInsightItem.cs" />
<Compile Include="Src\Editor\CodeCompletion\IInsightWindow.cs" />
<Compile Include="Src\Editor\CodeCompletion\NRefactoryCodeCompletionBinding.cs" />
<Compile Include="Src\Editor\CodeCompletion\TemplateCompletionItemProvider.cs" />
<Compile Include="Src\Editor\CodeCompletion\TextCompletionItemProvider.cs" />

38
src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditInsightWindow.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.AvalonEdit;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ICSharpCode.AvalonEdit.CodeCompletion;
namespace ICSharpCode.SharpDevelop.Editor
{
public class AvalonEditInsightWindow : InsightWindow, IInsightWindow
{
public AvalonEditInsightWindow(TextArea textArea) : base(textArea)
{
}
ObservableCollection<IInsightItem> items = new ObservableCollection<IInsightItem>();
public IList<IInsightItem> Items {
get { return items; }
}
public IInsightItem SelectedItem {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
}
}

20
src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextEditorAdapter.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
@ -129,7 +130,7 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -129,7 +130,7 @@ namespace ICSharpCode.SharpDevelop.Editor
public virtual void ShowCompletionWindow(ICompletionItemList data)
{
}
public object GetService(Type serviceType)
{
return textEditor.TextArea.GetService(serviceType);
@ -172,5 +173,22 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -172,5 +173,22 @@ namespace ICSharpCode.SharpDevelop.Editor
textEditor.TextArea.Caret.Position = new TextViewPosition(line, column, -1);
textEditor.TextArea.Caret.BringCaretToView();
}
AvalonEditInsightWindow activeInsightWindow;
public virtual IInsightWindow ActiveInsightWindow {
get {
return activeInsightWindow;
}
}
public virtual IInsightWindow OpenInsightWindow(IEnumerable<IInsightItem> items)
{
activeInsightWindow = new AvalonEditInsightWindow(textEditor.TextArea);
activeInsightWindow.Items.AddRange(items);
activeInsightWindow.SelectedItem = activeInsightWindow.Items[0];
return activeInsightWindow;
}
}
}

2
src/Main/Base/Project/Src/Editor/CodeCompletion/ICompletionItemList.cs

@ -18,7 +18,7 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -18,7 +18,7 @@ namespace ICSharpCode.SharpDevelop.Editor
IEnumerable<ICompletionItem> Items { get; }
/// <summary>
/// Gets/sets the suggested item.
/// Gets the suggested item.
/// This item will be pre-selected in the completion list.
/// </summary>
ICompletionItem SuggestedItem { get; }

20
src/Main/Base/Project/Src/Editor/CodeCompletion/IInsightItem.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.SharpDevelop.Editor
{
/// <summary>
/// An item in the insight window.
/// </summary>
public interface IInsightItem
{
object Header { get; }
object Content { get; }
}
}

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

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
namespace ICSharpCode.SharpDevelop.Editor
{
/// <summary>
/// Describes a set of insight items (e.g. multiple overloads of a method) to be displayed in the insight window.
/// </summary>
public interface IInsightWindow
{
/// <summary>
/// Gets the items to display.
/// </summary>
IList<IInsightItem> Items { get; }
/// <summary>
/// Gets/Sets the item that is currently selected.
/// </summary>
IInsightItem SelectedItem { get; set; }
/// <summary>
/// Gets/Sets whether the insight window should close automatically.
/// The default value is true.
/// </summary>
bool CloseAutomatically { get; set; }
/// <summary>
/// Gets/Sets the start of the text range in which the insight window stays open.
/// Has no effect if CloseAutomatically is false.
/// </summary>
int StartOffset { get; set; }
/// <summary>
/// Gets/Sets the end of the text range in which the insight window stays open.
/// Has no effect if CloseAutomatically is false.
/// </summary>
int EndOffset { get; set; }
/// <summary>
/// Closes the insight window.
/// </summary>
void Close();
}
}

15
src/Main/Base/Project/Src/Editor/ITextEditor.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using ICSharpCode.NRefactory;
using System.Collections.Generic;
namespace ICSharpCode.SharpDevelop.Editor
{
@ -60,10 +61,24 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -60,10 +61,24 @@ namespace ICSharpCode.SharpDevelop.Editor
string FileName { get; }
[Obsolete]
void ShowInsightWindow(ICSharpCode.TextEditor.Gui.InsightWindow.IInsightDataProvider provider);
[Obsolete]
void ShowCompletionWindow(ICSharpCode.TextEditor.Gui.CompletionWindow.ICompletionDataProvider provider, char ch);
void ShowCompletionWindow(ICompletionItemList data);
/// <summary>
/// Open a new insight window showing the specific insight items.
/// </summary>
/// <param name="items">The insight items to show in the window.</param>
/// <returns>The insight window.</returns>
IInsightWindow OpenInsightWindow(IEnumerable<IInsightItem> items);
/// <summary>
/// Gets the insight window that is currently open.
/// </summary>
IInsightWindow ActiveInsightWindow { get; }
}
public interface ITextEditorOptions

1
src/Main/Base/Project/Src/Gui/AbstractViewContent.cs

@ -229,6 +229,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -229,6 +229,7 @@ namespace ICSharpCode.SharpDevelop.Gui
/// </summary>
public virtual OpenedFile PrimaryFile {
get {
WorkbenchSingleton.AssertMainThread();
if (files.Count != 0)
return files[0];
else

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

@ -90,6 +90,8 @@ namespace ICSharpCode.SharpDevelop @@ -90,6 +90,8 @@ namespace ICSharpCode.SharpDevelop
protected virtual void ChangeFileName(string newValue)
{
WorkbenchSingleton.AssertMainThread();
fileName = newValue;
if (FileNameChanged != null) {

15
src/Main/Base/Project/Src/TextEditor/Gui/TextEditorAdapter.cs

@ -5,11 +5,13 @@ @@ -5,11 +5,13 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Editor;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Refactoring;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Actions;
@ -196,6 +198,17 @@ namespace ICSharpCode.SharpDevelop @@ -196,6 +198,17 @@ namespace ICSharpCode.SharpDevelop
{
sdtac.ActiveTextAreaControl.JumpTo(line - 1, column - 1);
}
public IInsightWindow ActiveInsightWindow {
get {
return null;
}
}
public IInsightWindow OpenInsightWindow(IEnumerable<IInsightItem> items)
{
throw new NotImplementedException();
}
}
sealed class CompletionItemListAdapter : ICompletionDataProvider

Loading…
Cancel
Save