cmdpal: Add "file" context items to the run items too (#40768)

After #39955, the "exe" items from the shell commands only ever have the
"Run{as admin, as other user}" commands. This adds the rest of the
"file" commands - copy path, open in explorer, etc.

This shuffles around some commands into the toolkit and common commands
project to make this easier.

<img width="814" height="505" alt="image"
src="https://github.com/user-attachments/assets/36ae2c75-d4d6-4762-98ec-796986f39c20"
/>
This commit is contained in:
Mike Griese
2025-07-28 20:03:49 -05:00
committed by GitHub
parent 6dc2d14e13
commit 3a0487f74a
31 changed files with 500 additions and 184 deletions

View File

@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.CommandPalette.Extensions.Toolkit.Properties;
namespace Microsoft.CommandPalette.Extensions.Toolkit;
public partial class CopyPathCommand : InvokableCommand
{
internal static IconInfo CopyPath { get; } = new("\uE8c8"); // Copy
private readonly string _path;
public CommandResult Result { get; set; } = CommandResult.ShowToast(Resources.CopyPathTextCommand_Result);
public CopyPathCommand(string fullPath)
{
this._path = fullPath;
this.Name = Resources.CopyPathTextCommand_Name;
this.Icon = CopyPath;
}
public override CommandResult Invoke()
{
try
{
ClipboardHelper.SetText(_path);
}
catch
{
}
return Result;
}
}

View File

@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.Diagnostics;
namespace Microsoft.CommandPalette.Extensions.Toolkit;
public partial class OpenFileCommand : InvokableCommand
{
internal static IconInfo OpenFile { get; } = new("\uE8E5"); // OpenFile
private readonly string _fullPath;
public CommandResult Result { get; set; } = CommandResult.Dismiss();
public OpenFileCommand(string fullPath)
{
this._fullPath = fullPath;
this.Name = "Open";
this.Icon = OpenFile;
}
public override CommandResult Invoke()
{
using (var process = new Process())
{
process.StartInfo.FileName = _fullPath;
process.StartInfo.UseShellExecute = true;
try
{
process.Start();
}
catch (Win32Exception ex)
{
ExtensionHost.LogMessage($"Unable to open {_fullPath}\n{ex}");
}
}
return Result;
}
}

View File

@@ -5,4 +5,4 @@ GetPackageFamilyNameFromToken
CoRevertToSelf
SHGetKnownFolderPath
KNOWN_FOLDER_FLAG
GetCurrentPackageId
GetCurrentPackageId

View File

@@ -69,6 +69,24 @@ namespace Microsoft.CommandPalette.Extensions.Toolkit.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Copy path.
/// </summary>
internal static string CopyPathTextCommand_Name {
get {
return ResourceManager.GetString("CopyPathTextCommand_Name", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Copied path to clipboard.
/// </summary>
internal static string CopyPathTextCommand_Result {
get {
return ResourceManager.GetString("CopyPathTextCommand_Result", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Copied to clipboard.
/// </summary>

View File

@@ -126,6 +126,12 @@
<data name="CopyTextCommand_CopiedToClipboard" xml:space="preserve">
<value>Copied to clipboard</value>
</data>
<data name="CopyPathTextCommand_Name" xml:space="preserve">
<value>Copy path</value>
</data>
<data name="CopyPathTextCommand_Result" xml:space="preserve">
<value>Copied path to clipboard</value>
</data>
<data name="OpenUrlCommand_Open" xml:space="preserve">
<value>Open</value>
</data>