Browse Source

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
pull/1/head
Martin Koníček 16 years ago
parent
commit
914b742a6d
  1. 1
      src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.addin
  2. 1
      src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj
  3. 2
      src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs
  4. 2
      src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs
  5. 38
      src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterfaceExplicit.cs
  6. 1
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs
  7. 22
      src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs

1
src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.addin

@ -42,6 +42,7 @@ @@ -42,6 +42,7 @@
<Class class="SharpRefactoring.ContextActions.MoveClassToFile" />
<Class class="SharpRefactoring.ContextActions.ImplementInterfaceProvider" />
<Class class="SharpRefactoring.ContextActions.ImplementAbstractClassProvider" />
<Class class="SharpRefactoring.ContextActions.ImplementInterfaceExplicitProvider" />
<Class class="SharpRefactoring.ContextActions.GenerateMemberProvider" />
<Class class="SharpRefactoring.ContextActions.CheckAssignmentNull" />
<Class class="SharpRefactoring.ContextActions.CheckAssignmentNotNull" />

1
src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj

@ -81,6 +81,7 @@ @@ -81,6 +81,7 @@
<Compile Include="Src\ContextActions\GenerateMember.cs" />
<Compile Include="Src\ContextActions\ImplementAbstractClass.cs" />
<Compile Include="Src\ContextActions\ImplementInterface.cs" />
<Compile Include="Src\ContextActions\ImplementInterfaceExplicit.cs" />
<Compile Include="Src\ContextActions\MoveClassToFile.cs" />
<Compile Include="Src\ContextActions\ParamCheck.cs" />
<Compile Include="Src\ContextActions\ParamCheckForNull.cs" />

2
src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs

@ -23,8 +23,6 @@ namespace SharpRefactoring.ContextActions @@ -23,8 +23,6 @@ namespace SharpRefactoring.ContextActions
{
public override IEnumerable<IContextAction> 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)) {

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

@ -29,8 +29,6 @@ namespace SharpRefactoring.ContextActions @@ -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)) {

38
src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterfaceExplicit.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Martin Konicek" email="martin.konicek@gmail.com"/>
// <version>$Revision: $</version>
// </file>
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
{
/// <summary>
/// Description of ImplementInterface.
/// </summary>
public class ImplementInterfaceExplicitProvider : ContextActionsProvider
{
public override IEnumerable<IContextAction> 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;
}
}
}
}
}

1
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs

@ -36,7 +36,6 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -36,7 +36,6 @@ namespace ICSharpCode.SharpDevelop.Refactoring
this.providers = AddInTree.BuildItems<IContextActionsProvider>("/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);
}
}

22
src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs

@ -477,23 +477,29 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -477,23 +477,29 @@ namespace ICSharpCode.SharpDevelop.Refactoring
/// <summary>
/// Gets actions which can add implementation of interface to given class.
/// </summary>
public static IEnumerable<ImplementInterfaceAction> GetImplementInterfaceActions(IClass c, bool returnMissingInterfacesOnly = true)
public static IEnumerable<ImplementInterfaceAction> 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<ImplementInterfaceAction> MakeImplementActions(IClass c, IEnumerable<IReturnType> interfaces, bool isExplit, string format)
static IEnumerable<ImplementInterfaceAction> MakeImplementActions(IClass c, IEnumerable<IReturnType> 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 @@ -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)) };
}
}

Loading…
Cancel
Save