mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
Have the button change its text when a value is picked
This is incredibly incredible
This commit is contained in:
@@ -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."
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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<object> 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)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<PropertyGroup>
|
||||
<RootNamespace>Microsoft.CmdPal.Ext.Bookmarks</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPal</OutputPath>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
|
||||
@@ -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); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user