/ src / modules / cmdpal / Microsoft.CmdPal.UI.ViewModels / CommandPalettePageViewModelFactory.cs
CommandPalettePageViewModelFactory.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using Microsoft.CmdPal.Core.ViewModels;
 6  using Microsoft.CommandPalette.Extensions;
 7  
 8  namespace Microsoft.CmdPal.UI.ViewModels;
 9  
10  public class CommandPalettePageViewModelFactory
11      : IPageViewModelFactoryService
12  {
13      private readonly TaskScheduler _scheduler;
14  
15      public CommandPalettePageViewModelFactory(TaskScheduler scheduler)
16      {
17          _scheduler = scheduler;
18      }
19  
20      public PageViewModel? TryCreatePageViewModel(IPage page, bool nested, AppExtensionHost host)
21      {
22          return page switch
23          {
24              IListPage listPage => new ListViewModel(listPage, _scheduler, host) { IsNested = nested },
25              IContentPage contentPage => new CommandPaletteContentPageViewModel(contentPage, _scheduler, host),
26              _ => null,
27          };
28      }
29  }