diff --git a/Debugger/ILSpy.Debugger/Commands/BreakpointCommand.cs b/Debugger/ILSpy.Debugger/Commands/BreakpointCommand.cs index 31d1c0560..75b8e8722 100644 --- a/Debugger/ILSpy.Debugger/Commands/BreakpointCommand.cs +++ b/Debugger/ILSpy.Debugger/Commands/BreakpointCommand.cs @@ -53,12 +53,13 @@ namespace ICSharpCode.ILSpy.Debugger.Commands } } + /* [ExportBookmarkContextMenuEntry(Header="Disable Breakpoint", Category="Debugger")] public class DisableBreakpointCommand : IBookmarkContextMenuEntry { - public bool IsVisible(IBookmark[] bookmarks) + public bool IsVisible(IBookmark bookmark) { - return bookmarks.Any(b => b is BreakpointBookmark && (b as BreakpointBookmark).IsEnabled); + return b => b is BreakpointBookmark && (b as BreakpointBookmark).IsEnabled; } public bool IsEnabled(IBookmark[] bookmarks) @@ -70,5 +71,5 @@ namespace ICSharpCode.ILSpy.Debugger.Commands { throw new NotImplementedException(); } - } + }*/ } diff --git a/ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarManager.cs b/ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarManager.cs index 12926b26f..3f27d7402 100644 --- a/ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarManager.cs +++ b/ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarManager.cs @@ -43,21 +43,5 @@ namespace ICSharpCode.ILSpy.AvalonEdit } public event EventHandler RedrawRequested; - - public void UpdateClassMemberBookmarks(Dictionary iconMappings, Type bookmarkType, Type memberType) - { - this.bookmarks.Clear(); - - if (iconMappings == null || iconMappings.Count == 0) - return; - - foreach (var n in iconMappings) { - if (n.Key is TypeDefinition) { - this.bookmarks.Add(Activator.CreateInstance(bookmarkType, n.Key, n.Value) as IBookmark); - } else { - this.bookmarks.Add(Activator.CreateInstance(memberType, n.Key, n.Value) as IBookmark); - } - } - } } } diff --git a/ILSpy/AvalonEdit/IconMarginActionsProvider.cs b/ILSpy/AvalonEdit/IconMarginActionsProvider.cs index d6a0361cc..6cb4d3c7d 100644 --- a/ILSpy/AvalonEdit/IconMarginActionsProvider.cs +++ b/ILSpy/AvalonEdit/IconMarginActionsProvider.cs @@ -30,9 +30,9 @@ namespace ICSharpCode.ILSpy.AvalonEdit #region Context menu extensibility public interface IBookmarkContextMenuEntry { - bool IsVisible(IBookmark[] bookmarks); - bool IsEnabled(IBookmark[] bookmarks); - void Execute(IBookmark[] bookmarks); + bool IsVisible(IBookmark bookmarks); + bool IsEnabled(IBookmark bookmarks); + void Execute(IBookmark bookmarks); } public interface IBookmarkContextMenuEntryMetadata @@ -129,7 +129,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit if (entryPair.Value.IsEnabled()) { entry.Execute(line); - } + } } } } @@ -144,7 +144,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit } if (e.ChangedButton == MouseButton.Right) { - // check if we are on a Member + // check if we are on a Member var bookmark = bookmarks.FirstOrDefault(b => b.LineNumber == line); if (bookmark == null) { // don't show the menu @@ -153,15 +153,17 @@ namespace ICSharpCode.ILSpy.AvalonEdit return; } - var marks = new[] { bookmark }; ContextMenu menu = new ContextMenu(); foreach (var category in contextEntries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) { - if (menu.Items.Count > 0) { - menu.Items.Add(new Separator()); - } + bool needSeparatorForCategory = true; foreach (var entryPair in category) { IBookmarkContextMenuEntry entry = entryPair.Value; - if (entry.IsVisible(marks)) { + if (entry.IsVisible(bookmark)) { + if (needSeparatorForCategory && menu.Items.Count > 0) { + menu.Items.Add(new Separator()); + needSeparatorForCategory = false; + } + MenuItem menuItem = new MenuItem(); menuItem.Header = entryPair.Metadata.Header; if (!string.IsNullOrEmpty(entryPair.Metadata.Icon)) { @@ -171,8 +173,8 @@ namespace ICSharpCode.ILSpy.AvalonEdit Source = Images.LoadImage(entry, entryPair.Metadata.Icon) }; } - if (entryPair.Value.IsEnabled(marks)) { - menuItem.Click += delegate { entry.Execute(marks); }; + if (entryPair.Value.IsEnabled(bookmark)) { + menuItem.Click += delegate { entry.Execute(bookmark); }; } else menuItem.IsEnabled = false; menu.Items.Add(menuItem); diff --git a/ILSpy/Bookmarks/Commands.cs b/ILSpy/Bookmarks/Commands.cs deleted file mode 100644 index 451b29cb0..000000000 --- a/ILSpy/Bookmarks/Commands.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 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 ICSharpCode.ILSpy.AvalonEdit; -using ICSharpCode.ILSpy.TreeNodes.Analyzer; -using Mono.Cecil; - -namespace ICSharpCode.ILSpy.Bookmarks -{ - [ExportBookmarkContextMenuEntry(Header = "Analyze", Icon = "images/Search.png", Category="Default")] - internal sealed class AnalyzeBookmarkEntry : IBookmarkContextMenuEntry - { - public bool IsVisible(IBookmark[] marks) - { - return true; - } - - public bool IsEnabled(IBookmark[] marks) - { - return true; - } - - public void Execute(IBookmark[] marks) - { - foreach (var mark in marks) { - if (!(mark is MemberBookmark)) - continue; - - var member = (mark as MemberBookmark).Member; - AnalyzeContextMenuEntry.Analyze(member); - } - } - } -} diff --git a/ILSpy/Bookmarks/MemberBookmark.cs b/ILSpy/Bookmarks/MemberBookmark.cs index 5731a518f..8de319a56 100644 --- a/ILSpy/Bookmarks/MemberBookmark.cs +++ b/ILSpy/Bookmarks/MemberBookmark.cs @@ -95,21 +95,4 @@ namespace ICSharpCode.ILSpy.Bookmarks throw new NotSupportedException(); } } - - public class TypeBookmark : MemberBookmark - { - public TypeBookmark(MemberReference member, int line) : base (member, line) - { - } - - public override ImageSource Image { - get { - if (Member is TypeDefinition) { - return TreeNodes.TypeTreeNode.GetIcon((TypeDefinition)Member); - } - - return null; - } - } - } } diff --git a/ILSpy/ContextMenuEntry.cs b/ILSpy/ContextMenuEntry.cs index f3a6e8b03..e4ae3210e 100644 --- a/ILSpy/ContextMenuEntry.cs +++ b/ILSpy/ContextMenuEntry.cs @@ -90,12 +90,14 @@ namespace ICSharpCode.ILSpy } ContextMenu menu = new ContextMenu(); foreach (var category in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) { - if (menu.Items.Count > 0) { - menu.Items.Add(new Separator()); - } + bool needSeparatorForCategory = true; foreach (var entryPair in category) { IContextMenuEntry entry = entryPair.Value; if (entry.IsVisible(selectedNodes)) { + if (needSeparatorForCategory && menu.Items.Count > 0) { + menu.Items.Add(new Separator()); + needSeparatorForCategory = false; + } MenuItem menuItem = new MenuItem(); menuItem.Header = entryPair.Metadata.Header; if (!string.IsNullOrEmpty(entryPair.Metadata.Icon)) { diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index cd22ded9d..1a80781fc 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -93,7 +93,6 @@ - diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index a63af47d9..ab6416e4d 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -485,20 +485,30 @@ namespace ICSharpCode.ILSpy return path.ToArray(); } - public void JumpToReference(object reference) + public ILSpyTreeNode FindTreeNode(object reference) { if (reference is TypeReference) { - SelectNode(assemblyListTreeNode.FindTypeNode(((TypeReference)reference).Resolve())); + return assemblyListTreeNode.FindTypeNode(((TypeReference)reference).Resolve()); } else if (reference is MethodReference) { - SelectNode(assemblyListTreeNode.FindMethodNode(((MethodReference)reference).Resolve())); + return assemblyListTreeNode.FindMethodNode(((MethodReference)reference).Resolve()); } else if (reference is FieldReference) { - SelectNode(assemblyListTreeNode.FindFieldNode(((FieldReference)reference).Resolve())); + return assemblyListTreeNode.FindFieldNode(((FieldReference)reference).Resolve()); } else if (reference is PropertyReference) { - SelectNode(assemblyListTreeNode.FindPropertyNode(((PropertyReference)reference).Resolve())); + return assemblyListTreeNode.FindPropertyNode(((PropertyReference)reference).Resolve()); } else if (reference is EventReference) { - SelectNode(assemblyListTreeNode.FindEventNode(((EventReference)reference).Resolve())); + return assemblyListTreeNode.FindEventNode(((EventReference)reference).Resolve()); } else if (reference is AssemblyDefinition) { - SelectNode(assemblyListTreeNode.FindAssemblyNode((AssemblyDefinition)reference)); + return assemblyListTreeNode.FindAssemblyNode((AssemblyDefinition)reference); + } else { + return null; + } + } + + public void JumpToReference(object reference) + { + ILSpyTreeNode treeNode = FindTreeNode(reference); + if (treeNode != null) { + SelectNode(treeNode); } else if (reference is Mono.Cecil.Cil.OpCode) { string link = "http://msdn.microsoft.com/library/system.reflection.emit.opcodes." + ((Mono.Cecil.Cil.OpCode)reference).Code.ToString().ToLowerInvariant() + ".aspx"; try { diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index 45b3711b4..20bdbf65b 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -369,10 +369,7 @@ namespace ICSharpCode.ILSpy.TextView int offset = pair.Value; if (member != null) { int line = document.GetLocation(offset).Line; - if (member is TypeDefinition) - manager.Bookmarks.Add(new TypeBookmark(member, line)); - else - manager.Bookmarks.Add(new MemberBookmark(member, line)); + manager.Bookmarks.Add(new MemberBookmark(member, line)); } } } diff --git a/ILSpy/TreeNodes/AssemblyListTreeNode.cs b/ILSpy/TreeNodes/AssemblyListTreeNode.cs index 8dbab2fbf..28c06b93a 100644 --- a/ILSpy/TreeNodes/AssemblyListTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyListTreeNode.cs @@ -183,7 +183,7 @@ namespace ICSharpCode.ILSpy.TreeNodes /// Looks up the method node corresponding to the method definition. /// Returns null if no matching node is found. /// - public SharpTreeNode FindMethodNode(MethodDefinition def) + public ILSpyTreeNode FindMethodNode(MethodDefinition def) { if (def == null) return null;