CmdPal: Add a viewmodel factory for pages (#40504)

_targets #40482_
ref #40113

A smaller refactor, to be sure.

This just moves the instantiation of PageViewModel objects out of the
ShellViewModel, and into its own class.

The idea being that other page types could be added, just by extending
that factory (or implementing your own), and then also handling those
new VMs in your ShellPage.xaml.cs equivalent.
This commit is contained in:
Mike Griese
2025-07-15 09:33:28 -05:00
committed by GitHub
parent 0783763dd0
commit 53bb471449
4 changed files with 46 additions and 17 deletions

View File

@@ -249,7 +249,19 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext
public interface IPageContext
{
public void ShowException(Exception ex, string? extensionHint = null);
void ShowException(Exception ex, string? extensionHint = null);
public TaskScheduler Scheduler { get; }
TaskScheduler Scheduler { get; }
}
public interface IPageViewModelFactoryService
{
/// <summary>
/// Creates a new instance of the page view model for the given page type.
/// </summary>
/// <param name="page">The page for which to create the view model.</param>
/// <param name="nested">Indicates whether the page is not the top-level page.</param>
/// <param name="host">The command palette host that will host the page (for status messages)</param>
/// <returns>A new instance of the page view model.</returns>
PageViewModel? TryCreatePageViewModel(IPage page, bool nested, CommandPaletteHost host);
}