2025-07-15 12:21:44 -05:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2025-07-15 09:33:28 -05:00
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
2025-07-15 12:21:44 -05:00
|
|
|
using Microsoft.CmdPal.Core.ViewModels;
|
2025-07-15 09:33:28 -05:00
|
|
|
using Microsoft.CommandPalette.Extensions;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.CmdPal.UI.ViewModels;
|
|
|
|
|
|
2025-07-15 12:21:44 -05:00
|
|
|
public class CommandPalettePageViewModelFactory
|
|
|
|
|
: IPageViewModelFactoryService
|
2025-07-15 09:33:28 -05:00
|
|
|
{
|
|
|
|
|
private readonly TaskScheduler _scheduler;
|
|
|
|
|
|
2025-07-15 12:21:44 -05:00
|
|
|
public CommandPalettePageViewModelFactory(TaskScheduler scheduler)
|
2025-07-15 09:33:28 -05:00
|
|
|
{
|
|
|
|
|
_scheduler = scheduler;
|
|
|
|
|
}
|
|
|
|
|
|
CmdPal: Load pinned command items from anywhere (#45566)
This doesn't actually have a UX to expose this yet - we need to stack a
couple of PRs up to get to that.
But this adds plumbing such that we can now stash away a command ID, and
retrieve it later as a top-level command. Kinda like pinning for apps,
but for _anything_.
It works off of a new command provider interface `ICommandProvider4`,
which lets us look up Command**Item**s by ID. If we see a command ID
stored in that command provider's settings, we will try to look it up,
and then load it from the command provider.
e.g.
```json
"com.microsoft.cmdpal.builtin.system": {
"IsEnabled": true,
"FallbackCommands": {
"com.microsoft.cmdpal.builtin.system.fallback": {
"IsEnabled": true,
"IncludeInGlobalResults": true
}
},
"PinnedCommandIds": [
"com.microsoft.cmdpal.builtin.system.lock",
"com.microsoft.cmdpal.builtin.system.restart_shell"
]
},
```
will get us
<img width="840" height="197" alt="image"
src="https://github.com/user-attachments/assets/9ed19003-8361-4318-8dc9-055414456a51"
/>
Then it's just a matter of plumbing the command provider ID through the
layers, so that the command item knows who it is from. We'll need that
later for actually wiring this to the command's context menu.
related to #45191
related to #45201
2026-02-19 16:20:05 -06:00
|
|
|
public PageViewModel? TryCreatePageViewModel(IPage page, bool nested, AppExtensionHost host, CommandProviderContext providerContext)
|
2025-07-15 09:33:28 -05:00
|
|
|
{
|
|
|
|
|
return page switch
|
|
|
|
|
{
|
CmdPal: Load pinned command items from anywhere (#45566)
This doesn't actually have a UX to expose this yet - we need to stack a
couple of PRs up to get to that.
But this adds plumbing such that we can now stash away a command ID, and
retrieve it later as a top-level command. Kinda like pinning for apps,
but for _anything_.
It works off of a new command provider interface `ICommandProvider4`,
which lets us look up Command**Item**s by ID. If we see a command ID
stored in that command provider's settings, we will try to look it up,
and then load it from the command provider.
e.g.
```json
"com.microsoft.cmdpal.builtin.system": {
"IsEnabled": true,
"FallbackCommands": {
"com.microsoft.cmdpal.builtin.system.fallback": {
"IsEnabled": true,
"IncludeInGlobalResults": true
}
},
"PinnedCommandIds": [
"com.microsoft.cmdpal.builtin.system.lock",
"com.microsoft.cmdpal.builtin.system.restart_shell"
]
},
```
will get us
<img width="840" height="197" alt="image"
src="https://github.com/user-attachments/assets/9ed19003-8361-4318-8dc9-055414456a51"
/>
Then it's just a matter of plumbing the command provider ID through the
layers, so that the command item knows who it is from. We'll need that
later for actually wiring this to the command's context menu.
related to #45191
related to #45201
2026-02-19 16:20:05 -06:00
|
|
|
IListPage listPage => new ListViewModel(listPage, _scheduler, host, providerContext) { IsNested = nested },
|
|
|
|
|
IContentPage contentPage => new CommandPaletteContentPageViewModel(contentPage, _scheduler, host, providerContext),
|
2025-07-15 09:33:28 -05:00
|
|
|
_ => null,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|