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
**Previous**: [Add top-level commands to your extension](add-top-level-commands-to-your-extension.md)
13
13
14
-
An [IInvokableCommand](./microsoft-commandpalette-extensions/iinvokablecommand.md)is a fundamental unit of *do something*in the Command Palette. The [Invoke](./microsoft-commandpalette-extensions/iinvokablecommand.md) method is called when the user selects the command, and it's where you *do something* in your extension. The **Invoke** method returns an **ICommandResult**, which tells the Command Palette what to do after the command has been invoked. This page details what's possible with each type of command result.
14
+
An [IInvokableCommand](./microsoft-commandpalette-extensions/iinvokablecommand.md)represents a single actionable item in the Command Palette—it's what gets triggered when a user selects a command.
15
15
16
-
The toolkit provides a number of helper methods to create command results. These are all static methods on the **CommandResult** class. Calling these methods on their own won't do anything. You must return those objects as the result of a **Invoke** method, for Command Palette to handle them.
16
+
When your command is selected, the [Invoke](./microsoft-commandpalette-extensions/iinvokablecommand.md) method is called. This is where you implement the logic for what your extension should do. The Invoke method must return an `CommandResult`, which tells the Command Palette how to respond after the command runs—for example, whether to show a message, open a file, or do nothing.
17
+
18
+
This page explains the 7 different types of `CommandResult` you can return and what each one does:
17
19
18
20
> [!NOTE]
19
21
> There are code examples for the various CommandResult methods listed on this page.
@@ -22,28 +24,28 @@ The toolkit provides a number of helper methods to create command results. These
22
24
23
25
## KeepOpen command result
24
26
25
-
The **KeepOpen** command result does nothing. It leaves the palette in its current state, with the current page stack and query. This can be useful for commands that want to keep the user in the Command Palette, to keep working with the current page.
27
+
The `KeepOpen` command result does nothing. It leaves the palette in its current state, with the current page stack and query. This can be useful for commands that want to keep the user in the Command Palette, to keep working with the current page.
26
28
27
29
> [!NOTE]
28
-
> Even when returning **KeepOpen**, launching a new app or window from the Command Palette will automatically hide the palette the next window receives focus.
30
+
> Even when returning `KeepOpen`, launching a new app or window from the Command Palette will automatically hide the palette the next window receives focus.
29
31
30
32
## Hide command result
31
33
32
-
This command result keeps the current page open, but hides the Command Palette. This can be useful for commands that want to take the user briefly out of the Command Palette, but then come back to this context.
34
+
This command result keeps the current page open, but hides the Command Palette. This can be useful for commands that want to take the user briefly out of the Command Palette, but then come back to this context.
33
35
34
36
## GoBack command result
35
37
36
38
This result takes the user back a page in the Command Palette, and keeps the window visible. This is perfect for form pages, where doing the command should take you the user back to the previous context.
37
39
38
40
## GoHome command result
39
41
40
-
This result takes the user back to the main page of the Command Palette. It will leave the Palette visible (unless the palette otherwise loses focus). Consider using this for scenarios where you've changed your top-level commands.
42
+
This result takes the user back to the main page of the Command Palette. It will leave the Palette visible (unless the palette otherwise loses focus). Consider using this for scenarios where you've changed your top-level commands.
41
43
42
44
## Dismiss command result
43
45
44
46
This result hides the Command Palette after the action is executed, and takes it back to the home page. On the next launch, the Command Palette will start from the main page with a blank query. This is useful for commands that are one-off actions, or that don't need to keep the Command Palette open.
45
47
46
-
If you don't know what else to use, this should be your default. Ideally, users should come into the palette, find what they need, and be done with it.
48
+
If you don't know what else to use, this should be your default. Ideally, users should come into the palette, find what they need, and be done with it.
47
49
48
50
## ShowToast command result
49
51
@@ -55,23 +57,20 @@ By default, [CommandResult.ShowToast(string)](./microsoft-commandpalette-extensi
55
57
56
58
## Confirm command result
57
59
58
-
This result displays a confirmation dialog to the user. If the user confirms the dialog, then the **PrimaryCommand** of the *ConfirmationArgs* will be performed.
60
+
This result displays a confirmation dialog to the user. If the user confirms the dialog, then the `PrimaryCommand` of the `ConfirmationArgs` will be performed.
59
61
60
62
This is useful for commands that might have destructive actions, or that need to confirm user intent.
61
63
62
64
## Example
63
65
64
-
As an example, here's a page with one command for each kind of command result:
65
-
66
-
> [!NOTE]
67
-
> If working from prior section, modify the code below from `CommandResultsPage` to `<ExtensionName>Page`.
66
+
Below is a page with one command for each kind of command result:
0 commit comments