명령 팔레트는 개발자가 색상표에 대한 고유한 환경을 만들 수 있도록 전체 확장 모델을 제공합니다.
가장 up-to-date 샘플은 GitHub에서 샘플 프로젝트를 확인하세요. 여기에는 명령 팔레트에서 사용할 수 있는 모든 항목의 up-to날짜 샘플이 포함됩니다.
작업을 수행하는 명령 만들기
IInvokableCommand를 구현하는 클래스를 만들고 Invoke 메서드를 구현합니다. 이 메서드는 사용자가 명령 팔레트에서 명령을 선택할 때 호출됩니다.
class MyCommand : Microsoft.CommandPalette.Extensions.Toolkit.InvokableCommand {
public class MyCommand()
{
Name = "Do it"; // A short name for the command
Icon = new("\uE945"); // Segoe UI LightningBolt
}
// Open GitHub in the user's default web browser
public ICommandResult Invoke() {
Process.Start(new ProcessStartInfo("https://github.com") { UseShellExecute = true });
// Hides the Command Palette window, without changing the page that's open
return CommandResult.Hide();
}
}
명령 페이지 만들기
다음 예제에서는 명령 페이지를 만드는 방법을 보여 줍니다. 사용자가 명령 팔레트에서 "열기" 명령을 선택하면 이 페이지가 표시됩니다.
using Microsoft.CommandPalette.Extensions.Toolkit;
class MyPage : ListPage {
public MyPage()
{
Icon = IconHelpers.FromRelativePath("Assets\\StoreLogo.png");
Title = "My sample extension";
Name = "Open";
}
public override IListItem[] GetItems()
{
return [
new ListItem(new OpenUrlCommand("https://github.com"))
{
Title = "Open GitHub",
},
new ListItem(new OpenUrlCommand("https://learn.microsoft.com"))
{
Title = "Open Microsoft Learn",
},
new ListItem(new OpenUrlCommand("https://github.com/microsoft/PowerToys"))
{
Title = "Open PowerToys on GitHub",
},
new ListItem(new CopyTextCommand("Foo bar"))
{
Title = "Copy 'Foo bar' to the clipboard",
},
];
}
}
아이콘
IIconInfo 클래스를 사용하는 아이콘은 여러 가지 방법으로 지정할 수 있습니다. 다음은 몇 가지 예입니다.
using Microsoft.CommandPalette.Extensions.Toolkit;
namespace ExtensionName;
internal sealed class Icons
{
// Icons can be specified as a Segoe Fluent icon, ...
internal static IconInfo OpenFile { get; } = new("\uE8E5"); // OpenFile
// ... or as an emoji, ...
internal static IconInfo OpenFileEmoji { get; } = new("📂");
// ... Or as a path to an image file, ...
internal static IconInfo FileExplorer { get; } = IconHelpers.FromRelativePath("Assets\\FileExplorer.png");
// ... which can be on a remote server, or svg's, or ...
internal static IconInfo FileExplorerSvg { get; } = new("https://raw.githubusercontent.com/microsoft/PowerToys/refs/heads/main/src/modules/cmdpal/Exts/Microsoft.CmdPal.Ext.Indexer/Assets/FileExplorer.svg");
// Or they can be embedded in a exe / dll:
internal static IconInfo FolderIcon { get; } = new("%systemroot%\\system32\\system32\\shell32.dll,3");
}
관련 콘텐츠
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
Windows developer