diff --git a/src/modules/cmdpal/.wt.json b/src/modules/cmdpal/.wt.json index 230329e876..69cd2c79cc 100644 --- a/src/modules/cmdpal/.wt.json +++ b/src/modules/cmdpal/.wt.json @@ -26,6 +26,11 @@ "input": "pushd .\\ExtensionTemplate\\ ; git archive -o ..\\Microsoft.CmdPal.UI.ViewModels\\Assets\\template.zip HEAD -- .\\TemplateCmdPalExtension\\ ; popd", "name": "Update template project", "description": "zips up the ExtensionTemplate into our assets. Run this in the cmdpal/ directory." + }, + { + "input": "pwsh -c .\\clean-sdk.ps1", + "name": "Delete old extensions output", + "description": "Delete old extensions output directory.\r\nUse this after regenerating the interface, otherwise it will not pass fast up to date checks." } ] } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ArgumentItemViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ArgumentItemViewModel.cs index acaeab5a48..43f096aa08 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ArgumentItemViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.Core.ViewModels/ArgumentItemViewModel.cs @@ -21,6 +21,11 @@ public partial class ArgumentItemViewModel : ExtensionObjectViewModel public bool Required { get; private set; } + private string ModelDisplayName { get; set; } = string.Empty; + + public string DisplayName => string.IsNullOrEmpty(ModelDisplayName) ? Name : ModelDisplayName; + + // TODO! This should be an ExtensionObject since it's out-of-proc public object? Value { get; set @@ -48,6 +53,7 @@ public partial class ArgumentItemViewModel : ExtensionObjectViewModel Name = model.Name; Required = model.Required; Value = model.Value; + ModelDisplayName = model.DisplayName; // Register for property changes model.PropChanged += Model_PropChanged; @@ -76,18 +82,49 @@ public partial class ArgumentItemViewModel : ExtensionObjectViewModel switch (propertyName) { case nameof(ICommandArgument.Type): + if (model.Type == Type) + { + return; + } + Type = model.Type; break; case nameof(ICommandArgument.Name): + if (model.Name == Name) + { + return; + } + Name = model.Name; + UpdateProperty(nameof(DisplayName)); break; case nameof(ICommandArgument.Required): + if (model.Required == Required) + { + return; + } + Required = model.Required; break; case nameof(ICommandArgument.Value): + if (model.Value == Value) + { + return; + } + Value = model.Value; break; + case nameof(ICommandArgument.DisplayName): + if (model.DisplayName == ModelDisplayName) + { + return; + } + + ModelDisplayName = model.DisplayName; + break; } + + UpdateProperty(propertyName); } private void SafeSetValue(object? value) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltInsCommandProvider.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltInsCommandProvider.cs index 501156f745..ff72d2cea4 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltInsCommandProvider.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/BuiltInsCommandProvider.cs @@ -80,6 +80,10 @@ public partial class BuiltInsCommandProvider : CommandProvider public object? Value { get; set; } + public string DisplayName => string.Empty; + + public IIconInfo? Icon => null; + public void ShowPicker(ulong hostHwnd) { } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs index 8729002faa..c6569519c7 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs @@ -360,6 +360,13 @@ public sealed partial class SearchBar : UserControl, { param.OpenPicker(); }; + button.SetBinding(Button.ContentProperty, new Microsoft.UI.Xaml.Data.Binding + { + Source = param, + Path = new PropertyPath("DisplayName"), + Mode = Microsoft.UI.Xaml.Data.BindingMode.OneWay, + UpdateSourceTrigger = Microsoft.UI.Xaml.Data.UpdateSourceTrigger.PropertyChanged, + }); ParametersPanel.Children.Add(button); } } 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 4a22bdfe21..17fe83d579 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 @@ -2174,6 +2174,8 @@ interface ICommandArgument requires INotifyPropChanged Boolean Required{ get; }; Object Value { get; set; }; + String DisplayName { get; }; + IIconInfo Icon { get; }; void ShowPicker(UInt64 hostHwnd); // todo diff --git a/src/modules/cmdpal/ext/MIcrosoft.CmdPal.Ext.Actions/Microsoft.CmdPal.Ext.Actions.csproj b/src/modules/cmdpal/ext/MIcrosoft.CmdPal.Ext.Actions/Microsoft.CmdPal.Ext.Actions.csproj index 40c3cca9f2..1073f17349 100644 --- a/src/modules/cmdpal/ext/MIcrosoft.CmdPal.Ext.Actions/Microsoft.CmdPal.Ext.Actions.csproj +++ b/src/modules/cmdpal/ext/MIcrosoft.CmdPal.Ext.Actions/Microsoft.CmdPal.Ext.Actions.csproj @@ -4,6 +4,7 @@ Microsoft.CmdPal.Ext.Bookmarks enable + preview $(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPal false false diff --git a/src/modules/cmdpal/ext/MIcrosoft.CmdPal.Ext.Actions/Pages/ActionsTestPage.cs b/src/modules/cmdpal/ext/MIcrosoft.CmdPal.Ext.Actions/Pages/ActionsTestPage.cs index bcc141a34c..a66d19e48a 100644 --- a/src/modules/cmdpal/ext/MIcrosoft.CmdPal.Ext.Actions/Pages/ActionsTestPage.cs +++ b/src/modules/cmdpal/ext/MIcrosoft.CmdPal.Ext.Actions/Pages/ActionsTestPage.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.CommandPalette.Extensions; @@ -73,13 +74,36 @@ internal sealed partial class ActionsTestPage : ListPage [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "meh")] public partial class CommandParameter : BaseObservable, ICommandArgument { - public string Name { get; set; } + public virtual string Name { get; set; } - public bool Required { get; set; } + public virtual bool Required { get; set; } - public ParameterType Type { get; set; } + public virtual ParameterType Type { get; set; } - public object? Value { get; set; } + public virtual object? Value + { + get; set + { + if (field != value) + { + field = value; + OnPropertyChanged(nameof(Value)); + OnPropertyChanged(nameof(DisplayName)); + } + } + } + + public virtual string? DisplayName => Value?.ToString() ?? string.Empty; + + public virtual IIconInfo? Icon + { + get => field; + set + { + field = value; + OnPropertyChanged(nameof(Icon)); + } + } public virtual void ShowPicker(ulong hostHwnd) { @@ -145,8 +169,12 @@ public partial class DoActionCommand : InvokableWithParams ActionInvocationResult.Success => MessageState.Success, _ => MessageState.Error, }; - var text = $"{c.Result.ToString()}: tion{c.ExtendedError}"; - var resultToast = new ToastStatusMessage(text); + var text = c.Result switch + { + ActionInvocationResult.Success => $"{c.Result.ToString()}", + _ => $"{c.Result.ToString()}: {c.ExtendedError}", + }; + var resultToast = new ToastStatusMessage(new StatusMessage() { Message = text, State = statusType }); resultToast.Show(); }); @@ -196,6 +224,8 @@ public partial class DoActionCommand : InvokableWithParams [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "meh")] public partial class ImageParameter : CommandParameter { + private string? _filePath; + public ImageParameter(string name = "", bool required = true) : base(name, required, ParameterType.Custom) { @@ -225,7 +255,11 @@ public partial class ImageParameter : CommandParameter var file = await picker.PickSingleFileAsync(); if (file != null) { - Value = file.Path; + _filePath = file.Path; + Value = _filePath; + Icon = new IconInfo(_filePath); + + // TODO! update display name } } catch (Exception ex) @@ -235,4 +269,9 @@ public partial class ImageParameter : CommandParameter } }); } + + public override string? DisplayName + { + get { return string.IsNullOrEmpty(_filePath) ? null : Path.GetFileName(_filePath); } + } } 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 c132289387..83fe021a28 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 @@ -257,6 +257,8 @@ namespace Microsoft.CommandPalette.Extensions Boolean Required{ get; }; Object Value { get; set; }; + String DisplayName { get; }; + IIconInfo Icon { get; }; void ShowPicker(UInt64 hostHwnd); // todo