pass selected file to codeviewer

This commit is contained in:
Matt Parker
2025-08-01 00:24:06 +10:00
parent 00909eebd4
commit 1d28ac7432
3 changed files with 22 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
@using SharpIDE.Photino.Services
@using SharpIDE.Application.Features.SolutionDiscovery
@using SharpIDE.Photino.Services
@inject RefreshOpenFileService RefreshOpenFileService
@@ -14,14 +15,15 @@
height: calc(100vh - 100px);
}
</style>
@{
}
<StandaloneCodeEditor @ref="_codeEditorRef" Id="my-editor-id" ConstructionOptions="@EditorConstructionOptions" OnDidChangeModelContent="IfDirtyMarkDirty" OnDidBlurEditorText="@SaveFileToDisk" />
@code {
[Parameter, EditorRequired]
public string FilePath { get; set; } = null!;
[Parameter, EditorRequired]
public SharpIdeFile? SelectedFile { get; set; }
private string? _fileContent;
private bool _unsavedEdits = false;

View File

@@ -28,6 +28,18 @@
[Parameter, EditorRequired]
public SharpIdeSolutionModel SolutionModel { get; set; } = null!;
[Parameter, EditorRequired]
public SharpIdeFile SelectedFile { get; set; } = null!;
[Parameter]
public EventCallback<SharpIdeFile> SelectedFileChanged { get; set; }
private async Task InvokeSelectedFileChanged(SharpIdeFile file)
{
SelectedFile = file;
await SelectedFileChanged.InvokeAsync(file);
}
private RenderFragment GetSolutionFolderFragment(SharpIdeSolutionFolder slnFolder) =>
@<text>
<MudTreeViewItem TextTypo="Typo.body2" Icon="@Icons.Material.Filled.Folder" IconColor="Color.Primary" Value="@slnFolder" Text="@slnFolder.Name">
@@ -77,7 +89,8 @@
private RenderFragment GetFileFragment(SharpIdeFile file) =>
@<text>
<MudTreeViewItem T="SharpIdeFile" Icon="@Icons.Custom.FileFormats.FileCode" TextTypo="Typo.body2" Text="@file.Name"/>
<MudTreeViewItem T="SharpIdeFile" Icon="@Icons.Custom.FileFormats.FileCode" TextTypo="Typo.body2" Text="@file.Name" Value="@file" OnClick="@(async () => await InvokeSelectedFileChanged(file))"/>
</text>;
}

View File

@@ -13,7 +13,7 @@
<MudDrawer @bind-Open="@_drawerOpen" Width="400px" ClipMode="DrawerClipMode.Always">
@if (_solutionFilePath is not null)
{
<SolutionExplorer SolutionModel="@_solutionModel" SolutionFilePath="@_solutionFilePath"/>
<SolutionExplorer @bind-SelectedFile="@_selectedFile" SolutionModel="@_solutionModel" SolutionFilePath="@_solutionFilePath"/>
}
@* <NavMenu/> *@
</MudDrawer>
@@ -22,7 +22,7 @@
@* @Body *@
@if (_solutionFilePath is not null)
{
<CodeViewer FilePath="C:\Users\Matthew\Documents\Git\SharpIDE.Photino\src\SharpIDE.Photino\Program.cs" />
<CodeViewer SelectedFile="@_selectedFile" FilePath="C:\Users\Matthew\Documents\Git\SharpIDE.Photino\src\SharpIDE.Photino\Program.cs" />
}
</MudContainer>
</MudMainContent>
@@ -38,6 +38,7 @@
private string? _solutionFilePath;
private SharpIdeSolutionModel? _solutionModel;
private SharpIdeFile? _selectedFile;
protected override async Task OnInitializedAsync()
{