Browse Source

Add 'open containing folder' and 'open command line here' commands.

pull/1253/head
Siegfried Pammer 7 years ago
parent
commit
822f3581b3
  1. 14
      ILSpy/MainWindow.xaml.cs
  2. 65
      ILSpy/TreeNodes/AssemblyTreeNode.cs

14
ILSpy/MainWindow.xaml.cs

@ -661,8 +661,20 @@ namespace ICSharpCode.ILSpy @@ -661,8 +661,20 @@ namespace ICSharpCode.ILSpy
// just ignore all of them.
}
}
public static void ExecuteCommand(string fileName, string arguments)
{
try {
Process.Start(fileName, arguments);
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
} catch (Exception) {
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
// Process.Start can throw several errors (not all of them documented),
// just ignore all of them.
}
}
#endregion
#region Open/Refresh
void OpenCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{

65
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -434,4 +434,69 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -434,4 +434,69 @@ namespace ICSharpCode.ILSpy.TreeNodes
MainWindow.Instance.CurrentAssemblyList.RefreshSave();
}
}
[ExportContextMenuEntry(Header = "_Open Containing Folder", Category = "Shell")]
sealed class OpenContainingFolder : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
{
if (context.SelectedTreeNodes == null)
return false;
return context.SelectedTreeNodes
.All(n => n is AssemblyTreeNode a && File.Exists(a.LoadedAssembly.FileName));
}
public bool IsEnabled(TextViewContext context)
{
if (context.SelectedTreeNodes == null)
return false;
return context.SelectedTreeNodes
.All(n => n is AssemblyTreeNode a && File.Exists(a.LoadedAssembly.FileName));
}
public void Execute(TextViewContext context)
{
if (context.SelectedTreeNodes == null)
return;
foreach (var node in context.SelectedTreeNodes.OfType<AssemblyTreeNode>()) {
var path = node.LoadedAssembly.FileName;
if (File.Exists(path)) {
MainWindow.ExecuteCommand("explorer.exe", $"/select,\"{path}\"");
}
}
}
}
[ExportContextMenuEntry(Header = "_Open Command Line Here", Category = "Shell")]
sealed class OpenCmdHere : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
{
if (context.SelectedTreeNodes == null)
return false;
return context.SelectedTreeNodes
.All(n => n is AssemblyTreeNode a && File.Exists(a.LoadedAssembly.FileName));
}
public bool IsEnabled(TextViewContext context)
{
if (context.SelectedTreeNodes == null)
return false;
return context.SelectedTreeNodes
.All(n => n is AssemblyTreeNode a && File.Exists(a.LoadedAssembly.FileName));
}
public void Execute(TextViewContext context)
{
if (context.SelectedTreeNodes == null)
return;
foreach (var node in context.SelectedTreeNodes.OfType<AssemblyTreeNode>()) {
var path = Path.GetDirectoryName(node.LoadedAssembly.FileName);
if (Directory.Exists(path)) {
MainWindow.ExecuteCommand("cmd.exe", $"/k \"cd {path}\"");
}
}
}
}
}

Loading…
Cancel
Save