@using SharpIDE.Application.Features.Build
@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
Build
Rebuild
Clean
Restore
@if (_solutionFilePath is not null)
{
}
@* *@
@* @Body *@
@if (_solutionFilePath is not null)
{
}
@if (_solutionFilePath is not null)
{
Terminal
}
@code {
private bool _drawerOpen = true;
private bool _terminalDrawerOpen = false;
private void DrawerToggle() => _drawerOpen = !_drawerOpen;
private void TerminalDrawerToggle() => _terminalDrawerOpen = !_terminalDrawerOpen;
private string? _solutionFilePath;
private SharpIdeSolutionModel? _solutionModel;
private SharpIdeFile? _selectedFile;
protected override async Task OnInitializedAsync()
{
var dialogRef = await DialogService.ShowAsync("Open Solution", 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;
if (AppState.IdeSettings.AutoOpenTerminalOnLaunch)
{
_ = Task.Run(async () =>
{
// The mud drawer is a pain, has an initial state, and won't open if you try to open it before it has rendered (presumably using js)
await Task.Delay(125).ConfigureAwait(false);
_terminalDrawerOpen = true;
await InvokeAsync(StateHasChanged).ConfigureAwait(false);
}).ConfigureAwait(false);
}
}
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) _terminalDrawerOpen = true;
_cancellationTokenSource = new CancellationTokenSource();
await BuildService.MsBuildSolutionAsync(_solutionFilePath!, buildType, _cancellationTokenSource.Token);
}
private async Task CancelBuild() => await _cancellationTokenSource!.CancelAsync();
private async Task OpenSettingsDialog()
{
var dialogRef = await DialogService.ShowAsync("SharpIDE Settings", new DialogOptions { MaxWidth = MaxWidth.Medium, CloseButton = true });
}
}