Browse Source

focus existing analyzer node instead of creating a new one

pull/348/head
Siegfried Pammer 14 years ago
parent
commit
34b0cd7e77
  1. 17
      ILSpy/AnalyzerTreeView.cs
  2. 15
      ILSpy/ContextMenuEntry.cs
  3. 19
      ILSpy/TreeNodes/Analyzer/AnalyzeContextMenuEntry.cs

17
ILSpy/AnalyzerTreeView.cs

@ -84,6 +84,23 @@ namespace ICSharpCode.ILSpy @@ -84,6 +84,23 @@ namespace ICSharpCode.ILSpy
this.SelectedItem = node;
this.FocusNode(node);
}
public void ShowOrFocus(AnalyzerTreeNode node)
{
if (node is AnalyzerEntityTreeNode) {
var an = node as AnalyzerEntityTreeNode;
var found = this.Root.Children.OfType<AnalyzerEntityTreeNode>().FirstOrDefault(n => n.Member == an.Member);
if (found != null) {
Show();
found.IsExpanded = true;
this.SelectedItem = found;
this.FocusNode(found);
return;
}
}
Show(node);
}
void IPane.Closed()
{

15
ILSpy/ContextMenuEntry.cs

@ -41,6 +41,12 @@ namespace ICSharpCode.ILSpy @@ -41,6 +41,12 @@ namespace ICSharpCode.ILSpy
/// </summary>
public SharpTreeNode[] SelectedTreeNodes { get; private set; }
/// <summary>
/// Returns the tree view the context menu is assigned to.
/// Returns null, if context menu is not assigned to a tree view.
/// </summary>
public SharpTreeView TreeView { get; private set; }
/// <summary>
/// Returns the text view the context menu is assigned to.
/// Returns null, if context menu is not assigned to a text view.
@ -53,10 +59,12 @@ namespace ICSharpCode.ILSpy @@ -53,10 +59,12 @@ namespace ICSharpCode.ILSpy
/// </summary>
public ReferenceSegment Reference { get; private set; }
public static TextViewContext Create(SharpTreeNode[] selectedTreeNodes = null, DecompilerTextView textView = null)
public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null)
{
var reference = textView != null ? textView.GetReferenceSegmentAtMousePosition() : null;
var selectedTreeNodes = treeView != null ? treeView.GetTopLevelSelection().ToArray() : null;
return new TextViewContext {
TreeView = treeView,
SelectedTreeNodes = selectedTreeNodes,
TextView = textView,
Reference = reference
@ -123,12 +131,11 @@ namespace ICSharpCode.ILSpy @@ -123,12 +131,11 @@ namespace ICSharpCode.ILSpy
void treeView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
SharpTreeNode[] selectedNodes = treeView.GetTopLevelSelection().ToArray();
if (selectedNodes.Length == 0) {
TextViewContext context = TextViewContext.Create(treeView);
if (context.SelectedTreeNodes.Length == 0) {
e.Handled = true; // don't show the menu
return;
}
TextViewContext context = TextViewContext.Create(selectedNodes);
ContextMenu menu;
if (ShowContextMenu(context, out menu))
treeView.ContextMenu = menu;

19
ILSpy/TreeNodes/Analyzer/AnalyzeContextMenuEntry.cs

@ -52,16 +52,13 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -52,16 +52,13 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
public void Execute(TextViewContext context)
{
var segment = context.Reference;
if (context.SelectedTreeNodes != null) {
// TODO: figure out when equivalent nodes are already present
// and focus those instead.
foreach (IMemberTreeNode node in context.SelectedTreeNodes) {
Analyze(node.Member);
}
} else if (segment != null && segment.Reference is MemberReference) {
if (segment.Reference is MemberReference)
Analyze((MemberReference)segment.Reference);
} else if (context.Reference != null && context.Reference.Reference is MemberReference) {
if (context.Reference.Reference is MemberReference)
Analyze((MemberReference)context.Reference.Reference);
// TODO: implement support for other references: ParameterReference, etc.
}
}
@ -72,19 +69,19 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -72,19 +69,19 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
if (member is TypeReference)
type = ((TypeReference)member).Resolve();
if (type != null)
AnalyzerTreeView.Instance.Show(new AnalyzedTypeTreeNode(type.Resolve()));
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedTypeTreeNode(type.Resolve()));
FieldDefinition field = member as FieldDefinition;
if (field != null)
AnalyzerTreeView.Instance.Show(new AnalyzedFieldTreeNode(field));
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedFieldTreeNode(field));
MethodDefinition method = member as MethodDefinition;
if (method != null)
AnalyzerTreeView.Instance.Show(new AnalyzedMethodTreeNode(method));
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedMethodTreeNode(method));
var propertyAnalyzer = AnalyzedPropertyTreeNode.TryCreateAnalyzer(member);
if (propertyAnalyzer != null)
AnalyzerTreeView.Instance.Show(propertyAnalyzer);
AnalyzerTreeView.Instance.ShowOrFocus(propertyAnalyzer);
var eventAnalyzer = AnalyzedEventTreeNode.TryCreateAnalyzer(member);
if (eventAnalyzer != null)
AnalyzerTreeView.Instance.Show(eventAnalyzer);
AnalyzerTreeView.Instance.ShowOrFocus(eventAnalyzer);
}
}
}

Loading…
Cancel
Save