Browse Source

Base type list: implemented jumping to a type.

pull/1/head
Daniel Grunwald 14 years ago
parent
commit
aa9599a31d
  1. 31
      ILSpy/AssemblyListTreeNode.cs
  2. 4
      ILSpy/AssemblyTreeNode.cs
  3. 22
      ILSpy/BaseTypesTreeNode.cs
  4. 4
      ILSpy/MainWindow.xaml
  5. 9
      ILSpy/MainWindow.xaml.cs
  6. 20
      ILSpy/TypeTreeNode.cs

31
ILSpy/AssemblyListTreeNode.cs

@ -17,13 +17,13 @@ @@ -17,13 +17,13 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using ICSharpCode.TreeView;
using Mono.Cecil;
@ -96,5 +96,34 @@ namespace ICSharpCode.ILSpy @@ -96,5 +96,34 @@ namespace ICSharpCode.ILSpy
}
public Action<SharpTreeNode> Select = delegate {};
ConcurrentDictionary<TypeDefinition, TypeTreeNode> typeDict = new ConcurrentDictionary<TypeDefinition, TypeTreeNode>();
public void RegisterTypeNode(TypeTreeNode node)
{
// called on background loading thread, so we need to use a ConcurrentDictionary
typeDict[node.TypeDefinition] = node;
}
public TypeTreeNode FindTypeNode(TypeDefinition def)
{
if (def.DeclaringType != null) {
TypeTreeNode decl = FindTypeNode(def.DeclaringType);
if (decl != null) {
decl.EnsureLazyChildren();
return decl.Children.OfType<TypeTreeNode>().FirstOrDefault(t => t.TypeDefinition == def);
}
} else {
TypeTreeNode node;
if (typeDict.TryGetValue(def, out node)) {
// Ensure that the node is connected to the tree
node.ParentAssemblyNode.EnsureLazyChildren();
// Validate that the node wasn't removed due to visibility settings:
if (node.Ancestors().Contains(this))
return node;
}
}
return null;
}
}
}

4
ILSpy/AssemblyTreeNode.cs

@ -76,7 +76,9 @@ namespace ICSharpCode.ILSpy @@ -76,7 +76,9 @@ namespace ICSharpCode.ILSpy
p.AssemblyResolver = new MyAssemblyResolver(this);
AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(fileName, p);
foreach (TypeDefinition type in assembly.MainModule.Types.OrderBy(t => t.FullName)) {
classes.Add(new TypeTreeNode(type));
TypeTreeNode node = new TypeTreeNode(type, this);
classes.Add(node);
assemblyList.RegisterTypeNode(node);
}
syncContext.Post(
delegate {

22
ILSpy/BaseTypesTreeNode.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq;
using ICSharpCode.TreeView;
using Mono.Cecil;
@ -75,9 +76,7 @@ namespace ICSharpCode.ILSpy @@ -75,9 +76,7 @@ namespace ICSharpCode.ILSpy
public override bool ShowExpander {
get {
if (isInterface || tr.FullName == "System.Object")
EnsureLazyChildren(); // need to create children to test whether we have any
return base.ShowExpander;
return def != null && (def.BaseType != null || def.HasInterfaces);
}
}
@ -99,6 +98,23 @@ namespace ICSharpCode.ILSpy @@ -99,6 +98,23 @@ namespace ICSharpCode.ILSpy
if (def != null)
AddBaseTypes(this.Children, def);
}
public override void ActivateItem(System.Windows.RoutedEventArgs e)
{
// on item activation, try to resolve once again (maybe the user loaded the assembly in the meantime)
if (def == null) {
def = tr.Resolve();
if (def != null)
this.LazyLoading = true; // re-load children
}
if (def != null) {
var assemblyListNode = this.Ancestors().OfType<AssemblyListTreeNode>().FirstOrDefault();
if (assemblyListNode != null) {
assemblyListNode.Select(assemblyListNode.FindTypeNode(def));
e.Handled = true;
}
}
}
}
}
}

4
ILSpy/MainWindow.xaml

@ -72,12 +72,12 @@ @@ -72,12 +72,12 @@
<Grid.ColumnDefinitions>
<ColumnDefinition
MinWidth="100"
Width="250" />
Width="0.4*" />
<ColumnDefinition
Width="3" />
<ColumnDefinition
MinWidth="100"
Width="0.514411764705882*" />
Width="0.6*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition

9
ILSpy/MainWindow.xaml.cs

@ -56,8 +56,13 @@ namespace ICSharpCode.ILSpy @@ -56,8 +56,13 @@ namespace ICSharpCode.ILSpy
textEditor.Text = "// Welcome to ILSpy!";
treeView.Root = assemblyList;
assemblyList.Select = delegate(SharpTreeNode obj) {
treeView.SelectedItem = obj;
treeView.ScrollIntoView(obj);
if (obj != null) {
foreach (SharpTreeNode node in obj.Ancestors())
node.IsExpanded = true;
treeView.SelectedItem = obj;
treeView.ScrollIntoView(obj);
}
};
foreach (Assembly asm in initialAssemblies)

20
ILSpy/TypeTreeNode.cs

@ -30,16 +30,27 @@ namespace ICSharpCode.ILSpy @@ -30,16 +30,27 @@ namespace ICSharpCode.ILSpy
sealed class TypeTreeNode : SharpTreeNode
{
readonly TypeDefinition type;
readonly AssemblyTreeNode parentAssemblyNode;
public TypeTreeNode(TypeDefinition type)
public TypeTreeNode(TypeDefinition type, AssemblyTreeNode parentAssemblyNode)
{
if (parentAssemblyNode == null)
throw new ArgumentNullException("parentAssemblyNode");
if (type == null)
throw new ArgumentNullException("type");
this.type = type;
this.parentAssemblyNode = parentAssemblyNode;
this.LazyLoading = true;
}
public TypeDefinition TypeDefinition {
get { return type; }
}
public AssemblyTreeNode ParentAssemblyNode {
get { return parentAssemblyNode; }
}
public string Name {
get { return type.Name; }
}
@ -68,9 +79,10 @@ namespace ICSharpCode.ILSpy @@ -68,9 +79,10 @@ namespace ICSharpCode.ILSpy
protected override void LoadChildren()
{
this.Children.Add(new BaseTypesTreeNode(type));
if (type.BaseType != null || type.HasInterfaces)
this.Children.Add(new BaseTypesTreeNode(type));
foreach (TypeDefinition nestedType in type.NestedTypes) {
this.Children.Add(new TypeTreeNode(nestedType));
this.Children.Add(new TypeTreeNode(nestedType, parentAssemblyNode));
}
foreach (FieldDefinition field in type.Fields) {
this.Children.Add(new FieldTreeNode(field));

Loading…
Cancel
Save