@using SharpIDE.Application.Features.Analysis @using SharpIDE.Application.Features.Build @using SharpIDE.Application.Features.Events @using SharpIDE.Application.Features.SolutionDiscovery @using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence @using SharpIDE.Photino.Models @inherits LayoutComponentBase @inject IDialogService DialogService @inject BuildService BuildService @inject AppState AppState @inject RoslynAnalysis RoslynAnalysis Build Rebuild Clean Restore @if (_solutionModel is not null) { } else { } @if (_solutionFilePath is not null) { } @if (_solutionFilePath is not null) { } @if (_solutionFilePath is not null) { } @* fake for StretchItems.Middle *@ @code { private bool _drawerOpen = true; private bool _bottomDrawerOpen = false; private void DrawerToggle() => _drawerOpen = !_drawerOpen; private string? _solutionFilePath; private SharpIdeSolutionModel? _solutionModel; private ISharpIdeNode? _selectedNode; private SharpIdeFile? _selectedFile; private BottomPanelType? _selectedBottomPanel = null; private string MainContentHeight => _bottomDrawerOpen ? "70%" : "100%"; private void ClickProblemsPanel() => SwitchOrToggleBottomPanel(BottomPanelType.Problems); private void ClickRunPanel() => SwitchOrToggleBottomPanel(BottomPanelType.Run); private void ClickBuildPanel() => SwitchOrToggleBottomPanel(BottomPanelType.Build); private void SwitchOrToggleBottomPanel(BottomPanelType bottomPanelType) { if (_selectedBottomPanel == bottomPanelType) { _selectedBottomPanel = null; _bottomDrawerOpen = false; } else { _selectedBottomPanel = bottomPanelType; _bottomDrawerOpen = true; } } private void SelectBottomPanel(BottomPanelType bottomPanelType) { _selectedBottomPanel = bottomPanelType; _bottomDrawerOpen = true; } protected override async Task OnInitializedAsync() { GlobalEvents.Instance = new GlobalEvents(); await LoadSolutionFromInteractivePicker(AppState.IdeSettings.AutoOpenLastSolution); GlobalEvents.Instance.StartedRunningProject.Subscribe(OnStartedRunningProject); } private void OnProblemSelected(SharpIdeFile file) { _selectedFile = file; _selectedNode = file; var parent = _selectedFile.Parent; parent.Expanded = true; while (parent is IChildSharpIdeNode childNode) { if (childNode is not IExpandableSharpIdeNode expandableParent) throw new InvalidOperationException("Parent node must implement IExpandableSharpIdeNode"); expandableParent.Expanded = true; parent = childNode.Parent; } if (parent is not SharpIdeSolutionModel solutionModel) throw new InvalidOperationException("Parent node must be a SharpIdeSolutionModel"); solutionModel.Expanded = true; StateHasChanged(); } private void AfterSelectedNodeChanged() { if (_selectedNode is SharpIdeFile file) { _selectedFile = file; } } private async Task OnStartedRunningProject() { SelectBottomPanel(BottomPanelType.Run); await InvokeAsync(StateHasChanged); } private async Task LoadSolutionFromInteractivePicker() => await LoadSolutionFromInteractivePicker(false); private async Task LoadSolutionFromInteractivePicker(bool autoOpenLastSolution) { var dialogRef = await DialogService.ShowAsync("Open Solution",new DialogParameters { [nameof(SolutionPickerDialog.AutoOpenLastSolution)] = autoOpenLastSolution }, new DialogOptions { FullWidth = true, MaxWidth = MaxWidth.Medium, BackdropClick = false }); var result = await dialogRef.Result; if (result is null) throw new InvalidOperationException("Dialog result is null"); if (result.Canceled) throw new OperationCanceledException("Dialog was canceled"); var solutionFilePath = (string)result.Data!; _solutionFilePath = solutionFilePath; var solutionModel = await VsPersistenceMapper.GetSolutionModel(_solutionFilePath); _solutionModel = solutionModel; RoslynAnalysis.StartLoadingSolutionInWorkspace(solutionModel); } private CancellationTokenSource? _cancellationTokenSource = null!; private async Task BuildSolution() => await MsBuildSolution(BuildType.Build); private async Task RebuildSolution() => await MsBuildSolution(BuildType.Rebuild); private async Task CleanSolution() => await MsBuildSolution(BuildType.Clean); private async Task RestoreSolution() => await MsBuildSolution(BuildType.Restore); private async Task MsBuildSolution(BuildType buildType) { if (AppState.IdeSettings.OpenTerminalOnBuildRebuildRestore) SelectBottomPanel(BottomPanelType.Build); _cancellationTokenSource = new CancellationTokenSource(); await BuildService.MsBuildAsync(_solutionFilePath!, buildType, _cancellationTokenSource.Token); _cancellationTokenSource = null; } private async Task CancelBuild() => await _cancellationTokenSource!.CancelAsync(); private bool IsRunningMsBuildJob() => _cancellationTokenSource is not null; private async Task OpenSettingsDialog() { var dialogRef = await DialogService.ShowAsync("SharpIDE Settings", new DialogOptions { MaxWidth = MaxWidth.Medium, CloseButton = true }); } }