Adds optional minOsBuild/maxOsBuild to a command; the WPF catalog projection hides commands that do not apply to the current OS build, so Windows 11-only tweaks never appear on Windows 10 (and vice-versa). - Domain: CommandDefinition gains MinOsBuild/MaxOsBuild + the pure AppliesToOsBuild(build) predicate (no Win32 dependency). - Infrastructure: CommandDto maps the fields; CatalogLoader validates positive values and maxOsBuild >= minOsBuild. ICatalogProvider still returns the full set, so the Debug panel and tests are unaffected. - WPF: CatalogViewModelBuilder.Build(catalog, osBuild) filters once, centrally — covering the list, palette, category counts and every dashboard. The OS build comes from the existing ISystemInfoService. - Catalog: gate the Win11 context-menu, taskbar-alignment and clock-seconds tweaks (minOsBuild 22000 / 22621). Tests: AppliesToOsBuild theory + catalog range/positive validation; 189 pass. App launches without startup regressions. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using System.Collections.ObjectModel;
|
|
using CommandForge.Application.Ports;
|
|
using CommandForge.Application.Search;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
namespace CommandForge.Wpf.ViewModels;
|
|
|
|
/// <summary>Command Palette (Ctrl+K): fuzzy search across the entire catalog.</summary>
|
|
public sealed partial class CommandPaletteViewModel : ObservableObject
|
|
{
|
|
private readonly IReadOnlyList<SearchableCommand> _searchable;
|
|
private readonly Dictionary<string, CommandItemViewModel> _itemsById;
|
|
|
|
public CommandPaletteViewModel(ICatalogProvider catalog, ISystemInfoService systemInfo)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(catalog);
|
|
ArgumentNullException.ThrowIfNull(systemInfo);
|
|
var vms = CatalogViewModelBuilder.Build(catalog, systemInfo.GetStatus().OsBuild);
|
|
_searchable = vms.Searchable;
|
|
_itemsById = vms.Items.ToDictionary(i => i.Command.Id, StringComparer.Ordinal);
|
|
ApplyFilter();
|
|
}
|
|
|
|
public ObservableCollection<CommandItemViewModel> Results { get; } = [];
|
|
|
|
/// <summary>Raised with the chosen command id when the user accepts a result.</summary>
|
|
public event Action<string>? CommandChosen;
|
|
|
|
[ObservableProperty]
|
|
private string _searchText = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private CommandItemViewModel? _selectedResult;
|
|
|
|
partial void OnSearchTextChanged(string value) => ApplyFilter();
|
|
|
|
[RelayCommand]
|
|
private void Accept()
|
|
{
|
|
if (SelectedResult is not null)
|
|
{
|
|
CommandChosen?.Invoke(SelectedResult.Command.Id);
|
|
}
|
|
}
|
|
|
|
private void ApplyFilter()
|
|
{
|
|
var hits = SearchCommandsUseCase.Search(_searchable, SearchText);
|
|
Results.Clear();
|
|
foreach (var hit in hits)
|
|
{
|
|
var item = _itemsById[hit.Command.Id];
|
|
item.TitleMatches = hit.TitleMatches;
|
|
Results.Add(item);
|
|
}
|
|
|
|
SelectedResult = Results.Count > 0 ? Results[0] : null;
|
|
}
|
|
}
|