Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3883 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
22 changed files with 571 additions and 86 deletions
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.ObjectModel; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Integrates AvalonEdit with SharpDevelop.
|
||||
/// </summary>
|
||||
public class CodeEditor : TextEditor |
||||
{ |
||||
readonly CodeEditorAdapter textEditorAdapter; |
||||
internal string FileName; |
||||
|
||||
public CodeEditor() |
||||
{ |
||||
textEditorAdapter = new CodeEditorAdapter(this); |
||||
this.Background = Brushes.White; |
||||
this.FontFamily = new FontFamily("Consolas"); |
||||
this.FontSize = 13; |
||||
} |
||||
|
||||
volatile static ReadOnlyCollection<ICodeCompletionBinding> codeCompletionBindings; |
||||
|
||||
public static ReadOnlyCollection<ICodeCompletionBinding> CodeCompletionBindings { |
||||
get { |
||||
if (codeCompletionBindings == null) { |
||||
codeCompletionBindings = AddInTree.BuildItems<ICodeCompletionBinding>("/AddIns/DefaultTextEditor/CodeCompletion", null, false).AsReadOnly(); |
||||
} |
||||
return codeCompletionBindings; |
||||
} |
||||
} |
||||
|
||||
protected override void OnPreviewTextInput(TextCompositionEventArgs e) |
||||
{ |
||||
base.OnPreviewTextInput(e); |
||||
if (!e.Handled && e.Text.Length == 1) { |
||||
foreach (ICodeCompletionBinding cc in CodeCompletionBindings) { |
||||
if (cc.HandleKeyPress(textEditorAdapter, e.Text[0])) { |
||||
e.Handled = true; |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Wraps the CodeEditor class to provide the ITextEditor interface.
|
||||
/// </summary>
|
||||
public class CodeEditorAdapter : AvalonEditTextEditorAdapter |
||||
{ |
||||
readonly CodeEditor codeEditor; |
||||
|
||||
public CodeEditorAdapter(CodeEditor codeEditor) : base(codeEditor) |
||||
{ |
||||
if (codeEditor == null) |
||||
throw new ArgumentNullException("codeEditor"); |
||||
this.codeEditor = codeEditor; |
||||
} |
||||
|
||||
public override string FileName { |
||||
get { return codeEditor.FileName; } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.AvalonEdit.Utils; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.AvalonEdit |
||||
{ |
||||
/// <summary>
|
||||
/// Contains weak event managers for the TexEditor events.
|
||||
/// </summary>
|
||||
public static class TextEditorWeakEventManager |
||||
{ |
||||
/// <summary>
|
||||
/// Weak event manager for the <see cref="TextEditor.DocumentChanged"/> event.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")] |
||||
public sealed class DocumentChanged : WeakEventManagerBase<DocumentChanged, TextEditor> |
||||
{ |
||||
/// <inheritdoc/>
|
||||
protected override void StartListening(TextEditor source) |
||||
{ |
||||
source.DocumentChanged += DeliverEvent; |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void StopListening(TextEditor source) |
||||
{ |
||||
source.DocumentChanged -= DeliverEvent; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,108 @@
@@ -0,0 +1,108 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.SharpDevelop |
||||
{ |
||||
/// <summary>
|
||||
/// Allows creating an <see cref="ICompletionDataList"/> from code-completion information.
|
||||
/// </summary>
|
||||
public class CodeCompletionItemProvider |
||||
{ |
||||
public virtual ICompletionItemList GenerateCompletionList(ITextEditor editor) |
||||
{ |
||||
if (editor == null) |
||||
throw new ArgumentNullException("textEditor"); |
||||
ExpressionResult expression = GetExpression(editor); |
||||
return GenerateCompletionListForExpression(editor, expression); |
||||
} |
||||
|
||||
public virtual ExpressionResult GetExpression(ITextEditor editor) |
||||
{ |
||||
if (editor == null) |
||||
throw new ArgumentNullException("editor"); |
||||
IDocument document = editor.Document; |
||||
IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(editor.FileName); |
||||
if (expressionFinder == null) { |
||||
return ExpressionResult.Empty; |
||||
} else { |
||||
return expressionFinder.FindExpression(document.GetText(0, editor.Caret.Offset), editor.Caret.Offset); |
||||
} |
||||
} |
||||
|
||||
public virtual ICompletionItemList GenerateCompletionListForExpression(ITextEditor editor, ExpressionResult expressionResult) |
||||
{ |
||||
if (expressionResult.Expression == null) { |
||||
return null; |
||||
} |
||||
if (LoggingService.IsDebugEnabled) { |
||||
if (expressionResult.Context == ExpressionContext.Default) |
||||
LoggingService.DebugFormatted("GenerateCompletionData for >>{0}<<", expressionResult.Expression); |
||||
else |
||||
LoggingService.DebugFormatted("GenerateCompletionData for >>{0}<<, context={1}", expressionResult.Expression, expressionResult.Context); |
||||
} |
||||
ResolveResult rr = Resolve(editor, expressionResult); |
||||
return GenerateCompletionListForResolveResult(rr, expressionResult.Context); |
||||
} |
||||
|
||||
public virtual ResolveResult Resolve(ITextEditor editor, ExpressionResult expressionResult) |
||||
{ |
||||
if (editor == null) |
||||
throw new ArgumentNullException("editor"); |
||||
return ParserService.Resolve(expressionResult, editor.Caret.Line, editor.Caret.Column, editor.FileName, editor.Document.Text); |
||||
} |
||||
|
||||
public virtual ICompletionItemList GenerateCompletionListForResolveResult(ResolveResult rr, ExpressionContext context) |
||||
{ |
||||
if (rr == null) |
||||
return null; |
||||
IProjectContent callingContent = rr.CallingClass != null ? rr.CallingClass.ProjectContent : null; |
||||
ArrayList arr = rr.GetCompletionData(callingContent ?? ParserService.CurrentProjectContent); |
||||
DefaultCompletionItemList result = new DefaultCompletionItemList(); |
||||
foreach (object o in arr) { |
||||
IEntity entity = o as IEntity; |
||||
if (entity != null) |
||||
result.Items.Add(new CodeCompletionItem(entity)); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
public virtual ICompletionItem CreateCompletionItem(IEntity entity) |
||||
{ |
||||
return new CodeCompletionItem(entity); |
||||
} |
||||
} |
||||
|
||||
public class CodeCompletionItem : ICompletionItem |
||||
{ |
||||
readonly IEntity entity; |
||||
|
||||
public CodeCompletionItem(IEntity entity) |
||||
{ |
||||
if (entity == null) |
||||
throw new ArgumentNullException("entity"); |
||||
this.entity = entity; |
||||
} |
||||
|
||||
public string Text { |
||||
get { |
||||
return entity.Name; |
||||
} |
||||
} |
||||
|
||||
public string Description { |
||||
get { |
||||
return entity.Documentation; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.SharpDevelop |
||||
{ |
||||
public interface ICompletionItem |
||||
{ |
||||
string Text { get; } |
||||
string Description { get; } |
||||
} |
||||
} |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.SharpDevelop |
||||
{ |
||||
public interface ICompletionItemList |
||||
{ |
||||
IEnumerable<ICompletionItem> Items { get; } |
||||
} |
||||
|
||||
public class DefaultCompletionItemList : ICompletionItemList |
||||
{ |
||||
IList<ICompletionItem> items; |
||||
|
||||
public DefaultCompletionItemList() |
||||
: this(new List<ICompletionItem>()) |
||||
{ |
||||
} |
||||
|
||||
public DefaultCompletionItemList(IList<ICompletionItem> items) |
||||
{ |
||||
this.items = items; |
||||
} |
||||
|
||||
public IList<ICompletionItem> Items { |
||||
get { return items; } |
||||
} |
||||
|
||||
IEnumerable<ICompletionItem> ICompletionItemList.Items { |
||||
get { return items; } |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue