diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandBarViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandBarViewModel.cs index f506c127f2..b3b5f989b4 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandBarViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandBarViewModel.cs @@ -149,12 +149,12 @@ public partial class CommandBarViewModel : ObservableObject, if (command.HasMoreCommands) { - WeakReferenceMessenger.Default.Send(new(command.Command.Model, command.Model)); + WeakReferenceMessenger.Default.Send(new(command)); return ContextKeybindingResult.KeepOpen; } else { - WeakReferenceMessenger.Default.Send(new(command.Command.Model, command.Model)); + WeakReferenceMessenger.Default.Send(new(command)); return ContextKeybindingResult.Hide; } } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandItemViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandItemViewModel.cs index 14b26bd8ab..d7d80d6c74 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandItemViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandItemViewModel.cs @@ -2,6 +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.Collections.ObjectModel; using Microsoft.CmdPal.Core.ViewModels.Messages; using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; @@ -64,7 +65,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa public bool HasParameters => Command.HasParameters; - public List Parameters => Command.Parameters; + public ObservableCollection Parameters => Command.Parameters; public List AllCommands { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandViewModel.cs index 0fe11b1035..dce167d9ea 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandViewModel.cs @@ -2,6 +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.Collections.ObjectModel; using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; @@ -31,7 +32,7 @@ public partial class CommandViewModel : ExtensionObjectViewModel public bool HasParameters { get; set; } - public List Parameters { get; private set; } = []; + public ObservableCollection Parameters { get; private set; } = new(); public CommandViewModel(ICommand? command, WeakReference pageContext) : base(pageContext) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentPageViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentPageViewModel.cs index 16611a31ac..a79f9ec211 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentPageViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContentPageViewModel.cs @@ -250,7 +250,7 @@ public partial class ContentPageViewModel : PageViewModel, ICommandBarContext { if (PrimaryCommand != null) { - WeakReferenceMessenger.Default.Send(new(PrimaryCommand.Command.Model, PrimaryCommand.Model)); + WeakReferenceMessenger.Default.Send(new(PrimaryCommand)); } } @@ -260,7 +260,7 @@ public partial class ContentPageViewModel : PageViewModel, ICommandBarContext { if (SecondaryCommand != null) { - WeakReferenceMessenger.Default.Send(new(SecondaryCommand.Command.Model, SecondaryCommand.Model)); + WeakReferenceMessenger.Default.Send(new(SecondaryCommand)); } } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContextMenuViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContextMenuViewModel.cs index bcc414859a..1b2056b058 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContextMenuViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ContextMenuViewModel.cs @@ -225,7 +225,7 @@ public partial class ContextMenuViewModel : ObservableObject, } else { - WeakReferenceMessenger.Default.Send(new(command.Command.Model, command.Model)); + WeakReferenceMessenger.Default.Send(new(command)); UpdateContextItems(); return ContextKeybindingResult.Hide; } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ListViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ListViewModel.cs index 6147287e22..7b0011bcf6 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ListViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ListViewModel.cs @@ -297,13 +297,12 @@ public partial class ListViewModel : PageViewModel, IDisposable { if (item != null) { - WeakReferenceMessenger.Default.Send(new(item.Command.Model, item.Model)); + WeakReferenceMessenger.Default.Send(new(item)); } else if (ShowEmptyContent && EmptyContent.PrimaryCommand?.Model.Unsafe != null) { WeakReferenceMessenger.Default.Send(new( - EmptyContent.PrimaryCommand.Command.Model, - EmptyContent.PrimaryCommand.Model)); + EmptyContent.PrimaryCommand)); } } @@ -315,14 +314,13 @@ public partial class ListViewModel : PageViewModel, IDisposable { if (item.SecondaryCommand != null) { - WeakReferenceMessenger.Default.Send(new(item.SecondaryCommand.Command.Model, item.Model)); + WeakReferenceMessenger.Default.Send(new(item.SecondaryCommand, item)); } } else if (ShowEmptyContent && EmptyContent.SecondaryCommand?.Model.Unsafe != null) { WeakReferenceMessenger.Default.Send(new( - EmptyContent.SecondaryCommand.Command.Model, - EmptyContent.SecondaryCommand.Model)); + EmptyContent.SecondaryCommand)); } } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/PerformCommandMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/PerformCommandMessage.cs index a098671af0..8e2e8c2ab1 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/PerformCommandMessage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/Messages/PerformCommandMessage.cs @@ -19,13 +19,12 @@ public record PerformCommandMessage public bool WithAnimation { get; set; } = true; public ICommandArgument?[] Arguments { get; set; } = []; - - public PerformCommandMessage(ExtensionObject command) - { - Command = command; - Context = null; - } + // public PerformCommandMessage(ExtensionObject command) + // { + // Command = command; + // Context = null; + // } public PerformCommandMessage(ExtensionObject command, ExtensionObject context) { Command = command; @@ -50,6 +49,16 @@ public record PerformCommandMessage Context = contextCommand.Model.Unsafe; } + public PerformCommandMessage(CommandItemViewModel item, CommandItemViewModel? context = null) + { + Command = item.Command.Model; + Context = context?.Model.Unsafe ?? item.Model.Unsafe; + if (item.Parameters != null && item.Parameters.Any()) + { + Arguments = item.Parameters.Select(p => p.Model.Unsafe).ToArray(); + } + } + public PerformCommandMessage(ConfirmResultViewModel vm) { Command = vm.PrimaryCommand.Model; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ShellViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ShellViewModel.cs index 4334abc541..23ce7965c4 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ShellViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ShellViewModel.cs @@ -93,7 +93,7 @@ public partial class ShellViewModel : ObservableObject, _rootPage = _rootPageService.GetRootPage(); // This sends a message to us to load the root page view model. - WeakReferenceMessenger.Default.Send(new(new ExtensionObject(_rootPage))); + WeakReferenceMessenger.Default.Send(new(new ExtensionObject(_rootPage), new ExtensionObject(null))); // Now that the root page is loaded, do any post-load work that the root page service needs to do. // This runs asynchronously, on a background thread. @@ -221,10 +221,9 @@ public partial class ShellViewModel : ObservableObject, { Logger.LogDebug($"Invoking command with args"); - var args = ArgumentsViewModel.Arguments; - var aa = args.Select(a => a.Model.Unsafe).ToArray() ?? []; - message.Arguments = aa; - + // var args = ArgumentsViewModel.Arguments; + // var aa = args.Select(a => a.Model.Unsafe).ToArray() ?? []; + // message.Arguments = aa; WeakReferenceMessenger.Default.Send(); HandleInvokeCommandWithArgs(message, commandWithParams, host); } 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 90013f9944..45883a8425 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj @@ -22,6 +22,8 @@ false false + + $(WarningsNotAsErrors);IL2059; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs index 2649c7371a..4f7e09f3f2 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs @@ -8,6 +8,7 @@ using CommunityToolkit.WinUI; using ManagedCommon; using Microsoft.CmdPal.Core.ViewModels; using Microsoft.CmdPal.Core.ViewModels.Messages; +using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CmdPal.UI.Events; using Microsoft.CmdPal.UI.Settings; using Microsoft.CmdPal.UI.ViewModels; @@ -17,7 +18,6 @@ using Microsoft.PowerToys.Telemetry; using Microsoft.UI.Dispatching; using Microsoft.UI.Input; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media.Animation; using DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue; @@ -447,7 +447,7 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page, { if (sender is Button button && button.DataContext is CommandViewModel commandViewModel) { - WeakReferenceMessenger.Default.Send(new(commandViewModel.Model)); + WeakReferenceMessenger.Default.Send(new(commandViewModel.Model, new ExtensionObject(null))); } }