mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
We learned a lot about adding interfaces in WinRT this week. I figured I'd send a PR to write it all down.
73 lines
2.5 KiB
C#
73 lines
2.5 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using Windows.Foundation;
|
|
|
|
namespace Microsoft.CommandPalette.Extensions.Toolkit;
|
|
|
|
public abstract partial class CommandProvider : ICommandProvider, ICommandProvider2
|
|
{
|
|
public virtual string Id { get; protected set; } = string.Empty;
|
|
|
|
public virtual string DisplayName { get; protected set; } = string.Empty;
|
|
|
|
public virtual IconInfo Icon { get; protected set; } = new IconInfo();
|
|
|
|
public event TypedEventHandler<object, IItemsChangedEventArgs>? ItemsChanged;
|
|
|
|
public abstract ICommandItem[] TopLevelCommands();
|
|
|
|
public virtual IFallbackCommandItem[]? FallbackCommands() => null;
|
|
|
|
public virtual ICommand? GetCommand(string id) => null;
|
|
|
|
public virtual ICommandSettings? Settings { get; protected set; }
|
|
|
|
public virtual bool Frozen { get; protected set; } = true;
|
|
|
|
IIconInfo ICommandProvider.Icon => Icon;
|
|
|
|
public virtual void InitializeWithHost(IExtensionHost host) => ExtensionHost.Initialize(host);
|
|
|
|
#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
|
|
public virtual void Dispose()
|
|
{
|
|
}
|
|
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize
|
|
|
|
protected void RaiseItemsChanged(int totalItems = -1)
|
|
{
|
|
try
|
|
{
|
|
// TODO #181 - This is the same thing that BaseObservable has to deal with.
|
|
ItemsChanged?.Invoke(this, new ItemsChangedEventArgs(totalItems));
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// This is used to manually populate the WinRT type cache in CmdPal with
|
|
/// any interfaces that might not follow a straight linear path of requires.
|
|
///
|
|
/// You don't need to call this as an extension author.
|
|
/// </summary>
|
|
/// <returns>an array of objects that implement all the leaf interfaces we support</returns>
|
|
public object[] GetApiExtensionStubs()
|
|
{
|
|
return [new SupportCommandsWithProperties()];
|
|
}
|
|
|
|
/// <summary>
|
|
/// A stub class which implements IExtendedAttributesProvider. Just marshalling this
|
|
/// across the ABI will be enough for CmdPal to store IExtendedAttributesProvider in
|
|
/// its type cache.
|
|
/// </summary>
|
|
private sealed partial class SupportCommandsWithProperties : IExtendedAttributesProvider
|
|
{
|
|
public IDictionary<string, object>? GetProperties() => null;
|
|
}
|
|
}
|