Browse Source

Implemented new "Implement interface" editor context action using the code recently decoupled from context menus.

It is turned off so far because the GUI is unfinished.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6187 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Martin Koníček 15 years ago
parent
commit
62d12aa208
  1. 27
      src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs

27
src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs

@ -25,6 +25,7 @@ namespace SharpRefactoring.ContextActions @@ -25,6 +25,7 @@ namespace SharpRefactoring.ContextActions
{
public IEnumerable<IContextAction> GetAvailableActions(EditorASTProvider editorAST)
{
yield break; // turned off temporarily
// Using CurrentLineAST is basically OK, but when the "class" keyword is on different line than class name,
// parsing only one line never tells us that we are looking at TypeDeclaration
@ -33,24 +34,34 @@ namespace SharpRefactoring.ContextActions @@ -33,24 +34,34 @@ namespace SharpRefactoring.ContextActions
if (currentLineAST == null)
yield break;
var editor = editorAST.Editor;
var ambience = AmbienceService.GetCurrentAmbience();
foreach (var declaration in currentLineAST.FindTypeDeclarations()) {
if (declaration.Type == Ast.ClassType.Class || declaration.Type == Ast.ClassType.Struct) {
var rr = ParserService.Resolve(new ExpressionResult(declaration.Name), editor.Caret.Line, editor.Caret.Column, editor.FileName, editor.Document.Text);
var targetClass = rr.ResolvedType == null ? null : rr.ResolvedType.GetUnderlyingClass();
if (targetClass != null) {
foreach (var implementAction in RefactoringService.GetImplementInterfaceActions(targetClass, false)) {
var implementActionCopy = implementAction;
yield return new DelegateAction {
Title = string.Format("Implement interface {0}", ambience.Convert(implementActionCopy.ClassToImplement)),
ExecuteAction = implementActionCopy.Execute
};
}
}
}
}
}
}
}
public class ImplementInterfaceAction : IContextAction
public class DelegateAction : IContextAction
{
public string Title {
get { return "Dummy implement interface"; }
}
public string Title { get; set; }
public System.Action ExecuteAction { get; set; }
public void Execute()
{
MessageBox.Show("Dummy implement interface");
if (this.ExecuteAction != null)
this.ExecuteAction();
}
}
}

Loading…
Cancel
Save