mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
[CmdPal][Apps]Add copy path command (#39984)
## Summary of the Pull Request Adds a *Copy path* command to the <kbd>Ctrl</kbd>+<kbd>K</kbd> menu in the All apps extension ## PR Checklist - [x] **Closes:** #39500 (as mentioned in the discussion, the other requests will be tracked over in #39501) - [x] **Communication:** I've discussed this with core contributors already + has Help wanted - [x] **Tests:** All pass - [x] **Localization:** All end user facing strings can be localized - [x] **Dev docs:** No need - [x] **New binaries:** None - [x] **Documentation updated:** No need ## Detailed Description of the Pull Request / Additional comments Copies the exe full path for standard programs. Copies the package directory for UWPs. Shows a *Copied to clipboard!* toast on a successful copy and closes. Shows a toast when copying fails, keeps CmdPal open.  ## Validation Steps Performed Manually tested copying for UWPs and Win32 programs
This commit is contained in:
@@ -0,0 +1,49 @@
|
|||||||
|
// 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;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
|
using ManagedCommon;
|
||||||
|
using Microsoft.CmdPal.Ext.Apps.Properties;
|
||||||
|
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||||
|
|
||||||
|
namespace Microsoft.CmdPal.Ext.Apps.Commands;
|
||||||
|
|
||||||
|
internal sealed partial class CopyPathCommand : InvokableCommand
|
||||||
|
{
|
||||||
|
private static readonly IconInfo TheIcon = new("\ue8c8");
|
||||||
|
|
||||||
|
private readonly string _target;
|
||||||
|
|
||||||
|
public CopyPathCommand(string target)
|
||||||
|
{
|
||||||
|
Name = Resources.copy_path;
|
||||||
|
Icon = TheIcon;
|
||||||
|
|
||||||
|
_target = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly CompositeFormat CopyFailedFormat = CompositeFormat.Parse(Resources.copy_failed);
|
||||||
|
|
||||||
|
public override CommandResult Invoke()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ClipboardHelper.SetText(_target);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError("Copy failed: " + ex.Message);
|
||||||
|
return CommandResult.ShowToast(
|
||||||
|
new ToastArgs
|
||||||
|
{
|
||||||
|
Message = string.Format(CultureInfo.CurrentCulture, CopyFailedFormat, ex.Message),
|
||||||
|
Result = CommandResult.KeepOpen(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return CommandResult.ShowToast(Resources.copied_to_clipboard);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -85,6 +85,10 @@ public class UWPApplication : IProgram
|
|||||||
// We don't add context menu to 'run as different user', because UWP applications normally installed per user and not for all users.
|
// We don't add context menu to 'run as different user', because UWP applications normally installed per user and not for all users.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commands.Add(
|
||||||
|
new CommandContextItem(
|
||||||
|
new CopyPathCommand(Location)));
|
||||||
|
|
||||||
commands.Add(
|
commands.Add(
|
||||||
new CommandContextItem(
|
new CommandContextItem(
|
||||||
new OpenPathCommand(Location)
|
new OpenPathCommand(Location)
|
||||||
|
|||||||
@@ -198,6 +198,9 @@ public class Win32Program : IProgram
|
|||||||
new RunAsUserCommand(!string.IsNullOrEmpty(LnkFilePath) ? LnkFilePath : FullPath, ParentDirectory)));
|
new RunAsUserCommand(!string.IsNullOrEmpty(LnkFilePath) ? LnkFilePath : FullPath, ParentDirectory)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commands.Add(new CommandContextItem(
|
||||||
|
new CopyPathCommand(FullPath)));
|
||||||
|
|
||||||
commands.Add(new CommandContextItem(
|
commands.Add(new CommandContextItem(
|
||||||
new OpenPathCommand(ParentDirectory)));
|
new OpenPathCommand(ParentDirectory)));
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,33 @@ namespace Microsoft.CmdPal.Ext.Apps.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Copied to clipboard!.
|
||||||
|
/// </summary>
|
||||||
|
internal static string copied_to_clipboard {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("copied_to_clipboard", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Copy failed ({0}). Please try again..
|
||||||
|
/// </summary>
|
||||||
|
internal static string copy_failed {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("copy_failed", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Copy path.
|
||||||
|
/// </summary>
|
||||||
|
internal static string copy_path {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("copy_path", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Include apps found on the desktop.
|
/// Looks up a localized string similar to Include apps found on the desktop.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -163,12 +163,22 @@
|
|||||||
<data name="open_location" xml:space="preserve">
|
<data name="open_location" xml:space="preserve">
|
||||||
<value>Open location</value>
|
<value>Open location</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="copy_path" xml:space="preserve">
|
||||||
|
<value>Copy path</value>
|
||||||
|
</data>
|
||||||
<data name="run_as_administrator" xml:space="preserve">
|
<data name="run_as_administrator" xml:space="preserve">
|
||||||
<value>Run as administrator</value>
|
<value>Run as administrator</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="run_as_different_user" xml:space="preserve">
|
<data name="run_as_different_user" xml:space="preserve">
|
||||||
<value>Run as different user</value>
|
<value>Run as different user</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="copy_failed" xml:space="preserve">
|
||||||
|
<value>Copy failed ({0}). Please try again.</value>
|
||||||
|
<comment>{0} is the error message</comment>
|
||||||
|
</data>
|
||||||
|
<data name="copied_to_clipboard" xml:space="preserve">
|
||||||
|
<value>Copied to clipboard!</value>
|
||||||
|
</data>
|
||||||
<data name="enable_start_menu_source" xml:space="preserve">
|
<data name="enable_start_menu_source" xml:space="preserve">
|
||||||
<value>Include apps found in the Start Menu</value>
|
<value>Include apps found in the Start Menu</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
Reference in New Issue
Block a user