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 @inject RefreshOpenFileService RefreshOpenFileService
@@ -14,14 +15,15 @@
height: calc(100vh - 100px); height: calc(100vh - 100px);
} }
</style> </style>
@{
}
<StandaloneCodeEditor @ref="_codeEditorRef" Id="my-editor-id" ConstructionOptions="@EditorConstructionOptions" OnDidChangeModelContent="IfDirtyMarkDirty" OnDidBlurEditorText="@SaveFileToDisk" /> <StandaloneCodeEditor @ref="_codeEditorRef" Id="my-editor-id" ConstructionOptions="@EditorConstructionOptions" OnDidChangeModelContent="IfDirtyMarkDirty" OnDidBlurEditorText="@SaveFileToDisk" />
@code { @code {
[Parameter, EditorRequired] [Parameter, EditorRequired]
public string FilePath { get; set; } = null!; public string FilePath { get; set; } = null!;
[Parameter, EditorRequired]
public SharpIdeFile? SelectedFile { get; set; }
private string? _fileContent; private string? _fileContent;
private bool _unsavedEdits = false; private bool _unsavedEdits = false;

View File

@@ -28,6 +28,18 @@
[Parameter, EditorRequired] [Parameter, EditorRequired]
public SharpIdeSolutionModel SolutionModel { get; set; } = null!; 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) => private RenderFragment GetSolutionFolderFragment(SharpIdeSolutionFolder slnFolder) =>
@<text> @<text>
<MudTreeViewItem TextTypo="Typo.body2" Icon="@Icons.Material.Filled.Folder" IconColor="Color.Primary" Value="@slnFolder" Text="@slnFolder.Name"> <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) => private RenderFragment GetFileFragment(SharpIdeFile file) =>
@<text> @<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>; </text>;
} }

View File

@@ -13,7 +13,7 @@
<MudDrawer @bind-Open="@_drawerOpen" Width="400px" ClipMode="DrawerClipMode.Always"> <MudDrawer @bind-Open="@_drawerOpen" Width="400px" ClipMode="DrawerClipMode.Always">
@if (_solutionFilePath is not null) @if (_solutionFilePath is not null)
{ {
<SolutionExplorer SolutionModel="@_solutionModel" SolutionFilePath="@_solutionFilePath"/> <SolutionExplorer @bind-SelectedFile="@_selectedFile" SolutionModel="@_solutionModel" SolutionFilePath="@_solutionFilePath"/>
} }
@* <NavMenu/> *@ @* <NavMenu/> *@
</MudDrawer> </MudDrawer>
@@ -22,7 +22,7 @@
@* @Body *@ @* @Body *@
@if (_solutionFilePath is not null) @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> </MudContainer>
</MudMainContent> </MudMainContent>
@@ -38,6 +38,7 @@
private string? _solutionFilePath; private string? _solutionFilePath;
private SharpIdeSolutionModel? _solutionModel; private SharpIdeSolutionModel? _solutionModel;
private SharpIdeFile? _selectedFile;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {