mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
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:
@@ -13,6 +13,7 @@
|
||||
<None Remove="Assets\Run.svg" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Microsoft.CmdPal.Common\Microsoft.CmdPal.Common.csproj" />
|
||||
<ProjectReference Include="..\..\extensionsdk\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj" />
|
||||
<ProjectReference Include="..\..\Microsoft.CmdPal.Common\Microsoft.CmdPal.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.Storage.Streams;
|
||||
using Windows.System;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Shell.Pages;
|
||||
|
||||
@@ -54,13 +55,13 @@ internal sealed partial class RunExeItem : ListItem
|
||||
{
|
||||
Name = Properties.Resources.cmd_run_as_administrator,
|
||||
Icon = Icons.AdminIcon,
|
||||
}),
|
||||
}) { RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.Enter) },
|
||||
new CommandContextItem(
|
||||
new AnonymousCommand(RunAsOther)
|
||||
{
|
||||
Name = Properties.Resources.cmd_run_as_user,
|
||||
Icon = Icons.UserIcon,
|
||||
}),
|
||||
}) { RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.U) },
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ internal sealed partial class ShellListPage : DynamicListPage, IDisposable
|
||||
|
||||
private readonly IRunHistoryService _historyService;
|
||||
|
||||
private RunExeItem? _exeItem;
|
||||
private ListItem? _exeItem;
|
||||
private List<ListItem> _pathItems = [];
|
||||
private ListItem? _uriItem;
|
||||
|
||||
@@ -319,20 +319,19 @@ internal sealed partial class ShellListPage : DynamicListPage, IDisposable
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
internal static RunExeItem CreateExeItem(string exe, string args, string fullExePath, Action<string>? addToHistory)
|
||||
internal static ListItem CreateExeItem(string exe, string args, string fullExePath, Action<string>? addToHistory)
|
||||
{
|
||||
// PathToListItem will return a RunExeItem if it can find a executable.
|
||||
// It will ALSO add the file search commands to the RunExeItem.
|
||||
return PathToListItem(fullExePath, exe, args, addToHistory) as RunExeItem ??
|
||||
new RunExeItem(exe, args, fullExePath, addToHistory);
|
||||
return PathToListItem(fullExePath, exe, args, addToHistory);
|
||||
}
|
||||
|
||||
private void CreateAndAddExeItems(string exe, string args, string fullExePath)
|
||||
{
|
||||
// If we already have an exe item, and the exe is the same, we can just update it
|
||||
if (_exeItem != null && _exeItem.FullExePath.Equals(fullExePath, StringComparison.OrdinalIgnoreCase))
|
||||
if (_exeItem is RunExeItem exeItem && exeItem.FullExePath.Equals(fullExePath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_exeItem.UpdateArgs(args);
|
||||
exeItem.UpdateArgs(args);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -345,7 +344,8 @@ internal sealed partial class ShellListPage : DynamicListPage, IDisposable
|
||||
// Is this path an executable?
|
||||
// check all the extensions in PATHEXT
|
||||
var extensions = Environment.GetEnvironmentVariable("PATHEXT")?.Split(';') ?? Array.Empty<string>();
|
||||
return extensions.Any(ext => string.Equals(Path.GetExtension(path), ext, StringComparison.OrdinalIgnoreCase));
|
||||
var extension = Path.GetExtension(path);
|
||||
return string.IsNullOrEmpty(extension) || extensions.Any(ext => string.Equals(extension, ext, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private async Task CreatePathItemsAsync(string searchPath, string originalPath, CancellationToken cancellationToken)
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.CmdPal.Common.Commands;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.System;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Shell;
|
||||
|
||||
@@ -58,18 +60,15 @@ internal sealed partial class PathListItem : ListItem
|
||||
}
|
||||
|
||||
TextToSuggest = suggestion;
|
||||
MoreCommands = [
|
||||
new CommandContextItem(new CopyTextCommand(path) { Name = Properties.Resources.copy_path_command_name }) { }
|
||||
];
|
||||
|
||||
// TODO: Follow-up during 0.4. Add the indexer commands here.
|
||||
// MoreCommands = [
|
||||
// new CommandContextItem(new OpenWithCommand(indexerItem)),
|
||||
// new CommandContextItem(new ShowFileInFolderCommand(indexerItem.FullPath) { Name = Resources.Indexer_Command_ShowInFolder }),
|
||||
// new CommandContextItem(new CopyPathCommand(indexerItem)),
|
||||
// new CommandContextItem(new OpenInConsoleCommand(indexerItem)),
|
||||
// new CommandContextItem(new OpenPropertiesCommand(indexerItem)),
|
||||
// ];
|
||||
MoreCommands = [
|
||||
new CommandContextItem(new OpenWithCommand(path)),
|
||||
new CommandContextItem(new ShowFileInFolderCommand(path)) { RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.E) },
|
||||
new CommandContextItem(new CopyPathCommand(path) { Name = Properties.Resources.copy_path_command_name }) { RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.C) },
|
||||
new CommandContextItem(new OpenInConsoleCommand(path)) { RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.R) },
|
||||
new CommandContextItem(new OpenPropertiesCommand(path)),
|
||||
];
|
||||
|
||||
_icon = new Lazy<IconInfo>(() =>
|
||||
{
|
||||
var iconStream = ThumbnailHelper.GetThumbnail(path).Result;
|
||||
|
||||
Reference in New Issue
Block a user