diff --git a/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj b/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj
index c6e59a50f6..ef738fea85 100644
--- a/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj
+++ b/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj
@@ -71,6 +71,7 @@
+
diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/DelegateAction.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/DelegateAction.cs
new file mode 100644
index 0000000000..a68932b6bb
--- /dev/null
+++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/DelegateAction.cs
@@ -0,0 +1,33 @@
+//
+//
+//
+//
+// $Revision: $
+//
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows;
+using ICSharpCode.NRefactory;
+using Ast = ICSharpCode.NRefactory.Ast;
+using ICSharpCode.SharpDevelop;
+using ICSharpCode.SharpDevelop.Dom;
+using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver;
+using ICSharpCode.SharpDevelop.Editor;
+using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
+using ICSharpCode.SharpDevelop.Refactoring;
+
+namespace SharpRefactoring.ContextActions
+{
+ public class DelegateAction : IContextAction
+ {
+ public string Title { get; set; }
+ public System.Action ExecuteAction { get; set; }
+
+ public void Execute()
+ {
+ if (this.ExecuteAction != null)
+ this.ExecuteAction();
+ }
+ }
+}
diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/Extensions.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/Extensions.cs
index 17bc63f641..9cb3cbb0f3 100644
--- a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/Extensions.cs
+++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/Extensions.cs
@@ -5,8 +5,13 @@
// $Revision: $
//
using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
+
using ICSharpCode.NRefactory.Ast;
+using ICSharpCode.SharpDevelop;
+using ICSharpCode.SharpDevelop.Dom;
+using ICSharpCode.SharpDevelop.Refactoring;
namespace SharpRefactoring.ContextActions
{
@@ -21,5 +26,19 @@ namespace SharpRefactoring.ContextActions
astTree.AcceptVisitor(findVisitor, null);
return findVisitor.Declarations;
}
+
+ public static IEnumerable GetClassesOnCurrentLine(this EditorASTProvider editorAST)
+ {
+ var currentLineAST = editorAST.CurrentLineAST;
+ if (currentLineAST == null)
+ yield break;
+ var editor = editorAST.Editor;
+ foreach (var declaration in currentLineAST.FindTypeDeclarations()) {
+ var rr = ParserService.Resolve(new ExpressionResult(declaration.Name), editor.Caret.Line, editor.Caret.Column, editor.FileName, editor.Document.Text);
+ if (rr != null && rr.ResolvedType != null) {
+ yield return rr.ResolvedType.GetUnderlyingClass();
+ }
+ }
+ }
}
}
diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs
index 61adbfff60..1f6f2deafd 100644
--- a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs
+++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs
@@ -6,7 +6,10 @@
//
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Windows;
+using ICSharpCode.SharpDevelop;
+using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
using ICSharpCode.SharpDevelop.Refactoring;
@@ -20,19 +23,18 @@ namespace SharpRefactoring.ContextActions
{
public IEnumerable GetAvailableActions(EditorASTProvider editorAST)
{
- yield break;
- }
- }
-
- public class ImplementAbstractClassAction : IContextAction
- {
- public string Title {
- get { return "Dummy implement abstract class"; }
- }
-
- public void Execute()
- {
- MessageBox.Show("Dummy implement abstract class");
+ var ambience = AmbienceService.GetCurrentAmbience();
+
+ foreach (var targetClass in editorAST.GetClassesOnCurrentLine().Where(c => c.ClassType == ClassType.Class)) {
+
+ foreach (var implementAction in RefactoringService.GetImplementAbstractClassActions(targetClass)) {
+ var implementActionCopy = implementAction;
+ yield return new DelegateAction {
+ Title = string.Format("Implement abstract class {0}", ambience.Convert(implementActionCopy.ClassToImplement)),
+ ExecuteAction = implementActionCopy.Execute
+ };
+ }
+ }
}
}
}
diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs
index ad69769262..1cf509275f 100644
--- a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs
+++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs
@@ -6,6 +6,7 @@
//
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Windows;
using ICSharpCode.NRefactory;
using Ast = ICSharpCode.NRefactory.Ast;
@@ -25,43 +26,22 @@ namespace SharpRefactoring.ContextActions
{
public IEnumerable 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
-
// Alternative solution could be to try to resolve also IdentifierExpression to see if it is class declaration.
- var currentLineAST = editorAST.CurrentLineAST;
- 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
- };
- }
- }
+
+ foreach (var targetClass in editorAST.GetClassesOnCurrentLine().
+ Where(c => c.ClassType == ClassType.Class || c.ClassType == ClassType.Interface)) {
+
+ 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 DelegateAction : IContextAction
- {
- public string Title { get; set; }
- public System.Action ExecuteAction { get; set; }
-
- public void Execute()
- {
- if (this.ExecuteAction != null)
- this.ExecuteAction();
- }
- }
}
diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs
index 7f3df7bcbf..808ea314ae 100644
--- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs
+++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs
@@ -39,6 +39,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
///
public IEnumerable GetAvailableActions(ITextEditor editor)
{
+ yield break;
var editorAST = new EditorASTProvider(editor);
// could run providers in parallel
foreach (var provider in this.providers) {