| 1 | using Avalonia.Controls; |
| 2 | using CascadeIDE.Cockpit.Composition.HostSurface; |
| 3 | using CascadeIDE.Models; |
| 4 | using CascadeIDE.Services; |
| 5 | using CascadeIDE.Services.Presentation; |
| 6 | using CascadeIDE.Views; |
| 7 | |
| 8 | namespace CascadeIDE.ViewModels; |
| 9 | |
| 10 | /// <summary>Presentation tier compact vs cockpit (ADR 0171).</summary> |
| 11 | public partial class MainWindowViewModel |
| 12 | { |
| 13 | private PresentationMonitorSnapshot _presentationMonitorSnapshot = PresentationMonitorSnapshot.SingleFallback; |
| 14 | private PresentationTierKind _effectivePresentationTier = PresentationTierKind.Compact; |
| 15 | |
| 16 | PresentationTierKind IMainWindowHostSurfaceInput.EffectivePresentationTier => _effectivePresentationTier; |
| 17 | |
| 18 | public PresentationTierKind EffectivePresentationTier => _effectivePresentationTier; |
| 19 | |
| 20 | public bool IsCompactPresentationTier => _effectivePresentationTier == PresentationTierKind.Compact; |
| 21 | |
| 22 | public bool IsCockpitPresentationTier => _effectivePresentationTier == PresentationTierKind.Cockpit; |
| 23 | |
| 24 | public bool UsesUltrawideCockpitLayout => |
| 25 | IsCockpitPresentationTier |
| 26 | && _presentationMonitorSnapshot.PhysicalScreenCount == 1 |
| 27 | && PresentationTierResolver.IsUltrawideCockpitCapable( |
| 28 | _settings.Display.Presentation, |
| 29 | _presentationMonitorSnapshot); |
| 30 | |
| 31 | public bool ShouldShowPresentationTierFirstRunWizard => |
| 32 | !_settings.Display.Presentation.TierFirstRunCompleted |
| 33 | && string.Equals( |
| 34 | _settings.Display.Presentation.Tier?.Trim(), |
| 35 | PresentationTierKindExtensions.AutoValue, |
| 36 | StringComparison.OrdinalIgnoreCase); |
| 37 | |
| 38 | private void InitializePresentationTier() |
| 39 | { |
| 40 | _presentationMonitorSnapshot = PresentationMonitorProbe.Capture(); |
| 41 | _effectivePresentationTier = PresentationTierResolver.Resolve( |
| 42 | _settings.Display.Presentation, |
| 43 | _presentationParse, |
| 44 | _presentationMonitorSnapshot); |
| 45 | |
| 46 | ApplyPresentationTierLayoutDefaults(); |
| 47 | ApplyIntercomHostPresentation(); |
| 48 | OnPropertyChanged(nameof(EffectivePresentationTier)); |
| 49 | OnPropertyChanged(nameof(IsCompactPresentationTier)); |
| 50 | OnPropertyChanged(nameof(IsCockpitPresentationTier)); |
| 51 | OnPropertyChanged(nameof(UsesUltrawideCockpitLayout)); |
| 52 | OnPropertyChanged(nameof(OpenMfdHostWindowOnStartup)); |
| 53 | OnPropertyChanged(nameof(OpenPfdHostWindowOnStartup)); |
| 54 | OnPropertyChanged(nameof(MainGridColumnDefinitions)); |
| 55 | NotifyCompactIdeLayoutChanged(); |
| 56 | } |
| 57 | |
| 58 | internal void ApplyPresentationTierLayoutDefaults() |
| 59 | { |
| 60 | if (!IsCompactPresentationTier) |
| 61 | return; |
| 62 | |
| 63 | ApplyPfdRegionExpanded(false); |
| 64 | if (!IsMfdRegionExpanded) |
| 65 | ApplyMfdRegionExpanded(true); |
| 66 | |
| 67 | ChatPanel.IsTopicNavigatorVisible = false; |
| 68 | |
| 69 | if (IsMfdContourContentVisible) |
| 70 | CoerceMfdShellPageToAllowed(); |
| 71 | } |
| 72 | |
| 73 | public async Task TryCompletePresentationTierFirstRunAsync(Window? owner) |
| 74 | { |
| 75 | if (!ShouldShowPresentationTierFirstRunWizard || owner is null) |
| 76 | return; |
| 77 | |
| 78 | var recommended = PresentationTierResolver.RecommendForFirstRun( |
| 79 | _settings.Display.Presentation, |
| 80 | _presentationParse, |
| 81 | _presentationMonitorSnapshot); |
| 82 | |
| 83 | var choice = await PresentationTierFirstRunDialog.ShowAsync( |
| 84 | owner, |
| 85 | _presentationMonitorSnapshot, |
| 86 | recommended).ConfigureAwait(true); |
| 87 | |
| 88 | _settings.Display.Presentation.TierFirstRunCompleted = true; |
| 89 | if (choice is PresentationTierKind tier) |
| 90 | _settings.Display.Presentation.Tier = tier.ToTomlValue(); |
| 91 | |
| 92 | SaveSettingsIfChanged(); |
| 93 | } |
| 94 | } |
| 95 | |