Browse Source

Move classes to separate files.

pull/234/merge
Ed Harvey 14 years ago
parent
commit
e32c170ec4
  1. 3
      ILSpy/ILSpy.csproj
  2. 104
      ILSpy/TreeNodes/BaseTypesEntryNode.cs
  3. 96
      ILSpy/TreeNodes/BaseTypesTreeNode.cs
  4. 111
      ILSpy/TreeNodes/DerivedTypesEntryNode.cs
  5. 111
      ILSpy/TreeNodes/DerivedTypesTreeNode.cs
  6. 40
      ILSpy/TreeNodes/FilterResult.cs
  7. 58
      ILSpy/TreeNodes/ILSpyTreeNode.cs

3
ILSpy/ILSpy.csproj

@ -158,6 +158,9 @@ @@ -158,6 +158,9 @@
<Compile Include="TreeNodes\Analyzer\AnalyzedVirtualMethodUsedByTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\Helpers.cs" />
<Compile Include="TreeNodes\Analyzer\ScopedWhereUsedAnalyzer.cs" />
<Compile Include="TreeNodes\BaseTypesEntryNode.cs" />
<Compile Include="TreeNodes\DerivedTypesEntryNode.cs" />
<Compile Include="TreeNodes\FilterResult.cs" />
<Compile Include="TreeNodes\IMemberTreeNode.cs" />
<Compile Include="TreeNodes\ResourceNodes\CursorResourceEntryNode.cs" />
<Compile Include="TreeNodes\ResourceNodes\ImageResourceEntryNode.cs" />

104
ILSpy/TreeNodes/BaseTypesEntryNode.cs

@ -0,0 +1,104 @@ @@ -0,0 +1,104 @@
// 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.Linq;
using ICSharpCode.Decompiler;
using ICSharpCode.TreeView;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes
{
sealed class BaseTypesEntryNode : ILSpyTreeNode, IMemberTreeNode
{
private TypeReference tr;
private TypeDefinition def;
private bool isInterface;
public BaseTypesEntryNode(TypeReference tr, bool isInterface)
{
if (tr == null)
throw new ArgumentNullException("tr");
this.tr = tr;
this.def = tr.Resolve();
this.isInterface = isInterface;
this.LazyLoading = true;
}
public override bool ShowExpander
{
get { return def != null && (def.BaseType != null || def.HasInterfaces); }
}
public override object Text
{
get { return this.Language.TypeToString(tr, true); }
}
public override object Icon
{
get
{
if (def != null)
return TypeTreeNode.GetIcon(def);
else
return isInterface ? Images.Interface : Images.Class;
}
}
protected override void LoadChildren()
{
if (def != null)
BaseTypesTreeNode.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
}
e.Handled = ActivateItem(this, def);
}
internal static bool ActivateItem(SharpTreeNode node, TypeDefinition def)
{
if (def != null) {
var assemblyListNode = node.Ancestors().OfType<AssemblyListTreeNode>().FirstOrDefault();
if (assemblyListNode != null) {
assemblyListNode.Select(assemblyListNode.FindTypeNode(def));
return true;
}
}
return false;
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, language.TypeToString(tr, true));
}
MemberReference IMemberTreeNode.Member
{
get { return tr; }
}
}
}

96
ILSpy/TreeNodes/BaseTypesTreeNode.cs

