diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandViewModel.cs index 5f02ab44a2..151464040b 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/CommandViewModel.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using Microsoft.CmdPal.Core.ViewModels.Models; using Microsoft.CommandPalette.Extensions; +using WinRT; namespace Microsoft.CmdPal.Core.ViewModels; @@ -93,6 +94,39 @@ public partial class CommandViewModel : ExtensionObjectViewModel Debug.WriteLine("}"); } + if (model is IHaveProperties command3) + { + var p = command3.Properties; + Debug.WriteLine($"{Name} can haz properties = {{"); + foreach (var kv in p) + { + Debug.WriteLine($"\t{kv.Key}: {kv.Value}"); + } + + Debug.WriteLine("}"); + } + + if (Name == "Whatever" || Name == "Revetahw" || Name == "Another") + { + var invokable = model as IInvokableCommand; + var page = model as IPage; + var props = model as IHaveProperties; + var com2 = model as ICommand2; + Debug.WriteLine($"{invokable},{page},{props},{com2}"); + + var f = model as IWinRTObject; + if (f != null) + { + var types = f.AdditionalTypeData; + foreach (var t in types) + { + Debug.WriteLine($"{t.Key}, {t.Value}"); + } + + Debug.WriteLine(string.Empty); + } + } + model.PropChanged += Model_PropChanged; } diff --git a/src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleListPage.cs b/src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleListPage.cs index 2489e44263..7f1574e8ab 100644 --- a/src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleListPage.cs +++ b/src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleListPage.cs @@ -2,8 +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 System.Diagnostics.CodeAnalysis; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; +using Windows.Foundation; using Windows.Foundation.Collections; using Windows.System; using Windows.Win32; @@ -170,10 +172,22 @@ internal sealed partial class SampleListPage : ListPage { Title = "Get the name of the Foreground window", }, + new ListItem(new JustHasProps()) + { + Title = "Not actually invokable", + }, new ListItem(new CommandWithProperties()) { Title = "I have properties", }, + new ListItem(new OtherCommandWithProperties()) + { + Title = "I also have properties", + }, + new ListItem(new AnotherCommandWithProperties()) + { + Title = "InvokableCommand, IHaveProperties", + }, ]; } @@ -188,4 +202,72 @@ internal sealed partial class SampleListPage : ListPage { "hmm?", null }, }; } + +#nullable enable + internal sealed partial class OtherCommandWithProperties : ICommand2, IInvokableCommand + { + public string Name => "Revetahw"; + + public IIconInfo Icon => new IconInfo("\uF146"); + + public string Id => string.Empty; + + public event TypedEventHandler? PropChanged; + + public ICommandResult Invoke(object sender) + { + PropChanged?.Invoke(this, new PropChangedEventArgs(nameof(Name))); + return CommandResult.ShowToast("whoop"); + } + + public IPropertySet OtherProperties => new PropertySet() + { + { "Foo", "bar" }, + { "Secret", 42 }, + { "hmm?", null }, + }; + } + + internal sealed partial class JustHasProps : ICommand2 + { + public string Name => "JustHasProps"; + + public IIconInfo Icon => new IconInfo("\uF147"); + + public string Id => string.Empty; + + public event TypedEventHandler? PropChanged; + + public ICommandResult Invoke(object sender) + { + PropChanged?.Invoke(this, new PropChangedEventArgs(nameof(Name))); + return CommandResult.ShowToast("whoop"); + } + + public IPropertySet OtherProperties => new PropertySet() + { + { "Foo", "bar" }, + { "Secret", 42 }, + { "hmm?", null }, + }; + } + + internal sealed partial class AnotherCommandWithProperties : InvokableCommand, IHaveProperties + { + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(IHaveProperties))] + static AnotherCommandWithProperties() + { + } + + public override string Name => "Another"; + + public override IconInfo Icon => new IconInfo("\uF147"); + + public IPropertySet Properties => new PropertySet() + { + { "it", "doesn't" }, + { "matter", 42 }, + { "nothing seems to", "work" }, + }; + } } 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 a4eba95771..dbd76c0b46 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 @@ -1,6 +1,6 @@ namespace Microsoft.CommandPalette.Extensions { - [contractversion(2)] + [contractversion(1)] apicontract ExtensionsContract {} [contract(Microsoft.CommandPalette.Extensions.ExtensionsContract, 1)] @@ -61,10 +61,15 @@ namespace Microsoft.CommandPalette.Extensions IIconInfo Icon{ get; }; } - [contract(Microsoft.CommandPalette.Extensions.ExtensionsContract, 2)] - interface ICommand2 { + [contract(Microsoft.CommandPalette.Extensions.ExtensionsContract, 1)] + interface ICommand2 requires ICommand { Windows.Foundation.Collections.IPropertySet OtherProperties { get; }; } + + [contract(Microsoft.CommandPalette.Extensions.ExtensionsContract, 1)] + interface IHaveProperties { + Windows.Foundation.Collections.IPropertySet Properties{ get; }; + } enum CommandResultKind { Dismiss, // Reset the palette to the main page and dismiss