Browse Source

Simplify bookmarks logic.

pull/285/head
Daniel Grunwald 14 years ago
parent
commit
becc8f14d0
  1. 7
      Debugger/ILSpy.Debugger/Commands/BreakpointCommand.cs
  2. 16
      ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarManager.cs
  3. 26
      ILSpy/AvalonEdit/IconMarginActionsProvider.cs
  4. 50
      ILSpy/Bookmarks/Commands.cs
  5. 17
      ILSpy/Bookmarks/MemberBookmark.cs
  6. 8
      ILSpy/ContextMenuEntry.cs
  7. 1
      ILSpy/ILSpy.csproj
  8. 24
      ILSpy/MainWindow.xaml.cs
  9. 5
      ILSpy/TextView/DecompilerTextView.cs
  10. 2
      ILSpy/TreeNodes/AssemblyListTreeNode.cs

7
Debugger/ILSpy.Debugger/Commands/BreakpointCommand.cs

@ -53,12 +53,13 @@ namespace ICSharpCode.ILSpy.Debugger.Commands
} }
} }
/*
[ExportBookmarkContextMenuEntry(Header="Disable Breakpoint", Category="Debugger")] [ExportBookmarkContextMenuEntry(Header="Disable Breakpoint", Category="Debugger")]
public class DisableBreakpointCommand : IBookmarkContextMenuEntry 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) public bool IsEnabled(IBookmark[] bookmarks)
@ -70,5 +71,5 @@ namespace ICSharpCode.ILSpy.Debugger.Commands
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }*/
} }

16
ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarManager.cs

@ -43,21 +43,5 @@ namespace ICSharpCode.ILSpy.AvalonEdit
} }
public event EventHandler RedrawRequested; public event EventHandler RedrawRequested;
public void UpdateClassMemberBookmarks(Dictionary<MemberReference, int> 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);
}
}
}
} }
} }

26
ILSpy/AvalonEdit/IconMarginActionsProvider.cs

@ -30,9 +30,9 @@ namespace ICSharpCode.ILSpy.AvalonEdit
#region Context menu extensibility #region Context menu extensibility
public interface IBookmarkContextMenuEntry public interface IBookmarkContextMenuEntry
{ {
bool IsVisible(IBookmark[] bookmarks); bool IsVisible(IBookmark bookmarks);
bool IsEnabled(IBookmark[] bookmarks); bool IsEnabled(IBookmark bookmarks);
void Execute(IBookmark[] bookmarks); void Execute(IBookmark bookmarks);
} }
public interface IBookmarkContextMenuEntryMetadata public interface IBookmarkContextMenuEntryMetadata
@ -129,7 +129,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit
if (entryPair.Value.IsEnabled()) { if (entryPair.Value.IsEnabled()) {
entry.Execute(line); entry.Execute(line);
} }
} }
} }
} }
@ -144,7 +144,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit
} }
if (e.ChangedButton == MouseButton.Right) { 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); var bookmark = bookmarks.FirstOrDefault(b => b.LineNumber == line);
if (bookmark == null) { if (bookmark == null) {
// don't show the menu // don't show the menu
@ -153,15 +153,17 @@ namespace ICSharpCode.ILSpy.AvalonEdit
return; return;
} }
var marks = new[] { bookmark };
ContextMenu menu = new ContextMenu(); ContextMenu menu = new ContextMenu();
foreach (var category in contextEntries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) { foreach (var category in contextEntries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) {
if (menu.Items.Count > 0) { bool needSeparatorForCategory = true;
menu.Items.Add(new Separator());
}
foreach (var entryPair in category) { foreach (var entryPair in category) {
IBookmarkContextMenuEntry entry = entryPair.Value; 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 menuItem = new MenuItem();
menuItem.Header = entryPair.Metadata.Header; menuItem.Header = entryPair.Metadata.Header;
if (!string.IsNullOrEmpty(entryPair.Metadata.Icon)) { if (!string.IsNullOrEmpty(entryPair.Metadata.Icon)) {
@ -171,8 +173,8 @@ namespace ICSharpCode.ILSpy.AvalonEdit
Source = Images.LoadImage(entry, entryPair.Metadata.Icon) Source = Images.LoadImage(entry, entryPair.Metadata.Icon)
}; };
} }
if (entryPair.Value.IsEnabled(marks)) { if (entryPair.Value.IsEnabled(bookmark)) {
menuItem.Click += delegate { entry.Execute(marks); }; menuItem.Click += delegate { entry.Execute(bookmark); };
} else } else
menuItem.IsEnabled = false; menuItem.IsEnabled = false;
menu.Items.Add(menuItem); menu.Items.Add(menuItem);

50
ILSpy/Bookmarks/Commands.cs

@ -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);
}
}
}
}

17
ILSpy/Bookmarks/MemberBookmark.cs

@ -95,21 +95,4 @@ namespace ICSharpCode.ILSpy.Bookmarks
throw new NotSupportedException(); 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;
}
}
}
} }

8
ILSpy/ContextMenuEntry.cs

