mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 01:36:31 +02:00
Cmdpal: Peek command in indexer (#44581)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Add a peek command, so we could quickly view the files found by indexer I’m aware that wiring the Peek command directly into the indexer extension is fairly PowerToys-specific. I’m open to suggestions if we think this should instead be handled via a more general extension / plugin mechanism; if a broader framework is planned, I’m happy to wait and revisit this once that structure is in place. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: #43517 <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed <img width="279" height="315" alt="image" src="https://github.com/user-attachments/assets/c095ac55-30a2-49e6-a972-b51b35939c53" />
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,73 @@
|
||||
// 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.Diagnostics;
|
||||
using System.IO;
|
||||
using ManagedCommon;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Properties;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// Command to preview a file using PowerToys Peek.
|
||||
/// </summary>
|
||||
public sealed partial class PeekFileCommand : InvokableCommand
|
||||
{
|
||||
private const string PeekExecutable = @"WinUI3Apps\PowerToys.Peek.UI.exe";
|
||||
|
||||
private static readonly Lazy<string> _peekPath = new(GetPeekExecutablePath);
|
||||
|
||||
private readonly string _fullPath;
|
||||
|
||||
public PeekFileCommand(string fullPath)
|
||||
{
|
||||
_fullPath = fullPath;
|
||||
Name = Resources.Indexer_Command_Peek;
|
||||
Icon = Icons.PeekIcon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether Peek is available on this system.
|
||||
/// </summary>
|
||||
public static bool IsPeekAvailable => !string.IsNullOrEmpty(_peekPath.Value);
|
||||
|
||||
public override CommandResult Invoke()
|
||||
{
|
||||
var peekExe = _peekPath.Value;
|
||||
if (string.IsNullOrEmpty(peekExe))
|
||||
{
|
||||
return CommandResult.ShowToast(Resources.Indexer_Command_Peek_NotAvailable);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using var process = new Process();
|
||||
process.StartInfo.FileName = peekExe;
|
||||
process.StartInfo.Arguments = $"\"{_fullPath}\"";
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExtensionHost.LogMessage($"Unable to launch Peek for {_fullPath}\n{ex}");
|
||||
return CommandResult.ShowToast(Resources.Indexer_Command_Peek_Failed);
|
||||
}
|
||||
|
||||
return CommandResult.Dismiss();
|
||||
}
|
||||
|
||||
private static string GetPeekExecutablePath()
|
||||
{
|
||||
var installPath = PowerToysPathResolver.GetPowerToysInstallPath();
|
||||
if (string.IsNullOrEmpty(installPath))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var peekPath = Path.Combine(installPath, PeekExecutable);
|
||||
return File.Exists(peekPath) ? peekPath : string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.CmdPal.Core.Common.Commands;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Commands;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Helpers;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Pages;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Properties;
|
||||
@@ -96,6 +97,13 @@ internal sealed partial class IndexerListItem : ListItem
|
||||
}
|
||||
|
||||
commands.Add(new CommandContextItem(new OpenWithCommand(fullPath)));
|
||||
|
||||
// Add Peek command if available (only for files, not directories)
|
||||
if (!isDir && PeekFileCommand.IsPeekAvailable)
|
||||
{
|
||||
commands.Add(new CommandContextItem(new PeekFileCommand(fullPath)) { RequestedShortcut = KeyChords.Peek });
|
||||
}
|
||||
|
||||
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 });
|
||||
|
||||
@@ -23,4 +23,6 @@ internal static class Icons
|
||||
internal static IconInfo FilesIcon { get; } = new("\uF571"); // PrintAllPages
|
||||
|
||||
internal static IconInfo FilterIcon { get; } = new("\uE71C"); // Filter
|
||||
|
||||
internal static IconInfo PeekIcon { get; } = IconHelpers.FromRelativePath("Assets\\Peek.png");
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
using Microsoft.CmdPal.Core.Common.Helpers;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.System;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer;
|
||||
|
||||
@@ -14,4 +16,6 @@ internal static class KeyChords
|
||||
internal static KeyChord CopyFilePath { get; } = WellKnownKeyChords.CopyFilePath;
|
||||
|
||||
internal static KeyChord OpenInConsole { get; } = WellKnownKeyChords.OpenInConsole;
|
||||
|
||||
internal static KeyChord Peek { get; } = KeyChordHelpers.FromModifiers(ctrl: true, vkey: (int)VirtualKey.Space);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
<Content Update="Assets\FileExplorer.svg">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="Assets\Peek.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -132,6 +132,33 @@ namespace Microsoft.CmdPal.Ext.Indexer.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Peek preview.
|
||||
/// </summary>
|
||||
internal static string Indexer_Command_Peek {
|
||||
get {
|
||||
return ResourceManager.GetString("Indexer_Command_Peek", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Failed to launch Peek.
|
||||
/// </summary>
|
||||
internal static string Indexer_Command_Peek_Failed {
|
||||
get {
|
||||
return ResourceManager.GetString("Indexer_Command_Peek_Failed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to PowerToys Peek is not available.
|
||||
/// </summary>
|
||||
internal static string Indexer_Command_Peek_NotAvailable {
|
||||
get {
|
||||
return ResourceManager.GetString("Indexer_Command_Peek_NotAvailable", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Search all files.
|
||||
/// </summary>
|
||||
|
||||
@@ -202,4 +202,13 @@ You can try searching all files on this PC or adjust your indexing settings.</va
|
||||
<data name="Indexer_Filter_Files_Only" xml:space="preserve">
|
||||
<value>Files</value>
|
||||
</data>
|
||||
<data name="Indexer_Command_Peek" xml:space="preserve">
|
||||
<value>Peek preview</value>
|
||||
</data>
|
||||
<data name="Indexer_Command_Peek_NotAvailable" xml:space="preserve">
|
||||
<value>PowerToys Peek is not available</value>
|
||||
</data>
|
||||
<data name="Indexer_Command_Peek_Failed" xml:space="preserve">
|
||||
<value>Failed to launch Peek</value>
|
||||
</data>
|
||||
</root>
|
||||
Reference in New Issue
Block a user