diff --git a/src/Uno.UI.RemoteControl.VS/Commands/UnoMenuCommand.cs b/src/Uno.UI.RemoteControl.VS/Commands/UnoMenuCommand.cs index 954db32a1939..2a4c5c52a137 100644 --- a/src/Uno.UI.RemoteControl.VS/Commands/UnoMenuCommand.cs +++ b/src/Uno.UI.RemoteControl.VS/Commands/UnoMenuCommand.cs @@ -21,10 +21,10 @@ internal sealed class UnoMenuCommand private static readonly int UnoMainMenu = 0x4100; private static readonly int DynamicMenuCommandId = 0x4103; - public List CommandList { get; set; } = []; + public List CommandList { get; set; } = []; public static UnoMenuCommand? Instance { get; private set; } - private UnoMenuCommand(AsyncPackage package, IdeChannelClient ideChannelClient, OleMenuCommandService commandService, CommandRequestIdeMessage cr) + private UnoMenuCommand(AsyncPackage package, IdeChannelClient ideChannelClient, OleMenuCommandService commandService, AddMenuItemRequestIdeMessage cr) { _package = package ?? throw new ArgumentNullException(nameof(_package)); CommandService = commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); @@ -43,7 +43,7 @@ private UnoMenuCommand(AsyncPackage package, IdeChannelClient ideChannelClient, } } - public static async Task InitializeAsync(AsyncPackage package, IdeChannelClient ideChannelClient, CommandRequestIdeMessage cr) + public static async Task InitializeAsync(AsyncPackage package, IdeChannelClient ideChannelClient, AddMenuItemRequestIdeMessage cr) { // Switch to the main thread - the call to AddCommand in DynamicMenu's constructor requires the UI thread. await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); @@ -91,10 +91,17 @@ private void OnInvokedDynamicItem(object sender, EventArgs args) { if (IdeChannelClient != null && sender is DynamicItemMenuCommand matchedCommand && - TryGetCommandRequestIdeMessage(matchedCommand, out var currentCommand)) + TryGetCommandRequestIdeMessage(matchedCommand, out var currentMenu) && + currentMenu.Command is Command cmd) { + var cmdMessage = + new CommandRequestIdeMessage( + System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle.ToInt64(), + cmd.Name, + cmd.Parameter); + // Ignoring the async call as the OleMenuCommand.execHandler is private and not async - _ = IdeChannelClient.SendToDevServerAsync(currentCommand, _package.DisposalToken); + _ = IdeChannelClient.SendToDevServerAsync(cmdMessage, _package.DisposalToken); } } @@ -109,9 +116,9 @@ private void OnBeforeQueryStatusDynamicItem(object sender, EventArgs args) matchedCommand.Enabled = true; matchedCommand.Visible = true; - if (TryGetCommandRequestIdeMessage(matchedCommand, out var currentCommand)) + if (TryGetCommandRequestIdeMessage(matchedCommand, out var currentMenu)) { - matchedCommand.Text = currentCommand.Command; + matchedCommand.Text = currentMenu.Command.Text; } // Clear the ID because we are done with this item. matchedCommand.MatchedCommandId = 0; @@ -121,6 +128,6 @@ private static int GetCurrentPosition(DynamicItemMenuCommand matchedCommand) => // The position of the command is the command ID minus the ID of the root dynamic start item. matchedCommand.MatchedCommandId == 0 ? 0 : matchedCommand.MatchedCommandId - (int)DynamicMenuCommandId; - private bool TryGetCommandRequestIdeMessage(DynamicItemMenuCommand matchedCommand, [NotNullWhen(true)] out CommandRequestIdeMessage result) + private bool TryGetCommandRequestIdeMessage(DynamicItemMenuCommand matchedCommand, [NotNullWhen(true)] out AddMenuItemRequestIdeMessage result) => (result = CommandList.Skip(GetCurrentPosition(matchedCommand)).FirstOrDefault()) != null; } diff --git a/src/Uno.UI.RemoteControl.VS/EntryPoint.cs b/src/Uno.UI.RemoteControl.VS/EntryPoint.cs index b84bec5f6170..d4a91495aff3 100644 --- a/src/Uno.UI.RemoteControl.VS/EntryPoint.cs +++ b/src/Uno.UI.RemoteControl.VS/EntryPoint.cs @@ -346,7 +346,7 @@ private async Task EnsureServerAsync() _ideChannelClient = new IdeChannelClient(pipeGuid, new Logger(this)); _ideChannelClient.ForceHotReloadRequested += OnForceHotReloadRequestedAsync; _ideChannelClient.OnMessageReceived += OnMessageReceivedAsync; - _ideChannelClient.OnCommandIdeMessageRequested += OnCommandIdeMessageRequestedAsync; + _ideChannelClient.OnAddMenuItemIdeMessageRequested += OnAddMenuItemRequestIdeMessageAsync; _ideChannelClient.ConnectToHost(); // Set the port to the projects @@ -441,7 +441,7 @@ await _asyncPackage.GetServiceAsync(typeof(SVsInfoBarUIFactory)) is IVsInfoBarUI } } - private async Task OnCommandIdeMessageRequestedAsync(object? sender, CommandRequestIdeMessage cr) + private async Task OnAddMenuItemRequestIdeMessageAsync(object? sender, AddMenuItemRequestIdeMessage cr) { try { @@ -461,7 +461,7 @@ private async Task OnCommandIdeMessageRequestedAsync(object? sender, CommandRequ } catch (Exception e) { - _debugAction?.Invoke($"Using Command Ide Message Requested fail {e.Message}"); + _debugAction?.Invoke($"Using AddMenuItem Ide Message Requested fail {e.Message}"); throw; } } diff --git a/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs b/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs index 816814518232..563b3c5ea5d4 100644 --- a/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs +++ b/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs @@ -22,7 +22,7 @@ internal class IdeChannelClient public event AsyncEventHandler? ForceHotReloadRequested; public event AsyncEventHandler? OnMessageReceived; - public event AsyncEventHandler? OnCommandIdeMessageRequested; + public event AsyncEventHandler? OnAddMenuItemIdeMessageRequested; public IdeChannelClient(Guid pipeGuid, ILogger logger) { @@ -93,9 +93,9 @@ private void ProcessDevServerMessage(object sender, IdeMessageEnvelope devServer var process = Task.CompletedTask; switch (devServerMessage) { - case CommandRequestIdeMessage cr: + case AddMenuItemRequestIdeMessage cr: _logger.Debug("Command Ide Message Requested"); - process = OnCommandIdeMessageRequested.InvokeAsync(this, cr); + process = OnAddMenuItemIdeMessageRequested.InvokeAsync(this, cr); break; case ForceHotReloadIdeMessage forceHotReloadMessage when ForceHotReloadRequested is { } hrRequested: