From 81a7b819270967bacefb6bfd3ec81a5d9f255a0b Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 28 Jul 2025 06:44:25 -0500 Subject: [PATCH] CmdPal: fix content on extension settings (#40794) Regressed in one of the #40113 prs. The Core.VM.PageViewModelFactory didn't actually know how to make a ContentPage, because Core can't handle a FormContent. But really, the CommandSettingsViewModel shouldn't have ever been in the .Core namespace, nor should it have used the ContentPageViewModel. To prevent future mistakes like this, * I got rid of `Core.ViewModels/PageViewModelFactory`, cause we didn't need it. * I made `ContentPageViewModel` abstract, to prevent you from trying to instantiate it Closes #40778 --- .../ContentPageViewModel.cs | 2 +- .../PageViewModelFactory.cs | 27 ------------------- .../CommandSettingsViewModel.cs | 8 +++--- 3 files changed, 5 insertions(+), 32 deletions(-) delete mode 100644 src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/PageViewModelFactory.cs diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentPageViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentPageViewModel.cs index 16611a31ac..a6bd2bb302 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentPageViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentPageViewModel.cs @@ -14,7 +14,7 @@ using Microsoft.CommandPalette.Extensions.Toolkit; namespace Microsoft.CmdPal.Core.ViewModels; -public partial class ContentPageViewModel : PageViewModel, ICommandBarContext +public abstract partial class ContentPageViewModel : PageViewModel, ICommandBarContext { private readonly ExtensionObject _model; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/PageViewModelFactory.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/PageViewModelFactory.cs deleted file mode 100644 index a30a2bd76b..0000000000 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/PageViewModelFactory.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Microsoft.CommandPalette.Extensions; - -namespace Microsoft.CmdPal.Core.ViewModels; - -public class PageViewModelFactory : IPageViewModelFactoryService -{ - private readonly TaskScheduler _scheduler; - - public PageViewModelFactory(TaskScheduler scheduler) - { - _scheduler = scheduler; - } - - public PageViewModel? TryCreatePageViewModel(IPage page, bool nested, AppExtensionHost host) - { - return page switch - { - IListPage listPage => new ListViewModel(listPage, _scheduler, host) { IsNested = nested }, - IContentPage contentPage => new ContentPageViewModel(contentPage, _scheduler, host), - _ => null, - }; - } -} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandSettingsViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandSettingsViewModel.cs index a23cb4621e..5709a643cb 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandSettingsViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandSettingsViewModel.cs @@ -3,11 +3,11 @@ // See the LICENSE file in the project root for more information. using ManagedCommon; +using Microsoft.CmdPal.Core.ViewModels; using Microsoft.CmdPal.Core.ViewModels.Models; -using Microsoft.CmdPal.UI.ViewModels; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.Core.ViewModels; +namespace Microsoft.CmdPal.UI.ViewModels; public partial class CommandSettingsViewModel(ICommandSettings? _unsafeSettings, CommandProviderWrapper provider, TaskScheduler mainThread) { @@ -29,9 +29,9 @@ public partial class CommandSettingsViewModel(ICommandSettings? _unsafeSettings, return; } - if (model.SettingsPage is IContentPage page) + if (model.SettingsPage != null) { - SettingsPage = new(page, mainThread, provider.ExtensionHost); + SettingsPage = new CommandPaletteContentPageViewModel(model.SettingsPage, mainThread, provider.ExtensionHost); SettingsPage.InitializeProperties(); } }