From 914b742a6dd199fe67a97f7697ac05832b1f22ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kon=C3=AD=C4=8Dek?= Date: Sun, 15 Aug 2010 15:18:04 +0000 Subject: [PATCH] Split ImplementInterface and ImplementInterfaceExplicit to 2 Context action providers so they can be disabled separately. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6416 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/SharpRefactoring.addin | 1 + .../Project/SharpRefactoring.csproj | 1 + .../ContextActions/ImplementAbstractClass.cs | 2 - .../Src/ContextActions/ImplementInterface.cs | 2 - .../ImplementInterfaceExplicit.cs | 38 +++++++++++++++++++ .../ContextActions/ContextActionsService.cs | 1 - .../RefactoringService/RefactoringService.cs | 22 +++++++---- 7 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterfaceExplicit.cs diff --git a/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.addin b/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.addin index d8494edc37..678ef91edb 100644 --- a/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.addin +++ b/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.addin @@ -42,6 +42,7 @@ + diff --git a/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj b/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj index 24cc7ab926..d052e1665e 100644 --- a/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj +++ b/src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj @@ -81,6 +81,7 @@ + diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs index dff5a8e69d..c670ffcdc6 100644 --- a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs +++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs @@ -23,8 +23,6 @@ namespace SharpRefactoring.ContextActions { public override IEnumerable GetAvailableActions(EditorContext editorContext) { - var ambience = AmbienceService.GetCurrentAmbience(); - foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine().Where(c => c.ClassType == ClassType.Class)) { foreach (var implementAction in RefactoringService.GetImplementAbstractClassActions(targetClass)) { diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs index 059c126b8b..5b4407c62d 100644 --- a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs +++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs @@ -29,8 +29,6 @@ namespace SharpRefactoring.ContextActions // 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 ambience = AmbienceService.GetCurrentAmbience(); - foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine(). Where(c => c.ClassType == ClassType.Class || c.ClassType == ClassType.Interface)) { diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterfaceExplicit.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterfaceExplicit.cs new file mode 100644 index 0000000000..bc202f3d77 --- /dev/null +++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterfaceExplicit.cs @@ -0,0 +1,38 @@ +// +// +// +// +// $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 +{ + /// + /// Description of ImplementInterface. + /// + public class ImplementInterfaceExplicitProvider : ContextActionsProvider + { + public override IEnumerable GetAvailableActions(EditorContext editorContext) + { + foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine(). + Where(c => c.ClassType == ClassType.Class || c.ClassType == ClassType.Interface)) { + + foreach (var implementAction in RefactoringService.GetImplementInterfaceActions(targetClass, true)) { + yield return implementAction; + } + } + } + } +} 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 e40cd8ba2d..e5d6a20d7f 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs @@ -36,7 +36,6 @@ namespace ICSharpCode.SharpDevelop.Refactoring this.providers = AddInTree.BuildItems("/SharpDevelop/ViewContent/AvalonEdit/ContextActions", null, false); var disabledActions = LoadProviderVisibilities().ToLookup(s => s); foreach (var provider in providers) { - // load from configuration provider.IsVisible = !disabledActions.Contains(provider.GetType().FullName); } } diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs b/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs index 517e518934..ad14c1dbb0 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs @@ -477,23 +477,29 @@ namespace ICSharpCode.SharpDevelop.Refactoring /// /// Gets actions which can add implementation of interface to given class. /// - public static IEnumerable GetImplementInterfaceActions(IClass c, bool returnMissingInterfacesOnly = true) + public static IEnumerable GetImplementInterfaceActions(IClass c, bool isExplicit = false, bool returnMissingInterfacesOnly = true) { var interfacesToImplement = GetInterfacesToImplement(c, returnMissingInterfacesOnly).ToList(); - if (c.ProjectContent.Language.SupportsImplicitInterfaceImplementation) { - return MakeImplementActions(c, interfacesToImplement, false, "Implement interface {0}").Concat( - MakeImplementActions(c, interfacesToImplement, true, "Implement interface {0} (explicit)")); + if (!isExplicit) { + if (c.ProjectContent.Language.SupportsImplicitInterfaceImplementation) { + return MakeImplementActions(c, interfacesToImplement, false, "Implement interface {0}"); + } else + return new ImplementInterfaceAction[0]; } else { - return MakeImplementActions(c, interfacesToImplement, true, "Implement interface {0}"); + if (c.ProjectContent.Language.SupportsImplicitInterfaceImplementation) { + return MakeImplementActions(c, interfacesToImplement, true, "Implement interface {0} (explicit)"); + } else { + return MakeImplementActions(c, interfacesToImplement, true, "Implement interface {0}"); + } } } - static IEnumerable MakeImplementActions(IClass c, IEnumerable interfaces, bool isExplit, string format) + static IEnumerable MakeImplementActions(IClass c, IEnumerable interfaces, bool isExplicit, string format) { var ambience = AmbienceService.GetCurrentAmbience(); foreach (var iface in interfaces) { - yield return new ImplementInterfaceAction(iface, c, isExplit) { + yield return new ImplementInterfaceAction(iface, c, isExplicit) { Title = string.Format(format, ambience.Convert(iface)) }; } @@ -527,7 +533,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring continue; } IReturnType rtCopy = rt; - yield return new ImplementAbstractClassAction(rtCopy, c) { + yield return new ImplementAbstractClassAction(rtCopy, c) { Title = string.Format("Implement abstract class {0}", ambience.Convert(rtCopy)) }; } }