incredible that this merge conflict worked

This commit is contained in:
Mike Griese
2025-07-19 15:54:46 -05:00
parent 000e443fec
commit d31fe2f390
10 changed files with 36 additions and 26 deletions

View File

@@ -149,12 +149,12 @@ public partial class CommandBarViewModel : ObservableObject,
if (command.HasMoreCommands)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(command.Command.Model, command.Model));
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(command));
return ContextKeybindingResult.KeepOpen;
}
else
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(command.Command.Model, command.Model));
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(command));
return ContextKeybindingResult.Hide;
}
}

View File

@@ -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<ArgumentItemViewModel> Parameters => Command.Parameters;
public ObservableCollection<ArgumentItemViewModel> Parameters => Command.Parameters;
public List<IContextItemViewModel> AllCommands
{

View File

@@ -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<ArgumentItemViewModel> Parameters { get; private set; } = [];
public ObservableCollection<ArgumentItemViewModel> Parameters { get; private set; } = new();
public CommandViewModel(ICommand? command, WeakReference<IPageContext> pageContext)
: base(pageContext)

View File

@@ -250,7 +250,7 @@ public partial class ContentPageViewModel : PageViewModel, ICommandBarContext
{
if (PrimaryCommand != null)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(PrimaryCommand.Command.Model, PrimaryCommand.Model));
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(PrimaryCommand));
}
}
@@ -260,7 +260,7 @@ public partial class ContentPageViewModel : PageViewModel, ICommandBarContext
{
if (SecondaryCommand != null)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(SecondaryCommand.Command.Model, SecondaryCommand.Model));
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(SecondaryCommand));
}
}

View File

@@ -225,7 +225,7 @@ public partial class ContextMenuViewModel : ObservableObject,
}
else
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(command.Command.Model, command.Model));
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(command));
UpdateContextItems();
return ContextKeybindingResult.Hide;
}

View File

@@ -297,13 +297,12 @@ public partial class ListViewModel : PageViewModel, IDisposable
{
if (item != null)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(item.Command.Model, item.Model));
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(item));
}
else if (ShowEmptyContent && EmptyContent.PrimaryCommand?.Model.Unsafe != null)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(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<PerformCommandMessage>(new(item.SecondaryCommand.Command.Model, item.Model));
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(item.SecondaryCommand, item));
}
}
else if (ShowEmptyContent && EmptyContent.SecondaryCommand?.Model.Unsafe != null)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(
EmptyContent.SecondaryCommand.Command.Model,
EmptyContent.SecondaryCommand.Model));
EmptyContent.SecondaryCommand));
}
}

View File

@@ -19,13 +19,12 @@ public record PerformCommandMessage
public bool WithAnimation { get; set; } = true;
public ICommandArgument?[] Arguments { get; set; } = [];
public PerformCommandMessage(ExtensionObject<ICommand> command)
{
Command = command;
Context = null;
}
// public PerformCommandMessage(ExtensionObject<ICommand> command)
// {
// Command = command;
// Context = null;
// }
public PerformCommandMessage(ExtensionObject<ICommand> command, ExtensionObject<IListItem> 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;

View File

@@ -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<PerformCommandMessage>(new(new ExtensionObject<ICommand>(_rootPage)));
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(new ExtensionObject<ICommand>(_rootPage), new ExtensionObject<ICommandContextItem>(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<BeginInvokeMessage>();
HandleInvokeCommandWithArgs(message, commandWithParams, host);
}

View File

@@ -22,6 +22,8 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<WarningsNotAsErrors>$(WarningsNotAsErrors);IL2059;</WarningsNotAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(EnableCmdPalAOT)' == 'true'">

View File

@@ -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<PerformCommandMessage>(new(commandViewModel.Model));
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(commandViewModel.Model, new ExtensionObject<IListItem>(null)));
}
}