Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplify bookmarks logic.

  • Loading branch information...
commit becc8f14d0067157215c81e31ac6596e491e52e0 1 parent c542648
@dgrunwald dgrunwald authored
View
7 Debugger/ILSpy.Debugger/Commands/BreakpointCommand.cs
@@ -53,12 +53,13 @@ public void Execute(int line)
}
}
+ /*
[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 @@ public void Execute(IBookmark[] bookmarks)
{
throw new NotImplementedException();
}
- }
+ }*/
}
View
16 ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarManager.cs
@@ -43,21 +43,5 @@ public void Redraw()
}
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);
- }
- }
- }
}
}
View
26 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 @@ void HandleMouseEvent(object sender, MouseButtonEventArgs e)
if (entryPair.Value.IsEnabled()) {
entry.Execute(line);
- }
+ }
}
}
}
@@ -144,7 +144,7 @@ void HandleMouseEvent(object sender, MouseButtonEventArgs e)
}
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 @@ void HandleMouseEvent(object sender, MouseButtonEventArgs e)
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 @@ void HandleMouseEvent(object sender, MouseButtonEventArgs e)
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);
View
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);
- }
- }
- }
-}
View
17 ILSpy/Bookmarks/MemberBookmark.cs
@@ -95,21 +95,4 @@ void IBookmark.Drop(int lineNumber)
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;
- }
- }
- }
}
View
8 ILSpy/ContextMenuEntry.cs
@@ -90,12 +90,14 @@ void treeView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
}
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)) {
View
1  ILSpy/ILSpy.csproj
@@ -93,7 +93,6 @@
<Compile Include="AssemblyList.cs" />
<Compile Include="AssemblyListManager.cs" />
<Compile Include="AvalonEdit\IconMarginActionsProvider.cs" />
- <Compile Include="Bookmarks\Commands.cs" />
<Compile Include="Bookmarks\MemberBookmark.cs" />
<Compile Include="Commands\BrowseBackCommand.cs" />
<Compile Include="Commands\BrowseForwardCommand.cs" />
View
24 ILSpy/MainWindow.xaml.cs
@@ -485,20 +485,30 @@ string[] GetPathForNode(SharpTreeNode node)
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 {
View
5 ILSpy/TextView/DecompilerTextView.cs
@@ -369,10 +369,7 @@ void ShowOutput(AvalonEditTextOutput textOutput, IHighlightingDefinition highlig
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));
}
}
}
View
2  ILSpy/TreeNodes/AssemblyListTreeNode.cs
@@ -183,7 +183,7 @@ public TypeTreeNode FindTypeNode(TypeDefinition def)
/// Looks up the method node corresponding to the method definition.
/// Returns null if no matching node is found.
/// </summary>
- public SharpTreeNode FindMethodNode(MethodDefinition def)
+ public ILSpyTreeNode FindMethodNode(MethodDefinition def)
{
if (def == null)
return null;
Please sign in to comment.
Something went wrong with that request. Please try again.