| 1 | using System.Globalization; |
| 2 | using System.Threading.Tasks; |
| 3 | using CascadeIDE.Features.UiChrome; |
| 4 | using CascadeIDE.Lang; |
| 5 | using CascadeIDE.Models; |
| 6 | using CascadeIDE.Services; |
| 7 | using CascadeIDE.ViewModels; |
| 8 | using CommunityToolkit.Mvvm.Input; |
| 9 | |
| 10 | namespace CascadeIDE.Features.Shell; |
| 11 | |
| 12 | /// <summary>Relay: меню приложения, тема, язык, окна-хосты (композитор — <see cref="MainWindowViewModel"/>).</summary> |
| 13 | public sealed partial class MainWindowApplicationShellViewModel : ViewModelBase |
| 14 | { |
| 15 | private readonly MainWindowViewModel _host; |
| 16 | |
| 17 | public MainWindowApplicationShellViewModel(MainWindowViewModel host) => _host = host; |
| 18 | |
| 19 | [RelayCommand] |
| 20 | private void OpenSolution() => _host.RequestOpenSolution?.Invoke(); |
| 21 | |
| 22 | [RelayCommand] |
| 23 | private void CreateNewSolution() => _host.RequestCreateNewSolution?.Invoke(); |
| 24 | |
| 25 | [RelayCommand] |
| 26 | private void OpenFolder() => _host.RequestOpenFolder?.Invoke(); |
| 27 | |
| 28 | [RelayCommand] |
| 29 | private void OpenFileFromDialog() => _host.RequestOpenFile?.Invoke(); |
| 30 | |
| 31 | [RelayCommand] |
| 32 | private void Exit() => _host.RequestClose?.Invoke(); |
| 33 | |
| 34 | [RelayCommand] |
| 35 | private void About() => _host.RequestShowAbout?.Invoke(); |
| 36 | |
| 37 | [RelayCommand] |
| 38 | private void OpenSettings() |
| 39 | { |
| 40 | var settingsPresentation = _host.McpSettings.Ai.Chat.SettingsPresentation ?? "mfd"; |
| 41 | if (string.Equals(settingsPresentation.Trim(), "window", StringComparison.OrdinalIgnoreCase)) |
| 42 | { |
| 43 | _host.RequestOpenSettings?.Invoke(); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | _host.ApplyMfdRegionExpanded(true); |
| 48 | _host.TryNavigateToMfdShellPage(MfdShellPage.AiChatSettings); |
| 49 | } |
| 50 | |
| 51 | [RelayCommand] |
| 52 | private void OpenFullSettingsWindow() => _host.RequestOpenSettings?.Invoke(); |
| 53 | |
| 54 | [RelayCommand(CanExecute = nameof(CanToggleMfdHostWindow))] |
| 55 | private void ToggleMfdHostWindow() => _host.RequestToggleMfdHostWindow?.Invoke(); |
| 56 | |
| 57 | private bool CanToggleMfdHostWindow() => _host.PresentationRequestsMfdHostWindow; |
| 58 | |
| 59 | [RelayCommand(CanExecute = nameof(CanTogglePmSplitHostWindow))] |
| 60 | private void TogglePmSplitHostWindow() => _host.RequestTogglePmSplitHostWindow?.Invoke(); |
| 61 | |
| 62 | private bool CanTogglePmSplitHostWindow() => _host.PresentationRequestsPmSplitHostWindow; |
| 63 | |
| 64 | [RelayCommand] |
| 65 | private async Task ApplyDarkThemeAsync() => |
| 66 | await UiThemeApply.ApplyOnUiThreadAsync(UiThemeApply.GetDarkThemeJson()); |
| 67 | |
| 68 | [RelayCommand] |
| 69 | private async Task ApplyLightThemeAsync() => |
| 70 | await UiThemeApply.ApplyOnUiThreadAsync(UiThemeApply.GetLightThemeJson()); |
| 71 | |
| 72 | [RelayCommand] |
| 73 | private async Task ApplyCursorLikeThemeAsync() => |
| 74 | await UiThemeApply.ApplyOnUiThreadAsync(UiThemeApply.GetCursorLikeThemeJson()); |
| 75 | |
| 76 | [RelayCommand] |
| 77 | private async Task ApplyPowerClassicThemeAsync() => |
| 78 | await UiThemeApply.ApplyOnUiThreadAsync(UiThemeApply.GetPowerThemeJson()); |
| 79 | |
| 80 | [RelayCommand] |
| 81 | private void SetUiLanguage(string? cultureName) |
| 82 | { |
| 83 | if (string.IsNullOrWhiteSpace(cultureName)) |
| 84 | return; |
| 85 | try |
| 86 | { |
| 87 | var culture = CultureInfo.GetCultureInfo(cultureName.Trim()); |
| 88 | LocViewModel.Current?.SetCulture(culture); |
| 89 | _host.McpNotifyPropertyChanged(nameof(MainWindowViewModel.SafetyLevelDescription)); |
| 90 | _host.McpSettings.Workspace.Culture = culture.Name; |
| 91 | _host.HostSaveSettingsIfChanged(); |
| 92 | } |
| 93 | catch (CultureNotFoundException) |
| 94 | { |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | [RelayCommand] |
| 99 | private void ResetUiLanguageToSystem() |
| 100 | { |
| 101 | _host.McpSettings.Workspace.Culture = ""; |
| 102 | UiCulture.ApplyFromSystem(); |
| 103 | _host.McpNotifyPropertyChanged(nameof(MainWindowViewModel.SafetyLevelDescription)); |
| 104 | _host.HostSaveSettingsIfChanged(); |
| 105 | } |
| 106 | |
| 107 | [RelayCommand] |
| 108 | private async Task OpenThemeFileAsync() |
| 109 | { |
| 110 | var path = _host.RequestOpenThemeFile != null ? await _host.RequestOpenThemeFile() : null; |
| 111 | if (string.IsNullOrEmpty(path)) |
| 112 | return; |
| 113 | await UiThemeApply.ApplyOnUiThreadAsync(UiThemeApply.GetThemeJsonFromFile(path)); |
| 114 | } |
| 115 | } |
| 116 | |