You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: hub/powertoys/command-palette/add-top-level-commands-to-your-extension.md
+31-29Lines changed: 31 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,59 +2,61 @@
2
2
title: Add top-level commands to your extension
3
3
description: Learn how to add new top-level commands to your Command Palette extension.
4
4
ms.date: 3/23/2025
5
-
ms.topic: concept-article
5
+
ms.topic: how-to
6
6
no-loc: [PowerToys, Windows, Insider]
7
7
# Customer intent: As a Windows developer, I want to learn how to develop an extension for the Command Palette.
8
8
---
9
9
10
-
# Adding top-level commands
10
+
# Adding top-level commands to your extension
11
11
12
12
**Previous**: [Update a list of commands](update-a-list-of-commands.md).
13
13
14
-
So far, we've only added commands to a single page, within your extension. You can also add more commands directly to the top-level list of commands too.
14
+
So far, you've only added commands to a single page within your extension. You can also add more commands directly to the top-level list of commands too.
15
+
16
+
## Adding the top-level commands
15
17
16
18
To do that, head on over to the `ExtensionNameCommandsProvider.cs` file. This file is where you'll add commands that should be shown at the top-level of the Command Palette. As you can see, there's currently only a single item there:
In this very simple extension, we're simply creating a list of commands when the extension is created, and then returning that list whenever we're asked for the top-level commands. This prevents us from re-creating the list of commands every time we're asked for the top-level commands, which can be a performance optimization.
36
+
This sample extension creates a list of commands when the extension is created and returns that list whenever it's asked for the top-level commands. This prevents the extension from re-creating the list of commands every time the top-level commands are requested. This is a performance optimization.
35
37
36
-
If we want to add another command to the top-level list of commands, we just need to add another `CommandItem`:
38
+
If you want to add another command to the top-level list of commands, you can add another **CommandItem**:
newCommandItem(newShowMessageCommand()) { Title="Send a message" },
48
+
];
49
+
}
48
50
```
49
51
50
52
There you have it. Now you can add additional top-level commands to your extension.
51
53
52
54
If you'd like to update the list of top-level commands dynamically, you can do so in the same way as you would update a list page. This can be useful for cases like an extension that might first require the user to log in, before showing certain commands. In that case, you can show the "log in" command at the top level initially. Then, once the user logs in successfully, you can update the list of top-level commands to include the commands that required authentication.
53
55
54
-
Once you've determined that you need to change the top level list, call [`RaiseItemsChanged()`](./microsoft-commandpalette-extensions-toolkit/commandprovider_raiseitemschanged.md) on your `CommandProvider`. Command Palette will then ask for the top-level commands via `TopLevelCommands()` again, and you can return the updated list.
56
+
Once you've determined that you need to change the top level list, call [RaiseItemsChanged](./microsoft-commandpalette-extensions-toolkit/commandprovider_raiseitemschanged.md) on your **CommandProvider**. Command Palette will then request the top-level commands via **TopLevelCommands** again, and you can return the updated list.
55
57
56
58
> [!TIP]
57
-
> Create the `CommandItem`s for the top-level commands before calling `RaiseItemsChanged()`. This will ensure that the new commands are available when Command Palette asks for the top-level commands. This will help keep the work being done in call to `TopLevelCommands()` method to a minimum.
59
+
> Create the **CommandItem** objects for the top-level commands before calling **RaiseItemsChanged**. This will ensure that the new commands are available when Command Palette requests the top-level commands. This will ensure that the work being executed in each call to **TopLevelCommands** method to a minimum.
58
60
59
61
### Next up: [Command Results](command-results.md)
Copy file name to clipboardExpand all lines: hub/powertoys/command-palette/adding-commands.md
+54-50Lines changed: 54 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,53 +1,57 @@
1
1
---
2
-
title: Adding commands
2
+
title: Adding commands to your extension
3
3
description: Learn how to add new commands to your Command Palette extension.
4
4
ms.date: 3/23/2025
5
-
ms.topic: concept-article
5
+
ms.topic: how-to
6
6
no-loc: [PowerToys, Windows, Insider]
7
7
# Customer intent: As a Windows developer, I want to learn how to develop an extension for the Command Palette.
8
8
---
9
9
10
-
# Adding commands
10
+
# Adding commands to your extension
11
11
12
12
**Previous**: [Creating an extension](creating-an-extension.md). We'll be starting with the project created in that article.
13
13
14
-
Now that you've created your extension, it's time to add some commands to it. We can start by navigating to the `ExtensionNamePage.cs` file. This file is the [`ListPage`](./microsoft-commandpalette-extensions-toolkit/listpage.md) that will be displayed when the user selects your extension. In there you should see:
14
+
Now that you've created your extension, it's time to add some commands to it.
15
+
16
+
## Add some commands
17
+
18
+
We can start by navigating to the `ExtensionNamePage.cs` file. This file is the [ListPage](./microsoft-commandpalette-extensions-toolkit/listpage.md) that will be displayed when the user selects your extension. In there you should see:
newListItem(newNoOpCommand()) { Title="TODO: Implement your extension here" }
31
+
];
32
+
}
29
33
```
30
34
31
-
Here you can see that we've set the icon for the page, the title, and the name that's shown at the top-level when you have the command selected. The `GetItems` method is where you'll return the list of commands that you want to show on this page. Right now, that's just returning a single command that does nothing. Let's instead try making that command open _this_ page in the user's default web browser.
35
+
Here you can see that we've set the icon for the page, the title, and the name that's shown at the top-level when you have the command selected. The **GetItems** method is where you'll return the list of commands that you want to show on this page. Right now, that's just returning a single command that does nothing. Let's instead try making that command open _this_ page in the user's default web browser.
32
36
33
-
We can change the implementation of `GetItems()` to the following:
37
+
We can change the implementation of **GetItems** to the following:
Re-deploy your app, run the "reload" command to refresh the extensions in the palette, and head to your extension. You should see that the command now opens the Command Palette documentation.
49
53
50
-
The `OpenUrlCommand` is a helper for just opening a URL in the user's default web browser. You can also just implement an extension however you want. Let's instead make a new command, that shows a MessageBox. To do that, we need to create a new class that implements `IInvokableCommand`
54
+
The **OpenUrlCommand** is a helper for opening a URL in the user's default web browser. You can also implement an extension however you want. Let's instead make a new command, that shows a **MessageBox**. To do that, we need to create a new class that implements **IInvokableCommand**.
Deploy and reload, and presto - a command to show a message box!
@@ -99,19 +103,19 @@ Deploy and reload, and presto - a command to show a message box!
99
103
## Adding more pages
100
104
101
105
So far, we've only worked with commands that "do something". However, you can also add commands that show additional pages withing the Command Palette. There are basically two types of "Commands" in the Palette:
102
-
*`IInvokableCommand` - These are commands that **do something**.
103
-
*`IPage` - These are commands that **show something**.
106
+
-**IInvokableCommand** - These are commands that *do something*.
107
+
-**IPage** - These are commands that *show something*.
104
108
105
-
Because `IPage`s are just `ICommand`s, you can use them anywhere you can use commands. This means you can add them to the top-level list of commands, or to a list of commands on a page, the context menu on an item, etc.
109
+
Because **IPage** implementations are **ICommand**'s, you can use them anywhere you can use commands. This means you can add them to the top-level list of commands, or to a list of commands on a page, the context menu on an item, etc.
106
110
107
111
There are two different kinds of pages you can show:
108
-
*[`ListPage`](./microsoft-commandpalette-extensions-toolkit/listpage.md) - This is a page that shows a list of commands. This is what we've been working with so far.
109
-
*[`ContentPage`](./microsoft-commandpalette-extensions-toolkit/contentpage.md) - This is a page that shows rich content to the user. This allows you to specify abstract content, and let Command Palette worry about rendering the content in a native experience. There are two different types of content supported so far:
110
-
*[Markdown content](./using-markdown-content.md) - This is content that's written in Markdown, and is rendered in the Command Palette. See [`MarkdownContent`](./microsoft-commandpalette-extensions-toolkit/markdowncontent.md) for details.
111
-
*[Form content](./using-form-pages.md) - This is content that shows a form to the user, and then returns the results of that form to the extension. These are powered by [Adaptive Cards](https://aka.ms/adaptive-cards) This is useful for getting user input, or displaying more complex layouts of information. See [`FormContent`](./microsoft-commandpalette-extensions-toolkit/formcontent.md) for details.
112
+
-[ListPage](./microsoft-commandpalette-extensions-toolkit/listpage.md) - This is a page that shows a list of commands. This is what we've been working with so far.
113
+
-[ContentPage](./microsoft-commandpalette-extensions-toolkit/contentpage.md) - This is a page that shows rich content to the user. This allows you to specify abstract content, and let Command Palette worry about rendering the content in a native experience. There are two different types of content supported so far:
114
+
-[Markdown content](./using-markdown-content.md) - This is content that's written in Markdown, and is rendered in the Command Palette. See [MarkdownContent](./microsoft-commandpalette-extensions-toolkit/markdowncontent.md) for details.
115
+
-[Form content](./using-form-pages.md) - This is content that shows a form to the user, and then returns the results of that form to the extension. These are powered by [Adaptive Cards](https://aka.ms/adaptive-cards) This is useful for getting user input, or displaying more complex layouts of information. See [FormContent](./microsoft-commandpalette-extensions-toolkit/formcontent.md) for details.
112
116
113
117
114
-
We'll start by adding a new page that shows a list of commands. We can create a new class that implements `ListPage`:
118
+
Start by adding a new page that shows a list of commands. Create a new class that implements **ListPage**:
0 commit comments