diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/CopyPathCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/CopyPathCommand.cs new file mode 100644 index 0000000000..30ad044f37 --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/CopyPathCommand.cs @@ -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); + } +} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs index 793000146d..4619bd70c9 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs @@ -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. } + commands.Add( + new CommandContextItem( + new CopyPathCommand(Location))); + commands.Add( new CommandContextItem( new OpenPathCommand(Location) diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs index 210febc549..1ccf797d35 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs @@ -198,6 +198,9 @@ public class Win32Program : IProgram new RunAsUserCommand(!string.IsNullOrEmpty(LnkFilePath) ? LnkFilePath : FullPath, ParentDirectory))); } + commands.Add(new CommandContextItem( + new CopyPathCommand(FullPath))); + commands.Add(new CommandContextItem( new OpenPathCommand(ParentDirectory))); diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs index 33531ba62f..cc07ac86b4 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs @@ -78,6 +78,33 @@ namespace Microsoft.CmdPal.Ext.Apps.Properties { } } + /// + /// Looks up a localized string similar to Copied to clipboard!. + /// + internal static string copied_to_clipboard { + get { + return ResourceManager.GetString("copied_to_clipboard", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Copy failed ({0}). Please try again.. + /// + internal static string copy_failed { + get { + return ResourceManager.GetString("copy_failed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Copy path. + /// + internal static string copy_path { + get { + return ResourceManager.GetString("copy_path", resourceCulture); + } + } + /// /// Looks up a localized string similar to Include apps found on the desktop. /// diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx index 98212f1066..ce4fb79689 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx @@ -163,12 +163,22 @@ Open location + + Copy path + Run as administrator Run as different user + + Copy failed ({0}). Please try again. + {0} is the error message + + + Copied to clipboard! + Include apps found in the Start Menu