Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: icsharpcode/ILSpy
base: c000780
...
head fork: icsharpcode/ILSpy
compare: 7345e82
  • 3 commits
  • 14 files changed
  • 0 commit comments
  • 1 contributor
View
16 Debugger/ILSpy.Debugger/Commands/DebuggerCommands.cs
@@ -179,12 +179,12 @@ void CurrentDebugger_IsProcessRunningChanged(object sender, EventArgs e)
}
}
- [ExportContextMenuEntry(Header = "_Debug Assembly", Icon = "Images/application-x-executable.png")]
+ [ExportContextMenuEntryAttribute(Header = "_Debug Assembly", Icon = "Images/application-x-executable.png")]
internal sealed class DebugExecutableNodeCommand : DebuggerCommand, IContextMenuEntry
{
- public bool IsVisible(SharpTreeNode[] selectedNodes)
+ public bool IsVisible(TextViewContext context)
{
- return selectedNodes.All(
+ return context.SelectedTreeNodes != null && context.SelectedTreeNodes.All(
delegate (SharpTreeNode n) {
AssemblyTreeNode a = n as AssemblyTreeNode;
if (a == null)
@@ -194,15 +194,17 @@ public bool IsVisible(SharpTreeNode[] selectedNodes)
});
}
- public bool IsEnabled(SharpTreeNode[] selectedNodes)
+ public bool IsEnabled(TextViewContext context)
{
- return selectedNodes.Length == 1;
+ return context.SelectedTreeNodes != null && context.SelectedTreeNodes.Length == 1;
}
- public void Execute(SharpTreeNode[] selectedNodes)
+ public void Execute(TextViewContext context)
{
+ if (context.SelectedTreeNodes == null)
+ return;
if (!CurrentDebugger.IsDebugging) {
- AssemblyTreeNode n = selectedNodes[0] as AssemblyTreeNode;
+ AssemblyTreeNode n = context.SelectedTreeNodes[0] as AssemblyTreeNode;
if (DebuggerSettings.Instance.AskForArguments) {
var window = new ExecuteProcessWindow { Owner = MainWindow.Instance,
View
106 ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/TypeDeclaration.cs
@@ -5,44 +5,43 @@
namespace Ricciolo.StylesExplorer.MarkupReflection
{
- internal class TypeDeclaration
+ class TypeDeclaration
{
- private readonly XmlBamlReader reader;
- private readonly bool _isExtension;
- private IType _type;
- private bool _typeLoaded;
- private readonly ITypeResolver resolver;
+ readonly XmlBamlReader reader;
+ readonly bool _isExtension;
+ IType _type;
+ bool _typeLoaded;
+ readonly ITypeResolver resolver;
+
+ protected TypeDeclaration(ITypeResolver resolver)
+ {
+ this.resolver = resolver;
+ }
public TypeDeclaration(ITypeResolver resolver, string name, string namespaceName, short assemblyId)
- : this(null, resolver, name, namespaceName, assemblyId, true)
+ : this(null, resolver, name, namespaceName, assemblyId)
{
}
public TypeDeclaration(ITypeResolver resolver, string name, string enclosingTypeName, string namespaceName, short assemblyId)
- : this(null, resolver, name, namespaceName, assemblyId, true)
+ : this(null, resolver, name, namespaceName, assemblyId)
{
this.EnclosingTypeName = enclosingTypeName;
}
public TypeDeclaration(ITypeResolver resolver, string name, string namespaceName, short assemblyId, bool isExtension)
- : this(null, resolver, name, namespaceName, assemblyId, true)
+ : this(null, resolver, name, namespaceName, assemblyId)
{
_isExtension = isExtension;
}
public TypeDeclaration(XmlBamlReader reader, ITypeResolver resolver, string name, string namespaceName, short assemblyId)
- : this(reader, resolver, name, namespaceName, assemblyId, true)
- {
- }
-
- public TypeDeclaration(XmlBamlReader reader, ITypeResolver resolver, string name, string namespaceName, short assemblyId, bool isKnown)
{
this.reader = reader;
this.resolver = resolver;
this.Name = name;
this.Namespace = namespaceName;
this.AssemblyId = assemblyId;
- this.IsKnown = isKnown;
if (!_isExtension)
_isExtension = name.EndsWith("Extension");
@@ -53,14 +52,14 @@ public override string ToString()
return this.Name;
}
- public string EnclosingTypeName { get; private set; }
+ protected virtual string EnclosingTypeName { get; set; }
public bool IsExtension
{
get { return _isExtension; }
}
- public string Assembly
+ public virtual string Assembly
{
get {
if (reader != null)
@@ -70,17 +69,13 @@ public string Assembly
}
}
- public short AssemblyId { get; private set; }
+ public virtual short AssemblyId { get; protected set; }
- public string Name { get; private set; }
-
- public bool IsKnown { get; private set; }
+ public virtual string Name { get; protected set; }
public IType Type {
- get
- {
- if (!_typeLoaded)
- {
+ get {
+ if (!_typeLoaded) {
if (this.Name.Length > 0)
_type = resolver.GetTypeByAssemblyQualifiedName(AssemblyQualifiedName);
_typeLoaded = true;
@@ -90,7 +85,7 @@ public string Assembly
}
}
- public string Namespace { get; private set; }
+ public virtual string Namespace { get; protected set; }
public string FullyQualifiedName {
get { return EnclosingTypeName == null ? string.Format("{0}.{1}", Namespace, Name) : string.Format("{0}.{1}+{2}", Namespace, EnclosingTypeName, Name); }
@@ -103,10 +98,10 @@ public string Assembly
public override bool Equals(object obj)
{
TypeDeclaration td = obj as TypeDeclaration;
- if (td != null)
+ if (td != null && !(obj is ResolverTypeDeclaration))
return (this.Name == td.Name && this.EnclosingTypeName == td.EnclosingTypeName && this.Namespace == td.Namespace && this.AssemblyId == td.AssemblyId);
- else
- return false;
+
+ return false;
}
public override int GetHashCode()
@@ -115,4 +110,57 @@ public override int GetHashCode()
}
}
+ class ResolverTypeDeclaration : TypeDeclaration
+ {
+ string assembly;
+
+ public override short AssemblyId {
+ get { throw new NotSupportedException(); }
+ protected set { throw new NotSupportedException(); }
+ }
+
+ public ResolverTypeDeclaration(ITypeResolver resolver, string assemblyQualifiedName)
+ : base(resolver)
+ {
+ string name, @namespace, assembly;
+ ParseName(assemblyQualifiedName, out name, out @namespace, out assembly);
+ Name = name;
+ Namespace = @namespace;
+ this.assembly = assembly;
+ }
+
+ void ParseName(string assemblyQualifiedName, out string name, out string @namespace, out string assembly)
+ {
+ int commaSeparator = assemblyQualifiedName.IndexOf(", ");
+ assembly = "";
+ if (commaSeparator >= 0) {
+ assembly = assemblyQualifiedName.Substring(commaSeparator + 2);
+ assemblyQualifiedName = assemblyQualifiedName.Remove(commaSeparator);
+ }
+ int namespaceSeparator = assemblyQualifiedName.LastIndexOf('.');
+ @namespace = "";
+ if (namespaceSeparator >= 0) {
+ @namespace = assemblyQualifiedName.Substring(0, namespaceSeparator);
+ }
+ name = assemblyQualifiedName.Substring(namespaceSeparator + 1);
+ }
+
+ public override string Assembly {
+ get { return assembly; }
+ }
+
+ public override bool Equals(object obj)
+ {
+ ResolverTypeDeclaration td = obj as ResolverTypeDeclaration;
+ if (td != null)
+ return (this.Name == td.Name && this.EnclosingTypeName == td.EnclosingTypeName && this.Namespace == td.Namespace);
+
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ return this.Name.GetHashCode() ^ this.EnclosingTypeName.GetHashCode() ^ this.Namespace.GetHashCode();
+ }
+ }
}
View
44 ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs
@@ -968,7 +968,8 @@ void ReadDefAttribute()
string recordName = this.stringTable[identifier];
if (recordName != "Key") throw new NotSupportedException(recordName);
pd = new PropertyDeclaration(recordName, XamlTypeDeclaration);
-
+ if (keys == null)
+ keys = new List<KeyMapping>();
keys.Add(new KeyMapping(text) { Position = -1 });
break;
}
@@ -1020,7 +1021,7 @@ void ReadXmlnsProperty()
if (mappingToChange == null)
throw new InvalidOperationException("Cannot find mapping");
- @namespace = String.Format("{0};assembly={1}", @namespace, GetAssembly(mappingToChange.AssemblyId).Replace(" ", ""));
+ @namespace = String.Format("{0};assembly={1}", @namespace, mappingToChange.Assembly.Replace(" ", ""));
mappingToChange.XmlNamespace = @namespace;
}
namespaces.Add(new XmlNamespace(prefix, @namespace));
@@ -1247,18 +1248,14 @@ void AddKeyToElement(string key)
XmlPIMapping FindByClrNamespaceAndAssemblyId(TypeDeclaration declaration)
{
- return FindByClrNamespaceAndAssemblyId(declaration.Namespace, declaration.AssemblyId);
+ return FindByClrNamespaceAndAssemblyName(declaration.Namespace, declaration.Assembly);
}
-
- XmlPIMapping FindByClrNamespaceAndAssemblyId(string clrNamespace, int assemblyId)
+
+ XmlPIMapping FindByClrNamespaceAndAssemblyName(string clrNamespace, string assemblyName)
{
- if (clrNamespace == XamlTypeDeclaration.Namespace && assemblyId == XamlTypeDeclaration.AssemblyId)
- return new XmlPIMapping(XmlPIMapping.XamlNamespace, 0, clrNamespace);
-
- for (int x = 0; x < Mappings.Count; x++)
- {
+ for (int x = 0; x < Mappings.Count; x++) {
XmlPIMapping xp = Mappings[x];
- if (xp.AssemblyId == assemblyId && String.CompareOrdinal(xp.ClrNamespace, clrNamespace) == 0)
+ if (string.Equals(xp.Assembly, assemblyName, StringComparison.Ordinal) && string.Equals(xp.ClrNamespace, clrNamespace, StringComparison.Ordinal))
return xp;
}
@@ -1271,7 +1268,7 @@ void ReadPIMapping()
string clrNamespace = reader.ReadString();
short assemblyId = reader.ReadInt16();
- Mappings.Add(new XmlPIMapping(xmlNamespace, assemblyId, clrNamespace));
+ Mappings.Add(new XmlPIMapping(xmlNamespace, GetAssembly(assemblyId), clrNamespace));
}
void ReadContentProperty()
@@ -1452,7 +1449,7 @@ string GetTypeExtension(short typeIdentifier)
string FormatTypeDeclaration(TypeDeclaration typeDeclaration)
{
- XmlPIMapping mapping = FindByClrNamespaceAndAssemblyId(typeDeclaration.Namespace, typeDeclaration.AssemblyId);
+ XmlPIMapping mapping = FindByClrNamespaceAndAssemblyName(typeDeclaration.Namespace, typeDeclaration.Assembly);
string prefix = (mapping != null) ? this.LookupPrefix(mapping.XmlNamespace, false) : null;
string name = typeDeclaration.Name;
if (name.EndsWith("Extension"))
@@ -1479,7 +1476,7 @@ string FormatPropertyDeclaration(PropertyDeclaration propertyDeclaration, bool w
bool differentType = ((propertyDeclaration.DeclaringType != propertyDeclaration.DeclaringType || !isDescendant));
if (withPrefix) {
- XmlPIMapping mapping = FindByClrNamespaceAndAssemblyId(propertyDeclaration.DeclaringType.Namespace, propertyDeclaration.DeclaringType.AssemblyId);
+ XmlPIMapping mapping = FindByClrNamespaceAndAssemblyName(propertyDeclaration.DeclaringType.Namespace, propertyDeclaration.DeclaringType.Assembly);
string prefix = (mapping != null) ? this.LookupPrefix(mapping.XmlNamespace, false) : null;
if (!String.IsNullOrEmpty(prefix)) {
@@ -1519,7 +1516,7 @@ object GetStaticResource(short identifier)
return keys[currentKey - 1].StaticResources[(int)identifier];
// return "???" + identifier + "???";
- throw new ArgumentException("Cannot find StaticResource", "identifier");
+ throw new ArgumentException("Cannot find StaticResource: " + identifier, "identifier");
}
void ReadTextWithConverter()
@@ -1542,11 +1539,11 @@ void ReadTypeInfo()
{
string name = fullName.Substring(length + 1);
string namespaceName = fullName.Substring(0, length);
- declaration = new TypeDeclaration(this, this.Resolver, name, namespaceName, assemblyId, false);
+ declaration = new TypeDeclaration(this, this.Resolver, name, namespaceName, assemblyId);
}
else
{
- declaration = new TypeDeclaration(this, this.Resolver, fullName, string.Empty, assemblyId, false);
+ declaration = new TypeDeclaration(this, this.Resolver, fullName, string.Empty, assemblyId);
}
this.typeTable.Add(typeId, declaration);
}
@@ -1579,14 +1576,13 @@ TypeDeclaration GetTypeDeclaration(short identifier)
return declaration;
}
- TypeDeclaration GetKnownTypeDeclarationByName(string name)
+ TypeDeclaration GetKnownTypeDeclarationByName(string assemblyQualifiedName)
{
foreach (var type in KnownInfo.KnownTypeTable) {
- if (name == type.AssemblyQualifiedName)
+ if (assemblyQualifiedName == type.AssemblyQualifiedName)
return type;
}
-
- throw new NotSupportedException("Type '" + name + "' not found!");
+ return new ResolverTypeDeclaration(_resolver, assemblyQualifiedName);
}
internal string GetAssembly(short identifier)
@@ -1616,8 +1612,8 @@ internal string GetAssembly(short identifier)
declaration = ((XmlBamlProperty)node).PropertyDeclaration.DeclaringType;
TypeDeclaration elementDeclaration = this.readingElements.Peek().TypeDeclaration;
- XmlPIMapping propertyMapping = FindByClrNamespaceAndAssemblyId(declaration) ?? XmlPIMapping.Presentation;
- XmlPIMapping elementMapping = FindByClrNamespaceAndAssemblyId(elementDeclaration) ?? XmlPIMapping.Presentation;
+ XmlPIMapping propertyMapping = FindByClrNamespaceAndAssemblyId(declaration) ?? XmlPIMapping.GetPresentationMapping(GetAssembly);
+ XmlPIMapping elementMapping = FindByClrNamespaceAndAssemblyId(elementDeclaration) ?? XmlPIMapping.GetPresentationMapping(GetAssembly);
if (((XmlBamlProperty)node).PropertyDeclaration.Name == "Name" &&
_resolver.IsLocalAssembly(((XmlBamlProperty)node).Parent.TypeDeclaration.Assembly))
@@ -1634,7 +1630,7 @@ internal string GetAssembly(short identifier)
XmlPIMapping mapping = FindByClrNamespaceAndAssemblyId(declaration);
if (mapping == null)
- mapping = XmlPIMapping.Presentation;
+ mapping = XmlPIMapping.GetPresentationMapping(GetAssembly);
return mapping.XmlNamespace;
}
View
27 ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlPIMapping.cs
@@ -10,20 +10,19 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
/// </summary>
public class XmlPIMapping
{
- private string _xmlNamespace;
- private short _assemblyId;
- private string _clrNamespace;
- private static XmlPIMapping _default = new XmlPIMapping(PresentationNamespace, 0, String.Empty);
+ string _xmlNamespace;
+ string assemblyName;
+ string _clrNamespace;
public const string XamlNamespace = "http://schemas.microsoft.com/winfx/2006/xaml";
public const string PresentationNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
public const string PresentationOptionsNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation/options";
public const string McNamespace = "http://schemas.openxmlformats.org/markup-compatibility/2006";
- public XmlPIMapping(string xmlNamespace, short assemblyId, string clrNamespace)
+ public XmlPIMapping(string xmlNamespace, string assembly, string clrNamespace)
{
_xmlNamespace = xmlNamespace;
- _assemblyId = assemblyId;
+ assemblyName = assembly;
_clrNamespace = clrNamespace;
}
@@ -37,11 +36,10 @@ public string XmlNamespace
}
/// <summary>
- /// Restituisce l'id dell'assembly
+ /// Name of the assembly.
/// </summary>
- public short AssemblyId
- {
- get { return _assemblyId; }
+ public string Assembly {
+ get { return assemblyName; }
}
/// <summary>
@@ -51,13 +49,10 @@ public string ClrNamespace
{
get { return _clrNamespace; }
}
-
- /// <summary>
- /// Restituisce il mapping di default di WPF
- /// </summary>
- public static XmlPIMapping Presentation
+
+ public static XmlPIMapping GetPresentationMapping(Func<short, string> assemblyResolve)
{
- get { return _default; }
+ return new XmlPIMapping(PresentationNamespace, assemblyResolve(0), string.Empty);
}
}
}
View
17 ILSpy/AnalyzerTreeView.cs
@@ -84,6 +84,23 @@ public void Show(AnalyzerTreeNode node)
this.SelectedItem = node;
this.FocusNode(node);
}
+
+ public void ShowOrFocus(AnalyzerTreeNode node)
+ {
+ if (node is AnalyzerEntityTreeNode) {
+ var an = node as AnalyzerEntityTreeNode;
+ var found = this.Root.Children.OfType<AnalyzerEntityTreeNode>().FirstOrDefault(n => n.Member == an.Member);
+ if (found != null) {
+ Show();
+
+ found.IsExpanded = true;
+ this.SelectedItem = found;
+ this.FocusNode(found);
+ return;
+ }
+ }
+ Show(node);
+ }
void IPane.Closed()
{
View
104 ILSpy/ContextMenuEntry.cs
@@ -19,17 +19,57 @@
using System;
using System.ComponentModel.Composition;
using System.Linq;
+using System.Windows;
using System.Windows.Controls;
-
+using ICSharpCode.ILSpy.TextView;
using ICSharpCode.TreeView;
namespace ICSharpCode.ILSpy
{
public interface IContextMenuEntry
{
- bool IsVisible(SharpTreeNode[] selectedNodes);
- bool IsEnabled(SharpTreeNode[] selectedNodes);
- void Execute(SharpTreeNode[] selectedNodes);
+ bool IsVisible(TextViewContext context);
+ bool IsEnabled(TextViewContext context);
+ void Execute(TextViewContext context);
+ }
+
+ public class TextViewContext
+ {
+ /// <summary>
+ /// Returns the selected nodes in the tree view.
+ /// Returns null, if context menu does not belong to a tree view.
+ /// </summary>
+ public SharpTreeNode[] SelectedTreeNodes { get; private set; }
+
+ /// <summary>
+ /// Returns the tree view the context menu is assigned to.
+ /// Returns null, if context menu is not assigned to a tree view.
+ /// </summary>
+ public SharpTreeView TreeView { get; private set; }
+
+ /// <summary>
+ /// Returns the text view the context menu is assigned to.
+ /// Returns null, if context menu is not assigned to a text view.
+ /// </summary>
+ public DecompilerTextView TextView { get; private set; }
+
+ /// <summary>
+ /// Returns the reference the mouse cursor is currently hovering above.
+ /// Returns null, if there was no reference found.
+ /// </summary>
+ public ReferenceSegment Reference { get; private set; }
+
+ public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null)
+ {
+ var reference = textView != null ? textView.GetReferenceSegmentAtMousePosition() : null;
+ var selectedTreeNodes = treeView != null ? treeView.GetTopLevelSelection().ToArray() : null;
+ return new TextViewContext {
+ TreeView = treeView,
+ SelectedTreeNodes = selectedTreeNodes,
+ TextView = textView,
+ Reference = reference
+ };
+ }
}
public interface IContextMenuEntryMetadata
@@ -61,39 +101,68 @@ internal class ContextMenuProvider
/// <summary>
/// Enables extensible context menu support for the specified tree view.
/// </summary>
- public static void Add(SharpTreeView treeView)
+ public static void Add(SharpTreeView treeView, DecompilerTextView textView = null)
{
- var provider = new ContextMenuProvider(treeView);
+ var provider = new ContextMenuProvider(treeView, textView);
treeView.ContextMenuOpening += provider.treeView_ContextMenuOpening;
// Context menu is shown only when the ContextMenu property is not null before the
// ContextMenuOpening event handler is called.
treeView.ContextMenu = new ContextMenu();
+ if (textView != null) {
+ textView.ContextMenuOpening += provider.textView_ContextMenuOpening;
+ // Context menu is shown only when the ContextMenu property is not null before the
+ // ContextMenuOpening event handler is called.
+ textView.ContextMenu = new ContextMenu();
+ }
}
readonly SharpTreeView treeView;
+ readonly DecompilerTextView textView;
[ImportMany(typeof(IContextMenuEntry))]
Lazy<IContextMenuEntry, IContextMenuEntryMetadata>[] entries = null;
- private ContextMenuProvider(SharpTreeView treeView)
+ ContextMenuProvider(SharpTreeView treeView, DecompilerTextView textView = null)
{
this.treeView = treeView;
+ this.textView = textView;
App.CompositionContainer.ComposeParts(this);
}
void treeView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
- SharpTreeNode[] selectedNodes = treeView.GetTopLevelSelection().ToArray();
- if (selectedNodes.Length == 0) {
+ TextViewContext context = TextViewContext.Create(treeView);
+ if (context.SelectedTreeNodes.Length == 0) {
e.Handled = true; // don't show the menu
return;
}
- ContextMenu menu = new ContextMenu();
+ ContextMenu menu;
+ if (ShowContextMenu(context, out menu))
+ treeView.ContextMenu = menu;
+ else
+ // hide the context menu.
+ e.Handled = true;
+ }
+
+ void textView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
+ {
+ TextViewContext context = TextViewContext.Create(textView: textView);
+ ContextMenu menu;
+ if (ShowContextMenu(context, out menu))
+ textView.ContextMenu = menu;
+ else
+ // hide the context menu.
+ e.Handled = true;
+ }
+
+ bool ShowContextMenu(TextViewContext context, out ContextMenu menu)
+ {
+ menu = new ContextMenu();
foreach (var category in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) {
bool needSeparatorForCategory = true;
foreach (var entryPair in category) {
IContextMenuEntry entry = entryPair.Value;
- if (entry.IsVisible(selectedNodes)) {
+ if (entry.IsVisible(context)) {
if (needSeparatorForCategory && menu.Items.Count > 0) {
menu.Items.Add(new Separator());
needSeparatorForCategory = false;
@@ -107,22 +176,15 @@ void treeView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
Source = Images.LoadImage(entry, entryPair.Metadata.Icon)
};
}
- if (entryPair.Value.IsEnabled(selectedNodes)) {
- menuItem.Click += delegate
- {
- entry.Execute(selectedNodes);
- };
+ if (entryPair.Value.IsEnabled(context)) {
+ menuItem.Click += delegate { entry.Execute(context); };
} else
menuItem.IsEnabled = false;
menu.Items.Add(menuItem);
}
}
}
- if (menu.Items.Count > 0)
- treeView.ContextMenu = menu;
- else
- // hide the context menu.
- e.Handled = true;
+ return menu.Items.Count > 0;
}
}
}
View
3  ILSpy/ILSpy.csproj
@@ -31,10 +31,11 @@
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
- <PlatformTarget>AnyCPU</PlatformTarget>
+ <PlatformTarget>x86</PlatformTarget>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
+ <FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
View
2  ILSpy/Languages/CSharpLanguage.cs
@@ -230,7 +230,6 @@ public static string GetPlatformDisplayName(ModuleDefinition module)
return "x86";
else
return "AnyCPU (64-bit preferred)";
- break;
case TargetArchitecture.AMD64:
return "x64";
case TargetArchitecture.IA64:
@@ -250,7 +249,6 @@ public static string GetPlatformName(ModuleDefinition module)
return "x86";
else
return "AnyCPU";
- break;
case TargetArchitecture.AMD64:
return "x64";
case TargetArchitecture.IA64:
View
2  ILSpy/MainWindow.xaml.cs
@@ -90,7 +90,7 @@ public MainWindow()
InitMainMenu();
InitToolbar();
- ContextMenuProvider.Add(treeView);
+ ContextMenuProvider.Add(treeView, decompilerTextView);
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
View
2  ILSpy/TextView/AvalonEditTextOutput.cs
@@ -33,7 +33,7 @@ namespace ICSharpCode.ILSpy.TextView
/// <summary>
/// A text segment that references some object. Used for hyperlinks in the editor.
/// </summary>
- sealed class ReferenceSegment : TextSegment
+ public sealed class ReferenceSegment : TextSegment
{
public object Reference;
public bool IsLocal;
View
11 ILSpy/TextView/DecompilerTextView.cs
@@ -182,7 +182,7 @@ void TextViewMouseHover(object sender, MouseEventArgs e)
TextViewPosition? position = textEditor.TextArea.TextView.GetPosition(e.GetPosition(textEditor.TextArea.TextView) + textEditor.TextArea.TextView.ScrollOffset);
if (position == null)
return;
- int offset = textEditor.Document.GetOffset(position.Value);
+ int offset = textEditor.Document.GetOffset(position.Value.Location);
ReferenceSegment seg = referenceElementGenerator.References.FindSegmentsContaining(offset).FirstOrDefault();
if (seg == null)
return;
@@ -761,6 +761,15 @@ internal static string CleanUpName(string text)
}
#endregion
+ internal ReferenceSegment GetReferenceSegmentAtMousePosition()
+ {
+ TextViewPosition? position = textEditor.TextArea.TextView.GetPosition(Mouse.GetPosition(textEditor.TextArea.TextView) + textEditor.TextArea.TextView.ScrollOffset);
+ if (position == null)
+ return null;
+ int offset = textEditor.Document.GetOffset(position.Value.Location);
+ return referenceElementGenerator.References.FindSegmentsContaining(offset).FirstOrDefault();
+ }
+
public DecompilerTextViewState GetState()
{
if (decompiledNodes == null)
View
43 ILSpy/TreeNodes/Analyzer/AnalyzeContextMenuEntry.cs
@@ -18,22 +18,27 @@
using System;
using System.Linq;
+using System.Windows;
using ICSharpCode.TreeView;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{
- [ExportContextMenuEntry(Header = "Analyze", Icon = "images/Search.png")]
+ [ExportContextMenuEntryAttribute(Header = "Analyze", Icon = "images/Search.png")]
internal sealed class AnalyzeContextMenuEntry : IContextMenuEntry
{
- public bool IsVisible(SharpTreeNode[] selectedNodes)
+ public bool IsVisible(TextViewContext context)
{
- return selectedNodes.All(n => n is IMemberTreeNode);
+ if (context.SelectedTreeNodes == null)
+ return context.Reference != null && context.Reference.Reference is MemberReference;
+ return context.SelectedTreeNodes.All(n => n is IMemberTreeNode);
}
- public bool IsEnabled(SharpTreeNode[] selectedNodes)
+ public bool IsEnabled(TextViewContext context)
{
- foreach (IMemberTreeNode node in selectedNodes) {
+ if (context.SelectedTreeNodes == null)
+ return context.Reference != null && context.Reference.Reference is MemberReference;
+ foreach (IMemberTreeNode node in context.SelectedTreeNodes) {
if (!(node.Member is TypeDefinition
|| node.Member is FieldDefinition
|| node.Member is MethodDefinition
@@ -45,32 +50,38 @@ public bool IsEnabled(SharpTreeNode[] selectedNodes)
return true;
}
- public void Execute(SharpTreeNode[] selectedNodes)
+ public void Execute(TextViewContext context)
{
- // TODO: figure out when equivalent nodes are already present
- // and focus those instead.
- foreach (IMemberTreeNode node in selectedNodes) {
- Analyze(node.Member);
+ if (context.SelectedTreeNodes != null) {
+ foreach (IMemberTreeNode node in context.SelectedTreeNodes) {
+ Analyze(node.Member);
+ }
+ } else if (context.Reference != null && context.Reference.Reference is MemberReference) {
+ if (context.Reference.Reference is MemberReference)
+ Analyze((MemberReference)context.Reference.Reference);
+ // TODO: implement support for other references: ParameterReference, etc.
}
}
public static void Analyze(MemberReference member)
{
- TypeDefinition type = member as TypeDefinition;
+ TypeDefinition type = null;
+ if (member is TypeReference)
+ type = ((TypeReference)member).Resolve();
if (type != null)
- AnalyzerTreeView.Instance.Show(new AnalyzedTypeTreeNode(type));
+ AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedTypeTreeNode(type.Resolve()));
FieldDefinition field = member as FieldDefinition;
if (field != null)
- AnalyzerTreeView.Instance.Show(new AnalyzedFieldTreeNode(field));
+ AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedFieldTreeNode(field));
MethodDefinition method = member as MethodDefinition;
if (method != null)
- AnalyzerTreeView.Instance.Show(new AnalyzedMethodTreeNode(method));
+ AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedMethodTreeNode(method));
var propertyAnalyzer = AnalyzedPropertyTreeNode.TryCreateAnalyzer(member);
if (propertyAnalyzer != null)
- AnalyzerTreeView.Instance.Show(propertyAnalyzer);
+ AnalyzerTreeView.Instance.ShowOrFocus(propertyAnalyzer);
var eventAnalyzer = AnalyzedEventTreeNode.TryCreateAnalyzer(member);
if (eventAnalyzer != null)
- AnalyzerTreeView.Instance.Show(eventAnalyzer);
+ AnalyzerTreeView.Instance.ShowOrFocus(eventAnalyzer);
}
}
}
View
16 ILSpy/TreeNodes/AssemblyTreeNode.cs
@@ -255,22 +255,26 @@ public override bool Save(DecompilerTextView textView)
}
}
- [ExportContextMenuEntry(Header = "_Remove", Icon = "images/Delete.png")]
+ [ExportContextMenuEntryAttribute(Header = "_Remove", Icon = "images/Delete.png")]
sealed class RemoveAssembly : IContextMenuEntry
{
- public bool IsVisible(SharpTreeNode[] selectedNodes)
+ public bool IsVisible(TextViewContext context)
{
- return selectedNodes.All(n => n is AssemblyTreeNode);
+ if (context.SelectedTreeNodes == null)
+ return false;
+ return context.SelectedTreeNodes.All(n => n is AssemblyTreeNode);
}
- public bool IsEnabled(SharpTreeNode[] selectedNodes)
+ public bool IsEnabled(TextViewContext context)
{
return true;
}
- public void Execute(SharpTreeNode[] selectedNodes)
+ public void Execute(TextViewContext context)
{
- foreach (var node in selectedNodes) {
+ if (context.SelectedTreeNodes == null)
+ return;
+ foreach (var node in context.SelectedTreeNodes) {
node.Delete();
}
}
View
16 TestPlugin/ContextMenuCommand.cs
@@ -11,22 +11,24 @@
namespace TestPlugin
{
- [ExportContextMenuEntry(Header = "_Save Assembly")]
+ [ExportContextMenuEntryAttribute(Header = "_Save Assembly")]
public class SaveAssembly : IContextMenuEntry
{
- public bool IsVisible(SharpTreeNode[] selectedNodes)
+ public bool IsVisible(TextViewContext context)
{
- return selectedNodes.All(n => n is AssemblyTreeNode);
+ return context.SelectedTreeNodes != null && context.SelectedTreeNodes.All(n => n is AssemblyTreeNode);
}
- public bool IsEnabled(SharpTreeNode[] selectedNodes)
+ public bool IsEnabled(TextViewContext context)
{
- return selectedNodes.Length == 1;
+ return context.SelectedTreeNodes != null && context.SelectedTreeNodes.Length == 1;
}
- public void Execute(SharpTreeNode[] selectedNodes)
+ public void Execute(TextViewContext context)
{
- AssemblyTreeNode node = (AssemblyTreeNode)selectedNodes[0];
+ if (context.SelectedTreeNodes == null)
+ return;
+ AssemblyTreeNode node = (AssemblyTreeNode)context.SelectedTreeNodes[0];
AssemblyDefinition asm = node.LoadedAssembly.AssemblyDefinition as AssemblyDefinition;
if (asm != null) {
SaveFileDialog dlg = new SaveFileDialog();

No commit comments for this range

Something went wrong with that request. Please try again.