Browse Source

Add 'Sort Assemblies' command to view menu

pull/569/head
Ed Harvey 10 years ago
parent
commit
359d04b3b6
  1. 45
      ILSpy/Commands/SortListCommand.cs
  2. 5
      ILSpy/ILSpy.csproj
  3. 1
      ILSpy/Images/Images.cs
  4. BIN
      ILSpy/Images/Sort.png
  5. 16
      ILSpy/LoadedAssembly.cs
  6. 5
      SharpTreeView/SharpTreeView.cs

45
ILSpy/Commands/SortListCommand.cs

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// 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;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.ILSpy.TreeNodes;
namespace ICSharpCode.ILSpy
{
[ExportMainMenuCommand(Menu = "_View", Header = "_Sort Assemblies", MenuIcon = "Images/Sort.png", MenuCategory = "List", MenuOrder = 3)]
sealed class SortListCommand : SimpleCommand
{
public override void Execute(object parameter)
{
//cache a (copied) list of the currently selected nodes
var selectedCache = MainWindow.Instance.SelectedNodes.Where(n => n is AssemblyTreeNode).Select(n => ((AssemblyTreeNode)n).LoadedAssembly).ToList();
MainWindow.Instance.CurrentAssemblyList.Sort(new LoadedAssembly.NameComparer());
MainWindow.Instance.treeView.SetSelectedNodes(GetNewSelectedNodes(selectedCache));
}
private IEnumerable<ILSpyTreeNode> GetNewSelectedNodes(IEnumerable<LoadedAssembly> cache)
{
foreach (var assy in cache) {
yield return MainWindow.Instance.AssemblyListTreeNode.FindAssemblyNode(assy);
}
}
}
}

5
ILSpy/ILSpy.csproj

@ -106,6 +106,7 @@ @@ -106,6 +106,7 @@
<Compile Include="CommandLineArguments.cs" />
<Compile Include="Commands\ExitCommand.cs" />
<Compile Include="Commands\CommandWrapper.cs" />
<Compile Include="Commands\SortListCommand.cs" />
<Compile Include="Commands\OpenListCommand.cs" />
<Compile Include="Controls\MarkupExtensions.cs" />
<Compile Include="Controls\ResourceObjectTable.xaml.cs">
@ -363,6 +364,7 @@ @@ -363,6 +364,7 @@
<Resource Include="Images\OverlayStatic.png" />
<Resource Include="Images\VirtualMethod.png" />
<Resource Include="Images\PInvokeMethod.png" />
<Resource Include="Images\Sort.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj">
@ -398,9 +400,6 @@ @@ -398,9 +400,6 @@
<Name>ICSharpCode.TreeView</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="AvalonEdit" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\ResourceXml.png" />
<Resource Include="Images\ResourceXsd.png" />

1
ILSpy/Images/Images.cs

@ -42,6 +42,7 @@ namespace ICSharpCode.ILSpy @@ -42,6 +42,7 @@ namespace ICSharpCode.ILSpy
public static readonly BitmapImage Delete = LoadBitmap("Delete");
public static readonly BitmapImage Search = LoadBitmap("Search");
public static readonly BitmapImage Sort = LoadBitmap("Sort");
public static readonly BitmapImage Assembly = LoadBitmap("Assembly");
public static readonly BitmapImage AssemblyWarning = LoadBitmap("AssemblyWarning");

BIN
ILSpy/Images/Sort.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

16
ILSpy/LoadedAssembly.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Threading;
@ -292,5 +293,20 @@ namespace ICSharpCode.ILSpy @@ -292,5 +293,20 @@ namespace ICSharpCode.ILSpy
{
assemblyTask.Wait();
}
public class NameComparer : Comparer<LoadedAssembly>
{
public override int Compare(LoadedAssembly x, LoadedAssembly y)
{
// correctly loaded assemblies sort first, then assemblies with errors
if (x.IsLoaded && y.HasLoadError)
return -1;
if (x.HasLoadError && y.IsLoaded)
return 1;
// within above groups, sort by assembly name
return x.Text.CompareTo(y.Text);
}
}
}
}

5
SharpTreeView/SharpTreeView.cs

@ -652,5 +652,10 @@ namespace ICSharpCode.TreeView @@ -652,5 +652,10 @@ namespace ICSharpCode.TreeView
}
#endregion
public void SetSelectedNodes(IEnumerable<SharpTreeNode> nodes)
{
this.SetSelectedItems(nodes.ToList());
}
}
}

Loading…
Cancel
Save