Browse Source

CopyFullyQualifiedTypeNameContextMenuEntry should work on members as well.

pull/863/head
Siegfried Pammer 8 years ago
parent
commit
63b2d697d1
  1. 2
      ILSpy/ILSpy.csproj
  2. 42
      ILSpy/TreeNodes/CopyFullyQualifiedNameContextMenuEntry.cs
  3. 42
      ILSpy/TreeNodes/CopyFullyQualifiedTypeNameContextMenuEntry.cs
  4. 4
      ILSpy/TreeNodes/NaturalStringComparer.cs

2
ILSpy/ILSpy.csproj

@ -195,7 +195,7 @@ @@ -195,7 +195,7 @@
<Compile Include="TreeNodes\Analyzer\Helpers.cs" />
<Compile Include="TreeNodes\Analyzer\ScopedWhereUsedAnalyzer.cs" />
<Compile Include="TreeNodes\BaseTypesEntryNode.cs" />
<Compile Include="TreeNodes\CopyFullyQualifiedTypeNameContextMenuEntry.cs" />
<Compile Include="TreeNodes\CopyFullyQualifiedNameContextMenuEntry.cs" />
<Compile Include="TreeNodes\DerivedTypesEntryNode.cs" />
<Compile Include="TreeNodes\FilterResult.cs" />
<Compile Include="TreeNodes\IMemberTreeNode.cs" />

42
ILSpy/TreeNodes/CopyFullyQualifiedNameContextMenuEntry.cs

@ -0,0 +1,42 @@ @@ -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 CopyFullyQualifiedNameContextMenuEntry : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
{
return GetMemberNodeFromContext(context) != null;
}
public bool IsEnabled(TextViewContext context) => true;
public void Execute(TextViewContext context)
{
var member = GetMemberNodeFromContext(context)?.Member;
if (member == null) return;
Clipboard.SetText(GetFullyQualifiedName(member));
}
private IMemberTreeNode GetMemberNodeFromContext(TextViewContext context)
{
return context.SelectedTreeNodes?.Length == 1 ? context.SelectedTreeNodes[0] as IMemberTreeNode : null;
}
/// <summary>
/// Resolve full type name using .NET type representation for nested types.
/// </summary>
private string GetFullyQualifiedName(MemberReference member)
{
if (member.DeclaringType != null) {
if (member is TypeReference)
return GetFullyQualifiedName(member.DeclaringType) + "+" + member.Name;
else
return GetFullyQualifiedName(member.DeclaringType) + "." + member.Name;
}
return (member is TypeReference t ? t.Namespace + "." : "") + member.Name;
}
}
}

42
ILSpy/TreeNodes/CopyFullyQualifiedTypeNameContextMenuEntry.cs

@ -1,42 +0,0 @@ @@ -1,42 +0,0 @@
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}";
}
}
}

4
ILSpy/TreeNodes/NaturalStringComparer.cs

@ -29,9 +29,9 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -29,9 +29,9 @@ namespace ICSharpCode.ILSpy.TreeNodes
public static readonly NaturalStringComparer Instance = new NaturalStringComparer();
public int Compare(string a, string b)
public int Compare(string x, string y)
{
return StrCmpLogicalW(a, b);
return StrCmpLogicalW(x, y);
}
}
}

Loading…
Cancel
Save