Forge
csharpdeeb25a2
1#nullable enable
2using CascadeIDE.Features.UiChrome;
3
4namespace CascadeIDE.ViewModels;
5
6/// <summary>C# 14 extension members: <see cref="MelodyPaletteLine"/> → строка палитры команд.</summary>
7public static class MelodyPaletteLineCommandPaletteExtensions
8{
9 extension(MelodyPaletteLine line)
10 {
11 public IdeCommandPaletteRowViewModel? ToCommandPaletteRow(HotkeyGestureMap hotkeys, UiModeFamily family) =>
12 line switch
13 {
14 MelodyPaletteHint hint => new IdeCommandPaletteRowViewModel(hint.Title, hint.Category),
15 MelodyPaletteCommand cmd when ParametricIntentMelody.IsPaletteOnlyAlias(cmd.Alias) && string.IsNullOrWhiteSpace(cmd.ArgsJson) =>
16 new IdeCommandPaletteRowViewModel(
17 ParametricIntentMelody.BuildAliasUsageHintForPalette(cmd.Alias),
18 ParametricIntentMelody.BuildAliasUsageCategoryForPalette(cmd.Alias)),
19 MelodyPaletteCommand cmd => IdeCommandPaletteCatalog.All.FirstOrDefault(e => e.CommandId == cmd.CommandId) is { } entry
20 ? new IdeCommandPaletteRowViewModel(entry, hotkeys.GetDisplayHint(entry.CommandId), family, cmd.Alias, cmd.ArgsJson)
21 : new IdeCommandPaletteRowViewModel(
22 cmd.CommandId,
23 cmd.Alias,
24 IdeCommandDocDisplay.ShortTitleForCommandId(cmd.CommandId),
25 hotkeys.GetDisplayHint(cmd.CommandId),
26 cmd.ArgsJson),
27 _ => throw new InvalidOperationException($"Unknown melody line: {line.GetType().Name}"),
28 };
29 }
30}
31
View only · write via MCP/CIDE