diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentFormViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentFormViewModel.cs index 29af210314..65bf3eb304 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentFormViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentFormViewModel.cs @@ -172,7 +172,9 @@ public partial class ContentFormViewModel(IFormContent _form, WeakReference(new(new(result))); } } diff --git a/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md b/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md index bdbf8ededc..d1e98a7b97 100644 --- a/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md +++ b/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md @@ -88,6 +88,7 @@ functionality. - [Addenda V: Extra content types](#addenda-v-extra-content-types) - [Image content](#image-content) - [Plain text content](#plain-text-content) + - [Addenda VI: Adaptive Card Actions](#addenda-vi-adaptive-card-actions) - [Class diagram](#class-diagram) - [Future considerations](#future-considerations) - [Arbitrary parameters and arguments](#arbitrary-parameters-and-arguments) @@ -2424,6 +2425,22 @@ interface IPlainTextContent requires IContent { } ``` +## Addenda VI: Adaptive Card Actions + +Adaptive Cards supports setting multiple actions on a card. Those actions can be +identified by an `id` property on the action. That `id` is not necessarily +encoded in the JSON payload of the action. + +For us to properly support the gammut of AC scenarios, we need to be able to +pass the `id` of the action back to the extension. This is a relatively simple +addition to the `IForm` interface. + +```csharp +interface IFormContent2 requires IFormContent { + ICommandResult SubmitAction(String actionId, String inputs, String data); +} +``` + ## Class diagram This is a diagram attempting to show the relationships between the various types we've defined for the SDK. Some elements are omitted for clarity. (Notably, `IconData` and `IPropChanged`, which are used in many places.) diff --git a/src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleContentPage.cs b/src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleContentPage.cs index 915e39e52e..334efa7206 100644 --- a/src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleContentPage.cs +++ b/src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleContentPage.cs @@ -256,6 +256,7 @@ internal sealed partial class SampleContentForm : FormContent "actions": [ { "type": "Action.Submit", + "id": "submit-form", "title": "Submit", "data": { "id": "1234567890" @@ -277,6 +278,7 @@ internal sealed partial class SampleContentForm : FormContent "actions": [ { "type": "Action.Submit", + "id": "submit-comment", "title": "OK" } ] @@ -368,6 +370,9 @@ internal sealed partial class SampleContentForm : FormContent // Application.Current.GetService().SaveSettingAsync("GlobalHotkey", formInput["hotkey"]?.ToString() ?? string.Empty); return CommandResult.GoHome(); } + + public override CommandResult SubmitAction(string actionId, string inputs, string data) => + CommandResult.ShowToast($"Submitted action: {actionId}"); } [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Sample code")] diff --git a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/CommandProvider.cs b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/CommandProvider.cs index 769d7010f3..3907877b24 100644 --- a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/CommandProvider.cs +++ b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/CommandProvider.cs @@ -78,7 +78,7 @@ public abstract partial class CommandProvider : /// an array of objects that implement all the leaf interfaces we support public object[] GetApiExtensionStubs() { - return [new SupportCommandsWithProperties()]; + return [new SupportCommandsWithProperties(), new SupportFormActions()]; } /// @@ -90,4 +90,21 @@ public abstract partial class CommandProvider : { public IDictionary? GetProperties() => null; } + + private sealed partial class SupportFormActions : IFormContent2 + { + public string TemplateJson => string.Empty; + + public string DataJson => string.Empty; + + public string StateJson => string.Empty; + + public ICommandResult SubmitForm(string inputs, string data) => CommandResult.KeepOpen(); + + public ICommandResult SubmitAction(string actionId, string inputs, string data) => CommandResult.KeepOpen(); + +#pragma warning disable CS0067 + public event Windows.Foundation.TypedEventHandler? PropChanged; +#pragma warning restore CS0067 + } } diff --git a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FormContent.cs b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FormContent.cs index dbfa5c2f03..07976ca26f 100644 --- a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FormContent.cs +++ b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FormContent.cs @@ -4,7 +4,7 @@ namespace Microsoft.CommandPalette.Extensions.Toolkit; -public partial class FormContent : BaseObservable, IFormContent +public partial class FormContent : BaseObservable, IFormContent2 { public virtual string DataJson { get; set => SetProperty(ref field, value); } = string.Empty; @@ -15,4 +15,6 @@ public partial class FormContent : BaseObservable, IFormContent public virtual ICommandResult SubmitForm(string inputs, string data) => SubmitForm(inputs); public virtual ICommandResult SubmitForm(string inputs) => CommandResult.KeepOpen(); + + public virtual ICommandResult SubmitAction(string actionId, string inputs, string data) => SubmitForm(inputs, data); } diff --git a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions/Microsoft.CommandPalette.Extensions.idl b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions/Microsoft.CommandPalette.Extensions.idl index 55d94c9317..12f946e1dc 100644 --- a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions/Microsoft.CommandPalette.Extensions.idl +++ b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions/Microsoft.CommandPalette.Extensions.idl @@ -490,5 +490,10 @@ namespace Microsoft.CommandPalette.Extensions Boolean WrapWords { get; }; } + [contract(Microsoft.CommandPalette.Extensions.ExtensionsContract, 1)] + interface IFormContent2 requires IFormContent { + ICommandResult SubmitAction(String actionId, String inputs, String data); + } + }