diff --git a/ILSpy/Commands/OpenCommandLineHereContextMenuEntry.cs b/ILSpy/Commands/OpenCommandLineHereContextMenuEntry.cs index 387803749..fa72057ca 100644 --- a/ILSpy/Commands/OpenCommandLineHereContextMenuEntry.cs +++ b/ILSpy/Commands/OpenCommandLineHereContextMenuEntry.cs @@ -58,7 +58,7 @@ namespace ILSpy.Commands var dirs = new List(nodes.Length); foreach (var node in nodes) { - var assembly = FindEnclosingAssemblyNode(node); + var assembly = AssemblyTreeNode.FindEnclosing(node); if (assembly is null) return Array.Empty(); var dir = Path.GetDirectoryName(assembly.LoadedAssembly.FileName); @@ -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) { diff --git a/ILSpy/Commands/OpenContainingFolderContextMenuEntry.cs b/ILSpy/Commands/OpenContainingFolderContextMenuEntry.cs index 37efdaa9c..33a1914fa 100644 --- a/ILSpy/Commands/OpenContainingFolderContextMenuEntry.cs +++ b/ILSpy/Commands/OpenContainingFolderContextMenuEntry.cs @@ -60,7 +60,7 @@ namespace ILSpy.Commands var paths = new List(nodes.Length); foreach (var node in nodes) { - var assembly = FindEnclosingAssemblyNode(node); + var assembly = AssemblyTreeNode.FindEnclosing(node); if (assembly is null) return System.Array.Empty(); var path = assembly.LoadedAssembly.FileName; @@ -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; - } } } diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index c1f7a7ae4..666d9fb2b 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -75,6 +75,21 @@ namespace ILSpy.TreeNodes { } + /// + /// Walks up from (inclusive) to the nearest enclosing assembly node, + /// or null when the node sits outside any assembly. + /// + 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.