mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
Allow CommandProviders to ItemsChanged themselves (#282)
Specs out #277 Extensions might want to change their list of top-level commands. Classic example is the bookmarks provider, or the spongebot. The API needs to allow this. This wasn't a problem in the prototype, because the prototype literally fetched the commands every time it went home.
This commit is contained in:
@@ -1371,7 +1371,7 @@ interface IFallbackCommandItem requires ICommandItem {
|
||||
IFallbackHandler FallbackHandler{ get; };
|
||||
};
|
||||
|
||||
interface ICommandProvider requires Windows.Foundation.IClosable
|
||||
interface ICommandProvider requires Windows.Foundation.IClosable, INotifyItemsChanged
|
||||
{
|
||||
String Id { get; };
|
||||
String DisplayName { get; };
|
||||
@@ -1397,6 +1397,14 @@ actions, or they can be pages that the user can navigate to.
|
||||
simpler form of `IListItem`, which can be displayed even as a stub (as described
|
||||
in [Caching](#caching)), before the extension process is loaded.
|
||||
|
||||
The `INotifyItemsChanged` interface can be used to let DevPal know at runtime
|
||||
that the list of top-level command items has changed. This can be used for
|
||||
something like an extension that might require the user to login before
|
||||
accessing certain pages within the extension. Command Providers which are
|
||||
`Frozen=true` can also use this event to change their list of cached commands,
|
||||
since the only time an extension can raise this event is when it's already
|
||||
running.
|
||||
|
||||
`Id` is only necessary to set if your extension implements multiple providers in
|
||||
the same package identity. This is an uncommon scenario which most developers
|
||||
shouldn't need to worry about. If you do set `Id`, it should be a stable string
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// 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.CmdPal.Extensions.Helpers;
|
||||
|
||||
public abstract partial class CommandProvider : ICommandProvider
|
||||
@@ -20,6 +22,8 @@ public abstract partial class CommandProvider : ICommandProvider
|
||||
|
||||
public IconDataType Icon { get => _icon; protected set => _icon = value; }
|
||||
|
||||
public event TypedEventHandler<object, ItemsChangedEventArgs>? ItemsChanged;
|
||||
|
||||
public abstract ICommandItem[] TopLevelCommands();
|
||||
|
||||
public virtual IFallbackCommandItem[]? FallbackCommands()
|
||||
@@ -47,4 +51,15 @@ public abstract partial class CommandProvider : ICommandProvider
|
||||
}
|
||||
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize
|
||||
|
||||
protected void RaiseItemsChanged(int totalItems)
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO #181 - This is the same thing that BaseObservable has to deal with.
|
||||
ItemsChanged?.Invoke(this, new ItemsChangedEventArgs(totalItems));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ namespace Microsoft.CmdPal.Extensions
|
||||
};
|
||||
|
||||
[contract(Microsoft.CmdPal.Extensions.ExtensionsContract, 1)]
|
||||
interface ICommandProvider requires Windows.Foundation.IClosable
|
||||
interface ICommandProvider requires Windows.Foundation.IClosable, INotifyItemsChanged
|
||||
{
|
||||
String Id { get; };
|
||||
String DisplayName { get; };
|
||||
|
||||
Reference in New Issue
Block a user