From d96c29d22d95a7ba406ab56d12a42ae9333ce9ea Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 14 Jul 2025 13:58:59 -0500 Subject: [PATCH 01/10] Replace our nuget.org feed with a public azure artifacts feed (#40486) _This madness has gone on too long, I say_ This replaces our default nuget.org feed with a public azure artifacts feed in the shine-oss org. This is what literally everyone else does, I don't know why we don't. This should unblock _wait where'd that issue go_ since we can just add the community toolkit labs feed as an upstream This has the negative side effect that it did prompt me to log in to azure artifacts with my MSA. I've cancelled like 5 prompts now, but it seems to still be working on it? --- nuget.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nuget.config b/nuget.config index e6a17ffdfe..51f9b3b3f7 100644 --- a/nuget.config +++ b/nuget.config @@ -2,10 +2,10 @@ - + - + From 5800b816386a7bad40b9ffe9c7327f88b4a5ab73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pol=C3=A1=C5=A1ek?= Date: Tue, 15 Jul 2025 03:03:52 +0200 Subject: [PATCH 02/10] Fix loading top-level commands (#40602) ## Summary of the Pull Request Updates LoadTopLevelCommandsFromProvider so it returns list of top-level commands for further instead of modifying TopLevelCommands collection directly. Reverts unintended change from cfa5f75 where LoadTopLevelCommandsFromProvider updates the shared TopLevelCommands collection directly from in a task, causing thread-safety issues and bypassing synchronization lock on the collection. ## PR Checklist - [ ] **Closes:** -- - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --- .../Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs index 752ca0e38e..d9beb0995d 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs @@ -104,14 +104,14 @@ public partial class TopLevelCommandManager : ObservableObject, List commands = []; foreach (var item in commandProvider.TopLevelItems) { - TopLevelCommands.Add(item); + commands.Add(item); } foreach (var item in commandProvider.FallbackItems) { if (item.IsEnabled) { - TopLevelCommands.Add(item); + commands.Add(item); } } From 19390e319879d6f751a16c8248608232a1aa36de Mon Sep 17 00:00:00 2001 From: Michael Jolley Date: Tue, 15 Jul 2025 08:59:32 -0500 Subject: [PATCH 03/10] Users can now pin/unpin apps from the top of AllApps extension (#40544) Users can now use Ctrl+P to toggle pinning and unpinning applications from the top of the All Apps extension. This pinned status persists through restarts & reboots. https://github.com/user-attachments/assets/86895a38-7312-438a-9409-b50a85979d12 Reference: #40543 --------- Co-authored-by: Mike Griese --- .../AllAppsCommandProvider.cs | 14 +- .../Microsoft.CmdPal.Ext.Apps/AllAppsPage.cs | 188 ++++++++++++------ .../ext/Microsoft.CmdPal.Ext.Apps/AppItem.cs | 5 +- .../Microsoft.CmdPal.Ext.Apps/AppListItem.cs | 41 +++- .../Commands/CopyPathCommand.cs | 5 +- .../Commands/OpenInConsoleCommand.cs | 5 +- .../Commands/OpenPathCommand.cs | 5 +- .../Commands/PinAppCommand.cs | 29 +++ .../Commands/RunAsAdminCommand.cs | 5 +- .../Commands/RunAsUserCommand.cs | 9 +- .../Commands/UnpinAppCommand.cs | 28 +++ .../Helpers/Icons.cs | 26 +++ .../JsonSerializationContext.cs | 21 ++ .../Programs/UWPApplication.cs | 31 ++- .../Programs/Win32Program.cs | 37 +++- .../Properties/Resources.Designer.cs | 18 ++ .../Properties/Resources.resx | 6 + .../State/PinStateChangedEventArgs.cs | 34 ++++ .../State/PinnedApps.cs | 47 +++++ .../State/PinnedAppsManager.cs | 82 ++++++++ 20 files changed, 548 insertions(+), 88 deletions(-) create mode 100644 src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/PinAppCommand.cs create mode 100644 src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/UnpinAppCommand.cs create mode 100644 src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Helpers/Icons.cs create mode 100644 src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/JsonSerializationContext.cs create mode 100644 src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinStateChangedEventArgs.cs create mode 100644 src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinnedApps.cs create mode 100644 src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinnedAppsManager.cs diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs index e62fc71e2b..6d860ee6cd 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs @@ -2,8 +2,12 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Collections.Generic; using System.Linq; +using Microsoft.CmdPal.Ext.Apps.Programs; using Microsoft.CmdPal.Ext.Apps.Properties; +using Microsoft.CmdPal.Ext.Apps.State; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -29,9 +33,12 @@ public partial class AllAppsCommandProvider : CommandProvider Subtitle = Resources.search_installed_apps, MoreCommands = [new CommandContextItem(AllAppsSettings.Instance.Settings.SettingsPage)], }; + + // Subscribe to pin state changes to refresh the command provider + PinnedAppsManager.Instance.PinStateChanged += OnPinStateChanged; } - public override ICommandItem[] TopLevelCommands() => [_listItem]; + public override ICommandItem[] TopLevelCommands() => [_listItem, ..Page.GetPinnedApps()]; public ICommandItem? LookupApp(string displayName) { @@ -62,4 +69,9 @@ public partial class AllAppsCommandProvider : CommandProvider return null; } + + private void OnPinStateChanged(object? sender, System.EventArgs e) + { + RaiseItemsChanged(0); + } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsPage.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsPage.cs index f271d4d556..46300f6bc7 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsPage.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsPage.cs @@ -2,14 +2,20 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Numerics; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using ManagedCommon; +using Microsoft.CmdPal.Ext.Apps.Commands; +using Microsoft.CmdPal.Ext.Apps.Helpers; using Microsoft.CmdPal.Ext.Apps.Programs; using Microsoft.CmdPal.Ext.Apps.Properties; +using Microsoft.CmdPal.Ext.Apps.State; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -18,16 +24,22 @@ namespace Microsoft.CmdPal.Ext.Apps; public sealed partial class AllAppsPage : ListPage { private readonly Lock _listLock = new(); - private AppListItem[] allAppsSection = []; + + private AppItem[] allApps = []; + private AppListItem[] unpinnedApps = []; + private AppListItem[] pinnedApps = []; public AllAppsPage() { this.Name = Resources.all_apps; - this.Icon = IconHelpers.FromRelativePath("Assets\\AllApps.svg"); + this.Icon = Icons.AllAppsIcon; this.ShowDetails = true; this.IsLoading = true; this.PlaceholderText = Resources.search_installed_apps_placeholder; + // Subscribe to pin state changes to refresh the command provider + PinnedAppsManager.Instance.PinStateChanged += OnPinStateChanged; + Task.Run(() => { lock (_listLock) @@ -37,89 +49,139 @@ public sealed partial class AllAppsPage : ListPage }); } + internal AppListItem[] GetPinnedApps() + { + BuildListItems(); + return pinnedApps; + } + public override IListItem[] GetItems() { - if (allAppsSection.Length == 0 || AppCache.Instance.Value.ShouldReload()) - { - lock (_listLock) - { - BuildListItems(); - } - } - - return allAppsSection; + // Build or update the list if needed + BuildListItems(); + return pinnedApps.Concat(unpinnedApps).ToArray(); } private void BuildListItems() { - this.IsLoading = true; + if (allApps.Length == 0 || AppCache.Instance.Value.ShouldReload()) + { + lock (_listLock) + { + this.IsLoading = true; - Stopwatch stopwatch = new(); - stopwatch.Start(); + Stopwatch stopwatch = new(); + stopwatch.Start(); - var apps = GetPrograms(); + var apps = GetPrograms(); + this.allApps = apps.AllApps; + this.pinnedApps = apps.PinnedItems; + this.unpinnedApps = apps.UnpinnedItems; - this.allAppsSection = apps - .Select((app) => new AppListItem(app, true)) - .ToArray(); + this.IsLoading = false; - this.IsLoading = false; + AppCache.Instance.Value.ResetReloadFlag(); - AppCache.Instance.Value.ResetReloadFlag(); - - stopwatch.Stop(); - Logger.LogTrace($"{nameof(AllAppsPage)}.{nameof(BuildListItems)} took: {stopwatch.ElapsedMilliseconds} ms"); + stopwatch.Stop(); + Logger.LogTrace($"{nameof(AllAppsPage)}.{nameof(BuildListItems)} took: {stopwatch.ElapsedMilliseconds} ms"); + } + } } - internal List GetPrograms() + private AppItem[] GetAllApps() { var uwpResults = AppCache.Instance.Value.UWPs - .Where((application) => application.Enabled) - .Select(UwpToAppItem); + .Where((application) => application.Enabled) + .Select(app => app.ToAppItem()); var win32Results = AppCache.Instance.Value.Win32s .Where((application) => application.Enabled && application.Valid) - .Select(app => - { - var icoPath = string.IsNullOrEmpty(app.IcoPath) ? - (app.AppType == Win32Program.ApplicationType.InternetShortcutApplication ? - app.IcoPath : - app.FullPath) : - app.IcoPath; + .Select(app => app.ToAppItem()); - // icoPath = icoPath.EndsWith(".lnk", System.StringComparison.InvariantCultureIgnoreCase) ? (icoPath + ",0") : icoPath; - icoPath = icoPath.EndsWith(".lnk", System.StringComparison.InvariantCultureIgnoreCase) ? - app.FullPath : - icoPath; - return new AppItem() - { - Name = app.Name, - Subtitle = app.Description, - Type = app.Type(), - IcoPath = icoPath, - ExePath = !string.IsNullOrEmpty(app.LnkFilePath) ? app.LnkFilePath : app.FullPath, - DirPath = app.Location, - Commands = app.GetCommands(), - }; - }); - - return uwpResults.Concat(win32Results).OrderBy(app => app.Name).ToList(); + var allApps = uwpResults.Concat(win32Results).ToArray(); + return allApps; } - private AppItem UwpToAppItem(UWPApplication app) + internal (AppItem[] AllApps, AppListItem[] PinnedItems, AppListItem[] UnpinnedItems) GetPrograms() { - var iconPath = app.LogoType != LogoType.Error ? app.LogoPath : string.Empty; - var item = new AppItem() + var allApps = GetAllApps(); + var pinned = new List(); + var unpinned = new List(); + + foreach (var app in allApps) { - Name = app.Name, - Subtitle = app.Description, - Type = UWPApplication.Type(), - IcoPath = iconPath, - DirPath = app.Location, - UserModelId = app.UserModelId, - IsPackaged = true, - Commands = app.GetCommands(), - }; - return item; + var isPinned = PinnedAppsManager.Instance.IsAppPinned(app.AppIdentifier); + var appListItem = new AppListItem(app, true, isPinned); + + if (isPinned) + { + appListItem.Tags = appListItem.Tags + .Concat([new Tag() { Icon = Icons.PinIcon }]) + .ToArray(); + pinned.Add(appListItem); + } + else + { + unpinned.Add(appListItem); + } + } + + return ( + allApps + .ToArray(), + pinned + .OrderBy(app => app.Title) + .ToArray(), + unpinned + .OrderBy(app => app.Title) + .ToArray()); + } + + private void OnPinStateChanged(object? sender, PinStateChangedEventArgs e) + { + /* + * Rebuilding all the lists is pretty expensive. + * So, instead, we'll just compare pinned items to move existing + * items between the two lists. + */ + var existingAppItem = allApps.FirstOrDefault(f => f.AppIdentifier == e.AppIdentifier); + + if (existingAppItem != null) + { + var appListItem = new AppListItem(existingAppItem, true, e.IsPinned); + + if (e.IsPinned) + { + // Remove it from the unpinned apps array + this.unpinnedApps = this.unpinnedApps + .Where(app => app.AppIdentifier != existingAppItem.AppIdentifier) + .OrderBy(app => app.Title) + .ToArray(); + + var newPinned = this.pinnedApps.ToList(); + newPinned.Add(appListItem); + + this.pinnedApps = newPinned + .OrderBy(app => app.Title) + .ToArray(); + } + else + { + // Remove it from the pinned apps array + this.pinnedApps = this.pinnedApps + .Where(app => app.AppIdentifier != existingAppItem.AppIdentifier) + .OrderBy(app => app.Title) + .ToArray(); + + var newUnpinned = this.unpinnedApps.ToList(); + newUnpinned.Add(appListItem); + + this.unpinnedApps = newUnpinned + .OrderBy(app => app.Title) + .ToArray(); + } + + RaiseItemsChanged(0); + } } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppItem.cs index 4bb26bed67..2e5ba78b1f 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppItem.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppItem.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Microsoft.CmdPal.Ext.Apps.Programs; +using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; namespace Microsoft.CmdPal.Ext.Apps; @@ -26,7 +27,9 @@ internal sealed class AppItem public bool IsPackaged { get; set; } - public List? Commands { get; set; } + public List? Commands { get; set; } + + public string AppIdentifier { get; set; } = string.Empty; public AppItem() { diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs index 57c9175d4d..4ac8f79aea 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.CmdPal.Ext.Apps.Commands; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; using Windows.Storage.Streams; @@ -23,14 +24,17 @@ internal sealed partial class AppListItem : ListItem public override IIconInfo? Icon { get => _icon.Value; set => base.Icon = value; } - public AppListItem(AppItem app, bool useThumbnails) + public string AppIdentifier => _app.AppIdentifier; + + public AppListItem(AppItem app, bool useThumbnails, bool isPinned) : base(new AppCommand(app)) { _app = app; Title = app.Name; Subtitle = app.Subtitle; Tags = [_appTag]; - MoreCommands = _app.Commands!.ToArray(); + + MoreCommands = AddPinCommands(_app.Commands!, isPinned); _details = new Lazy
(() => { @@ -121,4 +125,37 @@ internal sealed partial class AppListItem : ListItem return icon; } + + private IContextItem[] AddPinCommands(List commands, bool isPinned) + { + var newCommands = new List(); + newCommands.AddRange(commands); + + newCommands.Add(new SeparatorContextItem()); + + // 0x50 = P + // Full key chord would be Ctrl+P + var pinKeyChord = KeyChordHelpers.FromModifiers(true, false, false, false, 0x50, 0); + + if (isPinned) + { + newCommands.Add( + new CommandContextItem( + new UnpinAppCommand(this.AppIdentifier)) + { + RequestedShortcut = pinKeyChord, + }); + } + else + { + newCommands.Add( + new CommandContextItem( + new PinAppCommand(this.AppIdentifier)) + { + RequestedShortcut = pinKeyChord, + }); + } + + return newCommands.ToArray(); + } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/CopyPathCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/CopyPathCommand.cs index 30ad044f37..9618e2fa43 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/CopyPathCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/CopyPathCommand.cs @@ -6,6 +6,7 @@ using System; using System.Globalization; using System.Text; using ManagedCommon; +using Microsoft.CmdPal.Ext.Apps.Helpers; using Microsoft.CmdPal.Ext.Apps.Properties; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -13,14 +14,12 @@ namespace Microsoft.CmdPal.Ext.Apps.Commands; internal sealed partial class CopyPathCommand : InvokableCommand { - private static readonly IconInfo TheIcon = new("\ue8c8"); - private readonly string _target; public CopyPathCommand(string target) { Name = Resources.copy_path; - Icon = TheIcon; + Icon = Icons.CopyIcon; _target = target; } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenInConsoleCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenInConsoleCommand.cs index 41e934759a..e4f6ec5228 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenInConsoleCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenInConsoleCommand.cs @@ -6,6 +6,7 @@ using System; using System.Diagnostics; using System.Threading.Tasks; using ManagedCommon; +using Microsoft.CmdPal.Ext.Apps.Helpers; using Microsoft.CmdPal.Ext.Apps.Properties; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -13,14 +14,12 @@ namespace Microsoft.CmdPal.Ext.Apps.Commands; internal sealed partial class OpenInConsoleCommand : InvokableCommand { - private static readonly IconInfo TheIcon = new("\ue838"); - private readonly string _target; public OpenInConsoleCommand(string target) { Name = Resources.open_path_in_console; - Icon = TheIcon; + Icon = Icons.OpenConsoleIcon; _target = target; } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenPathCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenPathCommand.cs index 88c7df5d94..06ad9c67ce 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenPathCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenPathCommand.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Threading.Tasks; +using Microsoft.CmdPal.Ext.Apps.Helpers; using Microsoft.CmdPal.Ext.Apps.Properties; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -11,14 +12,12 @@ namespace Microsoft.CmdPal.Ext.Apps.Commands; internal sealed partial class OpenPathCommand : InvokableCommand { - private static readonly IconInfo TheIcon = new("\ue838"); - private readonly string _target; public OpenPathCommand(string target) { Name = Resources.open_location; - Icon = TheIcon; + Icon = Icons.OpenPathIcon; _target = target; } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/PinAppCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/PinAppCommand.cs new file mode 100644 index 0000000000..6f26fde6c2 --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/PinAppCommand.cs @@ -0,0 +1,29 @@ +// 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 System.Diagnostics.CodeAnalysis; +using Microsoft.CmdPal.Ext.Apps.Helpers; +using Microsoft.CmdPal.Ext.Apps.Properties; +using Microsoft.CmdPal.Ext.Apps.State; +using Microsoft.CommandPalette.Extensions.Toolkit; + +namespace Microsoft.CmdPal.Ext.Apps.Commands; + +internal sealed partial class PinAppCommand : InvokableCommand +{ + private readonly string _appIdentifier; + + public PinAppCommand(string appIdentifier) + { + _appIdentifier = appIdentifier; + Name = Resources.pin_app; + Icon = Icons.PinIcon; + } + + public override CommandResult Invoke() + { + PinnedAppsManager.Instance.PinApp(_appIdentifier); + return CommandResult.KeepOpen(); + } +} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/RunAsAdminCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/RunAsAdminCommand.cs index 0a6d43f608..d3714ea8ae 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/RunAsAdminCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/RunAsAdminCommand.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Threading.Tasks; +using Microsoft.CmdPal.Ext.Apps.Helpers; using Microsoft.CmdPal.Ext.Apps.Properties; using Microsoft.CmdPal.Ext.Apps.Utils; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -13,8 +14,6 @@ namespace Microsoft.CmdPal.Ext.Apps.Commands; internal sealed partial class RunAsAdminCommand : InvokableCommand { - private static readonly IconInfo TheIcon = new("\uE7EF"); - private readonly string _target; private readonly string _parentDir; private readonly bool _packaged; @@ -22,7 +21,7 @@ internal sealed partial class RunAsAdminCommand : InvokableCommand public RunAsAdminCommand(string target, string parentDir, bool packaged) { Name = Resources.run_as_administrator; - Icon = TheIcon; + Icon = Icons.RunAsIcon; _target = target; _parentDir = parentDir; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/RunAsUserCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/RunAsUserCommand.cs index c897aed560..7afa8e7e13 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/RunAsUserCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/RunAsUserCommand.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Threading.Tasks; +using Microsoft.CmdPal.Ext.Apps.Helpers; using Microsoft.CmdPal.Ext.Apps.Properties; using Microsoft.CmdPal.Ext.Apps.Utils; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -13,21 +14,19 @@ namespace Microsoft.CmdPal.Ext.Apps.Commands; internal sealed partial class RunAsUserCommand : InvokableCommand { - private static readonly IconInfo TheIcon = new("\uE7EE"); - private readonly string _target; private readonly string _parentDir; public RunAsUserCommand(string target, string parentDir) { Name = Resources.run_as_different_user; - Icon = TheIcon; + Icon = Icons.RunAsUserIcon; _target = target; _parentDir = parentDir; } - internal static async Task RunAsAdmin(string target, string parentDir) + internal static async Task RunAsUser(string target, string parentDir) { await Task.Run(() => { @@ -39,7 +38,7 @@ internal sealed partial class RunAsUserCommand : InvokableCommand public override CommandResult Invoke() { - _ = RunAsAdmin(_target, _parentDir).ConfigureAwait(false); + _ = RunAsUser(_target, _parentDir).ConfigureAwait(false); return CommandResult.Dismiss(); } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/UnpinAppCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/UnpinAppCommand.cs new file mode 100644 index 0000000000..cf829f8521 --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/UnpinAppCommand.cs @@ -0,0 +1,28 @@ +// 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.CmdPal.Ext.Apps.Helpers; +using Microsoft.CmdPal.Ext.Apps.Properties; +using Microsoft.CmdPal.Ext.Apps.State; +using Microsoft.CommandPalette.Extensions.Toolkit; + +namespace Microsoft.CmdPal.Ext.Apps.Commands; + +internal sealed partial class UnpinAppCommand : InvokableCommand +{ + private readonly string _appIdentifier; + + public UnpinAppCommand(string appIdentifier) + { + _appIdentifier = appIdentifier; + Name = Resources.unpin_app; + Icon = Icons.UnpinIcon; + } + + public override CommandResult Invoke() + { + PinnedAppsManager.Instance.UnpinApp(_appIdentifier); + return CommandResult.KeepOpen(); + } +} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Helpers/Icons.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Helpers/Icons.cs new file mode 100644 index 0000000000..45a10af4e5 --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Helpers/Icons.cs @@ -0,0 +1,26 @@ +// 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.Toolkit; + +namespace Microsoft.CmdPal.Ext.Apps.Helpers; + +public static partial class Icons +{ + public static IconInfo UnpinIcon { get; } = new("\uE77A"); + + public static IconInfo PinIcon { get; } = new("\uE840"); + + public static IconInfo RunAsIcon { get; } = new("\uE7EF"); + + public static IconInfo RunAsUserIcon { get; } = new("\uE7EE"); + + public static IconInfo CopyIcon { get; } = new("\ue8c8"); + + public static IconInfo OpenConsoleIcon { get; } = new("\ue838"); + + public static IconInfo OpenPathIcon { get; } = new("\ue838"); + + public static IconInfo AllAppsIcon { get; } = IconHelpers.FromRelativePath("Assets\\AllApps.svg"); +} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/JsonSerializationContext.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/JsonSerializationContext.cs new file mode 100644 index 0000000000..5a11d9c135 --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/JsonSerializationContext.cs @@ -0,0 +1,21 @@ +// 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 System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using Microsoft.CmdPal.Ext.Apps.State; + +namespace Microsoft.CmdPal.Ext.Apps; + +[JsonSerializable(typeof(string))] +[JsonSerializable(typeof(PinnedApps))] +[JsonSerializable(typeof(List), TypeInfoPropertyName = "StringList")] +[JsonSourceGenerationOptions(UseStringEnumConverter = true, WriteIndented = true, IncludeFields = true, PropertyNameCaseInsensitive = true, AllowTrailingCommas = true)] +internal sealed partial class JsonSerializationContext : JsonSerializerContext +{ +} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs index 1cf4bc4463..f0f8de8a35 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs @@ -10,7 +10,9 @@ using System.Xml; using ManagedCommon; using Microsoft.CmdPal.Ext.Apps.Commands; using Microsoft.CmdPal.Ext.Apps.Properties; +using Microsoft.CmdPal.Ext.Apps.State; using Microsoft.CmdPal.Ext.Apps.Utils; +using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; using Windows.System; using Windows.Win32; @@ -70,9 +72,15 @@ public class UWPApplication : IProgram return Resources.packaged_application; } - public List GetCommands() + public string GetAppIdentifier() { - List commands = []; + // Use UserModelId for UWP apps as it's unique + return UserModelId; + } + + public List GetCommands() + { + List commands = []; if (CanRunElevated) { @@ -511,6 +519,25 @@ public class UWPApplication : IProgram } } + internal AppItem ToAppItem() + { + var app = this; + var iconPath = app.LogoType != LogoType.Error ? app.LogoPath : string.Empty; + var item = new AppItem() + { + Name = app.Name, + Subtitle = app.Description, + Type = UWPApplication.Type(), + IcoPath = iconPath, + DirPath = app.Location, + UserModelId = app.UserModelId, + IsPackaged = true, + Commands = app.GetCommands(), + AppIdentifier = app.GetAppIdentifier(), + }; + return item; + } + /* public ImageSource Logo() { diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs index dd6bdd875d..d8bebcd9a4 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs @@ -19,7 +19,9 @@ using System.Windows.Input; using ManagedCommon; using Microsoft.CmdPal.Ext.Apps.Commands; using Microsoft.CmdPal.Ext.Apps.Properties; +using Microsoft.CmdPal.Ext.Apps.State; using Microsoft.CmdPal.Ext.Apps.Utils; +using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; using Microsoft.Win32; using Windows.System; @@ -186,9 +188,9 @@ public class Win32Program : IProgram return true; } - public List GetCommands() + public List GetCommands() { - List commands = new List(); + List commands = new List(); if (AppType != ApplicationType.InternetShortcutApplication && AppType != ApplicationType.Folder && AppType != ApplicationType.GenericFile) { @@ -231,6 +233,12 @@ public class Win32Program : IProgram return ExecutableName; } + public string GetAppIdentifier() + { + // Use a combination of name and path to create a unique identifier + return $"{Name}|{FullPath}"; + } + private static Win32Program CreateWin32Program(string path) { try @@ -933,4 +941,29 @@ public class Win32Program : IProgram return Array.Empty(); } } + + internal AppItem ToAppItem() + { + var app = this; + var icoPath = string.IsNullOrEmpty(app.IcoPath) ? + (app.AppType == Win32Program.ApplicationType.InternetShortcutApplication ? + app.IcoPath : + app.FullPath) : + app.IcoPath; + + icoPath = icoPath.EndsWith(".lnk", System.StringComparison.InvariantCultureIgnoreCase) ? + app.FullPath : + icoPath; + return new AppItem() + { + Name = app.Name, + Subtitle = app.Description, + Type = app.Type(), + IcoPath = icoPath, + ExePath = !string.IsNullOrEmpty(app.LnkFilePath) ? app.LnkFilePath : app.FullPath, + DirPath = app.Location, + Commands = app.GetCommands(), + AppIdentifier = app.GetAppIdentifier(), + }; + } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs index cc07ac86b4..419bba3580 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs @@ -213,6 +213,15 @@ namespace Microsoft.CmdPal.Ext.Apps.Properties { } } + /// + /// Looks up a localized string similar to Pin. + /// + internal static string pin_app { + get { + return ResourceManager.GetString("pin_app", resourceCulture); + } + } + /// /// Looks up a localized string similar to Run as administrator. /// @@ -267,6 +276,15 @@ namespace Microsoft.CmdPal.Ext.Apps.Properties { } } + /// + /// Looks up a localized string similar to Unpin. + /// + internal static string unpin_app { + get { + return ResourceManager.GetString("unpin_app", resourceCulture); + } + } + /// /// Looks up a localized string similar to Experimental: When enabled, Command Palette will load thumbnails from the Windows Shell. Using thumbnails may cause the app to crash on launch. /// diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx index ce4fb79689..1e4c8fa4bd 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx @@ -199,4 +199,10 @@ Experimental: When enabled, Command Palette will load thumbnails from the Windows Shell. Using thumbnails may cause the app to crash on launch A description for "use_thumbnails_setting_label" + + Pin + + + Unpin + \ No newline at end of file diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinStateChangedEventArgs.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinStateChangedEventArgs.cs new file mode 100644 index 0000000000..75cbbde56d --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinStateChangedEventArgs.cs @@ -0,0 +1,34 @@ +// 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 System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.CmdPal.Ext.Apps.State; + +public class PinStateChangedEventArgs : EventArgs +{ + /// + /// Gets the identifier of the application whose pin state has changed. + /// + public string AppIdentifier { get; } + + /// + /// Gets a value indicating whether the specified app identifier was pinned or not. + /// + public bool IsPinned { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The identifier of the application whose pin state has changed. + public PinStateChangedEventArgs(string appIdentifier, bool isPinned) + { + AppIdentifier = appIdentifier ?? throw new ArgumentNullException(nameof(appIdentifier)); + IsPinned = isPinned; + } +} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinnedApps.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinnedApps.cs new file mode 100644 index 0000000000..ff76043bf1 --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinnedApps.cs @@ -0,0 +1,47 @@ +// 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 System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Text.Json; + +namespace Microsoft.CmdPal.Ext.Apps.State; + +public sealed class PinnedApps +{ + public List PinnedAppIdentifiers { get; set; } = []; + + public static PinnedApps ReadFromFile(string path) + { + if (!File.Exists(path)) + { + return new PinnedApps(); + } + + try + { + var jsonString = File.ReadAllText(path); + var result = JsonSerializer.Deserialize(jsonString, JsonSerializationContext.Default.PinnedApps); + return result ?? new PinnedApps(); + } + catch + { + return new PinnedApps(); + } + } + + public static void WriteToFile(string path, PinnedApps data) + { + try + { + var jsonString = JsonSerializer.Serialize(data, JsonSerializationContext.Default.PinnedApps); + File.WriteAllText(path, jsonString); + } + catch + { + // Silently fail - we don't want pinning issues to crash the extension + } + } +} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinnedAppsManager.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinnedAppsManager.cs new file mode 100644 index 0000000000..4540caf78d --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/State/PinnedAppsManager.cs @@ -0,0 +1,82 @@ +// 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 System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Linq; +using ManagedCommon; +using Microsoft.CommandPalette.Extensions.Toolkit; + +namespace Microsoft.CmdPal.Ext.Apps.State; + +public sealed class PinnedAppsManager +{ + private static readonly Lazy _instance = new(() => new PinnedAppsManager()); + private readonly string _pinnedAppsFilePath; + + public static PinnedAppsManager Instance => _instance.Value; + + private PinnedApps _pinnedApps = new(); + + // Add event for when pinning state changes + public event EventHandler? PinStateChanged; + + private PinnedAppsManager() + { + _pinnedAppsFilePath = GetPinnedAppsFilePath(); + LoadPinnedApps(); + } + + public bool IsAppPinned(string appIdentifier) + { + return _pinnedApps.PinnedAppIdentifiers.Contains(appIdentifier, StringComparer.OrdinalIgnoreCase); + } + + public void PinApp(string appIdentifier) + { + if (!IsAppPinned(appIdentifier)) + { + _pinnedApps.PinnedAppIdentifiers.Add(appIdentifier); + SavePinnedApps(); + Logger.LogTrace($"Pinned app: {appIdentifier}"); + PinStateChanged?.Invoke(this, new PinStateChangedEventArgs(appIdentifier, true)); + } + } + + public string[] GetPinnedAppIdentifiers() + { + return _pinnedApps.PinnedAppIdentifiers.ToArray(); + } + + public void UnpinApp(string appIdentifier) + { + var removed = _pinnedApps.PinnedAppIdentifiers.RemoveAll(id => + string.Equals(id, appIdentifier, StringComparison.OrdinalIgnoreCase)); + + if (removed > 0) + { + SavePinnedApps(); + Logger.LogTrace($"Unpinned app: {appIdentifier}"); + PinStateChanged?.Invoke(this, new PinStateChangedEventArgs(appIdentifier, false)); + } + } + + private void LoadPinnedApps() + { + _pinnedApps = PinnedApps.ReadFromFile(_pinnedAppsFilePath); + } + + private void SavePinnedApps() + { + PinnedApps.WriteToFile(_pinnedAppsFilePath, _pinnedApps); + } + + private static string GetPinnedAppsFilePath() + { + var directory = Utilities.BaseSettingsPath("Microsoft.CmdPal"); + Directory.CreateDirectory(directory); + return Path.Combine(directory, "apps.pinned.json"); + } +} From 0783763dd080baa43f2736acaabe35550ecde9d9 Mon Sep 17 00:00:00 2001 From: Yu Leng <42196638+moooyo@users.noreply.github.com> Date: Tue, 15 Jul 2025 22:15:18 +0800 Subject: [PATCH 04/10] [AOT] Enable AOT for CmdPal (#40551) ## Summary of the Pull Request Base on https://github.com/microsoft/PowerToys/pull/40486 we can easily use lab package. So all blocker has been resolved. 1. Replace CommunityToolkit.WinUI.UI.Controls.Markdown with CommunityToolkit.Labs.WinUI.Controls.MarkdownTextBlock 2. Add default markdown style config to align some configuration with the original one. (but still have some gap) 3. Add new configuration in pipeline to control the AOT enable/disable. ## PR Checklist - [x] **Closes:** #38279 - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --------- Co-authored-by: Yu Leng (from Dev Box) Co-authored-by: Mike Griese --- .github/actions/spell-check/expect.txt | 1 + .pipelines/v2/release.yml | 7 +++++- .pipelines/verifyDepsJsonLibraryVersions.ps1 | 2 +- Directory.Packages.props | 1 + NOTICE.md | 2 +- src/Common.Dotnet.AotCompatibility.props | 3 ++- .../ShortcutDialogContentControl.xaml | 4 ++-- .../ShortcutWithTextLabelControl.xaml | 4 ++-- .../ExtViews/ContentPage.xaml | 22 ++++++++++--------- .../Microsoft.CmdPal.UI.csproj | 10 ++++++++- .../Microsoft.CmdPal.UI/NativeMethods.txt | 1 - .../Microsoft.CmdPal.UI/Pages/ShellPage.xaml | 16 +++++++++----- .../PublishProfiles/win-arm64.pubxml | 4 ++-- .../Properties/PublishProfiles/win-x64.pubxml | 4 ++-- 14 files changed, 51 insertions(+), 30 deletions(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index cd6e9b0a2b..3d22a06313 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -1383,6 +1383,7 @@ RIGHTSCROLLBAR riid RKey RNumber +Rns rop ROUNDSMALL ROWSETEXT diff --git a/.pipelines/v2/release.yml b/.pipelines/v2/release.yml index 227dd1cf71..18163e899a 100644 --- a/.pipelines/v2/release.yml +++ b/.pipelines/v2/release.yml @@ -38,6 +38,11 @@ parameters: displayName: "Build Using Visual Studio Preview" default: false + - name: enableAOT + type: boolean + displayName: "Enable AOT (Ahead-of-Time) Compilation for CmdPal" + default: true + name: $(BuildDefinitionName)_$(date:yyMM).$(date:dd)$(rev:rrr) variables: @@ -95,7 +100,7 @@ extends: useManagedIdentity: $(SigningUseManagedIdentity) clientId: $(SigningOriginalClientId) # Have msbuild use the release nuget config profile - additionalBuildOptions: /p:RestoreConfigFile="$(Build.SourcesDirectory)\.pipelines\release-nuget.config" + additionalBuildOptions: /p:RestoreConfigFile="$(Build.SourcesDirectory)\.pipelines\release-nuget.config" /p:EnableCmdPalAOT=${{ parameters.enableAOT }} beforeBuildSteps: # Sets versions for all PowerToy created DLLs - pwsh: |- diff --git a/.pipelines/verifyDepsJsonLibraryVersions.ps1 b/.pipelines/verifyDepsJsonLibraryVersions.ps1 index 085e1e439a..6123316b5f 100644 --- a/.pipelines/verifyDepsJsonLibraryVersions.ps1 +++ b/.pipelines/verifyDepsJsonLibraryVersions.ps1 @@ -19,7 +19,7 @@ Get-ChildItem $targetDir -Recurse -Filter *.deps.json -Exclude *UITest*,MouseJum # Temporarily exclude All UI-Test, Fuzzer-Test projects because of Appium.WebDriver dependencies $depsJsonFullFileName = $_.FullName - if ($depsJsonFullFileName -like "*CmdPal*") { + if ($depsJsonFullFileName -like "*CmdPal*" -or $depsJsonFullFileName -like "*CommandPalette*") { return } diff --git a/Directory.Packages.props b/Directory.Packages.props index 5ebced2715..f29669d9e7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -21,6 +21,7 @@ + diff --git a/NOTICE.md b/NOTICE.md index 2b1201bc50..b2232e4984 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -1497,6 +1497,7 @@ SOFTWARE. - Appium.WebDriver 4.4.5 - Azure.AI.OpenAI 1.0.0-beta.17 - CommunityToolkit.Common 8.4.0 +- CommunityToolkit.Labs.WinUI.Controls.MarkdownTextBlock 0.1.250703-build.2173 - CommunityToolkit.Mvvm 8.4.0 - CommunityToolkit.WinUI.Animations 8.2.250402 - CommunityToolkit.WinUI.Collections 8.2.250402 @@ -1579,4 +1580,3 @@ SOFTWARE. - WinUIEx 2.2.0 - WPF-UI 3.0.5 - WyHash 1.0.5 - diff --git a/src/Common.Dotnet.AotCompatibility.props b/src/Common.Dotnet.AotCompatibility.props index 82988104dd..bebb88428c 100644 --- a/src/Common.Dotnet.AotCompatibility.props +++ b/src/Common.Dotnet.AotCompatibility.props @@ -7,6 +7,7 @@ 2 - IL2081;CsWinRT1028;$(WarningsNotAsErrors) + + IL2081;CsWinRT1028;CA1416;$(WarningsNotAsErrors) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml index 7932a27e91..56ae0bfca6 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml @@ -4,8 +4,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:Microsoft.CmdPal.UI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:labToolkit="using:CommunityToolkit.Labs.WinUI.MarkdownTextBlock" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:tk7controls="using:CommunityToolkit.WinUI.UI.Controls" x:Name="ShortcutContentControl" mc:Ignorable="d"> @@ -66,7 +66,7 @@ IsTabStop="{Binding ElementName=ShortcutContentControl, Path=IsWarningAltGr, Mode=OneWay}" Severity="Warning" /> - @@ -36,7 +36,7 @@ - + + + - @@ -61,12 +66,9 @@ - diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj index 75e49fd695..44ef3483e2 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj @@ -1,5 +1,6 @@  + @@ -23,6 +24,13 @@ false + + true + false + false + true + + true @@ -71,7 +79,7 @@ - + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt b/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt index 165933fe93..a432d9a808 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt @@ -22,7 +22,6 @@ SetActiveWindow MonitorFromWindow GetMonitorInfo GetDpiForMonitor -CoAllowSetForegroundWindow WM_HOTKEY WM_NCLBUTTONDBLCLK diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml index 63877834e9..9df81e1513 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml @@ -9,8 +9,10 @@ xmlns:cpcontrols="using:Microsoft.CmdPal.UI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:help="using:Microsoft.CmdPal.UI.Helpers" + xmlns:labToolkit="using:CommunityToolkit.Labs.WinUI.MarkdownTextBlock" + xmlns:markdownTextBlockRns="using:CommunityToolkit.WinUI.Controls.MarkdownTextBlockRns" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls" + xmlns:toolkit="using:CommunityToolkit.WinUI.Controls" xmlns:ui="using:CommunityToolkit.WinUI" xmlns:viewModels="using:Microsoft.CmdPal.UI.ViewModels" Background="Transparent" @@ -144,6 +146,11 @@ + + @@ -406,14 +413,11 @@ TextWrapping="WrapWholeWords" Visibility="{x:Bind ViewModel.Details.Title, Converter={StaticResource StringNotEmptyToVisibilityConverter}, Mode=OneWay}" /> - False False True - False - False + True + False \ No newline at end of file diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Properties/PublishProfiles/win-x64.pubxml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Properties/PublishProfiles/win-x64.pubxml index 5ff16b291b..7f6d14d1ad 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Properties/PublishProfiles/win-x64.pubxml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Properties/PublishProfiles/win-x64.pubxml @@ -13,7 +13,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. False False True - False - False + True + False \ No newline at end of file From 53bb471449ba0f6379a3d8997c5ad3505efe1146 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 15 Jul 2025 09:33:28 -0500 Subject: [PATCH 05/10] 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. --- .../PageViewModel.cs | 16 +++++++++-- .../PageViewModelFactory.cs | 27 +++++++++++++++++++ .../ShellViewModel.cs | 19 +++---------- .../cmdpal/Microsoft.CmdPal.UI/App.xaml.cs | 1 + 4 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModelFactory.cs diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModel.cs index 126efa83ca..681f7bc7f1 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModel.cs @@ -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 +{ + /// + /// Creates a new instance of the page view model for the given page type. + /// + /// The page for which to create the view model. + /// Indicates whether the page is not the top-level page. + /// The command palette host that will host the page (for status messages) + /// A new instance of the page view model. + PageViewModel? TryCreatePageViewModel(IPage page, bool nested, CommandPaletteHost host); } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModelFactory.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModelFactory.cs new file mode 100644 index 0000000000..83dbe51624 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModelFactory.cs @@ -0,0 +1,27 @@ +// 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.UI.ViewModels; + +public class PageViewModelFactory : IPageViewModelFactoryService +{ + private readonly TaskScheduler _scheduler; + + public PageViewModelFactory(TaskScheduler scheduler) + { + _scheduler = scheduler; + } + + public PageViewModel? TryCreatePageViewModel(IPage page, bool nested, CommandPaletteHost 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/ShellViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ShellViewModel.cs index 112c2b67df..294b0021c7 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ShellViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ShellViewModel.cs @@ -21,6 +21,7 @@ public partial class ShellViewModel : ObservableObject, { private readonly IRootPageService _rootPageService; private readonly TaskScheduler _scheduler; + private readonly IPageViewModelFactoryService _pageViewModelFactory; private readonly Lock _invokeLock = new(); private Task? _handleInvokeTask; @@ -65,8 +66,9 @@ public partial class ShellViewModel : ObservableObject, public bool IsNested { get => _isNested; } - public ShellViewModel(TaskScheduler scheduler, IRootPageService rootPageService) + public ShellViewModel(TaskScheduler scheduler, IRootPageService rootPageService, IPageViewModelFactoryService pageViewModelFactory) { + _pageViewModelFactory = pageViewModelFactory; _scheduler = scheduler; _rootPageService = rootPageService; _currentPage = new LoadingPageViewModel(null, _scheduler); @@ -252,7 +254,7 @@ public partial class ShellViewModel : ObservableObject, _isNested = !isMainPage; // Construct our ViewModel of the appropriate type and pass it the UI Thread context. - var pageViewModel = GetViewModelForPage(page, _isNested, host); + var pageViewModel = _pageViewModelFactory.TryCreatePageViewModel(page, _isNested, host); if (pageViewModel == null) { Logger.LogError($"Failed to create ViewModel for page {page.GetType().Name}"); @@ -397,19 +399,6 @@ public partial class ShellViewModel : ObservableObject, } } - private PageViewModel? GetViewModelForPage(IPage page, bool nested, CommandPaletteHost host) - { - return page switch - { - IListPage listPage => new ListViewModel(listPage, _scheduler, host) - { - IsNested = nested, - }, - IContentPage contentPage => new ContentPageViewModel(contentPage, _scheduler, host), - _ => null, - }; - } - public void SetActiveExtension(IExtensionWrapper? extension) { if (extension != _activeExtension) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs index a9f416483a..1007998f7c 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs @@ -149,6 +149,7 @@ public partial class App : Application // ViewModels services.AddSingleton(); + services.AddSingleton(); return services.BuildServiceProvider(); } From cc16b61eb7c16b566fe1ed0aa4f7031fa2acf675 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 15 Jul 2025 12:21:44 -0500 Subject: [PATCH 06/10] Create a Microsoft.CmdPal.Core.ViewModels project (#40560) _targets #40504_ Major refactoring for #40113 This moves a large swath of the codebase to a `.Core` project. "Core" doesn't have any explicit dependencies on "extensions", settings or the current `MainListPage`. It's just a filterable list of stuff. This should let us make this component a bit more reusable. This is half of a PR. As I did this, I noticed a particular bit of code for TopLevelVViewModels and CommandPaletteHost that was _very rough_. Solving it in this PR would make "move everything to a new project" much harder to review. So I'm submitting two PRs simultaneously, so we can see the changes separately, then merge together. --- PowerToys.sln | 14 ++ .../AppExtensionHost.cs | 168 ++++++++++++++++++ .../CommandBarViewModel.cs | 6 +- .../CommandContextItemViewModel.cs | 8 +- .../CommandItemViewModel.cs | 8 +- .../CommandViewModel.cs | 6 +- .../ConfirmResultViewModel.cs | 6 +- .../ContentPageViewModel.cs | 30 ++-- .../ContentViewModel.cs | 4 +- .../ContextMenuViewModel.cs | 4 +- .../DetailsCommandsViewModel.cs | 6 +- .../DetailsDataViewModel.cs | 6 +- .../DetailsElementViewModel.cs | 6 +- .../DetailsLinkViewModel.cs | 6 +- .../DetailsSeparatorViewModel.cs | 6 +- .../DetailsTagsViewModel.cs | 6 +- .../DetailsViewModel.cs | 6 +- .../ExtensionObjectViewModel.cs | 4 +- .../GlobalLogPageContext.cs | 2 +- .../IContextItemViewModel.cs | 2 +- .../IRootPageService.cs | 10 +- .../IconDataViewModel.cs | 6 +- .../IconInfoViewModel.cs | 6 +- .../ListItemViewModel.cs | 6 +- .../ListViewModel.cs | 15 +- .../LoadingPageViewModel.cs | 8 +- .../LogMessageViewModel.cs | 6 +- .../ActivateSecondaryCommandMessage.cs | 4 +- .../ActivateSelectedListItemMessage.cs | 2 +- .../Messages/BeginInvokeMessage.cs | 4 +- .../Messages/ClearSearchMessage.cs | 4 +- .../Messages/CloseContextMenuMessage.cs | 2 +- .../Messages/CmdPalInvokeResultMessage.cs | 4 +- .../Messages/DismissMessage.cs | 4 +- .../Messages/FocusSearchBoxMessage.cs | 4 +- .../Messages/GoBackMessage.cs | 4 +- .../Messages/GoHomeMessage.cs | 4 +- .../Messages/HandleCommandResultMessage.cs | 6 +- .../Messages/HideDetailsMessage.cs | 6 +- .../Messages/HotkeySummonMessage.cs | 4 +- .../Messages/LaunchUriMessage.cs | 6 +- .../Messages/NavigateBackMessage.cs | 4 +- .../Messages/NavigateNextCommand.cs | 4 +- .../Messages/NavigatePreviousCommand.cs | 4 +- .../Messages/NavigateToPageMessage.cs | 4 +- .../Messages/OpenContextMenuMessage.cs | 4 +- .../Messages/OpenSettingsMessage.cs | 6 +- .../Messages/PerformCommandMessage.cs | 15 +- .../Messages/QuitMessage.cs | 6 +- .../Messages/ReloadCommandsMessage.cs | 4 +- .../Messages/SettingsWindowClosedMessage.cs | 4 +- .../Messages/ShowConfirmationMessage.cs | 4 +- .../Messages/ShowDetailsMessage.cs | 6 +- .../Messages/ShowToastMessage.cs | 4 +- .../Messages/ShowWindowMessage.cs | 4 +- .../Messages/TryCommandKeybindingMessage.cs | 4 +- .../Messages/UpdateCommandBarMessage.cs | 4 +- .../Messages/UpdateFallbackItemsMessage.cs | 4 +- .../Microsoft.CmdPal.Core.ViewModels.csproj | 60 +++++++ .../Models/ExtensionObject`1.cs | 4 +- .../NativeMethods.json | 4 + .../NativeMethods.txt | 19 ++ .../PageViewModel.cs | 14 +- .../PageViewModelFactory.cs | 6 +- .../ProgressViewModel.cs | 6 +- .../SeparatorContextItemViewModel.cs | 4 +- .../ShellViewModel.cs | 142 +++------------ .../StatusMessageViewModel.cs | 10 +- .../TagViewModel.cs | 6 +- .../ToastViewModel.cs | 4 +- .../AliasManager.cs | 5 +- .../CommandPaletteContentPageViewModel.cs | 28 +++ .../CommandPaletteHost.cs | 163 +---------------- .../CommandPalettePageViewModelFactory.cs | 29 +++ .../CommandProviderWrapper.cs | 3 +- .../CommandSettingsViewModel.cs | 5 +- .../Commands/BuiltInsCommandProvider.cs | 2 +- .../Commands/BuiltinsExtensionHost.cs | 8 - .../Commands/LogMessagesPage.cs | 4 +- .../Commands/MainListPage.cs | 2 +- .../Commands/NewExtensionFormBase.cs | 2 +- .../Commands/OpenSettingsCommand.cs | 2 +- .../Commands/QuitAction.cs | 2 +- .../Commands/ReloadExtensionsCommand.cs | 2 +- .../ContentFormViewModel.cs | 5 +- .../ContentMarkdownViewModel.cs | 3 +- .../ContentTreeViewModel.cs | 23 ++- .../Microsoft.CmdPal.UI.ViewModels.csproj | 1 + .../Models/ExtensionWrapper.cs | 3 +- .../ProviderSettingsViewModel.cs | 3 +- .../TopLevelCommandManager.cs | 3 +- .../TopLevelViewModel.cs | 10 +- .../cmdpal/Microsoft.CmdPal.UI/App.xaml.cs | 4 +- .../Controls/CommandBar.xaml | 3 +- .../Controls/CommandBar.xaml.cs | 4 +- .../Controls/ContextMenu.xaml | 9 +- .../Controls/ContextMenu.xaml.cs | 9 +- .../Microsoft.CmdPal.UI/Controls/IconBox.cs | 2 +- .../Controls/SearchBar.xaml.cs | 4 +- .../Microsoft.CmdPal.UI/Controls/Tag.xaml.cs | 2 +- .../Converters/ContentTemplateSelector.cs | 1 + .../Converters/ContextItemTemplateSelector.cs | 3 +- .../Converters/DetailsDataTemplateSelector.cs | 2 +- .../ExtViews/CleanupHelper.xaml.cs | 7 - .../ExtViews/ContentPage.xaml | 1 + .../ExtViews/ContentPage.xaml.cs | 4 +- .../ExtViews/ListPage.xaml | 5 +- .../ExtViews/ListPage.xaml.cs | 3 +- .../Helpers/IconCacheProvider.cs | 3 +- .../Helpers/IconCacheService.cs | 2 +- .../Helpers/TelemetryForwarder.cs | 2 +- .../Helpers/TrayIconService.cs | 2 +- .../Microsoft.CmdPal.UI/MainWindow.xaml.cs | 3 +- .../Pages/LoadingPage.xaml.cs | 2 +- .../Microsoft.CmdPal.UI/Pages/ShellPage.xaml | 13 +- .../Pages/ShellPage.xaml.cs | 6 +- .../PowerToysAppHostService.cs | 29 +++ .../PowerToysRootPageService.cs | 75 +++++++- .../Settings/SettingsWindow.xaml.cs | 3 +- .../Microsoft.CmdPal.UI/ToastWindow.xaml.cs | 6 +- .../Views/ICurrentPageAware.cs | 4 +- 121 files changed, 733 insertions(+), 571 deletions(-) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/AppExtensionHost.cs rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/CommandBarViewModel.cs (97%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/CommandContextItemViewModel.cs (87%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/CommandItemViewModel.cs (98%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/CommandViewModel.cs (96%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/ConfirmResultViewModel.cs (91%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/ContentPageViewModel.cs (91%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/ContentViewModel.cs (79%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/ContextMenuViewModel.cs (98%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/DetailsCommandsViewModel.cs (90%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/DetailsDataViewModel.cs (69%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/DetailsElementViewModel.cs (85%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/DetailsLinkViewModel.cs (90%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/DetailsSeparatorViewModel.cs (82%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/DetailsTagsViewModel.cs (89%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/DetailsViewModel.cs (94%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/ExtensionObjectViewModel.cs (96%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/GlobalLogPageContext.cs (92%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/IContextItemViewModel.cs (88%) rename src/modules/cmdpal/{Microsoft.CmdPal.Common/Services => Microsoft.CmdPal.Core.ViewModels}/IRootPageService.cs (84%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/IconDataViewModel.cs (91%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/IconInfoViewModel.cs (92%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/ListItemViewModel.cs (97%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/ListViewModel.cs (98%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/LoadingPageViewModel.cs (71%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/LogMessageViewModel.cs (83%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/ActivateSecondaryCommandMessage.cs (77%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/ActivateSelectedListItemMessage.cs (86%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/BeginInvokeMessage.cs (65%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/ClearSearchMessage.cs (66%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/CloseContextMenuMessage.cs (85%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/CmdPalInvokeResultMessage.cs (72%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/DismissMessage.cs (66%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/FocusSearchBoxMessage.cs (66%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/GoBackMessage.cs (77%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/GoHomeMessage.cs (77%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/HandleCommandResultMessage.cs (66%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/HideDetailsMessage.cs (62%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/HotkeySummonMessage.cs (69%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/LaunchUriMessage.cs (62%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/NavigateBackMessage.cs (69%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/NavigateNextCommand.cs (76%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/NavigatePreviousCommand.cs (77%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/NavigateToPageMessage.cs (70%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/OpenContextMenuMessage.cs (85%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/OpenSettingsMessage.cs (55%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/PerformCommandMessage.cs (77%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/QuitMessage.cs (68%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/ReloadCommandsMessage.cs (66%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/SettingsWindowClosedMessage.cs (67%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/ShowConfirmationMessage.cs (72%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/ShowDetailsMessage.cs (64%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/ShowToastMessage.cs (67%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/ShowWindowMessage.cs (67%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/TryCommandKeybindingMessage.cs (77%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/UpdateCommandBarMessage.cs (95%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Messages/UpdateFallbackItemsMessage.cs (67%) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Microsoft.CmdPal.Core.ViewModels.csproj rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/Models/ExtensionObject`1.cs (83%) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/NativeMethods.json create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/NativeMethods.txt rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/PageViewModel.cs (96%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/PageViewModelFactory.cs (86%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/ProgressViewModel.cs (92%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/SeparatorContextItemViewModel.cs (79%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/ShellViewModel.cs (72%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/StatusMessageViewModel.cs (87%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/TagViewModel.cs (91%) rename src/modules/cmdpal/{Microsoft.CmdPal.UI.ViewModels => Microsoft.CmdPal.Core.ViewModels}/ToastViewModel.cs (81%) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPaletteContentPageViewModel.cs create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPalettePageViewModelFactory.cs create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UI/PowerToysAppHostService.cs diff --git a/PowerToys.sln b/PowerToys.sln index 0775b28def..6010ed421d 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -736,6 +736,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedCsWin32", "src\commo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerRenameUITest", "src\modules\powerrename\PowerRenameUITest\PowerRenameUITest.csproj", "{9D3F3793-EFE3-4525-8782-238015DABA62}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Core.ViewModels", "src\modules\cmdpal\Microsoft.CmdPal.Core.ViewModels\Microsoft.CmdPal.Core.ViewModels.csproj", "{24133F7F-C1D1-DE04-EFA8-F5D5467FE027}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -2718,6 +2722,14 @@ Global {14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}.Release|ARM64.Build.0 = Release|ARM64 {14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}.Release|x64.ActiveCfg = Release|x64 {14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}.Release|x64.Build.0 = Release|x64 + {24133F7F-C1D1-DE04-EFA8-F5D5467FE027}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {24133F7F-C1D1-DE04-EFA8-F5D5467FE027}.Debug|ARM64.Build.0 = Debug|ARM64 + {24133F7F-C1D1-DE04-EFA8-F5D5467FE027}.Debug|x64.ActiveCfg = Debug|x64 + {24133F7F-C1D1-DE04-EFA8-F5D5467FE027}.Debug|x64.Build.0 = Debug|x64 + {24133F7F-C1D1-DE04-EFA8-F5D5467FE027}.Release|ARM64.ActiveCfg = Release|ARM64 + {24133F7F-C1D1-DE04-EFA8-F5D5467FE027}.Release|ARM64.Build.0 = Release|ARM64 + {24133F7F-C1D1-DE04-EFA8-F5D5467FE027}.Release|x64.ActiveCfg = Release|x64 + {24133F7F-C1D1-DE04-EFA8-F5D5467FE027}.Release|x64.Build.0 = Release|x64 {9D3F3793-EFE3-4525-8782-238015DABA62}.Debug|ARM64.ActiveCfg = Debug|ARM64 {9D3F3793-EFE3-4525-8782-238015DABA62}.Debug|ARM64.Build.0 = Debug|ARM64 {9D3F3793-EFE3-4525-8782-238015DABA62}.Debug|x64.ActiveCfg = Debug|x64 @@ -3010,6 +3022,8 @@ Global {43E779F3-D83C-48B1-BA8D-1912DBD76FC9} = {A2221D7E-55E7-4BEA-90D1-4F162D670BBF} {2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6} = {1AFB6476-670D-4E80-A464-657E01DFF482} {14AFD976-B4D2-49D0-9E6C-AA93CC061B8A} = {1AFB6476-670D-4E80-A464-657E01DFF482} + {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {3846508C-77EB-4034-A702-F8BB263C4F79} + {24133F7F-C1D1-DE04-EFA8-F5D5467FE027} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} {9D3F3793-EFE3-4525-8782-238015DABA62} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/AppExtensionHost.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/AppExtensionHost.cs new file mode 100644 index 0000000000..3a828a3e5d --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/AppExtensionHost.cs @@ -0,0 +1,168 @@ +// 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 System.Collections.ObjectModel; +using System.Diagnostics; +using ManagedCommon; +using Microsoft.CommandPalette.Extensions; +using Microsoft.CommandPalette.Extensions.Toolkit; +using Windows.Foundation; + +namespace Microsoft.CmdPal.Core.ViewModels; + +public abstract partial class AppExtensionHost : IExtensionHost +{ + private static readonly GlobalLogPageContext _globalLogPageContext = new(); + + private static ulong _hostingHwnd; + + public static ObservableCollection LogMessages { get; } = []; + + public ulong HostingHwnd => _hostingHwnd; + + public string LanguageOverride => string.Empty; + + public ObservableCollection StatusMessages { get; } = []; + + public static void SetHostHwnd(ulong hostHwnd) => _hostingHwnd = hostHwnd; + + public void DebugLog(string message) + { +#if DEBUG + this.ProcessLogMessage(new LogMessage(message)); +#endif + } + + public IAsyncAction HideStatus(IStatusMessage? message) + { + if (message == null) + { + return Task.CompletedTask.AsAsyncAction(); + } + + _ = Task.Run(() => + { + ProcessHideStatusMessage(message); + }); + return Task.CompletedTask.AsAsyncAction(); + } + + public void Log(string message) + { + this.ProcessLogMessage(new LogMessage(message)); + } + + public IAsyncAction LogMessage(ILogMessage? message) + { + if (message == null) + { + return Task.CompletedTask.AsAsyncAction(); + } + + Logger.LogDebug(message.Message); + + _ = Task.Run(() => + { + ProcessLogMessage(message); + }); + + // We can't just make a LogMessageViewModel : ExtensionObjectViewModel + // because we don't necessarily know the page context. Butts. + return Task.CompletedTask.AsAsyncAction(); + } + + public void ProcessHideStatusMessage(IStatusMessage message) + { + Task.Factory.StartNew( + () => + { + try + { + var vm = StatusMessages.Where(messageVM => messageVM.Model.Unsafe == message).FirstOrDefault(); + if (vm != null) + { + StatusMessages.Remove(vm); + } + } + catch + { + } + }, + CancellationToken.None, + TaskCreationOptions.None, + _globalLogPageContext.Scheduler); + } + + public void ProcessLogMessage(ILogMessage message) + { + var vm = new LogMessageViewModel(message, _globalLogPageContext); + vm.SafeInitializePropertiesSynchronous(); + + Task.Factory.StartNew( + () => + { + LogMessages.Add(vm); + }, + CancellationToken.None, + TaskCreationOptions.None, + _globalLogPageContext.Scheduler); + } + + public void ProcessStatusMessage(IStatusMessage message, StatusContext context) + { + // If this message is already in the list of messages, just bring it to the top + var oldVm = StatusMessages.Where(messageVM => messageVM.Model.Unsafe == message).FirstOrDefault(); + if (oldVm != null) + { + Task.Factory.StartNew( + () => + { + StatusMessages.Remove(oldVm); + StatusMessages.Add(oldVm); + }, + CancellationToken.None, + TaskCreationOptions.None, + _globalLogPageContext.Scheduler); + return; + } + + var vm = new StatusMessageViewModel(message, new(_globalLogPageContext)); + vm.SafeInitializePropertiesSynchronous(); + + Task.Factory.StartNew( + () => + { + StatusMessages.Add(vm); + }, + CancellationToken.None, + TaskCreationOptions.None, + _globalLogPageContext.Scheduler); + } + + public IAsyncAction ShowStatus(IStatusMessage? message, StatusContext context) + { + if (message == null) + { + return Task.CompletedTask.AsAsyncAction(); + } + + Debug.WriteLine(message.Message); + + _ = Task.Run(() => + { + ProcessStatusMessage(message, context); + }); + + return Task.CompletedTask.AsAsyncAction(); + } + + public abstract string? GetExtensionDisplayName(); +} + +public interface IAppHostService +{ + AppExtensionHost GetDefaultHost(); + + AppExtensionHost GetHostForCommand(object? context, AppExtensionHost? currentHost); +} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandBarViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandBarViewModel.cs similarity index 97% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandBarViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandBarViewModel.cs index e0112acaff..4dda2c455d 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandBarViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandBarViewModel.cs @@ -1,15 +1,15 @@ -// Copyright (c) Microsoft Corporation +// 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 System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; -using Microsoft.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CommandPalette.Extensions.Toolkit; using Windows.System; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class CommandBarViewModel : ObservableObject, IRecipient diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandContextItemViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandContextItemViewModel.cs similarity index 87% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandContextItemViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandContextItemViewModel.cs index f1c35b1f50..60fc815a52 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandContextItemViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandContextItemViewModel.cs @@ -1,13 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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 CommunityToolkit.Mvvm.Messaging; -using Microsoft.CmdPal.UI.ViewModels.Messages; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class CommandContextItemViewModel(ICommandContextItem contextItem, WeakReference context) : CommandItemViewModel(new(contextItem), context), IContextItemViewModel { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandItemViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandItemViewModel.cs similarity index 98% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandItemViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandItemViewModel.cs index 0602abeea2..75a8eb9a56 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandItemViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandItemViewModel.cs @@ -1,13 +1,13 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Messages; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBarContext { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandViewModel.cs similarity index 96% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandViewModel.cs index c1d3c4e6f9..6e48cef382 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class CommandViewModel : ExtensionObjectViewModel { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ConfirmResultViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ConfirmResultViewModel.cs similarity index 91% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ConfirmResultViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ConfirmResultViewModel.cs index 53466cb1ce..45cd18f4dd 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ConfirmResultViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ConfirmResultViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class ConfirmResultViewModel(IConfirmationArgs _args, WeakReference context) : ExtensionObjectViewModel(context) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentPageViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentPageViewModel.cs similarity index 91% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentPageViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentPageViewModel.cs index 0d37a81112..16611a31ac 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentPageViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentPageViewModel.cs @@ -7,12 +7,12 @@ using System.Diagnostics.CodeAnalysis; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; -using Microsoft.CmdPal.UI.ViewModels.Messages; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class ContentPageViewModel : PageViewModel, ICommandBarContext { @@ -47,7 +47,7 @@ public partial class ContentPageViewModel : PageViewModel, ICommandBarContext // Remember - "observable" properties from the model (via PropChanged) // cannot be marked [ObservableProperty] - public ContentPageViewModel(IContentPage model, TaskScheduler scheduler, CommandPaletteHost host) + public ContentPageViewModel(IContentPage model, TaskScheduler scheduler, AppExtensionHost host) : base(model, scheduler, host) { _model = new(model); @@ -91,16 +91,12 @@ public partial class ContentPageViewModel : PageViewModel, ICommandBarContext }); } - public static ContentViewModel? ViewModelFromContent(IContent content, WeakReference context) + public virtual ContentViewModel? ViewModelFromContent(IContent content, WeakReference context) { - ContentViewModel? viewModel = content switch - { - IFormContent form => new ContentFormViewModel(form, context), - IMarkdownContent markdown => new ContentMarkdownViewModel(markdown, context), - ITreeContent tree => new ContentTreeViewModel(tree, context), - _ => null, - }; - return viewModel; + // The core ContentPageViewModel doesn't actually handle any content, + // so we just return null here. + // The real content is handled by the derived class CommandPaletteContentPageViewModel + return null; } public override void InitializeProperties() @@ -115,15 +111,15 @@ public partial class ContentPageViewModel : PageViewModel, ICommandBarContext Commands = model.Commands .ToList() - .Select(item => + .Select(item => { if (item is CommandContextItem contextItem) { - return new CommandContextItemViewModel(contextItem, PageContext) as IContextItemViewModel; + return new CommandContextItemViewModel(contextItem, PageContext); } else { - return new SeparatorContextItemViewModel() as IContextItemViewModel; + return new SeparatorContextItemViewModel(); } }) .ToList(); @@ -182,7 +178,7 @@ public partial class ContentPageViewModel : PageViewModel, ICommandBarContext } else { - return new SeparatorContextItemViewModel() as IContextItemViewModel; + return new SeparatorContextItemViewModel(); } }) .ToList(); diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentViewModel.cs similarity index 79% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentViewModel.cs index 21d2d6748f..42a2e5c6d9 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentViewModel.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public abstract partial class ContentViewModel(WeakReference context) : ExtensionObjectViewModel(context) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContextMenuViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContextMenuViewModel.cs similarity index 98% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContextMenuViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContextMenuViewModel.cs index ed95768865..42820bb0d3 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContextMenuViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContextMenuViewModel.cs @@ -5,13 +5,13 @@ using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; -using Microsoft.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; using Microsoft.Diagnostics.Utilities; using Windows.System; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class ContextMenuViewModel : ObservableObject, IRecipient, diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsCommandsViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsCommandsViewModel.cs similarity index 90% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsCommandsViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsCommandsViewModel.cs index 316209a296..b85aeaba81 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsCommandsViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsCommandsViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class DetailsCommandsViewModel( IDetailsElement _detailsElement, diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsDataViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsDataViewModel.cs similarity index 69% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsDataViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsDataViewModel.cs index 30084f7c7a..9165dde656 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsDataViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsDataViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public abstract partial class DetailsDataViewModel(IPageContext context) : ExtensionObjectViewModel(context) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsElementViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsElementViewModel.cs similarity index 85% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsElementViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsElementViewModel.cs index e836dbf180..390459f26c 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsElementViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsElementViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public abstract partial class DetailsElementViewModel(IDetailsElement _detailsElement, WeakReference context) : ExtensionObjectViewModel(context) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsLinkViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsLinkViewModel.cs similarity index 90% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsLinkViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsLinkViewModel.cs index 0d600958da..e7aa9b67af 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsLinkViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsLinkViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class DetailsLinkViewModel( IDetailsElement _detailsElement, diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsSeparatorViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsSeparatorViewModel.cs similarity index 82% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsSeparatorViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsSeparatorViewModel.cs index 44b48f0802..e4c76918c0 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsSeparatorViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsSeparatorViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class DetailsSeparatorViewModel( IDetailsElement _detailsElement, diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsTagsViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsTagsViewModel.cs similarity index 89% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsTagsViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsTagsViewModel.cs index e188983047..803585c1ce 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsTagsViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsTagsViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class DetailsTagsViewModel( IDetailsElement _detailsElement, diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsViewModel.cs similarity index 94% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsViewModel.cs index 893a94f86e..034e247519 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/DetailsViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/DetailsViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class DetailsViewModel(IDetails _details, WeakReference context) : ExtensionObjectViewModel(context) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ExtensionObjectViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ExtensionObjectViewModel.cs similarity index 96% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ExtensionObjectViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ExtensionObjectViewModel.cs index 08d1128106..f0bb9de118 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ExtensionObjectViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ExtensionObjectViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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 CommunityToolkit.Mvvm.ComponentModel; using ManagedCommon; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public abstract partial class ExtensionObjectViewModel : ObservableObject { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/GlobalLogPageContext.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/GlobalLogPageContext.cs similarity index 92% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/GlobalLogPageContext.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/GlobalLogPageContext.cs index fde1a36817..228ccc5f4b 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/GlobalLogPageContext.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/GlobalLogPageContext.cs @@ -2,7 +2,7 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public class GlobalLogPageContext : IPageContext { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/IContextItemViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IContextItemViewModel.cs similarity index 88% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/IContextItemViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IContextItemViewModel.cs index 743687147c..704947c3a8 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/IContextItemViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IContextItemViewModel.cs @@ -8,7 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public interface IContextItemViewModel { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Common/Services/IRootPageService.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IRootPageService.cs similarity index 84% rename from src/modules/cmdpal/Microsoft.CmdPal.Common/Services/IRootPageService.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IRootPageService.cs index 24e509b8a4..77eaecae4b 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Common/Services/IRootPageService.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IRootPageService.cs @@ -2,9 +2,7 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Threading.Tasks; - -namespace Microsoft.CmdPal.Common.Services; +namespace Microsoft.CmdPal.Core.ViewModels; public interface IRootPageService { @@ -29,9 +27,11 @@ public interface IRootPageService Task PostLoadRootPageAsync(); /// - /// Called when a top-level command is performed. The context is the + /// Called when a command is performed. The context is the /// sender context for the invoked command. This is typically the IListItem /// or ICommandContextItem that was used to invoke the command. /// - void OnPerformTopLevelCommand(object? context); + void OnPerformCommand(object? context, bool topLevel, AppExtensionHost? currentHost); + + void GoHome(); } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/IconDataViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IconDataViewModel.cs similarity index 91% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/IconDataViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IconDataViewModel.cs index 35d91f6739..70b143864c 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/IconDataViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IconDataViewModel.cs @@ -1,13 +1,13 @@ -// Copyright (c) Microsoft Corporation +// 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 CommunityToolkit.Mvvm.ComponentModel; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; using Windows.Storage.Streams; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class IconDataViewModel : ObservableObject, IIconData { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/IconInfoViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IconInfoViewModel.cs similarity index 92% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/IconInfoViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IconInfoViewModel.cs index 93f8ece969..21ddbe99d9 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/IconInfoViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/IconInfoViewModel.cs @@ -1,12 +1,12 @@ -// Copyright (c) Microsoft Corporation +// 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 CommunityToolkit.Mvvm.ComponentModel; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class IconInfoViewModel : ObservableObject, IIconInfo { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListItemViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ListItemViewModel.cs similarity index 97% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListItemViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ListItemViewModel.cs index 48542ba628..682bf4daea 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListItemViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ListItemViewModel.cs @@ -1,13 +1,13 @@ -// Copyright (c) Microsoft Corporation +// 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 System.Diagnostics.CodeAnalysis; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class ListItemViewModel(IListItem model, WeakReference context) : CommandItemViewModel(new(model), context) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ListViewModel.cs similarity index 98% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ListViewModel.cs index 5a5917bc67..9cf15cb70e 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ListViewModel.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation +// 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. @@ -6,13 +6,13 @@ using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; -using Microsoft.CmdPal.UI.ViewModels.Messages; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; using Windows.Foundation; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class ListViewModel : PageViewModel, IDisposable { @@ -72,7 +72,7 @@ public partial class ListViewModel : PageViewModel, IDisposable } } - public ListViewModel(IListPage model, TaskScheduler scheduler, CommandPaletteHost host) + public ListViewModel(IListPage model, TaskScheduler scheduler, AppExtensionHost host) : base(model, scheduler, host) { _model = new(model); @@ -158,10 +158,7 @@ public partial class ListViewModel : PageViewModel, IDisposable } // Cancel any ongoing search - if (_cancellationTokenSource != null) - { - _cancellationTokenSource.Cancel(); - } + _cancellationTokenSource?.Cancel(); lock (_listLock) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/LoadingPageViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/LoadingPageViewModel.cs similarity index 71% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/LoadingPageViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/LoadingPageViewModel.cs index 60571cbe73..3e2cd420c2 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/LoadingPageViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/LoadingPageViewModel.cs @@ -1,15 +1,15 @@ -// Copyright (c) Microsoft Corporation +// 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.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class LoadingPageViewModel : PageViewModel { - public LoadingPageViewModel(IPage? model, TaskScheduler scheduler) - : base(model, scheduler, CommandPaletteHost.Instance) + public LoadingPageViewModel(IPage? model, TaskScheduler scheduler, AppExtensionHost host) + : base(model, scheduler, host) { ModelIsLoading = true; IsInitialized = false; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/LogMessageViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/LogMessageViewModel.cs similarity index 83% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/LogMessageViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/LogMessageViewModel.cs index 60d065ac04..9ebff20304 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/LogMessageViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/LogMessageViewModel.cs @@ -2,10 +2,10 @@ // 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class LogMessageViewModel : ExtensionObjectViewModel { @@ -13,8 +13,6 @@ public partial class LogMessageViewModel : ExtensionObjectViewModel public string Message { get; private set; } = string.Empty; - public string ExtensionPfn { get; set; } = string.Empty; - public LogMessageViewModel(ILogMessage message, IPageContext context) : base(context) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ActivateSecondaryCommandMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ActivateSecondaryCommandMessage.cs similarity index 77% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ActivateSecondaryCommandMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ActivateSecondaryCommandMessage.cs index 1e35d6d796..1ecd7431d2 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ActivateSecondaryCommandMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ActivateSecondaryCommandMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; /// /// Used to perform a list item's secondary command when the user presses ctrl+enter in the search box diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ActivateSelectedListItemMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ActivateSelectedListItemMessage.cs similarity index 86% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ActivateSelectedListItemMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ActivateSelectedListItemMessage.cs index 339e0c1b3d..bdd1876d4e 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ActivateSelectedListItemMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ActivateSelectedListItemMessage.cs @@ -2,7 +2,7 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; /// /// Used to perform a list item's command when the user presses enter in the search box diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/BeginInvokeMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/BeginInvokeMessage.cs similarity index 65% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/BeginInvokeMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/BeginInvokeMessage.cs index 2c7fb406b8..8ed180a27c 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/BeginInvokeMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/BeginInvokeMessage.cs @@ -1,7 +1,7 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record BeginInvokeMessage; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ClearSearchMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ClearSearchMessage.cs similarity index 66% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ClearSearchMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ClearSearchMessage.cs index e3b7ee831e..47bd0e7be8 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ClearSearchMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ClearSearchMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record ClearSearchMessage() { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/CloseContextMenuMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/CloseContextMenuMessage.cs similarity index 85% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/CloseContextMenuMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/CloseContextMenuMessage.cs index daa18498e7..5178e00631 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/CloseContextMenuMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/CloseContextMenuMessage.cs @@ -2,7 +2,7 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; /// /// Used to announce that a context menu should close diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/CmdPalInvokeResultMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/CmdPalInvokeResultMessage.cs similarity index 72% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/CmdPalInvokeResultMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/CmdPalInvokeResultMessage.cs index 1ecc1be460..da81db6e3c 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/CmdPalInvokeResultMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/CmdPalInvokeResultMessage.cs @@ -1,7 +1,7 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record CmdPalInvokeResultMessage(Microsoft.CommandPalette.Extensions.CommandResultKind Kind); diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/DismissMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/DismissMessage.cs similarity index 66% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/DismissMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/DismissMessage.cs index 273952897d..98a5b34562 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/DismissMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/DismissMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record DismissMessage() { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/FocusSearchBoxMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/FocusSearchBoxMessage.cs similarity index 66% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/FocusSearchBoxMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/FocusSearchBoxMessage.cs index 4e6db37daa..73fad88301 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/FocusSearchBoxMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/FocusSearchBoxMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record FocusSearchBoxMessage() { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/GoBackMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/GoBackMessage.cs similarity index 77% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/GoBackMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/GoBackMessage.cs index d200a8454f..86872d6bb1 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/GoBackMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/GoBackMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record GoBackMessage(bool WithAnimation = true, bool FocusSearch = true) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/GoHomeMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/GoHomeMessage.cs similarity index 77% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/GoHomeMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/GoHomeMessage.cs index 5a7f56d021..d99cbbdd16 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/GoHomeMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/GoHomeMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; // TODO! sticking these properties here feels like leaking the UI into the models public record GoHomeMessage(bool WithAnimation = true, bool FocusSearch = true) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/HandleCommandResultMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/HandleCommandResultMessage.cs similarity index 66% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/HandleCommandResultMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/HandleCommandResultMessage.cs index 3adf7ae30c..7c60f7cb4e 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/HandleCommandResultMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/HandleCommandResultMessage.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record HandleCommandResultMessage(ExtensionObject Result) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/HideDetailsMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/HideDetailsMessage.cs similarity index 62% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/HideDetailsMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/HideDetailsMessage.cs index a04455b519..43fa403731 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/HideDetailsMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/HideDetailsMessage.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record HideDetailsMessage() { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/HotkeySummonMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/HotkeySummonMessage.cs similarity index 69% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/HotkeySummonMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/HotkeySummonMessage.cs index bff7af364e..4dcef111a3 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/HotkeySummonMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/HotkeySummonMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record HotkeySummonMessage(string CommandId, IntPtr Hwnd) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/LaunchUriMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/LaunchUriMessage.cs similarity index 62% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/LaunchUriMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/LaunchUriMessage.cs index dba45af1b7..3835b7cc7f 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/LaunchUriMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/LaunchUriMessage.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record LaunchUriMessage(Uri Uri) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigateBackMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigateBackMessage.cs similarity index 69% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigateBackMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigateBackMessage.cs index 5e19bfc57f..3e085184ed 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigateBackMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigateBackMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record NavigateBackMessage(bool FromBackspace = false) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigateNextCommand.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigateNextCommand.cs similarity index 76% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigateNextCommand.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigateNextCommand.cs index c996e0eecf..4ad61b20e6 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigateNextCommand.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigateNextCommand.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; /// /// Used to navigate to the next command in the page when pressing the Down key in the SearchBox. diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigatePreviousCommand.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigatePreviousCommand.cs similarity index 77% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigatePreviousCommand.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigatePreviousCommand.cs index 76f0f07908..4d28fce50b 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigatePreviousCommand.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigatePreviousCommand.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; /// /// Used to navigate to the previous command in the page when pressing the Down key in the SearchBox. diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigateToPageMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigateToPageMessage.cs similarity index 70% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigateToPageMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigateToPageMessage.cs index 784ce8f2bc..3d17f3b3cc 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/NavigateToPageMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/NavigateToPageMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record NavigateToPageMessage(PageViewModel Page, bool WithAnimation) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/OpenContextMenuMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/OpenContextMenuMessage.cs similarity index 85% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/OpenContextMenuMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/OpenContextMenuMessage.cs index 3cdcf72cee..9c19c9474e 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/OpenContextMenuMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/OpenContextMenuMessage.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation +// 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. @@ -6,7 +6,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls.Primitives; using Windows.Foundation; -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; /// /// Used to announce the context menu should open diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/OpenSettingsMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/OpenSettingsMessage.cs similarity index 55% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/OpenSettingsMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/OpenSettingsMessage.cs index 115593d5ae..e4b02b5c0c 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/OpenSettingsMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/OpenSettingsMessage.cs @@ -1,10 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.BuiltinCommands; - -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record OpenSettingsMessage() { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/PerformCommandMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/PerformCommandMessage.cs similarity index 77% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/PerformCommandMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/PerformCommandMessage.cs index b0e5e4829a..cd07a51beb 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/PerformCommandMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/PerformCommandMessage.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; /// /// Used to do a command - navigate to a page or invoke it @@ -18,21 +18,12 @@ public record PerformCommandMessage public bool WithAnimation { get; set; } = true; - public CommandPaletteHost? ExtensionHost { get; private set; } - public PerformCommandMessage(ExtensionObject command) { Command = command; Context = null; } - public PerformCommandMessage(TopLevelViewModel topLevelCommand) - { - Command = topLevelCommand.CommandViewModel.Model; - Context = null; - ExtensionHost = topLevelCommand.ExtensionHost; - } - public PerformCommandMessage(ExtensionObject command, ExtensionObject context) { Command = command; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/QuitMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/QuitMessage.cs similarity index 68% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/QuitMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/QuitMessage.cs index 2951aa57fb..12b9cec827 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/QuitMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/QuitMessage.cs @@ -1,10 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.BuiltinCommands; - -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; /// /// Message which closes the application. Used by via . diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ReloadCommandsMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ReloadCommandsMessage.cs similarity index 66% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ReloadCommandsMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ReloadCommandsMessage.cs index c427da4f9c..a553568f50 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ReloadCommandsMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ReloadCommandsMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record ReloadCommandsMessage() { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/SettingsWindowClosedMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/SettingsWindowClosedMessage.cs similarity index 67% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/SettingsWindowClosedMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/SettingsWindowClosedMessage.cs index 6627ab6192..f58637e8a5 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/SettingsWindowClosedMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/SettingsWindowClosedMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record SettingsWindowClosedMessage { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowConfirmationMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowConfirmationMessage.cs similarity index 72% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowConfirmationMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowConfirmationMessage.cs index c4059fbecd..fb7c5e88a8 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowConfirmationMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowConfirmationMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record ShowConfirmationMessage(Microsoft.CommandPalette.Extensions.IConfirmationArgs? Args) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowDetailsMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowDetailsMessage.cs similarity index 64% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowDetailsMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowDetailsMessage.cs index b51300d6d0..69dda7a589 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowDetailsMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowDetailsMessage.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record ShowDetailsMessage(DetailsViewModel Details) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowToastMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowToastMessage.cs similarity index 67% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowToastMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowToastMessage.cs index 0ec61dffd8..869d169858 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowToastMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowToastMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record ShowToastMessage(string Message) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowWindowMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowWindowMessage.cs similarity index 67% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowWindowMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowWindowMessage.cs index 9e880c08f0..01c05ff9b7 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/ShowWindowMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/ShowWindowMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record ShowWindowMessage(IntPtr Hwnd) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/TryCommandKeybindingMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/TryCommandKeybindingMessage.cs similarity index 77% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/TryCommandKeybindingMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/TryCommandKeybindingMessage.cs index 3df48ec3a0..48f7305e0a 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/TryCommandKeybindingMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/TryCommandKeybindingMessage.cs @@ -1,10 +1,10 @@ -// Copyright (c) Microsoft Corporation +// 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 Windows.System; -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record TryCommandKeybindingMessage(bool Ctrl, bool Alt, bool Shift, bool Win, VirtualKey Key) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/UpdateCommandBarMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/UpdateCommandBarMessage.cs similarity index 95% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/UpdateCommandBarMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/UpdateCommandBarMessage.cs index 9acec4bfe1..36b7653af5 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/UpdateCommandBarMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/UpdateCommandBarMessage.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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 System.ComponentModel; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; /// /// Used to update the command bar at the bottom to reflect the commands for a list item diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/UpdateFallbackItemsMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/UpdateFallbackItemsMessage.cs similarity index 67% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/UpdateFallbackItemsMessage.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/UpdateFallbackItemsMessage.cs index c7503ce1fb..8a913f7a3f 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/UpdateFallbackItemsMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/UpdateFallbackItemsMessage.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Messages; +namespace Microsoft.CmdPal.Core.ViewModels.Messages; public record UpdateFallbackItemsMessage() { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Microsoft.CmdPal.Core.ViewModels.csproj b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Microsoft.CmdPal.Core.ViewModels.csproj new file mode 100644 index 0000000000..1508994524 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Microsoft.CmdPal.Core.ViewModels.csproj @@ -0,0 +1,60 @@ + + + + + + enable + enable + false + false + $(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPal + + preview + + SA1313; + + + + true + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + + + + + + + Resources.resx + True + True + + + + + + + + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Models/ExtensionObject`1.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Models/ExtensionObject`1.cs similarity index 83% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Models/ExtensionObject`1.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Models/ExtensionObject`1.cs index 822229addc..c90225f344 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Models/ExtensionObject`1.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Models/ExtensionObject`1.cs @@ -1,8 +1,8 @@ -// Copyright (c) Microsoft Corporation +// 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. -namespace Microsoft.CmdPal.UI.ViewModels.Models; +namespace Microsoft.CmdPal.Core.ViewModels.Models; public class ExtensionObject(T? value) // where T : IInspectable { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/NativeMethods.json b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/NativeMethods.json new file mode 100644 index 0000000000..59fa7259c4 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/NativeMethods.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://aka.ms/CsWin32.schema.json", + "allowMarshaling": false +} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/NativeMethods.txt b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/NativeMethods.txt new file mode 100644 index 0000000000..981c7446f7 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/NativeMethods.txt @@ -0,0 +1,19 @@ +GetPhysicallyInstalledSystemMemory +GlobalMemoryStatusEx +GetSystemInfo +CoCreateInstance +SetForegroundWindow +IsIconic +RegisterHotKey +SetWindowLongPtr +CallWindowProc +ShowWindow +SetForegroundWindow +SetFocus +SetActiveWindow +MonitorFromWindow +GetMonitorInfo +SHCreateStreamOnFileEx +CoAllowSetForegroundWindow +SHCreateStreamOnFileEx +SHLoadIndirectString diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/PageViewModel.cs similarity index 96% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/PageViewModel.cs index 681f7bc7f1..552971b96c 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/PageViewModel.cs @@ -1,14 +1,14 @@ -// Copyright (c) Microsoft Corporation +// 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 System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class PageViewModel : ExtensionObjectViewModel, IPageContext { @@ -43,7 +43,7 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext public bool ShowSuggestion => !string.IsNullOrEmpty(TextToSuggest) && TextToSuggest != Filter; [ObservableProperty] - public partial CommandPaletteHost ExtensionHost { get; private set; } + public partial AppExtensionHost ExtensionHost { get; private set; } public bool HasStatusMessage => MostRecentStatusMessage != null; @@ -69,7 +69,7 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext public IconInfoViewModel Icon { get; protected set; } - public PageViewModel(IPage? model, TaskScheduler scheduler, CommandPaletteHost extensionHost) + public PageViewModel(IPage? model, TaskScheduler scheduler, AppExtensionHost extensionHost) : base((IPageContext?)null) { _pageModel = new(model); @@ -220,7 +220,7 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext { // Set the extensionHint to the Page Title (if we have one, and one not provided). // extensionHint ??= _pageModel?.Unsafe?.Title; - extensionHint ??= ExtensionHost.Extension?.ExtensionDisplayName ?? Title; + extensionHint ??= ExtensionHost.GetExtensionDisplayName() ?? Title; Task.Factory.StartNew( () => { @@ -263,5 +263,5 @@ public interface IPageViewModelFactoryService /// Indicates whether the page is not the top-level page. /// The command palette host that will host the page (for status messages) /// A new instance of the page view model. - PageViewModel? TryCreatePageViewModel(IPage page, bool nested, CommandPaletteHost host); + PageViewModel? TryCreatePageViewModel(IPage page, bool nested, AppExtensionHost host); } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModelFactory.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/PageViewModelFactory.cs similarity index 86% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModelFactory.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/PageViewModelFactory.cs index 83dbe51624..a30a2bd76b 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModelFactory.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/PageViewModelFactory.cs @@ -1,10 +1,10 @@ -// Copyright (c) Microsoft Corporation +// 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.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public class PageViewModelFactory : IPageViewModelFactoryService { @@ -15,7 +15,7 @@ public class PageViewModelFactory : IPageViewModelFactoryService _scheduler = scheduler; } - public PageViewModel? TryCreatePageViewModel(IPage page, bool nested, CommandPaletteHost host) + public PageViewModel? TryCreatePageViewModel(IPage page, bool nested, AppExtensionHost host) { return page switch { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ProgressViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ProgressViewModel.cs similarity index 92% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ProgressViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ProgressViewModel.cs index 3a2d4512ed..40ea290dd4 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ProgressViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ProgressViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class ProgressViewModel : ExtensionObjectViewModel { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SeparatorContextItemViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/SeparatorContextItemViewModel.cs similarity index 79% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SeparatorContextItemViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/SeparatorContextItemViewModel.cs index 7d700e3625..c6858f490d 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SeparatorContextItemViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/SeparatorContextItemViewModel.cs @@ -2,10 +2,10 @@ // 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class SeparatorContextItemViewModel() : IContextItemViewModel, ISeparatorContextItem { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ShellViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ShellViewModel.cs similarity index 72% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ShellViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ShellViewModel.cs index 294b0021c7..170103b09c 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ShellViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ShellViewModel.cs @@ -1,25 +1,22 @@ -// Copyright (c) Microsoft Corporation +// 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 System.Runtime.InteropServices; -using System.Runtime.Versioning; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using ManagedCommon; -using Microsoft.CmdPal.Common.Services; -using Microsoft.CmdPal.UI.ViewModels.Messages; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -using WinRT; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class ShellViewModel : ObservableObject, IRecipient { private readonly IRootPageService _rootPageService; + private readonly IAppHostService _appHostService; private readonly TaskScheduler _scheduler; private readonly IPageViewModelFactoryService _pageViewModelFactory; private readonly Lock _invokeLock = new(); @@ -61,17 +58,22 @@ public partial class ShellViewModel : ObservableObject, private IPage? _rootPage; - private IExtensionWrapper? _activeExtension; private bool _isNested; public bool IsNested { get => _isNested; } - public ShellViewModel(TaskScheduler scheduler, IRootPageService rootPageService, IPageViewModelFactoryService pageViewModelFactory) + public ShellViewModel( + TaskScheduler scheduler, + IRootPageService rootPageService, + IPageViewModelFactoryService pageViewModelFactory, + IAppHostService appHostService) { _pageViewModelFactory = pageViewModelFactory; _scheduler = scheduler; _rootPageService = rootPageService; - _currentPage = new LoadingPageViewModel(null, _scheduler); + _appHostService = appHostService; + + _currentPage = new LoadingPageViewModel(null, _scheduler, appHostService.GetDefaultHost()); // Register to receive messages WeakReferenceMessenger.Default.Register(this); @@ -173,11 +175,6 @@ public partial class ShellViewModel : ObservableObject, } } - public void PerformTopLevelCommand(PerformCommandMessage message) - { - _rootPageService.OnPerformTopLevelCommand(message.Context); - } - public void Receive(PerformCommandMessage message) { PerformCommand(message); @@ -191,61 +188,12 @@ public partial class ShellViewModel : ObservableObject, return; } - if (!CurrentPage.IsNested) - { - // on the main page here - PerformTopLevelCommand(message); - } + var host = _appHostService.GetHostForCommand(message.Context, CurrentPage.ExtensionHost); - IExtensionWrapper? extension = null; + _rootPageService.OnPerformCommand(message.Context, !CurrentPage.IsNested, host); try { - // In the case that we're coming from a top-level command, the - // current page's host is the global instance. We only really want - // to use that as the host of last resort. - var pageHost = CurrentPage?.ExtensionHost; - if (pageHost == CommandPaletteHost.Instance) - { - pageHost = null; - } - - var messageHost = message.ExtensionHost; - - // Use the host from the current page if it has one, else use the - // one specified in the PerformMessage for a top-level command, - // else just use the global one. - CommandPaletteHost host; - - // Top level items can come through without a Extension set on the - // message. In that case, the `Context` is actually the - // TopLevelViewModel itself, and we can use that to get at the - // extension object. - extension = pageHost?.Extension ?? messageHost?.Extension ?? null; - if (extension == null && message.Context is TopLevelViewModel topLevelViewModel) - { - extension = topLevelViewModel.ExtensionHost?.Extension; - host = pageHost ?? messageHost ?? topLevelViewModel?.ExtensionHost ?? CommandPaletteHost.Instance; - } - else - { - host = pageHost ?? messageHost ?? CommandPaletteHost.Instance; - } - - if (extension != null) - { - if (messageHost != null) - { - Logger.LogDebug($"Activated top-level command from {extension.ExtensionDisplayName}"); - } - else - { - Logger.LogDebug($"Activated command from {extension.ExtensionDisplayName}"); - } - } - - SetActiveExtension(extension); - if (command is IPage page) { Logger.LogDebug($"Navigating to page"); @@ -274,18 +222,18 @@ public partial class ShellViewModel : ObservableObject, Logger.LogDebug($"Invoking command"); WeakReferenceMessenger.Default.Send(); - StartInvoke(message, invokable); + StartInvoke(message, invokable, host); } } catch (Exception ex) { // TODO: It would be better to do this as a page exception, rather // than a silent log message. - CommandPaletteHost.Instance.Log(ex.Message); + host?.Log(ex.Message); } } - private void StartInvoke(PerformCommandMessage message, IInvokableCommand invokable) + private void StartInvoke(PerformCommandMessage message, IInvokableCommand invokable, AppExtensionHost? host) { // TODO GH #525 This needs more better locking. lock (_invokeLock) @@ -298,13 +246,13 @@ public partial class ShellViewModel : ObservableObject, { _handleInvokeTask = Task.Run(() => { - SafeHandleInvokeCommandSynchronous(message, invokable); + SafeHandleInvokeCommandSynchronous(message, invokable, host); }); } } } - private void SafeHandleInvokeCommandSynchronous(PerformCommandMessage message, IInvokableCommand invokable) + private void SafeHandleInvokeCommandSynchronous(PerformCommandMessage message, IInvokableCommand invokable, AppExtensionHost? host) { try { @@ -324,7 +272,7 @@ public partial class ShellViewModel : ObservableObject, // TODO: It would be better to do this as a page exception, rather // than a silent log message. - CommandPaletteHost.Instance.Log(ex.Message); + host?.Log(ex.Message); } } @@ -399,41 +347,9 @@ public partial class ShellViewModel : ObservableObject, } } - public void SetActiveExtension(IExtensionWrapper? extension) - { - if (extension != _activeExtension) - { - // There's not really a CoDisallowSetForegroundWindow, so we don't - // need to handle that - _activeExtension = extension; - - var extensionWinRtObject = _activeExtension?.GetExtensionObject(); - if (extensionWinRtObject != null) - { - try - { - unsafe - { - var winrtObj = (IWinRTObject)extensionWinRtObject; - var intPtr = winrtObj.NativeObject.ThisPtr; - var hr = Native.CoAllowSetForegroundWindow(intPtr); - if (hr != 0) - { - Logger.LogWarning($"Error giving foreground rights: 0x{hr.Value:X8}"); - } - } - } - catch (Exception ex) - { - Logger.LogError(ex.ToString()); - } - } - } - } - public void GoHome(bool withAnimation = true, bool focusSearch = true) { - SetActiveExtension(null); + _rootPageService.GoHome(); WeakReferenceMessenger.Default.Send(new(withAnimation, focusSearch)); } @@ -442,20 +358,6 @@ public partial class ShellViewModel : ObservableObject, WeakReferenceMessenger.Default.Send(new(withAnimation, focusSearch)); } - // You may ask yourself, why aren't we using CsWin32 for this? - // The CsWin32 projected version includes some object marshalling, like so: - // - // HRESULT CoAllowSetForegroundWindow([MarshalAs(UnmanagedType.IUnknown)] object pUnk,...) - // - // And if you do it like that, then the IForegroundTransfer interface isn't marshalled correctly - internal sealed class Native - { - [DllImport("OLE32.dll", ExactSpelling = true)] - [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] - [SupportedOSPlatform("windows5.0")] - internal static extern unsafe global::Windows.Win32.Foundation.HRESULT CoAllowSetForegroundWindow(nint pUnk, [Optional] void* lpvReserved); - } - private void OnUIThread(Action action) { _ = Task.Factory.StartNew( diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/StatusMessageViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/StatusMessageViewModel.cs similarity index 87% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/StatusMessageViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/StatusMessageViewModel.cs index 32328b0eb1..fb8b333637 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/StatusMessageViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/StatusMessageViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class StatusMessageViewModel : ExtensionObjectViewModel { @@ -15,14 +15,10 @@ public partial class StatusMessageViewModel : ExtensionObjectViewModel public MessageState State { get; private set; } = MessageState.Info; - public string ExtensionPfn { get; set; } = string.Empty; - public ProgressViewModel? Progress { get; private set; } public bool HasProgress => Progress != null; - // public bool IsIndeterminate => Progress != null && Progress.IsIndeterminate; - // public double ProgressValue => (Progress?.ProgressPercent ?? 0) / 100.0; public StatusMessageViewModel(IStatusMessage message, WeakReference context) : base(context) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TagViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/TagViewModel.cs similarity index 91% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TagViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/TagViewModel.cs index 414f1882a5..98ea66f4e8 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TagViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/TagViewModel.cs @@ -1,11 +1,11 @@ -// Copyright (c) Microsoft Corporation +// 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class TagViewModel(ITag _tag, WeakReference context) : ExtensionObjectViewModel(context) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ToastViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ToastViewModel.cs similarity index 81% rename from src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ToastViewModel.cs rename to src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ToastViewModel.cs index 156a47f557..719d7edd5d 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ToastViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ToastViewModel.cs @@ -4,9 +4,9 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; -using Microsoft.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Messages; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class ToastViewModel : ObservableObject { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/AliasManager.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/AliasManager.cs index 2d5fd66145..131d633940 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/AliasManager.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/AliasManager.cs @@ -4,7 +4,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; -using Microsoft.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Messages; namespace Microsoft.CmdPal.UI.ViewModels; @@ -38,7 +38,8 @@ public partial class AliasManager : ObservableObject if (topLevelCommand != null) { WeakReferenceMessenger.Default.Send(); - WeakReferenceMessenger.Default.Send(new(topLevelCommand)); + + WeakReferenceMessenger.Default.Send(topLevelCommand.GetPerformCommandMessage()); return true; } } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPaletteContentPageViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPaletteContentPageViewModel.cs new file mode 100644 index 0000000000..e3cd8a92d7 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPaletteContentPageViewModel.cs @@ -0,0 +1,28 @@ +// 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.CmdPal.Core.ViewModels; +using Microsoft.CommandPalette.Extensions; + +namespace Microsoft.CmdPal.UI.ViewModels; + +public partial class CommandPaletteContentPageViewModel : ContentPageViewModel +{ + public CommandPaletteContentPageViewModel(IContentPage model, TaskScheduler scheduler, AppExtensionHost host) + : base(model, scheduler, host) + { + } + + public override ContentViewModel? ViewModelFromContent(IContent content, WeakReference context) + { + ContentViewModel? viewModel = content switch + { + IFormContent form => new ContentFormViewModel(form, context), + IMarkdownContent markdown => new ContentMarkdownViewModel(markdown, context), + ITreeContent tree => new ContentTreeViewModel(tree, context), + _ => null, + }; + return viewModel; + } +} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPaletteHost.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPaletteHost.cs index 9aa12dc037..ab507950c5 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPaletteHost.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPaletteHost.cs @@ -1,35 +1,19 @@ -// Copyright (c) Microsoft Corporation +// 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 System.Collections.ObjectModel; -using System.Diagnostics; -using ManagedCommon; using Microsoft.CmdPal.Common.Services; +using Microsoft.CmdPal.Core.ViewModels; using Microsoft.CommandPalette.Extensions; -using Microsoft.CommandPalette.Extensions.Toolkit; -using Windows.Foundation; namespace Microsoft.CmdPal.UI.ViewModels; -public sealed partial class CommandPaletteHost : IExtensionHost +public sealed partial class CommandPaletteHost : AppExtensionHost, IExtensionHost { // Static singleton, so that we can access this from anywhere // Post MVVM - this should probably be like, a dependency injection thing. public static CommandPaletteHost Instance { get; } = new(); - private static readonly GlobalLogPageContext _globalLogPageContext = new(); - - private static ulong _hostingHwnd; - - public ulong HostingHwnd => _hostingHwnd; - - public string LanguageOverride => string.Empty; - - public static ObservableCollection LogMessages { get; } = []; - - public ObservableCollection StatusMessages { get; } = []; - public IExtensionWrapper? Extension { get; } private readonly ICommandProvider? _builtInProvider; @@ -48,145 +32,8 @@ public sealed partial class CommandPaletteHost : IExtensionHost _builtInProvider = builtInProvider; } - public IAsyncAction ShowStatus(IStatusMessage? message, StatusContext context) + public override string? GetExtensionDisplayName() { - if (message == null) - { - return Task.CompletedTask.AsAsyncAction(); - } - - Debug.WriteLine(message.Message); - - _ = Task.Run(() => - { - ProcessStatusMessage(message, context); - }); - - return Task.CompletedTask.AsAsyncAction(); - } - - public IAsyncAction HideStatus(IStatusMessage? message) - { - if (message == null) - { - return Task.CompletedTask.AsAsyncAction(); - } - - _ = Task.Run(() => - { - ProcessHideStatusMessage(message); - }); - return Task.CompletedTask.AsAsyncAction(); - } - - public IAsyncAction LogMessage(ILogMessage? message) - { - if (message == null) - { - return Task.CompletedTask.AsAsyncAction(); - } - - Logger.LogDebug(message.Message); - - _ = Task.Run(() => - { - ProcessLogMessage(message); - }); - - // We can't just make a LogMessageViewModel : ExtensionObjectViewModel - // because we don't necessarily know the page context. Butts. - return Task.CompletedTask.AsAsyncAction(); - } - - public void ProcessLogMessage(ILogMessage message) - { - var vm = new LogMessageViewModel(message, _globalLogPageContext); - vm.SafeInitializePropertiesSynchronous(); - - if (Extension != null) - { - vm.ExtensionPfn = Extension.PackageFamilyName; - } - - Task.Factory.StartNew( - () => - { - LogMessages.Add(vm); - }, - CancellationToken.None, - TaskCreationOptions.None, - _globalLogPageContext.Scheduler); - } - - public void ProcessStatusMessage(IStatusMessage message, StatusContext context) - { - // If this message is already in the list of messages, just bring it to the top - var oldVm = StatusMessages.Where(messageVM => messageVM.Model.Unsafe == message).FirstOrDefault(); - if (oldVm != null) - { - Task.Factory.StartNew( - () => - { - StatusMessages.Remove(oldVm); - StatusMessages.Add(oldVm); - }, - CancellationToken.None, - TaskCreationOptions.None, - _globalLogPageContext.Scheduler); - return; - } - - var vm = new StatusMessageViewModel(message, new(_globalLogPageContext)); - vm.SafeInitializePropertiesSynchronous(); - - if (Extension != null) - { - vm.ExtensionPfn = Extension.PackageFamilyName; - } - - Task.Factory.StartNew( - () => - { - StatusMessages.Add(vm); - }, - CancellationToken.None, - TaskCreationOptions.None, - _globalLogPageContext.Scheduler); - } - - public void ProcessHideStatusMessage(IStatusMessage message) - { - Task.Factory.StartNew( - () => - { - try - { - var vm = StatusMessages.Where(messageVM => messageVM.Model.Unsafe == message).FirstOrDefault(); - if (vm != null) - { - StatusMessages.Remove(vm); - } - } - catch - { - } - }, - CancellationToken.None, - TaskCreationOptions.None, - _globalLogPageContext.Scheduler); - } - - public static void SetHostHwnd(ulong hostHwnd) => _hostingHwnd = hostHwnd; - - public void DebugLog(string message) - { -#if DEBUG - this.ProcessLogMessage(new LogMessage(message)); -#endif - } - - public void Log(string message) - { - this.ProcessLogMessage(new LogMessage(message)); + return Extension?.ExtensionDisplayName; } } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPalettePageViewModelFactory.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPalettePageViewModelFactory.cs new file mode 100644 index 0000000000..90e70d7fef --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandPalettePageViewModelFactory.cs @@ -0,0 +1,29 @@ +// 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.CmdPal.Core.ViewModels; +using Microsoft.CommandPalette.Extensions; + +namespace Microsoft.CmdPal.UI.ViewModels; + +public class CommandPalettePageViewModelFactory + : IPageViewModelFactoryService +{ + private readonly TaskScheduler _scheduler; + + public CommandPalettePageViewModelFactory(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 CommandPaletteContentPageViewModel(contentPage, _scheduler, host), + _ => null, + }; + } +} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandProviderWrapper.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandProviderWrapper.cs index 302fe448ab..852babe4b7 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandProviderWrapper.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandProviderWrapper.cs @@ -4,7 +4,8 @@ using ManagedCommon; using Microsoft.CmdPal.Common.Services; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; using Microsoft.Extensions.DependencyInjection; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandSettingsViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandSettingsViewModel.cs index f6cc2cd5a9..a23cb4621e 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandSettingsViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandSettingsViewModel.cs @@ -3,10 +3,11 @@ // See the LICENSE file in the project root for more information. using ManagedCommon; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels.Models; +using Microsoft.CmdPal.UI.ViewModels; using Microsoft.CommandPalette.Extensions; -namespace Microsoft.CmdPal.UI.ViewModels; +namespace Microsoft.CmdPal.Core.ViewModels; public partial class CommandSettingsViewModel(ICommandSettings? _unsafeSettings, CommandProviderWrapper provider, TaskScheduler mainThread) { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltInsCommandProvider.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltInsCommandProvider.cs index 9552e108ef..3a3a9bd405 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltInsCommandProvider.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltInsCommandProvider.cs @@ -2,7 +2,7 @@ // 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.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltinsExtensionHost.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltinsExtensionHost.cs index f643f0fc84..9b8bd8ed48 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltinsExtensionHost.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltinsExtensionHost.cs @@ -2,15 +2,7 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics.CodeAnalysis; -using System.IO.Compression; -using System.Text.Json; -using System.Text.Json.Nodes; using Microsoft.CmdPal.Common; -using Microsoft.CmdPal.UI.ViewModels.Messages; -using Microsoft.CommandPalette.Extensions; -using Microsoft.CommandPalette.Extensions.Toolkit; -using Windows.Foundation; namespace Microsoft.CmdPal.UI.ViewModels.BuiltinCommands; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/LogMessagesPage.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/LogMessagesPage.cs index e0be3beb90..acb04889fb 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/LogMessagesPage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/LogMessagesPage.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Collections.Specialized; +using Microsoft.CmdPal.Core.ViewModels; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -10,7 +11,7 @@ namespace Microsoft.CmdPal.UI.ViewModels.Commands; public partial class LogMessagesPage : ListPage { - private readonly List _listItems = new(); + private readonly List _listItems = []; public LogMessagesPage() { @@ -31,7 +32,6 @@ public partial class LogMessagesPage : ListPage var li = new ListItem(new NoOpCommand()) { Title = logMessageViewModel.Message, - Subtitle = logMessageViewModel.ExtensionPfn, }; _listItems.Insert(0, li); } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs index 04277083ef..5be7c872c3 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs @@ -6,8 +6,8 @@ using System.Collections.Immutable; using System.Collections.Specialized; using CommunityToolkit.Mvvm.Messaging; using ManagedCommon; +using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CmdPal.Ext.Apps; -using Microsoft.CmdPal.UI.ViewModels.Messages; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; using Microsoft.Extensions.DependencyInjection; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/NewExtensionFormBase.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/NewExtensionFormBase.cs index e68fef10a4..5a68c2a2cf 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/NewExtensionFormBase.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/NewExtensionFormBase.cs @@ -6,7 +6,7 @@ using System.Diagnostics.CodeAnalysis; using System.IO.Compression; using System.Text.Json; using System.Text.Json.Nodes; -using Microsoft.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; using Windows.Foundation; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/OpenSettingsCommand.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/OpenSettingsCommand.cs index 91d6d3c9e3..a5af351fd4 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/OpenSettingsCommand.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/OpenSettingsCommand.cs @@ -3,7 +3,7 @@ // See the LICENSE file in the project root for more information. using CommunityToolkit.Mvvm.Messaging; -using Microsoft.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/QuitAction.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/QuitAction.cs index bd3cee3159..313685f6f2 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/QuitAction.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/QuitAction.cs @@ -3,7 +3,7 @@ // See the LICENSE file in the project root for more information. using CommunityToolkit.Mvvm.Messaging; -using Microsoft.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/ReloadExtensionsCommand.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/ReloadExtensionsCommand.cs index c2fb9f916b..77efb05a73 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/ReloadExtensionsCommand.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/ReloadExtensionsCommand.cs @@ -3,7 +3,7 @@ // See the LICENSE file in the project root for more information. using CommunityToolkit.Mvvm.Messaging; -using Microsoft.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentFormViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentFormViewModel.cs index 5477242a32..d561a0e00f 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentFormViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentFormViewModel.cs @@ -7,8 +7,9 @@ using AdaptiveCards.ObjectModel.WinUI3; using AdaptiveCards.Templating; using CommunityToolkit.Mvvm.Messaging; using ManagedCommon; -using Microsoft.CmdPal.UI.ViewModels.Messages; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels; +using Microsoft.CmdPal.Core.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; using Windows.Data.Json; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentMarkdownViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentMarkdownViewModel.cs index c8508e414a..8ae0935f12 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentMarkdownViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentMarkdownViewModel.cs @@ -2,7 +2,8 @@ // 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.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; namespace Microsoft.CmdPal.UI.ViewModels; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentTreeViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentTreeViewModel.cs index 77734921aa..6368f86ac6 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentTreeViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentTreeViewModel.cs @@ -3,7 +3,8 @@ // See the LICENSE file in the project root for more information. using System.Collections.ObjectModel; -using Microsoft.CmdPal.UI.ViewModels.Models; +using Microsoft.CmdPal.Core.ViewModels; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -37,7 +38,7 @@ public partial class ContentTreeViewModel(ITreeContent _tree, WeakReference context) + { + ContentViewModel? viewModel = content switch + { + IFormContent form => new ContentFormViewModel(form, context), + IMarkdownContent markdown => new ContentMarkdownViewModel(markdown, context), + ITreeContent tree => new ContentTreeViewModel(tree, context), + _ => null, + }; + return viewModel; + } + // TODO: Does this need to hop to a _different_ thread, so that we don't block the extension while we're fetching? private void Model_ItemsChanged(object sender, IItemsChangedEventArgs args) => FetchContent(); @@ -78,7 +93,7 @@ public partial class ContentTreeViewModel(ITreeContent _tree, WeakReference + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Models/ExtensionWrapper.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Models/ExtensionWrapper.cs index 5b4eee44ef..5cab466b6f 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Models/ExtensionWrapper.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Models/ExtensionWrapper.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation +// 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. @@ -12,7 +12,6 @@ using Windows.Win32; using Windows.Win32.System.Com; using WinRT; -// [assembly: System.Runtime.CompilerServices.DisableRuntimeMarshalling] namespace Microsoft.CmdPal.UI.ViewModels.Models; public class ExtensionWrapper : IExtensionWrapper diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ProviderSettingsViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ProviderSettingsViewModel.cs index 61bb7f946d..3c8e402364 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ProviderSettingsViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ProviderSettingsViewModel.cs @@ -6,7 +6,8 @@ using System.Diagnostics.CodeAnalysis; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; using Microsoft.CmdPal.Common.Services; -using Microsoft.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels; +using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CmdPal.UI.ViewModels.Properties; using Microsoft.Extensions.DependencyInjection; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs index d9beb0995d..b4f6542c93 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs @@ -10,7 +10,8 @@ using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using ManagedCommon; using Microsoft.CmdPal.Common.Services; -using Microsoft.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels; +using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; using Microsoft.Extensions.DependencyInjection; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelViewModel.cs index 16704e6cf7..dabfdca3f6 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelViewModel.cs @@ -6,7 +6,8 @@ using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; using ManagedCommon; -using Microsoft.CmdPal.UI.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels; +using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CmdPal.UI.ViewModels.Settings; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -254,7 +255,7 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem private void UpdateTags() { - List tags = new(); + List tags = []; if (Hotkey != null) { @@ -341,4 +342,9 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem return false; } + + public PerformCommandMessage GetPerformCommandMessage() + { + return new PerformCommandMessage(this.CommandViewModel.Model, new Core.ViewModels.Models.ExtensionObject(this)); + } } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs index 1007998f7c..36c742ba7f 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs @@ -5,6 +5,7 @@ using ManagedCommon; using Microsoft.CmdPal.Common.Helpers; using Microsoft.CmdPal.Common.Services; +using Microsoft.CmdPal.Core.ViewModels; using Microsoft.CmdPal.Ext.Apps; using Microsoft.CmdPal.Ext.Bookmarks; using Microsoft.CmdPal.Ext.Calc; @@ -145,11 +146,12 @@ public partial class App : Application services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(new TelemetryForwarder()); // ViewModels services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); return services.BuildServiceProvider(); } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/CommandBar.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/CommandBar.xaml index 1bbd0ab619..0edcf04a9c 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/CommandBar.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/CommandBar.xaml @@ -6,6 +6,7 @@ xmlns:animations="using:CommunityToolkit.WinUI.Animations" xmlns:cmdpalUI="using:Microsoft.CmdPal.UI" xmlns:converters="using:CommunityToolkit.WinUI.Converters" + xmlns:coreViewModels="using:Microsoft.CmdPal.Core.ViewModels" xmlns:cpcontrols="using:Microsoft.CmdPal.UI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:help="using:Microsoft.CmdPal.UI.Helpers" @@ -87,7 +88,7 @@ ItemsSource="{x:Bind CurrentPageViewModel.StatusMessages, Mode=OneWay}" Layout="{StaticResource VerticalStackLayout}"> - + @@ -27,7 +28,7 @@ Separator="{StaticResource SeparatorContextMenuViewModelTemplate}" /> - + @@ -57,7 +58,7 @@ - + @@ -88,7 +89,7 @@ - + - + - + - + - +