@ -90,12 +90,14 @@ namespace ICSharpCode.ILSpy
} }
ContextMenu menu = new ContextMenu(); ContextMenu menu = new ContextMenu();
foreach (var category in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) { foreach (var category in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) {
if (menu.Items.Count > 0) { bool needSeparatorForCategory = true;
menu.Items.Add(new Separator());
}
foreach (var entryPair in category) { foreach (var entryPair in category) {
IContextMenuEntry entry = entryPair.Value; IContextMenuEntry entry = entryPair.Value;
if (entry.IsVisible(selectedNodes)) { if (entry.IsVisible(selectedNodes)) {
if (needSeparatorForCategory && menu.Items.Count > 0) {
menu.Items.Add(new Separator());
needSeparatorForCategory = false;
}
MenuItem menuItem = new MenuItem(); MenuItem menuItem = new MenuItem();
menuItem.Header = entryPair.Metadata.Header; menuItem.Header = entryPair.Metadata.Header;
if (!string.IsNullOrEmpty(entryPair.Metadata.Icon)) { if (!string.IsNullOrEmpty(entryPair.Metadata.Icon)) {

1
ILSpy/ILSpy.csproj

@ -93,7 +93,6 @@
<Compile Include="AssemblyList.cs" /> <Compile Include="AssemblyList.cs" />
<Compile Include="AssemblyListManager.cs" /> <Compile Include="AssemblyListManager.cs" />
<Compile Include="AvalonEdit\IconMarginActionsProvider.cs" /> <Compile Include="AvalonEdit\IconMarginActionsProvider.cs" />
<Compile Include="Bookmarks\Commands.cs" />
<Compile Include="Bookmarks\MemberBookmark.cs" /> <Compile Include="Bookmarks\MemberBookmark.cs" />
<Compile Include="Commands\BrowseBackCommand.cs" /> <Compile Include="Commands\BrowseBackCommand.cs" />
<Compile Include="Commands\BrowseForwardCommand.cs" /> <Compile Include="Commands\BrowseForwardCommand.cs" />

24
ILSpy/MainWindow.xaml.cs

@ -485,20 +485,30 @@ namespace ICSharpCode.ILSpy
return path.ToArray(); return path.ToArray();
} }
public void JumpToReference(object reference) public ILSpyTreeNode FindTreeNode(object reference)
{ {
if (reference is TypeReference) { if (reference is TypeReference) {
SelectNode(assemblyListTreeNode.FindTypeNode(((TypeReference)reference).Resolve())); return assemblyListTreeNode.FindTypeNode(((TypeReference)reference).Resolve());
} else if (reference is MethodReference) { } else if (reference is MethodReference) {
SelectNode(assemblyListTreeNode.FindMethodNode(((MethodReference)reference).Resolve())); return assemblyListTreeNode.FindMethodNode(((MethodReference)reference).Resolve());
} else if (reference is FieldReference) { } else if (reference is FieldReference) {
SelectNode(assemblyListTreeNode.FindFieldNode(((FieldReference)reference).Resolve())); return assemblyListTreeNode.FindFieldNode(((FieldReference)reference).Resolve());
} else if (reference is PropertyReference) { } else if (reference is PropertyReference) {
SelectNode(assemblyListTreeNode.FindPropertyNode(((PropertyReference)reference).Resolve())); return assemblyListTreeNode.FindPropertyNode(((PropertyReference)reference).Resolve());
} else if (reference is EventReference) { } else if (reference is EventReference) {
SelectNode(assemblyListTreeNode.FindEventNode(((EventReference)reference).Resolve())); return assemblyListTreeNode.FindEventNode(((EventReference)reference).Resolve());
} else if (reference is AssemblyDefinition) { } 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) { } 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"; string link = "http://msdn.microsoft.com/library/system.reflection.emit.opcodes." + ((Mono.Cecil.Cil.OpCode)reference).Code.ToString().ToLowerInvariant() + ".aspx";
try { try {

5
ILSpy/TextView/DecompilerTextView.cs

@ -369,10 +369,7 @@ namespace ICSharpCode.ILSpy.TextView
int offset = pair.Value; int offset = pair.Value;
if (member != null) { if (member != null) {
int line = document.GetLocation(offset).Line; int line = document.GetLocation(offset).Line;
if (member is TypeDefinition) manager.Bookmarks.Add(new MemberBookmark(member, line));
manager.Bookmarks.Add(new TypeBookmark(member, line));
else
manager.Bookmarks.Add(new MemberBookmark(member, line));
} }
} }
} }

2
ILSpy/TreeNodes/AssemblyListTreeNode.cs

@ -183,7 +183,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// Looks up the method node corresponding to the method definition. /// Looks up the method node corresponding to the method definition.
/// Returns null if no matching node is found. /// Returns null if no matching node is found.
/// </summary> /// </summary>
public SharpTreeNode FindMethodNode(MethodDefinition def) public ILSpyTreeNode FindMethodNode(MethodDefinition def)
{ {
if (def == null) if (def == null)
return null; return null;

Loading…
Cancel
Save