diff --git a/ILSpy/Commands/CreateDiagramContextMenuEntry.cs b/ILSpy/Commands/CreateDiagramContextMenuEntry.cs
index a0dfaf401..cffe4c803 100644
--- a/ILSpy/Commands/CreateDiagramContextMenuEntry.cs
+++ b/ILSpy/Commands/CreateDiagramContextMenuEntry.cs
@@ -99,8 +99,7 @@ namespace ILSpy.Commands
output.WriteLine();
output.WriteLine();
var diagramHtml = Path.Combine(outputFolder, "index.html");
- output.AddButton(null, Resources.OpenExplorer, (_, _) => ShellHelper.RevealFile(diagramHtml));
- output.WriteLine();
+ output.AddRevealFileButton(diagramHtml);
return output;
}
diff --git a/ILSpy/Commands/ExtractPackageEntryContextMenuEntry.cs b/ILSpy/Commands/ExtractPackageEntryContextMenuEntry.cs
index 8a76f1efe..c38a6c366 100644
--- a/ILSpy/Commands/ExtractPackageEntryContextMenuEntry.cs
+++ b/ILSpy/Commands/ExtractPackageEntryContextMenuEntry.cs
@@ -133,9 +133,10 @@ namespace ILSpy.Commands
output.Write(string.Format(Resources.GenerationCompleteInSeconds, stopwatch.Elapsed.TotalSeconds.ToString("F1")));
output.WriteLine();
output.WriteLine();
- var openTarget = isFile ? path : path;
- output.AddButton(null, Resources.OpenExplorer, (_, _) => { if (isFile) ShellHelper.RevealFile(openTarget); else ShellHelper.OpenFolder(openTarget); });
- output.WriteLine();
+ if (isFile)
+ output.AddRevealFileButton(path);
+ else
+ output.AddOpenFolderButton(path);
return output;
}, token)).ConfigureAwait(true);
}
diff --git a/ILSpy/Commands/PdbGenerator.cs b/ILSpy/Commands/PdbGenerator.cs
index 42408db7e..3bdec887b 100644
--- a/ILSpy/Commands/PdbGenerator.cs
+++ b/ILSpy/Commands/PdbGenerator.cs
@@ -136,8 +136,7 @@ namespace ILSpy.Commands
output.Write(string.Format(Resources.GenerationCompleteInSeconds, totalWatch.Elapsed.TotalSeconds.ToString("F1")));
output.WriteLine();
output.WriteLine();
- output.AddButton(null, Resources.OpenExplorer, (_, _) => ShellHelper.OpenFolder(folder));
- output.WriteLine();
+ output.AddOpenFolderButton(folder);
return output;
}, token)).ConfigureAwait(true);
}
diff --git a/ILSpy/Commands/ProjectExport.cs b/ILSpy/Commands/ProjectExport.cs
index 5234050eb..896f22f89 100644
--- a/ILSpy/Commands/ProjectExport.cs
+++ b/ILSpy/Commands/ProjectExport.cs
@@ -86,9 +86,7 @@ namespace ILSpy.Commands
o.WriteLine();
if (result.Success && Directory.Exists(options.OutputDirectory))
{
- o.AddButton(null, ICSharpCode.ILSpy.Properties.Resources.OpenExplorer,
- (_, _) => ShellHelper.OpenFolder(options.OutputDirectory));
- o.WriteLine();
+ o.AddOpenFolderButton(options.OutputDirectory);
}
return o;
});
diff --git a/ILSpy/Commands/SaveCodeHelper.cs b/ILSpy/Commands/SaveCodeHelper.cs
index bbaa6aff8..76f19bb6f 100644
--- a/ILSpy/Commands/SaveCodeHelper.cs
+++ b/ILSpy/Commands/SaveCodeHelper.cs
@@ -81,8 +81,7 @@ namespace ILSpy.Commands
o.WriteLine();
if (Path.GetDirectoryName(path) is { Length: > 0 } directory)
{
- o.AddButton(null, Resources.OpenExplorer, (_, _) => ShellHelper.OpenFolder(directory));
- o.WriteLine();
+ o.AddOpenFolderButton(directory);
}
return o;
}, token), node.Text?.ToString()).ConfigureAwait(true);
diff --git a/ILSpy/Commands/SolutionExport.cs b/ILSpy/Commands/SolutionExport.cs
index 6bcaa44b5..631e687e6 100644
--- a/ILSpy/Commands/SolutionExport.cs
+++ b/ILSpy/Commands/SolutionExport.cs
@@ -82,8 +82,7 @@ namespace ILSpy.Commands
o.WriteLine();
if (result.Success && Path.GetDirectoryName(path) is { Length: > 0 } directory)
{
- o.AddButton(null, Resources.OpenExplorer, (_, _) => ShellHelper.OpenFolder(directory));
- o.WriteLine();
+ o.AddOpenFolderButton(directory);
}
return o;
}).ConfigureAwait(true);
diff --git a/ILSpy/SmartTextOutputExtensions.cs b/ILSpy/SmartTextOutputExtensions.cs
index 4c3f95769..8bce49d7e 100644
--- a/ILSpy/SmartTextOutputExtensions.cs
+++ b/ILSpy/SmartTextOutputExtensions.cs
@@ -25,12 +25,35 @@ using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Media;
+using ICSharpCode.ILSpy.Properties;
+
using ILSpy.TextView;
+using ILSpy.Util;
namespace ILSpy
{
public static class SmartTextOutputExtensions
{
+ ///
+ /// Appends the standard "Open Explorer" result button that opens in
+ /// the OS file manager, followed by a blank line. Shared tail of the export / save / PDB outputs.
+ ///
+ public static void AddOpenFolderButton(this ISmartTextOutput output, string folder)
+ {
+ output.AddButton(null, Resources.OpenExplorer, (_, _) => ShellHelper.OpenFolder(folder));
+ output.WriteLine();
+ }
+
+ ///
+ /// Appends an "Open Explorer" result button that reveals in the OS file
+ /// manager (selecting it where supported), followed by a blank line.
+ ///
+ public static void AddRevealFileButton(this ISmartTextOutput output, string file)
+ {
+ output.AddButton(null, Resources.OpenExplorer, (_, _) => ShellHelper.RevealFile(file));
+ output.WriteLine();
+ }
+
public static void AddButton(this ISmartTextOutput output, IImage? icon, string text, EventHandler click)
{
ArgumentNullException.ThrowIfNull(output);