Browse Source

fix item 6 of #553: right clicking on an item in the search for types list should display an "Analyze" popup menu

pull/569/head
Siegfried Pammer 10 years ago
parent
commit
8c4a38d12e
  1. 41
      ILSpy/ContextMenuEntry.cs
  2. 1
      ILSpy/SearchPane.cs

41
ILSpy/ContextMenuEntry.cs

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

1
ILSpy/SearchPane.cs

@ -62,6 +62,7 @@ namespace ICSharpCode.ILSpy @@ -62,6 +62,7 @@ namespace ICSharpCode.ILSpy
searchModeComboBox.Items.Add(new { Image = Images.Property, Name = "Member" });
searchModeComboBox.Items.Add(new { Image = Images.Literal, Name = "Constant" });
searchModeComboBox.SelectedIndex = (int)SearchMode.Type;
ContextMenuProvider.Add(listBox);
MainWindow.Instance.CurrentAssemblyListChanged += MainWindow_Instance_CurrentAssemblyListChanged;
}

Loading…
Cancel
Save