|
|
|
@ -55,6 +55,12 @@ namespace ICSharpCode.ILSpy
@@ -55,6 +55,12 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DecompilerTextView TextView { get; private set; } |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the list box the context menu is assigned to.
|
|
|
|
|
/// Returns null, if context menu is not assigned to a list box.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ListBox ListBox { get; private set; } |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the reference the mouse cursor is currently hovering above.
|
|
|
|
|
/// Returns null, if there was no reference found.
|
|
|
|
@ -67,9 +73,15 @@ namespace ICSharpCode.ILSpy
@@ -67,9 +73,15 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
/// </summary>
|
|
|
|
|
public TextViewPosition? Position { get; private set; } |
|
|
|
|
|
|
|
|
|
public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null) |
|
|
|
|
public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null, ListBox listBox = null) |
|
|
|
|
{ |
|
|
|
|
var reference = textView != null ? textView.GetReferenceSegmentAtMousePosition() : null; |
|
|
|
|
ReferenceSegment reference; |
|
|
|
|
if (textView != null) |
|
|
|
|
reference = textView.GetReferenceSegmentAtMousePosition(); |
|
|
|
|
else if (listBox != null) |
|
|
|
|
reference = new ReferenceSegment { Reference = ((SearchResult)listBox.SelectedItem).Member }; |
|
|
|
|
else |
|
|
|
|
reference = null; |
|
|
|
|
var position = textView != null ? textView.GetPositionFromMousePosition() : null; |
|
|
|
|
var selectedTreeNodes = treeView != null ? treeView.GetTopLevelSelection().ToArray() : null; |
|
|
|
|
return new TextViewContext { |
|
|
|
@ -126,8 +138,16 @@ namespace ICSharpCode.ILSpy
@@ -126,8 +138,16 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void Add(ListBox listBox) |
|
|
|
|
{ |
|
|
|
|
var provider = new ContextMenuProvider(listBox); |
|
|
|
|
listBox.ContextMenuOpening += provider.listBox_ContextMenuOpening; |
|
|
|
|
listBox.ContextMenu = new ContextMenu(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
readonly SharpTreeView treeView; |
|
|
|
|
readonly DecompilerTextView textView; |
|
|
|
|
readonly ListBox listBox; |
|
|
|
|
|
|
|
|
|
[ImportMany(typeof(IContextMenuEntry))] |
|
|
|
|
Lazy<IContextMenuEntry, IContextMenuEntryMetadata>[] entries = null; |
|
|
|
@ -139,6 +159,12 @@ namespace ICSharpCode.ILSpy
@@ -139,6 +159,12 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
App.CompositionContainer.ComposeParts(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ContextMenuProvider(ListBox listBox) |
|
|
|
|
{ |
|
|
|
|
this.listBox = listBox; |
|
|
|
|
App.CompositionContainer.ComposeParts(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void treeView_ContextMenuOpening(object sender, ContextMenuEventArgs e) |
|
|
|
|
{ |
|
|
|
|
TextViewContext context = TextViewContext.Create(treeView); |
|
|
|
@ -165,6 +191,17 @@ namespace ICSharpCode.ILSpy
@@ -165,6 +191,17 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
e.Handled = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void listBox_ContextMenuOpening(object sender, ContextMenuEventArgs e) |
|
|
|
|
{ |
|
|
|
|
TextViewContext context = TextViewContext.Create(listBox: listBox); |
|
|
|
|
ContextMenu menu; |
|
|
|
|
if (ShowContextMenu(context, out menu)) |
|
|
|
|
listBox.ContextMenu = menu; |
|
|
|
|
else |
|
|
|
|
// hide the context menu.
|
|
|
|
|
e.Handled = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool ShowContextMenu(TextViewContext context, out ContextMenu menu) |
|
|
|
|
{ |
|
|
|
|
menu = new ContextMenu(); |
|
|
|
|