121 lines
5.3 KiB
Plaintext
121 lines
5.3 KiB
Plaintext
@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
|
|
|
|
<MudLayout>
|
|
<MudAppBar Dense="true" Gutters="false" Class="px-2">
|
|
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="1">
|
|
<MudButton OnClick="@DrawerToggle" Style="min-width: 20px;">
|
|
<MudIcon Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit"/>
|
|
</MudButton>
|
|
<MudButton Style="min-width: 20px;">
|
|
<MudIcon Icon="@Icons.Material.Filled.FolderOpen" Color="Color.Inherit"/>
|
|
</MudButton>
|
|
<MudButtonGroup OverrideStyles="false">
|
|
<MudButton Variant="Variant.Filled" Size="Size.Small" Color="Color.Primary" OnClick="@BuildSolution">Build</MudButton>
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" Color="Color.Primary" OnClick="@RebuildSolution">Rebuild</MudButton>
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" Color="Color.Primary" OnClick="@CleanSolution">Clean</MudButton>
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" Color="Color.Primary" OnClick="@RestoreSolution">Restore</MudButton>
|
|
</MudButtonGroup>
|
|
<MudButton OnClick="@CancelBuild" Disabled="@(_cancellationTokenSource is null or { IsCancellationRequested: true })" Style="min-width: 20px;">
|
|
<MudIcon Disabled="@(_cancellationTokenSource is null or { IsCancellationRequested: true })" Icon="@Icons.Material.Filled.Cancel" Color="Color.Error"/>
|
|
</MudButton>
|
|
</MudStack>
|
|
<MudSpacer/>
|
|
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="1">
|
|
<MudButton Style="min-width: 20px;" OnClick="@TerminalDrawerToggle">
|
|
<MudIcon Icon="@Icons.Material.Filled.Terminal" Size="Size.Medium" Color="Color.Default"/>
|
|
</MudButton>
|
|
<MudButton Style="min-width: 20px;">
|
|
<MudIcon Icon="@Icons.Material.Filled.PlayArrow" Size="Size.Medium" Color="Color.Success"/>
|
|
</MudButton>
|
|
<MudButton Style="min-width: 20px;" OnClick="@OpenSettingsDialog">
|
|
<MudIcon Icon="@Icons.Material.Filled.Settings" Size="Size.Medium" Color="Color.Default"/>
|
|
</MudButton>
|
|
</MudStack>
|
|
</MudAppBar>
|
|
<MudDrawer @bind-Open="@_drawerOpen" Width="400px" ClipMode="DrawerClipMode.Always">
|
|
@if (_solutionFilePath is not null)
|
|
{
|
|
<SolutionExplorer @bind-SelectedFile="@_selectedFile" SolutionModel="@_solutionModel"/>
|
|
}
|
|
@* <NavMenu/> *@
|
|
</MudDrawer>
|
|
<MudMainContent>
|
|
<MudContainer MaxWidth="MaxWidth.False" Class="mt-2">
|
|
@* @Body *@
|
|
@if (_solutionFilePath is not null)
|
|
{
|
|
<CodeViewer SelectedFile="@_selectedFile" />
|
|
}
|
|
</MudContainer>
|
|
</MudMainContent>
|
|
<MudDrawer @bind-Open="@_terminalDrawerOpen" Elevation="2" Variant="DrawerVariant.Temporary" Overlay="false" Anchor="Anchor.Bottom">
|
|
@if (_solutionFilePath is not null)
|
|
{
|
|
<MudText>Terminal</MudText>
|
|
<TerminalOutputDisplay/>
|
|
}
|
|
</MudDrawer>
|
|
</MudLayout>
|
|
|
|
@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<SolutionPickerDialog>("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);
|
|
_cancellationTokenSource = null;
|
|
}
|
|
private async Task CancelBuild() => await _cancellationTokenSource!.CancelAsync();
|
|
|
|
private async Task OpenSettingsDialog()
|
|
{
|
|
var dialogRef = await DialogService.ShowAsync<IdeSettingsDialog>("SharpIDE Settings", new DialogOptions { MaxWidth = MaxWidth.Medium, CloseButton = true });
|
|
}
|
|
|
|
}
|