@ -17,9 +17,7 @@ @@ -17,9 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq;
using System.Windows.Threading;
using ICSharpCode.Decompiler;
using ICSharpCode.TreeView;
using Mono.Cecil;
@ -32,26 +30,28 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -32,26 +30,28 @@ namespace ICSharpCode.ILSpy.TreeNodes
sealed class BaseTypesTreeNode : ILSpyTreeNode
{
readonly TypeDefinition type;
public BaseTypesTreeNode(TypeDefinition type)
{
this.type = type;
this.LazyLoading = true;
}
public override object Text {
public override object Text
{
get { return "Base Types"; }
}
public override object Icon {
public override object Icon
{
get { return Images.SuperTypes; }
}
protected override void LoadChildren()
{
AddBaseTypes(this.Children, type);
}
internal static void AddBaseTypes(SharpTreeNodeCollection children, TypeDefinition type)
{
if (type.BaseType != null)
@ -60,7 +60,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -60,7 +60,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
children.Add(new BaseTypesEntryNode(i, true));
}
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(EnsureLazyChildren));
@ -69,78 +69,4 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -69,78 +69,4 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
}
}
sealed class BaseTypesEntryNode : ILSpyTreeNode, IMemberTreeNode
{
TypeReference tr;
TypeDefinition def;
bool isInterface;
public BaseTypesEntryNode(TypeReference tr, bool isInterface)
{
if (tr == null)
throw new ArgumentNullException("tr");
this.tr = tr;
this.def = tr.Resolve();
this.isInterface = isInterface;
this.LazyLoading = true;
}
public override bool ShowExpander {
get {
return def != null && (def.BaseType != null || def.HasInterfaces);
}
}
public override object Text {
get { return this.Language.TypeToString(tr, true); }
}
public override object Icon {
get {
if (def != null)
return TypeTreeNode.GetIcon(def);
else
return isInterface ? Images.Interface : Images.Class;
}
}
protected override void LoadChildren()
{
if (def != null)
BaseTypesTreeNode.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
}
e.Handled = ActivateItem(this, def);
}
internal static bool ActivateItem(SharpTreeNode node, TypeDefinition def)
{
if (def != null) {
var assemblyListNode = node.Ancestors().OfType<AssemblyListTreeNode>().FirstOrDefault();
if (assemblyListNode != null) {
assemblyListNode.Select(assemblyListNode.FindTypeNode(def));
return true;
}
}
return false;
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, language.TypeToString(tr, true));
}
MemberReference IMemberTreeNode.Member {
get { return tr; }
}
}
}
}

111
ILSpy/TreeNodes/DerivedTypesEntryNode.cs

@ -0,0 +1,111 @@ @@ -0,0 +1,111 @@
// 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.Generic;
using System.Threading;
using ICSharpCode.Decompiler;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes
{
class DerivedTypesEntryNode : ILSpyTreeNode, IMemberTreeNode
{
private TypeDefinition type;
private AssemblyDefinition[] assemblies;
private ThreadingSupport threading;
public DerivedTypesEntryNode(TypeDefinition type, AssemblyDefinition[] assemblies)
{
this.type = type;
this.assemblies = assemblies;
this.LazyLoading = true;
threading = new ThreadingSupport();
}
public override bool ShowExpander
{
get { return !type.IsSealed && base.ShowExpander; }
}
public override object Text
{
get { return this.Language.TypeToString(type, true); }
}
public override object Icon
{
get { return TypeTreeNode.GetIcon(type); }
}
public override FilterResult Filter(FilterSettings settings)
{
if (!settings.ShowInternalApi && !IsPublicAPI)
return FilterResult.Hidden;
if (settings.SearchTermMatches(type.Name)) {
if (type.IsNested && !settings.Language.ShowMember(type))
return FilterResult.Hidden;
else
return FilterResult.Match;
} else
return FilterResult.Recurse;
}
public bool IsPublicAPI
{
get
{
switch (type.Attributes & TypeAttributes.VisibilityMask) {
case TypeAttributes.Public:
case TypeAttributes.NestedPublic:
case TypeAttributes.NestedFamily:
case TypeAttributes.NestedFamORAssem:
return true;
default:
return false;
}
}
}
protected override void LoadChildren()
{
threading.LoadChildren(this, FetchChildren);
}
IEnumerable<ILSpyTreeNode> FetchChildren(CancellationToken ct)
{
// FetchChildren() runs on the main thread; but the enumerator will be consumed on a background thread
return DerivedTypesTreeNode.FindDerivedTypes(type, assemblies, ct);
}
public override void ActivateItem(System.Windows.RoutedEventArgs e)
{
e.Handled = BaseTypesEntryNode.ActivateItem(this, type);
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, language.TypeToString(type, true));
}
MemberReference IMemberTreeNode.Member
{
get { return type; }
}
}
}

