mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
> [!IMPORTANT] > For extension developers, this release includes a new required `string Id` property for `FallbackCommandItem`. While your existing extensions will continue to work, without this `Id` being set, your fallbacks will not display and will not be rankable. > Before this is released, you will want to prepare your extension fallbacks. > > As an example, we are naming our built-in extensions as: > - Calculator extension provider Id: `com.microsoft.cmdpal.builtin.calculator` > - Calculator extension fallback: `com.microsoft.cmdpal.builtin.calculator.fallback` > > While the content of the Id isn't important, what is important is that it is unique to your extension and fallback to avoid conflicting with other extensions. Now the good stuff: ## What the heck does it do!? ### The backstory In PowerToys 0.95, we released performance improvements to Command Palette. One of the many ways we improved its speed is by no longer ranking fallback commands with other "top level" commands. Instead, all fallbacks would surface at the bottom of the results and be listed in the order they were registered with Command Palette. But this was only a temporary solution until the work included in this pull request was ready. In reality, not all fallbacks were treated equally. We marked the calculator and run fallbacks as "special." Special fallbacks **were** ranked like top-level commands and allowed to surface to the top of the results. ### The new "hotness" This PR brings the power of fallback management back to the people. In the Command Palette settings, you, dear user, can specify what order you want fallbacks to display in at the bottom of the results. This keeps those fallbacks unranked by Command Palette but displays them in an order that makes sense for you. But keep in mind, these will still live at the bottom of search results. But alas, we have also heard your cries that you'd like _some_ fallbacks to be ranked by Command Palette and surface to the top of the results. So, this PR allows you to mark any fallback as "special" by choosing to include them in the global results. Special (Global) fallbacks are treated like "top level" commands and appear in the search result based on their title & description. ### Screenshots/video <img width="1005" height="611" alt="image" src="https://github.com/user-attachments/assets/8ba5d861-f887-47ed-8552-ba78937322d2" /> <img width="1501" height="973" alt="image" src="https://github.com/user-attachments/assets/9edb7675-8084-4f14-8bdc-72d7d06d500e" /> <img width="706" height="744" alt="image" src="https://github.com/user-attachments/assets/81ae0252-b87d-4172-a5ea-4d3102134baf" /> <img width="666" height="786" alt="image" src="https://github.com/user-attachments/assets/acb76acf-531d-4e60-bb44-d1edeec77dce" /> ### GitHub issue maintenance details Closes #38312 Closes #38288 Closes #42524 Closes #41024 Closes #40351 Closes #41696 Closes #40193 --------- Co-authored-by: Niels Laute <niels.laute@live.nl> Co-authored-by: Jiří Polášek <me@jiripolasek.com>
87 lines
2.5 KiB
C#
87 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 CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
using Microsoft.CmdPal.Core.ViewModels;
|
|
using Microsoft.CmdPal.UI.ViewModels.Messages;
|
|
|
|
namespace Microsoft.CmdPal.UI.ViewModels;
|
|
|
|
public partial class FallbackSettingsViewModel : ObservableObject
|
|
{
|
|
private readonly SettingsModel _settings;
|
|
private readonly FallbackSettings _fallbackSettings;
|
|
|
|
public string DisplayName { get; private set; } = string.Empty;
|
|
|
|
public IconInfoViewModel Icon { get; private set; } = new(null);
|
|
|
|
public string Id { get; private set; } = string.Empty;
|
|
|
|
public bool IsEnabled
|
|
{
|
|
get => _fallbackSettings.IsEnabled;
|
|
set
|
|
{
|
|
if (value != _fallbackSettings.IsEnabled)
|
|
{
|
|
_fallbackSettings.IsEnabled = value;
|
|
|
|
if (!_fallbackSettings.IsEnabled)
|
|
{
|
|
_fallbackSettings.IncludeInGlobalResults = false;
|
|
}
|
|
|
|
Save();
|
|
OnPropertyChanged(nameof(IsEnabled));
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IncludeInGlobalResults
|
|
{
|
|
get => _fallbackSettings.IncludeInGlobalResults;
|
|
set
|
|
{
|
|
if (value != _fallbackSettings.IncludeInGlobalResults)
|
|
{
|
|
_fallbackSettings.IncludeInGlobalResults = value;
|
|
|
|
if (!_fallbackSettings.IsEnabled)
|
|
{
|
|
_fallbackSettings.IsEnabled = true;
|
|
}
|
|
|
|
Save();
|
|
OnPropertyChanged(nameof(IncludeInGlobalResults));
|
|
}
|
|
}
|
|
}
|
|
|
|
public FallbackSettingsViewModel(
|
|
TopLevelViewModel fallback,
|
|
FallbackSettings fallbackSettings,
|
|
SettingsModel settingsModel,
|
|
ProviderSettingsViewModel providerSettings)
|
|
{
|
|
_settings = settingsModel;
|
|
_fallbackSettings = fallbackSettings;
|
|
|
|
Id = fallback.Id;
|
|
DisplayName = string.IsNullOrWhiteSpace(fallback.DisplayTitle)
|
|
? (string.IsNullOrWhiteSpace(fallback.Title) ? providerSettings.DisplayName : fallback.Title)
|
|
: fallback.DisplayTitle;
|
|
|
|
Icon = new(fallback.InitialIcon);
|
|
Icon.InitializeProperties();
|
|
}
|
|
|
|
private void Save()
|
|
{
|
|
SettingsModel.SaveSettings(_settings);
|
|
WeakReferenceMessenger.Default.Send<ReloadCommandsMessage>(new());
|
|
}
|
|
}
|