Browse Source

Share the enclosing-assembly walk as AssemblyTreeNode.FindEnclosing

The "walk up to the enclosing AssemblyTreeNode" helper was byte-identical
in the open-terminal and open-containing-folder commands. Lift it to a
static on AssemblyTreeNode and route both through it.

Assisted-by: Claude:claude-opus-4-8:Claude Code
pull/3755/head
Siegfried Pammer 4 weeks ago
parent
commit
42ebbe9bea
  1. 12
      ILSpy/Commands/OpenCommandLineHereContextMenuEntry.cs
  2. 12
      ILSpy/Commands/OpenContainingFolderContextMenuEntry.cs
  3. 15
      ILSpy/TreeNodes/AssemblyTreeNode.cs

12
ILSpy/Commands/OpenCommandLineHereContextMenuEntry.cs

@ -58,7 +58,7 @@ namespace ILSpy.Commands @@ -58,7 +58,7 @@ namespace ILSpy.Commands
var dirs = new List<string>(nodes.Length);
foreach (var node in nodes)
{
var assembly = FindEnclosingAssemblyNode(node);
var assembly = AssemblyTreeNode.FindEnclosing(node);
if (assembly is null)
return Array.Empty<string>();
var dir = Path.GetDirectoryName(assembly.LoadedAssembly.FileName);
@ -69,16 +69,6 @@ namespace ILSpy.Commands @@ -69,16 +69,6 @@ namespace ILSpy.Commands
return dirs;
}
static AssemblyTreeNode? FindEnclosingAssemblyNode(SharpTreeNode? node)
{
while (node != null)
{
if (node is AssemblyTreeNode a)
return a;
node = node.Parent;
}
return null;
}
static void OpenTerminalAt(string directory)
{

12
ILSpy/Commands/OpenContainingFolderContextMenuEntry.cs

@ -60,7 +60,7 @@ namespace ILSpy.Commands @@ -60,7 +60,7 @@ namespace ILSpy.Commands
var paths = new List<string>(nodes.Length);
foreach (var node in nodes)
{
var assembly = FindEnclosingAssemblyNode(node);
var assembly = AssemblyTreeNode.FindEnclosing(node);
if (assembly is null)
return System.Array.Empty<string>();
var path = assembly.LoadedAssembly.FileName;
@ -71,16 +71,6 @@ namespace ILSpy.Commands @@ -71,16 +71,6 @@ namespace ILSpy.Commands
return paths;
}
static AssemblyTreeNode? FindEnclosingAssemblyNode(SharpTreeNode? node)
{
while (node != null)
{
if (node is AssemblyTreeNode a)
return a;
node = node.Parent;
}
return null;
}
}
}

15
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -75,6 +75,21 @@ namespace ILSpy.TreeNodes @@ -75,6 +75,21 @@ namespace ILSpy.TreeNodes
{
}
/// <summary>
/// Walks up from <paramref name="node"/> (inclusive) to the nearest enclosing assembly node,
/// or null when the node sits outside any assembly.
/// </summary>
public static AssemblyTreeNode? FindEnclosing(SharpTreeNode? node)
{
while (node != null)
{
if (node is AssemblyTreeNode a)
return a;
node = node.Parent;
}
return null;
}
// Drag-drop (handled generically by SharpTreeView, which delegates to these). The drag
// payload is the assemblies' file paths so a reorder and an external file drop unify through
// AssemblyListTreeNode.Drop -> OpenAssembly (which dedupes) + Move.

Loading…
Cancel
Save