mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
Adds support for a basic Indexer-based file search extension. Co-authored-by: Mike Griese <migrie@microsoft.com>
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
// 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.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using ManagedCommon;
|
|
using Microsoft.CmdPal.Ext.Indexer.Data;
|
|
using Microsoft.CmdPal.Ext.Indexer.Properties;
|
|
using Microsoft.CmdPal.Extensions.Helpers;
|
|
|
|
namespace Microsoft.CmdPal.Ext.Indexer.Commands;
|
|
|
|
internal sealed partial class OpenInConsoleCommand : InvokableCommand
|
|
{
|
|
private readonly IndexerItem _item;
|
|
|
|
internal OpenInConsoleCommand(IndexerItem item)
|
|
{
|
|
this._item = item;
|
|
this.Name = Resources.Indexer_Command_OpenPathInConsole;
|
|
this.Icon = new("\uE756");
|
|
}
|
|
|
|
public override CommandResult Invoke()
|
|
{
|
|
using (var process = new Process())
|
|
{
|
|
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(_item.FullPath);
|
|
process.StartInfo.FileName = "cmd.exe";
|
|
|
|
try
|
|
{
|
|
process.Start();
|
|
}
|
|
catch (Win32Exception ex)
|
|
{
|
|
Logger.LogError($"Unable to open {_item.FullPath}", ex);
|
|
}
|
|
}
|
|
|
|
return CommandResult.GoHome();
|
|
}
|
|
}
|