| 1 | using System.ComponentModel; |
| 2 | using CascadeIDE.Features.Editor; |
| 3 | using CascadeIDE.Features.Editor.Application; |
| 4 | using CascadeIDE.Features.Editor.Application.Presentation; |
| 5 | using CascadeIDE.Services; |
| 6 | |
| 7 | namespace CascadeIDE.ViewModels; |
| 8 | |
| 9 | /// <summary> |
| 10 | /// Wave 2: <see cref="EditorWorkspaceViewModel"/> + прокси на MWVM для существующих привязок и MCP. |
| 11 | /// </summary> |
| 12 | public partial class MainWindowViewModel |
| 13 | { |
| 14 | /// <summary>Активный документ в редакторе (путь, текст, selection, HUD, брейкпоинты).</summary> |
| 15 | public EditorWorkspaceViewModel Editor { get; private set; } = null!; |
| 16 | |
| 17 | public string? CurrentFilePath |
| 18 | { |
| 19 | get => Editor.CurrentFilePath; |
| 20 | set => Editor.CurrentFilePath = value; |
| 21 | } |
| 22 | |
| 23 | public bool IsLoadingCurrentFile |
| 24 | { |
| 25 | get => Editor.IsLoadingCurrentFile; |
| 26 | set => Editor.IsLoadingCurrentFile = value; |
| 27 | } |
| 28 | |
| 29 | public string EditorText |
| 30 | { |
| 31 | get => Editor.EditorText; |
| 32 | set => Editor.EditorText = value; |
| 33 | } |
| 34 | |
| 35 | public int? EditorSelectionStart |
| 36 | { |
| 37 | get => Editor.EditorSelectionStart; |
| 38 | set => Editor.EditorSelectionStart = value; |
| 39 | } |
| 40 | |
| 41 | public int? EditorSelectionLength |
| 42 | { |
| 43 | get => Editor.EditorSelectionLength; |
| 44 | set => Editor.EditorSelectionLength = value; |
| 45 | } |
| 46 | |
| 47 | public bool IsMarkdownFile => Editor.IsMarkdownFile; |
| 48 | |
| 49 | public bool IsMarkdownPreviewVisible => Editor.IsMarkdownPreviewVisible; |
| 50 | |
| 51 | public IReadOnlyList<int> BreakpointLinesInCurrentFile => Editor.BreakpointLinesInCurrentFile; |
| 52 | |
| 53 | public IReadOnlyList<int> AllBreakpointLinesInCurrentFile => Editor.AllBreakpointLinesInCurrentFile; |
| 54 | |
| 55 | public IReadOnlyList<int> GetAllBreakpointLinesForFile(string? filePath) => |
| 56 | Editor.GetAllBreakpointLinesForFile(filePath); |
| 57 | |
| 58 | public string? DebugPositionFile |
| 59 | { |
| 60 | get => Editor.DebugPositionFile; |
| 61 | set => Editor.DebugPositionFile = value; |
| 62 | } |
| 63 | |
| 64 | public int DebugPositionLine |
| 65 | { |
| 66 | get => Editor.DebugPositionLine; |
| 67 | set => Editor.DebugPositionLine = value; |
| 68 | } |
| 69 | |
| 70 | public int GetDebugCurrentLineForFile(string? filePath) => Editor.GetDebugCurrentLineForFile(filePath); |
| 71 | |
| 72 | public int DebugCurrentLineInCurrentFile => Editor.DebugCurrentLineInCurrentFile; |
| 73 | |
| 74 | public string? EditorHudBannerText |
| 75 | { |
| 76 | get => Editor.EditorHudBannerText; |
| 77 | set => Editor.EditorHudBannerText = value; |
| 78 | } |
| 79 | |
| 80 | public bool IsEditorHudBannerVisible => Editor.IsEditorHudBannerVisible; |
| 81 | |
| 82 | public bool IsEditorHudChromeVisible => IsEditorHudBannerVisible; |
| 83 | |
| 84 | public IReadOnlyList<EditorTrailingInlayPart> GetEditorInlineHintsForFile(string filePath, string sourceText) => |
| 85 | Editor.GetEditorInlineHintsForFile(filePath, sourceText); |
| 86 | |
| 87 | public IReadOnlyList<EditorDebugHintStrip> GetEditorDebugHintsForFile(string filePath, string sourceText) => |
| 88 | Editor.GetEditorDebugHintsForFile(filePath, sourceText); |
| 89 | |
| 90 | internal void SetActiveEditorStabilizedHudHandler(Action<EditorInputDelta>? handler) => |
| 91 | Editor.SetActiveEditorStabilizedHudHandler(handler); |
| 92 | |
| 93 | internal void ClearActiveEditorStabilizedHudHandlerIfEquals(Action<EditorInputDelta>? handler) => |
| 94 | Editor.ClearActiveEditorStabilizedHudHandlerIfEquals(handler); |
| 95 | |
| 96 | internal bool TryPostEditorStabilizedInput(EditorInputDelta delta) => |
| 97 | Editor.TryPostEditorStabilizedInput(delta); |
| 98 | |
| 99 | internal void ShutdownEditorStabilizedInput() => Editor.ShutdownEditorStabilizedInput(); |
| 100 | |
| 101 | private void OnEditorWorkspacePropertyChanged(object? sender, PropertyChangedEventArgs e) |
| 102 | { |
| 103 | if (e.PropertyName is null) |
| 104 | return; |
| 105 | |
| 106 | OnPropertyChanged(e.PropertyName); |
| 107 | |
| 108 | if (e.PropertyName == nameof(EditorWorkspaceViewModel.CurrentFilePath)) |
| 109 | { |
| 110 | OnPropertyChanged(nameof(IsMarkdownFile)); |
| 111 | OnPropertyChanged(nameof(IsMarkdownPreviewVisible)); |
| 112 | OnPropertyChanged(nameof(BreakpointLinesInCurrentFile)); |
| 113 | OnPropertyChanged(nameof(AllBreakpointLinesInCurrentFile)); |
| 114 | OnPropertyChanged(nameof(DebugCurrentLineInCurrentFile)); |
| 115 | } |
| 116 | else if (e.PropertyName == nameof(EditorWorkspaceViewModel.IsLoadingCurrentFile)) |
| 117 | { |
| 118 | OnPropertyChanged(nameof(IsMarkdownPreviewVisible)); |
| 119 | } |
| 120 | else if (e.PropertyName is nameof(EditorWorkspaceViewModel.DebugPositionFile) |
| 121 | or nameof(EditorWorkspaceViewModel.DebugPositionLine)) |
| 122 | { |
| 123 | OnPropertyChanged(nameof(DebugCurrentLineInCurrentFile)); |
| 124 | } |
| 125 | else if (e.PropertyName == nameof(EditorWorkspaceViewModel.EditorHudBannerText)) |
| 126 | { |
| 127 | OnPropertyChanged(nameof(IsEditorHudBannerVisible)); |
| 128 | OnPropertyChanged(nameof(IsEditorHudChromeVisible)); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | /// <summary>Бывший <c>OnCurrentFilePathChanged</c> из DocumentsDock.</summary> |
| 133 | internal void OnEditorCurrentFilePathChanged() |
| 134 | { |
| 135 | if (!TryPreserveControlFlowNavigateCaretOnFileChange()) |
| 136 | UpdateCodeNavigationMapCaretOffset(null); |
| 137 | RefreshLocBadgeFromCurrentFile(); |
| 138 | Editor.RefreshEditorHudBanner(); |
| 139 | ScheduleWorkspaceNavigationMapRefresh(); |
| 140 | } |
| 141 | |
| 142 | internal void OnEditorIsLoadingCurrentFileChanged() => |
| 143 | OnPropertyChanged(nameof(IsMarkdownPreviewVisible)); |
| 144 | |
| 145 | /// <summary>Бывший <c>OnEditorTextChanged</c> из DocumentsDock.</summary> |
| 146 | internal void OnEditorTextChanged(string value) |
| 147 | { |
| 148 | Documents.ApplyEditorTextFromHost(value); |
| 149 | OnPropertyChanged(nameof(EditorTextGroup2)); |
| 150 | OnPropertyChanged(nameof(EditorTextGroup3)); |
| 151 | Editor.RefreshEditorHudBanner(); |
| 152 | } |
| 153 | |
| 154 | internal void OnWorkspaceDiagnosticsChangedForHud() => Editor.OnWorkspaceDiagnosticsChangedForHud(); |
| 155 | |
| 156 | private void ScheduleEditorHudBannerRefresh() => Editor.ScheduleEditorHudBannerRefresh(); |
| 157 | |
| 158 | internal void SetStabilizedEditorHudContext(EditorHudStabilizedContext? context) => |
| 159 | Editor.SetStabilizedEditorHudContext(context); |
| 160 | |
| 161 | private void RefreshEditorHudBanner() => Editor.RefreshEditorHudBanner(); |
| 162 | |
| 163 | internal async Task<string> DebugLaunchInteractiveAsync() => |
| 164 | await Debug.DebugLaunchInteractiveAsync().ConfigureAwait(true); |
| 165 | } |
| 166 | |