Final PR cleanup

This commit is contained in:
Mike Griese
2025-11-21 10:47:51 -06:00
parent 1e71527cf2
commit 697736c5b5
11 changed files with 62 additions and 62 deletions

View File

@@ -15,9 +15,18 @@ using Windows.Foundation;
namespace Microsoft.CmdPal.Core.ViewModels;
/// <summary>
/// View models for parameters. This file has both the viewmodels for all the
/// different run types, and the page view model.
/// </summary>
#pragma warning disable SA1402 // File may only contain a single type
#pragma warning disable SA1649 // File name should match first type name
/// <summary>
/// Base class for all parameter run view models. This includes both labels and
/// parameters that accept values.
/// </summary>
public abstract partial class ParameterRunViewModel : ExtensionObjectViewModel
{
private ExtensionObject<IParameterRun> _model;
@@ -68,6 +77,10 @@ public abstract partial class ParameterRunViewModel : ExtensionObjectViewModel
}
}
/// <summary>
/// View model for label runs. This is a non-interactive run that just displays
/// text.
/// </summary>
public partial class LabelRunViewModel : ParameterRunViewModel
{
private ExtensionObject<ILabelRun> _model;
@@ -84,10 +97,6 @@ public partial class LabelRunViewModel : ParameterRunViewModel
{
base.InitializeProperties();
// if (IsInitialized)
// {
// return;
// }
var labelRun = _model.Unsafe;
if (labelRun == null)
{
@@ -99,6 +108,24 @@ public partial class LabelRunViewModel : ParameterRunViewModel
Initialized = InitializedState.Initialized;
}
protected override void FetchProperty(string propertyName)
{
var model = this._model.Unsafe;
if (model is null)
{
return; // throw?
}
switch (propertyName)
{
case nameof(ILabelRun.Text):
Text = model.Text;
break;
}
UpdateProperty(propertyName);
}
}
public partial class ParameterValueRunViewModel : ParameterRunViewModel
@@ -119,10 +146,6 @@ public partial class ParameterValueRunViewModel : ParameterRunViewModel
{
base.InitializeProperties();
// if (IsInitialized)
// {
// return;
// }
var valueRun = _model.Unsafe;
if (valueRun == null)
{
@@ -178,10 +201,6 @@ public partial class StringParameterRunViewModel : ParameterValueRunViewModel
{
base.InitializeProperties();
// if (IsInitialized)
// {
// return;
// }
var stringRun = _model.Unsafe;
if (stringRun == null)
{
@@ -271,10 +290,6 @@ public partial class CommandParameterRunViewModel : ParameterValueRunViewModel,
{
base.InitializeProperties();
// if (IsInitialized)
// {
// return;
// }
var commandRun = _model.Unsafe;
if (commandRun == null)
{
@@ -390,15 +405,10 @@ public partial class ParametersPageViewModel : PageViewModel, IDisposable
IsInitialized &&
IsLoading == false &&
!NeedsAnyValues()
// FilteredItems.Count == 0 &&
// (!_isFetching) &&
;
private readonly Lock _listLock = new();
public event TypedEventHandler<ParametersPageViewModel, object>? ItemsUpdated;
public ParametersPageViewModel(IParametersPage model, TaskScheduler scheduler, AppExtensionHost host)
: base(model, scheduler, host)
{
@@ -423,8 +433,6 @@ public partial class ParametersPageViewModel : PageViewModel, IDisposable
Command.SlowInitializeProperties();
FetchItems();
// model.ItemsChanged += Model_ItemsChanged; // TODO!
}
//// Run on background thread, from InitializeAsync or Model_ItemsChanged
@@ -488,8 +496,7 @@ public partial class ParametersPageViewModel : PageViewModel, IDisposable
() =>
{
CoreLogger.LogDebug($"raising parameter items changed, {Items.Count} parameters");
ItemsUpdated?.Invoke(this, EventArgs.Empty);
OnPropertyChanged(nameof(Items)); // TODO! hack
OnPropertyChanged(nameof(Items)); // This _could_ be promoted to a dedicated ItemsUpdated, but meh
UpdateCommand();
WeakReferenceMessenger.Default.Send(new FocusSearchBoxMessage());
@@ -589,30 +596,12 @@ public partial class ParametersPageViewModel : PageViewModel, IDisposable
public void Dispose()
{
GC.SuppressFinalize(this);
// TODO!
// _cancellationTokenSource?.Cancel();
// _cancellationTokenSource?.Dispose();
// _cancellationTokenSource = null;
// _fetchItemsCancellationTokenSource?.Cancel();
// _fetchItemsCancellationTokenSource?.Dispose();
// _fetchItemsCancellationTokenSource = null;
}
protected override void UnsafeCleanup()
{
base.UnsafeCleanup();
// _cancellationTokenSource?.Cancel();
// _fetchItemsCancellationTokenSource?.Cancel();
var model = _model.Unsafe;
if (model is not null)
{
// model.ItemsChanged -= Model_ItemsChanged;
}
lock (_listLock)
{
foreach (var item in Items)

View File

@@ -60,7 +60,7 @@ A markdown page is a page inside of command palette that displays markdown conte
```csharp
interface IMarkdownPage requires IPage {
String[] Bodies(); // TODO! should this be an IBody, so we can make it observable?
String[] Bodies();
IDetails Details();
IContextItem[] Commands { get; };
}

View File

@@ -1,7 +1,7 @@
---
author: Mike Griese
created on: 2024-07-19
last updated: 2025-09-04
last updated: 2025-11-21
issue id: n/a
---
@@ -2210,10 +2210,9 @@ Extensions will often want to provide rich search experiences for their users.
This addenda is broken into multiple draft specs currently. These represent
different approaches to the same goals.
* **A**: [Rich Search Box](./RichSearchBox-draft-A.md)
* **B**: [Prefix Search](./PrefixSearch-draft-B.md)
* **C**: [ZWSP tokens](./PlainRichSearch-draft-C.md)
* **A**: [Rich Search Box](./drafts/RichSearchBox-draft-A.md)
* **B**: [Prefix Search](./drafts/PrefixSearch-draft-B.md)
* **C**: [ZWSP tokens](./drafts/PlainRichSearch-draft-C.md)
### Nov 2025 status

View File

@@ -9,11 +9,18 @@ namespace Microsoft.CommandPalette.Extensions.Toolkit;
public partial class FilePickerParameterRun : CommandParameterRun
{
public static readonly IconInfo AddIcon = new("\uE710"); // Add
public StorageFile? File { get; private set; }
public override object? Value => File;
public override string? DisplayText { get => File != null ? File.DisplayName : "Select a file"; }
public override string? DisplayText
{
get => File != null ?
File.Name :
Properties.Resources.FilePickerParameterRun_PlaceholderText;
}
public Action<FileOpenPicker>? SetupFilePicker { get; set; }
@@ -23,15 +30,12 @@ public partial class FilePickerParameterRun : CommandParameterRun
command.FileSelected += (s, file) =>
{
File = file;
// Value = file != null ? file : (object?)null;
// OnPropertyChanged(nameof(Value));
OnPropertyChanged(nameof(NeedsValue));
OnPropertyChanged(nameof(DisplayText));
};
command.RequestCustomizePicker += ConfigureFilePicker;
PlaceholderText = "Select a file";
Icon = new IconInfo("\uE710"); // Add
PlaceholderText = Properties.Resources.FilePickerParameterRun_PlaceholderText;
Icon = AddIcon;
Command = command;
}
@@ -42,9 +46,9 @@ public partial class FilePickerParameterRun : CommandParameterRun
private sealed partial class FilePickerCommand : InvokableCommand, IRequiresHostHwnd
{
public override IconInfo Icon => new("\uE710"); // Add
public override IconInfo Icon => FilePickerParameterRun.AddIcon;
public override string Name => "Pick a file";
public override string Name => Properties.Resources.FilePickerParameterRun_PlaceholderText;
public event EventHandler<StorageFile?>? FileSelected;
@@ -83,7 +87,3 @@ public partial class FilePickerParameterRun : CommandParameterRun
picker.FileTypeFilter.Add("*");
}
}
#pragma warning restore SA1649 // File name should match first type name
#pragma warning restore SA1402 // File may only contain a single type
#nullable disable

View File

@@ -19,7 +19,7 @@ namespace Microsoft.CommandPalette.Extensions.Toolkit.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
@@ -114,6 +114,15 @@ namespace Microsoft.CommandPalette.Extensions.Toolkit.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Select a file.
/// </summary>
internal static string FilePickerParameterRun_PlaceholderText {
get {
return ResourceManager.GetString("FilePickerParameterRun_PlaceholderText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Open.
/// </summary>

View File

@@ -157,4 +157,7 @@
<value>Copy failed ({0}). Please try again.</value>
<comment>{0} is the error message</comment>
</data>
<data name="FilePickerParameterRun_PlaceholderText" xml:space="preserve">
<value>Select a file</value>
</data>
</root>