Browse Source

Fix #822 - Sort Items in the TreeView using Natural Sort Instead

pull/863/head
Siegfried Pammer 8 years ago
parent
commit
4ce1fbcb00
  1. 1
      ILSpy/ILSpy.csproj
  2. 4
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  3. 37
      ILSpy/TreeNodes/NaturalStringComparer.cs
  4. 10
      ILSpy/TreeNodes/TypeTreeNode.cs

1
ILSpy/ILSpy.csproj

@ -200,6 +200,7 @@
<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" />
<Compile Include="TreeNodes\NaturalStringComparer.cs" />
<Compile Include="TreeNodes\ResourceNodes\CursorResourceEntryNode.cs" /> <Compile Include="TreeNodes\ResourceNodes\CursorResourceEntryNode.cs" />
<Compile Include="TreeNodes\ResourceNodes\IconResourceEntryNode.cs" /> <Compile Include="TreeNodes\ResourceNodes\IconResourceEntryNode.cs" />
<Compile Include="TreeNodes\ResourceNodes\ImageListResourceEntryNode.cs" /> <Compile Include="TreeNodes\ResourceNodes\ImageListResourceEntryNode.cs" />

4
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -155,7 +155,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
foreach (NamespaceTreeNode ns in namespaces.Values) { foreach (NamespaceTreeNode ns in namespaces.Values) {
ns.Children.Clear(); ns.Children.Clear();
} }
foreach (TypeDefinition type in moduleDefinition.Types.OrderBy(t => t.FullName)) { foreach (TypeDefinition type in moduleDefinition.Types.OrderBy(t => t.FullName, NaturalStringComparer.Instance)) {
NamespaceTreeNode ns; NamespaceTreeNode ns;
if (!namespaces.TryGetValue(type.Namespace, out ns)) { if (!namespaces.TryGetValue(type.Namespace, out ns)) {
ns = new NamespaceTreeNode(type.Namespace); ns = new NamespaceTreeNode(type.Namespace);
@ -165,7 +165,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
typeDict[type] = node; typeDict[type] = node;
ns.Children.Add(node); ns.Children.Add(node);
} }
foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name)) { foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name, NaturalStringComparer.Instance)) {
if (ns.Children.Count > 0) if (ns.Children.Count > 0)
this.Children.Add(ns); this.Children.Add(ns);
} }

37
ILSpy/TreeNodes/NaturalStringComparer.cs

@ -0,0 +1,37 @@
// Copyright (c) 2015 Siegfried Pammer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace ICSharpCode.ILSpy.TreeNodes
{
public sealed class NaturalStringComparer : IComparer<string>
{
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
static extern int StrCmpLogicalW(string psz1, string psz2);
public static readonly NaturalStringComparer Instance = new NaturalStringComparer();
public int Compare(string a, string b)
{
return StrCmpLogicalW(a, b);
}
}
}

10
ILSpy/TreeNodes/TypeTreeNode.cs

@ -96,21 +96,21 @@ namespace ICSharpCode.ILSpy.TreeNodes
this.Children.Add(new BaseTypesTreeNode(type)); this.Children.Add(new BaseTypesTreeNode(type));
if (!type.IsSealed) if (!type.IsSealed)
this.Children.Add(new DerivedTypesTreeNode(parentAssemblyNode.AssemblyList, type)); this.Children.Add(new DerivedTypesTreeNode(parentAssemblyNode.AssemblyList, type));
foreach (TypeDefinition nestedType in type.NestedTypes.OrderBy(m => m.Name)) { foreach (TypeDefinition nestedType in type.NestedTypes.OrderBy(m => m.Name, NaturalStringComparer.Instance)) {
this.Children.Add(new TypeTreeNode(nestedType, parentAssemblyNode)); this.Children.Add(new TypeTreeNode(nestedType, parentAssemblyNode));
} }
foreach (FieldDefinition field in type.Fields.OrderBy(m => m.Name)) { foreach (FieldDefinition field in type.Fields.OrderBy(m => m.Name, NaturalStringComparer.Instance)) {
this.Children.Add(new FieldTreeNode(field)); this.Children.Add(new FieldTreeNode(field));
} }
foreach (PropertyDefinition property in type.Properties.OrderBy(m => m.Name)) { foreach (PropertyDefinition property in type.Properties.OrderBy(m => m.Name, NaturalStringComparer.Instance)) {
this.Children.Add(new PropertyTreeNode(property)); this.Children.Add(new PropertyTreeNode(property));
} }
foreach (EventDefinition ev in type.Events.OrderBy(m => m.Name)) { foreach (EventDefinition ev in type.Events.OrderBy(m => m.Name, NaturalStringComparer.Instance)) {
this.Children.Add(new EventTreeNode(ev)); this.Children.Add(new EventTreeNode(ev));
} }
HashSet<MethodDefinition> accessorMethods = type.GetAccessorMethods(); HashSet<MethodDefinition> accessorMethods = type.GetAccessorMethods();
foreach (MethodDefinition method in type.Methods.OrderBy(m => m.Name)) { foreach (MethodDefinition method in type.Methods.OrderBy(m => m.Name, NaturalStringComparer.Instance)) {
if (!accessorMethods.Contains(method)) { if (!accessorMethods.Contains(method)) {
this.Children.Add(new MethodTreeNode(method)); this.Children.Add(new MethodTreeNode(method));
} }

Loading…
Cancel
Save