111
ILSpy/TreeNodes/DerivedTypesTreeNode.cs

@ -20,7 +20,6 @@ using System; @@ -20,7 +20,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using ICSharpCode.Decompiler;
using ICSharpCode.NRefactory.Utils;
using Mono.Cecil;
@ -35,7 +34,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -35,7 +34,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
readonly AssemblyList list;
readonly TypeDefinition type;
ThreadingSupport threading;
public DerivedTypesTreeNode(AssemblyList list, TypeDefinition type)
{
this.list = list;
@ -43,27 +42,29 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -43,27 +42,29 @@ namespace ICSharpCode.ILSpy.TreeNodes
this.LazyLoading = true;
this.threading = new ThreadingSupport();
}
public override object Text {
public override object Text
{
get { return "Derived Types"; }
}
public override object Icon {
public override object Icon
{
get { return Images.SubTypes; }
}
protected override void LoadChildren()
{
threading.LoadChildren(this, FetchChildren);
}
IEnumerable<ILSpyTreeNode> FetchChildren(CancellationToken cancellationToken)
{
// FetchChildren() runs on the main thread; but the enumerator will be consumed on a background thread
var assemblies = list.GetAssemblies().Select(node => node.AssemblyDefinition).Where(asm => asm != null).ToArray();
return FindDerivedTypes(type, assemblies, cancellationToken);
}
internal static IEnumerable<DerivedTypesEntryNode> FindDerivedTypes(TypeDefinition type, AssemblyDefinition[] assemblies, CancellationToken cancellationToken)
{
foreach (AssemblyDefinition asm in assemblies) {
@ -80,7 +81,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -80,7 +81,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
}
}
static bool IsSameType(TypeReference typeRef, TypeDefinition type)
{
if (typeRef.FullName == type.FullName)
@ -96,96 +97,10 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -96,96 +97,10 @@ namespace ICSharpCode.ILSpy.TreeNodes
return false;
return true;
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
threading.Decompile(language, output, options, EnsureLazyChildren);
}
}
class DerivedTypesEntryNode : ILSpyTreeNode, IMemberTreeNode
{
TypeDefinition type;
AssemblyDefinition[] assemblies;
ThreadingSupport threading;
public DerivedTypesEntryNode(TypeDefinition type, AssemblyDefinition[] assemblies)
{
this.type = type;
this.assemblies = assemblies;
this.LazyLoading = true;
threading = new ThreadingSupport();
}
public override bool ShowExpander {
get {
return !type.IsSealed && base.ShowExpander;
}
}
public override object Text {
get { return this.Language.TypeToString(type, true); }
}
public override object Icon {
get {
return TypeTreeNode.GetIcon(type);
}
}
public override FilterResult Filter(FilterSettings settings)
{
if (!settings.ShowInternalApi && !IsPublicAPI)
return FilterResult.Hidden;
if (settings.SearchTermMatches(type.Name)) {
if (type.IsNested && !settings.Language.ShowMember(type))
return FilterResult.Hidden;
else
return FilterResult.Match;
} else {
return FilterResult.Recurse;
}
}
public bool IsPublicAPI
{
get
{
switch (type.Attributes & TypeAttributes.VisibilityMask) {
case TypeAttributes.Public:
case TypeAttributes.NestedPublic:
case TypeAttributes.NestedFamily:
case TypeAttributes.NestedFamORAssem:
return true;
default:
return false;
}
}
}
protected override void LoadChildren()
{
threading.LoadChildren(this, FetchChildren);
}
IEnumerable<ILSpyTreeNode> FetchChildren(CancellationToken ct)
{
// FetchChildren() runs on the main thread; but the enumerator will be consumed on a background thread
return DerivedTypesTreeNode.FindDerivedTypes(type, assemblies, ct);
}
public override void ActivateItem(System.Windows.RoutedEventArgs e)
{
e.Handled = BaseTypesEntryNode.ActivateItem(this, type);
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, language.TypeToString(type, true));
}
MemberReference IMemberTreeNode.Member {
get { return type; }
threading.Decompile(language, output, options, EnsureLazyChildren);
}
}
}
}

