Skip to content

Commit 97fd8a7

Browse files
committed
updated docs to be consistant and added images, add-commmands.md still need mark down and form images
1 parent 0c96b74 commit 97fd8a7

File tree

7 files changed

+140
-47
lines changed

7 files changed

+140
-47
lines changed
61.2 KB
Loading
57.1 KB
Loading
38.1 KB
Loading

hub/powertoys/command-palette/add-top-level-commands-to-your-extension.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ no-loc: [PowerToys, Windows, Insider]
1111

1212
**Previous**: [Update a list of commands](update-a-list-of-commands.md).
1313

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.
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.
1515

16-
## Adding the top-level commands
1716

18-
To do that, head on over to the `<ExtensionName>CommandsProvider.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:
17+
## Top-level commands
18+
19+
To add commands at the top level of the Command Palette, open the `<ExtensionName>CommandsProvider.cs` file. This is where you define the commands that will appear at the root level of the Command Palette.
20+
21+
Currently, the file contains only one command:
1922

2023
```csharp
2124
public <ExtensionName>CommandsProvider()
@@ -33,24 +36,38 @@ public override ICommandItem[] TopLevelCommands()
3336
}
3437
```
3538

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.
39+
When the extension is created, it builds a list of commands and stores them in the `_commands` field. Every time the extension is asked for its top-level commands, it simply returns this prebuilt list. This approach avoids recreating the command list on each request, which improves performance.
3740

38-
If you want to add another command to the top-level list of commands, you can add another **CommandItem**:
41+
## Add another top level command
3942

40-
```csharp
43+
1. In Visual Studio, open `<ExtensionName>CommandsProvider.cs`
44+
1. Add another `CommandItem`:
45+
46+
```diff
4147
public <ExtensionName>CommandsProvider()
4248
{
4349
DisplayName = "My sample extension";
4450
Icon = IconHelpers.FromRelativePath("Assets\\StoreLogo.png");
4551
_commands = [
4652
new CommandItem(new <ExtensionName>Page()) { Title = DisplayName },
47-
new CommandItem(new ShowMessageCommand()) { Title = "Send a message" },
53+
+ new CommandItem(new ShowMessageCommand()) { Title = "Send a message" },
4854
];
4955
}
5056
```
5157

