| 1 | #nullable enable |
| 2 | |
| 3 | using CascadeIDE.Features.Chat; |
| 4 | |
| 5 | namespace CascadeIDE.Features.Cockpit; |
| 6 | |
| 7 | /// <summary>Реализация <see cref="ICockpitCommandLineSession"/> поверх <see cref="ChatPanelViewModel"/>.</summary> |
| 8 | internal sealed class CockpitCommandLineSession : ICockpitCommandLineSession |
| 9 | { |
| 10 | private readonly ChatPanelViewModel _owner; |
| 11 | private readonly SlashCommandPreviewService _previewService; |
| 12 | private CockpitCommandLineHostKind _activeHost = CockpitCommandLineHostKind.Intercom; |
| 13 | |
| 14 | public CockpitCommandLineSession(ChatPanelViewModel owner, SlashCommandPreviewService previewService) |
| 15 | { |
| 16 | _owner = owner; |
| 17 | _previewService = previewService; |
| 18 | } |
| 19 | |
| 20 | public bool IsOpen => _owner.IsCockpitCommandLineOpen; |
| 21 | |
| 22 | public CockpitCommandLineHostKind ActiveHost => _activeHost; |
| 23 | |
| 24 | public string BufferText |
| 25 | { |
| 26 | get => _owner.CockpitCommandLineText; |
| 27 | set => _owner.CockpitCommandLineText = value; |
| 28 | } |
| 29 | |
| 30 | public int CaretIndex |
| 31 | { |
| 32 | get => _owner.CockpitCommandLineCaretIndex; |
| 33 | set => _owner.CockpitCommandLineCaretIndex = value; |
| 34 | } |
| 35 | |
| 36 | public string? PreviewSummary => |
| 37 | string.IsNullOrWhiteSpace(_owner.CommandLineSlashPreview) ? null : _owner.CommandLineSlashPreview; |
| 38 | |
| 39 | public SlashCommandPreviewKind PreviewKind => _owner.CommandLineSlashPreviewKind; |
| 40 | |
| 41 | public string? PreviewAccessibilityToolTip => _owner.CommandLineSlashPreviewToolTip; |
| 42 | |
| 43 | public void Open(CockpitCommandLineHostKind? host = null, string initialText = "/") |
| 44 | { |
| 45 | _activeHost = host ?? CockpitCommandLineHostKind.Intercom; |
| 46 | _owner.OpenCockpitCommandLine(initialText); |
| 47 | _owner.NotifyCockpitCommandLinePresentationChanged(); |
| 48 | } |
| 49 | |
| 50 | public void Close() => _owner.CloseCockpitCommandLine(); |
| 51 | |
| 52 | public void RefreshPreview() => _owner.UpdateSlashPreview(TciInputSurface.CockpitCommandLine); |
| 53 | |
| 54 | public async Task<CockpitCommandLineCommitResult> TryCommitAsync(CancellationToken cancellationToken = default) |
| 55 | { |
| 56 | var success = await _owner.TryCommitCockpitCommandLineAsync(cancellationToken).ConfigureAwait(false); |
| 57 | return new(true, success, null); |
| 58 | } |
| 59 | } |
| 60 | |