Browse Source

Add context menu action to copy FQN for selected class

pull/720/merge
Alex Povar 9 years ago committed by Siegfried Pammer
parent
commit
9be9b0b954
  1. 4
      ILSpy/ILSpy.csproj
  2. BIN
      ILSpy/Images/Copy.png
  3. 42
      ILSpy/TreeNodes/CopyFullyQualifiedTypeNameContextMenuEntry.cs

4
ILSpy/ILSpy.csproj

@ -207,6 +207,7 @@
<Compile Include="TreeNodes\Analyzer\Helpers.cs" /> <Compile Include="TreeNodes\Analyzer\Helpers.cs" />
<Compile Include="TreeNodes\Analyzer\ScopedWhereUsedAnalyzer.cs" /> <Compile Include="TreeNodes\Analyzer\ScopedWhereUsedAnalyzer.cs" />
<Compile Include="TreeNodes\BaseTypesEntryNode.cs" /> <Compile Include="TreeNodes\BaseTypesEntryNode.cs" />
<Compile Include="TreeNodes\CopyFullyQualifiedTypeNameContextMenuEntry.cs" />
<Compile Include="TreeNodes\DerivedTypesEntryNode.cs" /> <Compile Include="TreeNodes\DerivedTypesEntryNode.cs" />
<Compile Include="TreeNodes\FilterResult.cs" /> <Compile Include="TreeNodes\FilterResult.cs" />
<Compile Include="TreeNodes\IMemberTreeNode.cs" /> <Compile Include="TreeNodes\IMemberTreeNode.cs" />
@ -413,5 +414,8 @@
<ItemGroup> <ItemGroup>
<Resource Include="Images\SearchMsdn.png" /> <Resource Include="Images\SearchMsdn.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Resource Include="Images\Copy.png" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project> </Project>

BIN
ILSpy/Images/Copy.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 469 B

42
ILSpy/TreeNodes/CopyFullyQualifiedTypeNameContextMenuEntry.cs

@ -0,0 +1,42 @@
using System.Windows;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes
{
[ExportContextMenuEntry(Header = "Copy FQ Name", Icon = "images/Copy.png", Order = 9999)]
public class CopyFullyQualifiedTypeNameContextMenuEntry : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
{
return GetTypeNodeFromContext(context) != null;
}
public bool IsEnabled(TextViewContext context) => true;
public void Execute(TextViewContext context)
{
var typeDefinition = GetTypeNodeFromContext(context)?.TypeDefinition;
if (typeDefinition == null) return;
Clipboard.SetText(GetFullyQualifiedName(typeDefinition));
}
private TypeTreeNode GetTypeNodeFromContext(TextViewContext context)
{
return context.SelectedTreeNodes?.Length == 1 ? context.SelectedTreeNodes[0] as TypeTreeNode : null;
}
/// <summary>
/// Resolve full type name using .NET type representation for nested types.
/// </summary>
private string GetFullyQualifiedName(TypeDefinition typeDefinition)
{
if (typeDefinition.IsNested)
{
return $"{GetFullyQualifiedName(typeDefinition.DeclaringType)}+{typeDefinition.Name}";
}
return $"{typeDefinition.Namespace}.{typeDefinition.Name}";
}
}
}
Loading…
Cancel
Save