58+
> [!NOTE]
59+
> `ShowMessageCommand()` section was created prior at [InvokableCommand Command](adding-commands#invokableCommand-command)
60+
61+
1. Deploy your extension
62+
1. In command palette, `Reload`
63+
64+
![Screenshot of extension with send message command at top level](../../images/command-palette/top-level-command.png)
65+
5266
There you have it. Now you can add additional top-level commands to your extension.
5367

68+
69+
70+
5471
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.
5572

5673
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.

hub/powertoys/command-palette/adding-commands.md

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Now that you've created your extension, it's time to add some commands to it.
1717

1818
We can start by navigating to the `<ExtensionName>Page.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:
1919

20-
```csharp
20+
```csharp
2121
public <ExtensionName>Page()
2222
{
2323
Icon = IconHelpers.FromRelativePath("Assets\\StoreLogo.png");
@@ -32,9 +32,9 @@ public override IListItem[] GetItems()
3232
}
3333
```
3434

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.
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.
3636

37-
We can change the implementation of **GetItems** to the following:
37+
1. Update `GetItems` to the following:
3838

3939
```csharp
4040
public override IListItem[] GetItems()
@@ -51,17 +51,17 @@ public override IListItem[] GetItems()
5151

5252
To update the extension in the Command Palette you need to:
5353

54-
1. Deploy your app
54+
1. Deploy your extension
5555
1. In the Command Palette, type the "reload" command to refresh the extensions in the palette
5656

5757
![Screenshot of reload](../../images/command-palette/reload.png)
5858

5959
> [!NOTE]
6060
> There are several reload options, make sure to select the **Reload Command Palette extensions**
6161
62-
1. Scroll down to your extension and press `enter`
62+
1. Scroll down to your extension and press `Enter`
6363
1. Press `enter` on `Open the Command Palette documentation`
64-
1. You should see that the command now opens the Command Palette documentation
64+
1. You should see that the command opens the Command Palette documentation
6565

6666
The **OpenUrlCommand** is a helper for opening a URL in the user's default web browser.
6767

@@ -87,7 +87,7 @@ As your building your extension, you'll most likely want to debug it.
8787
}
8888
```
8989

90-
1. Deploy your app, wait until it's successful
90+
1. Deploy your extension, wait until it's successful
9191
1. Confirm You're in Debug Configuration
9292

9393
<details>
@@ -106,13 +106,22 @@ As your building your extension, you'll most likely want to debug it.
106106

107107
![Screenshot of reload](../../images/command-palette/output.png)
108108

109-
1. In the Command Palette, `reload`
109+
1. In the Command Palette, run `reload`
110110
1. Go to your extension and select `Open the Command Palette documentation`.
111-
1. In Visual Studio's output window, you should see `Debug message from GetItems`
111+
1. In Visual Studio's Output window, you should see `Debug message from GetItems`
112112

113113
## InvokableCommand Command
114114

115-
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**.
115+
Let's continue building a new command, that shows a **MessageBox**. To do that, we need to create a new class that implements `InvokableCommand`.
116+
117+
1. In Visual Studio, Add a New Class File
118+
- Keyboard Shortcut: Press Ctrl + Shift + A
119+
- Or in the Solution Explorer, go to Project > Add New Item...
120+
1. In the Add New Item dialog:
121+
1. Select Class from the list.
122+
1. Name your class file: `ShowMessageCommand.cs`
123+
1. Click Add.
124+
1. Replace the default class code with:
116125

117126
```csharp
118127
using System.Runtime.InteropServices;
@@ -139,6 +148,8 @@ internal sealed partial class ShowMessageCommand : InvokableCommand
139148

140149
Now we can add this command to the list of commands in the `<ExtensionName>Page.cs` file:
141150

151+
1. In the `<ExtensionName>.cs`, update the `GetItems`:
152+
142153
```csharp
143154
public override IListItem[] GetItems()
144155
{
@@ -154,29 +165,46 @@ public override IListItem[] GetItems()
154165
}
155166
```
156167

157-
Deploy and reload, and presto - a command to show a message box!
168+
1. Deploy your extension
169+
1. In command palette, `Reload`
170+
171+
And presto - a command to show a message box!
158172

159173
> [!TIP]
160174
> At about this point, you'll probably want to initialize a git repo / {other source control method of your choice} for your project. This will make it easier to track changes, and to share your extension with others.
161175
>
162176
> We recommend using GitHub, as it's easy to collaborate on your extension with others, and get feedback, and share it with the world.
163177
164-
## Adding more pages
178+
## Types of Pages
165179

166180
So far, we've only worked with commands that "do something". However, you can also add commands that show additional pages within the Command Palette. There are basically two types of "Commands" in the Palette:
167-
- **IInvokableCommand** - These are commands that *do something*.
168-
- **IPage** - These are commands that *show something*.
169181

170-
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.
182+
- `InvokableCommand` - These are commands that **do something**
183+
- `IPage` - These are commands that **show something**
184+
185+
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.
171186

172187
There are two different kinds of pages you can show:
188+
173189
- [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.
190+
191+
![Screenshot of ListPage](../../images/command-palette/ListPage.png)
192+
174193
- [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:
175194
- [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.
195+
196+
![Screenshot of Markdown content](../../images/command-palette/reload.png)
197+
176198
- [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.
177199

200+
![Screenshot of Form content](../../images/command-palette/reload.png)
178201

179-
Start by adding a new page that shows a list of commands. Create a new class that implements **ListPage**:
202+
## Add more commands
203+
204+
Start by adding a new page that shows a list of commands. Create a new class that implements **ListPage**.
205+
206+
1. In the `Pages` folder, create a new class called `MySecondPage`
207+
1. Update the code to:
180208

181209
```csharp
182210
using Microsoft.CommandPalette.Extensions.Toolkit;
@@ -206,7 +234,7 @@ internal sealed partial class MySecondPage : ListPage
206234
}
207235
```
208236

209-
Next, update the `<ExtensionName>Page.cs` to include this new page:
237+
1.Update the `<ExtensionName>Page.cs` to include this new page:
210238

211239
```diff
212240
public override IListItem[] GetItems()
@@ -218,12 +246,15 @@ Next, update the `<ExtensionName>Page.cs` to include this new page:
218246
Title = "Open the Command Palette documentation",
219247
},
220248
new ListItem(new ShowMessageCommand()),
221-
+ new ListItem(new MySecondPage()) { Title = "My second page", Subtitle = "A second page of commands" },
249+
+ new ListItem(new MySecondPage()) { Title = "My second page", Subtitle = "A second page of commands" },
222250
];
223251
}
224252
```
225253

226-
Deploy, reload, and you should now see a new page in your extension that shows 100 commands that copy a number to the clipboard.
254+
1. Deploy your extension
255+
1. In command palette, `Reload`
256+
257+
You should now see a new page in your extension that shows 100 commands that copy a number to the clipboard.
227258

228259
### Next up: [Update a list of commands](update-a-list-of-commands.md)
229260

hub/powertoys/command-palette/creating-an-extension.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ no-loc: [PowerToys, Windows, Insider]
99

1010
# Creating an extension
1111

12-
Extensions are written in C#. The fastest way to get started writing extensions is from the Command Palette itself. Just run the "Create a new extension" command, fill out the fields to populate the template project, and you should be ready to start.
12+
Extensions are written in C#. The fastest way to get started writing extensions is from the Command Palette itself.
13+
14+
1. Open Command Palette
15+
1. Run the `Create a new extension` command
16+
1. Fill out the fields to populate the template project, and you should be ready to start.
1317

1418
## Create a new extension
1519

1620
The form will ask you for the following information:
1721

1822
- **ExtensionName**: The name of your extension. This will be used as the name of the project and the name of the class that implements your commands. Make sure it's a valid C# class name - it shouldn't have any spaces or special characters, and should start with a capital letter. Reference in docs as `<ExtensionName>`.
19-
- **Extension Display Name**: The name of your extension as it will appear in the Command Palette. This can be a more human-readable name.
20-
- **Output Path**: The folder where the project will be created.
21-
- The project will be created in a subdirectory of the path you provided.
23+
- **Extension Display Name**: The name of your extension as it will appear in the Command Palette. This can be a more human-readable name.
24+
- **Output Path**: The folder where the project will be created.
25+
- The project will be created in a subdirectory of the path you provided.
2226
- If this path doesn't exist, it will be created for you.
2327

2428
![The "Create a new extension" page of the Windows Command Palette](../../images/command-palette/create-extension-page.png)
@@ -51,7 +55,18 @@ Once you submit the form, Command Palette will automatically generate the projec
5155

5256
(with `<ExtensionName>` replaced with the name you provided)
5357

54-
From here, you can immediately build the project and run it. Once your package is deployed and running, Command Palette will automatically discover your extension and load it into the palette.
58+
You can deploy and run your extension:
59+
60+
- In Visual Studio, Deploy your extension
61+
<details>
62+
<summary>How to Deploy your extension</summary>
63+
64+
1. In the navigation bar, click on `Build`
65+
1. Click on `Deploy <ExtensionName>`
66+
67+
</details>
68+
69+
Once your package is deployed and running, Command Palette will automatically discover your extension and load it into the palette.
5570

5671
> [!TIP]
5772
> Make sure you _deploy_ your app! Just **build**ing your application won't update the package in the same way that deploying it will.
@@ -66,7 +81,9 @@ From here, you can immediately build the project and run it. Once your package i
6681
> ```
6782
> These files are used by WinAppSdk to deploy your app as a package. Without it, anyone who clones your repo won't be able to deploy your extension.
6883
69-
You should be able to see your extension in the Command Palette at the end of the list of commands. Entering that command should take you to the page for your command, and you should see a single command that says `TODO: Implement your extension here`.
84+
1. In the Command Palette, scroll down the list of commands
85+
1. Press `Enter` on your <ExtensionName>
86+
1. You should see a single command that says `TODO: Implement your extension here`.
7087
7188
![A screenshot of the empty extension template, running in the command palette](../../images/command-palette/initial-created-extension-list.png)
7289
@@ -76,7 +93,6 @@ When you make changes to your extension, you can rebuild your project and deploy
7693
7794
![Screenshot of reload](../../images/command-palette/reload.png)
7895
79-
8096
### Next up: [Add commands to your extension](adding-commands.md)
8197
8298
## Related content

0 commit comments

Comments
 (0)