Skip to content

Commit 17da273

Browse files
committed
massaged page to closer inline with tone and style, added image of markdown sample to adding-command
1 parent 9fe3fc8 commit 17da273

File tree

5 files changed

+44
-21
lines changed

5 files changed

+44
-21
lines changed
48 KB
Loading
13.3 KB
Loading
1.81 KB
Loading

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ There are two different kinds of pages you can show:
193193
- [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:
194194
- [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.
195195

196-
![Screenshot of Markdown content](../../images/command-palette/reload.png)
196+
![Screenshot of extension using ContentPage](../../images/command-palette/markdown.png)
197197

198198
- [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.
199199

hub/powertoys/command-palette/using-markdown-content.md

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@ So far, we've only shown how to display a list of commands in a **ListPage**. Ho
1717

1818
[IContentPage](./microsoft-commandpalette-extensions/icontentpage.md) (and its toolkit implementation, [ContentPage](microsoft-commandpalette-extensions-toolkit/contentpage.md)) is the base for displaying all types of rich content in the Command Palette. To display markdown content, you can use the [MarkdownContent](microsoft-commandpalette-extensions-toolkit/markdowncontent.md) class.
1919

20-
As a simple example, we can create the following page:
21-
22-
> [!NOTE]
23-
> If working from prior sections, modify the code below from `MarkdownPage` to `<ExtensionName>Page`.
20+
1. In your <ExtensionName>Page.cs, replace content with:
2421

2522
```csharp
26-
public class MarkdownPage : ContentPage
23+
internal sealed partial class <ExtensionName>Page : ContentPage
2724
{
28-
public MarkdownPage()
25+
public <ExtensionName>Page()
2926
{
30-
Icon = IconHelpers.FromRelativePath("Assets\\StoreLogo.png");
27+
Icon = new("\uE8A5"); // Document icon
3128
Title = "Markdown page";
29+
Name = "Preview file";
3230
}
3331

3432
public override IContent[] GetContent()
@@ -40,49 +38,74 @@ public class MarkdownPage : ContentPage
4038
}
4139
```
4240

43-
In this example, a new **MarkdownPage** that displays a simple markdown string is created. The **MarkdownContent** class takes a string of markdown content and renders it in the Command Palette.
41+
1. Deploy your extension
42+
1. In command palette, `Reload`
4443

45-
You can also add multiple blocks of content to a page. For example, you can add two blocks of markdown content:
44+
In this example, a new `ContentPage` that displays a simple markdown string is created. The 'MarkdownContent' class takes a string of markdown content and renders it in the Command Palette.
4645

47-
```csharp
46+
![Screenshot of extension using ContentPage](../../images/command-palette/markdown.png)
47+
48+
You can also add multiple blocks of content to a page. For example, you can add two blocks of markdown content.
49+
50+
1. Update `GetContent`:
51+
52+
```diff
4853
public override IContent[] GetContent()
4954
{
5055
return [
5156
new MarkdownContent("# Hello, world!\n This is a **markdown** page."),
52-
new MarkdownContent("## Second block\n This is another block of content."),
57+
+ new MarkdownContent("## Second block\n This is another block of content."),
5358
];
5459
}
5560
```
5661

62+
1. Deploy your extension
63+
1. In command palette, `Reload`
64+
5765
This allows you to mix-and-match different types of content on a single page.
5866

59-
## Adding commands
67+
## Adding CommandContextItem
68+
69+
You can also add commands to a `ContentPage`. This allows you to add additional commands to be invoked by the user, while in the context of the content. For example, if you had a page that displayed a document, you could add a command to open the document in File Explorer:
6070

61-
You can also add commands to a **ContentPage**. This allows you to add additional commands to be invoked by the user, while in the context of the content. For example, if you had a page that displayed a document, you could add a command to open the document in File Explorer:
71+
1. In your <ExtensionName>Page.cs, add `doc_path`, `Commands` and `MarkdownContent`:
6272

63-
```csharp
73+
```diff
6474

65-
public class MarkdownExamplePage : ContentPage
75+
public class <ExtensionName>Page : ContentPage
6676
{
67-
public MarkdownExamplePage()
77+
+ private string doc_path = "C:\\Path\\to\\file.txt";
78+
public <ExtensionName>Page()
6879
{
6980
Icon = new("\uE8A5"); // Document icon
7081
Title = "Markdown page";
7182
Name = "Preview file";
83+
path =
7284

73-
Commands = [
74-
new CommandContextItem(new OpenUrlCommand("C:\\Path\\to\\file.txt")) { Title = "Open in File Explorer" },
75-
];
85+
+ Commands = [
86+
+ new CommandContextItem(new OpenUrlCommand("C:\\Path\\to\\file.txt")) { Title = "Open in File Explorer" },
87+
+ ];
7688
}
7789
public override IContent[] GetContent()
7890
{
7991
return [
80-
new MarkdownContent("# Hello, world!\n This is a **markdown** document.\nI live at `C:\\Path\\to\\file.txt`"),
92+
new MarkdownContent("# Hello, world!\n This is a **markdown** document."),
93+
new MarkdownContent("## Second block\n This is another block of content."),
94+
+ new MarkdownContent($"## Press enter to open `{doc_path}`"),
8195
];
8296
}
8397
}
8498
```
8599

100+
1. Update the path in the `doc_path` to a .txt file on your local machine
101+
1. Deploy your extension
102+
1. In command palette, `Reload`
103+
1. Select <ExtensionName>
104+
1. Press `Enter` key, the docs should open
105+
106+
![Screenshot of extension using CommandContextItem](../../images/command-palette/CommandContextItem.png)
107+
108+
86109
### Next up: [Get user input with forms](using-form-pages.md)
87110

88111
## Related content

0 commit comments

Comments
 (0)