diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Common/Helpers/WellKnownKeyChords.cs b/src/modules/cmdpal/Microsoft.CmdPal.Common/Helpers/WellKnownKeyChords.cs new file mode 100644 index 0000000000..8e481b936c --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.Common/Helpers/WellKnownKeyChords.cs @@ -0,0 +1,51 @@ +// 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; +using Microsoft.CommandPalette.Extensions.Toolkit; + +using Windows.System; + +namespace Microsoft.CmdPal.Common.Helpers; + +/// +/// Well-known key chords used in the Command Palette and extensions. +/// +/// +/// Assigned key chords should not conflict with system or application shortcuts. +/// However, the key chords in this class are not guaranteed to be unique and may conflict +/// with each other, especially when commands appear together in the same menu. +/// +public static class WellKnownKeyChords +{ + /// + /// Gets the well-known key chord for opening the file location. Shortcut: Ctrl+Shift+E. + /// + public static KeyChord OpenFileLocation { get; } = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: (int)VirtualKey.E); + + /// + /// Gets the well-known key chord for copying the file path. Shortcut: Ctrl+Shift+C. + /// + public static KeyChord CopyFilePath { get; } = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: (int)VirtualKey.C); + + /// + /// Gets the well-known key chord for opening the current location in a console. Shortcut: Ctrl+Shift+R. + /// + public static KeyChord OpenInConsole { get; } = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: (int)VirtualKey.R); + + /// + /// Gets the well-known key chord for running the selected item as administrator. Shortcut: Ctrl+Shift+Enter. + /// + public static KeyChord RunAsAdministrator { get; } = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: (int)VirtualKey.Enter); + + /// + /// Gets the well-known key chord for running the selected item as a different user. Shortcut: Ctrl+Shift+U. + /// + public static KeyChord RunAsDifferentUser { get; } = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: (int)VirtualKey.U); + + /// + /// Gets the well-known key chord for toggling the pin state. Shortcut: Ctrl+P. + /// + public static KeyChord TogglePin { get; } = KeyChordHelpers.FromModifiers(ctrl: true, vkey: (int)VirtualKey.P); +} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs index ba8dfc1213..d91c195552 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs @@ -133,17 +133,13 @@ internal sealed partial class AppListItem : ListItem newCommands.Add(new Separator()); - // 0x50 = P - // Full key chord would be Ctrl+P - var pinKeyChord = KeyChordHelpers.FromModifiers(true, false, false, false, 0x50, 0); - if (isPinned) { newCommands.Add( new CommandContextItem( new UnpinAppCommand(this.AppIdentifier)) { - RequestedShortcut = pinKeyChord, + RequestedShortcut = KeyChords.TogglePin, }); } else @@ -152,7 +148,7 @@ internal sealed partial class AppListItem : ListItem new CommandContextItem( new PinAppCommand(this.AppIdentifier)) { - RequestedShortcut = pinKeyChord, + RequestedShortcut = KeyChords.TogglePin, }); } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/KeyChords.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/KeyChords.cs new file mode 100644 index 0000000000..6b4063f35d --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/KeyChords.cs @@ -0,0 +1,23 @@ +// 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.CmdPal.Common.Helpers; +using Microsoft.CommandPalette.Extensions; + +namespace Microsoft.CmdPal.Ext.Apps; + +internal static class KeyChords +{ + internal static KeyChord OpenFileLocation { get; } = WellKnownKeyChords.OpenFileLocation; + + internal static KeyChord CopyFilePath { get; } = WellKnownKeyChords.CopyFilePath; + + internal static KeyChord OpenInConsole { get; } = WellKnownKeyChords.OpenInConsole; + + internal static KeyChord RunAsAdministrator { get; } = WellKnownKeyChords.RunAsAdministrator; + + internal static KeyChord RunAsDifferentUser { get; } = WellKnownKeyChords.RunAsDifferentUser; + + internal static KeyChord TogglePin { get; } = WellKnownKeyChords.TogglePin; +} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Microsoft.CmdPal.Ext.Apps.csproj b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Microsoft.CmdPal.Ext.Apps.csproj index 311a725e4a..fb074407f8 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Microsoft.CmdPal.Ext.Apps.csproj +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Microsoft.CmdPal.Ext.Apps.csproj @@ -25,6 +25,7 @@ + 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 541de2eee1..525e5b3ca8 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 @@ -87,7 +87,7 @@ public class UWPApplication : IUWPApplication new CommandContextItem( new RunAsAdminCommand(UniqueIdentifier, string.Empty, true)) { - RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.Enter), + RequestedShortcut = KeyChords.RunAsAdministrator, }); // We don't add context menu to 'run as different user', because UWP applications normally installed per user and not for all users. @@ -97,7 +97,7 @@ public class UWPApplication : IUWPApplication new CommandContextItem( new CopyTextCommand(Location) { Name = Resources.copy_path }) { - RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.C), + RequestedShortcut = KeyChords.CopyFilePath, }); commands.Add( @@ -107,14 +107,14 @@ public class UWPApplication : IUWPApplication Name = Resources.open_containing_folder, }) { - RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.E), + RequestedShortcut = KeyChords.OpenFileLocation, }); commands.Add( new CommandContextItem( new OpenInConsoleCommand(Package.Location)) { - RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.R), + RequestedShortcut = KeyChords.OpenInConsole, }); commands.Add( 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 dea7fb1e20..151a6ee6d7 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 @@ -191,32 +191,32 @@ public class Win32Program : IProgram commands.Add(new CommandContextItem( new RunAsAdminCommand(!string.IsNullOrEmpty(LnkFilePath) ? LnkFilePath : FullPath, ParentDirectory, false)) { - RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.Enter), + RequestedShortcut = KeyChords.RunAsAdministrator, }); commands.Add(new CommandContextItem( new RunAsUserCommand(!string.IsNullOrEmpty(LnkFilePath) ? LnkFilePath : FullPath, ParentDirectory)) { - RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.U), + RequestedShortcut = KeyChords.RunAsDifferentUser, }); } commands.Add(new CommandContextItem( new CopyTextCommand(FullPath) { Name = Resources.copy_path }) { - RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.C), + RequestedShortcut = KeyChords.CopyFilePath, }); commands.Add(new CommandContextItem( new OpenPathCommand(ParentDirectory)) { - RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.E), + RequestedShortcut = KeyChords.OpenFileLocation, }); commands.Add(new CommandContextItem( new OpenInConsoleCommand(ParentDirectory)) { - RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.R), + RequestedShortcut = KeyChords.OpenInConsole, }); if (AppType == ApplicationType.ShortcutApplication || AppType == ApplicationType.ApprefApplication || AppType == ApplicationType.Win32Application) diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Data/IndexerListItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Data/IndexerListItem.cs index 9e4d3a4387..25ac912c40 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Data/IndexerListItem.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Data/IndexerListItem.cs @@ -91,9 +91,9 @@ internal sealed partial class IndexerListItem : ListItem } commands.Add(new CommandContextItem(new OpenWithCommand(fullPath))); - commands.Add(new CommandContextItem(new ShowFileInFolderCommand(fullPath) { Name = Resources.Indexer_Command_ShowInFolder })); - commands.Add(new CommandContextItem(new CopyPathCommand(fullPath) { Name = Resources.Indexer_Command_CopyPath })); - commands.Add(new CommandContextItem(new OpenInConsoleCommand(fullPath))); + commands.Add(new CommandContextItem(new ShowFileInFolderCommand(fullPath) { Name = Resources.Indexer_Command_ShowInFolder }) { RequestedShortcut = KeyChords.OpenFileLocation }); + commands.Add(new CommandContextItem(new CopyPathCommand(fullPath) { Name = Resources.Indexer_Command_CopyPath }) { RequestedShortcut = KeyChords.CopyFilePath }); + commands.Add(new CommandContextItem(new OpenInConsoleCommand(fullPath)) { RequestedShortcut = KeyChords.OpenInConsole }); commands.Add(new CommandContextItem(new OpenPropertiesCommand(fullPath))); if (IsActionsFeatureEnabled && ApiInformation.IsApiContractPresent("Windows.AI.Actions.ActionsContract", 4)) diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/KeyChords.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/KeyChords.cs new file mode 100644 index 0000000000..39ac4ae627 --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/KeyChords.cs @@ -0,0 +1,17 @@ +// 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.CmdPal.Common.Helpers; +using Microsoft.CommandPalette.Extensions; + +namespace Microsoft.CmdPal.Ext.Indexer; + +internal static class KeyChords +{ + internal static KeyChord OpenFileLocation { get; } = WellKnownKeyChords.OpenFileLocation; + + internal static KeyChord CopyFilePath { get; } = WellKnownKeyChords.CopyFilePath; + + internal static KeyChord OpenInConsole { get; } = WellKnownKeyChords.OpenInConsole; +}