40
ILSpy/TreeNodes/FilterResult.cs

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
// 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.
namespace ICSharpCode.ILSpy.TreeNodes
{
public enum FilterResult
{
/// <summary>
/// Hides the node.
/// </summary>
Hidden,
/// <summary>
/// Shows the node (and resets the search term for child nodes).
/// </summary>
Match,
/// <summary>
/// Hides the node only if all children are hidden (and resets the search term for child nodes).
/// </summary>
MatchAndRecurse,
/// <summary>
/// Hides the node only if all children are hidden (doesn't reset the search term for child nodes).
/// </summary>
Recurse
}
}

58
ILSpy/TreeNodes/ILSpyTreeNode.cs

@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
@ -33,21 +32,24 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -33,21 +32,24 @@ namespace ICSharpCode.ILSpy.TreeNodes
{
FilterSettings filterSettings;
bool childrenNeedFiltering;
public FilterSettings FilterSettings {
public FilterSettings FilterSettings
{
get { return filterSettings; }
set {
set
{
if (filterSettings != value) {
filterSettings = value;
OnFilterSettingsChanged();
}
}
}
public Language Language {
public Language Language
{
get { return filterSettings != null ? filterSettings.Language : Languages.AllLanguages[0]; }
}
public virtual FilterResult Filter(FilterSettings settings)
{
if (string.IsNullOrEmpty(settings.SearchTerm))
@ -55,15 +57,15 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -55,15 +57,15 @@ namespace ICSharpCode.ILSpy.TreeNodes
else
return FilterResult.Hidden;
}
protected static object HighlightSearchMatch(string text, string suffix = null)
{
// TODO: implement highlighting the search match
return text + suffix;
}
public abstract void Decompile(Language language, ITextOutput output, DecompilationOptions options);
/// <summary>
/// Used to implement special view logic for some items.
/// This method is called on the main thread when only a single item is selected.
@ -73,7 +75,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -73,7 +75,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
{
return false;
}
/// <summary>
/// Used to implement special save logic for some items.
/// This method is called on the main thread when only a single item is selected.
@ -83,7 +85,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -83,7 +85,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
{
return false;
}
protected override void OnChildrenChanged(NotifyCollectionChangedEventArgs e)
{
if (e.NewItems != null) {
@ -96,7 +98,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -96,7 +98,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
base.OnChildrenChanged(e);
}
void ApplyFilterToChild(ILSpyTreeNode child)
{
FilterResult r;
@ -126,7 +128,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -126,7 +128,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
throw new InvalidEnumArgumentException();
}
}
FilterSettings StripSearchTerm(FilterSettings filterSettings)
{
if (filterSettings == null)
@ -137,7 +139,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -137,7 +139,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
return filterSettings;
}
protected virtual void OnFilterSettingsChanged()
{
RaisePropertyChanged("Text");
@ -148,13 +150,13 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -148,13 +150,13 @@ namespace ICSharpCode.ILSpy.TreeNodes
childrenNeedFiltering = true;
}
}
protected override void OnIsVisibleChanged()
{
base.OnIsVisibleChanged();
EnsureChildrenFiltered();
}
void EnsureChildrenFiltered()
{
EnsureLazyChildren();
@ -165,24 +167,4 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -165,24 +167,4 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
}
}
public enum FilterResult
{
/// <summary>
/// Hides the node.
/// </summary>
Hidden,
/// <summary>
/// Shows the node (and resets the search term for child nodes).
/// </summary>
Match,
/// <summary>
/// Hides the node only if all children are hidden (and resets the search term for child nodes).
/// </summary>
MatchAndRecurse,
/// <summary>
/// Hides the node only if all children are hidden (doesn't reset the search term for child nodes).
/// </summary>
Recurse
}
}
}
Loading…
Cancel
Save