From b78f30af35d76d0c69d93026982f5b60eb9d8a40 Mon Sep 17 00:00:00 2001 From: "Matt Parker [SSW]" <61717342+MattParkerDev@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:23:38 +1000 Subject: [PATCH] monaco --- .../Components/CodeViewer.razor | 39 +++++++++++++++++++ src/SharpIDE.Photino/Layout/MainLayout.razor | 4 +- src/SharpIDE.Photino/Pages/Home.razor | 2 +- src/SharpIDE.Photino/SharpIDE.Photino.csproj | 1 + src/SharpIDE.Photino/_Imports.razor | 3 ++ src/SharpIDE.Photino/wwwroot/index.html | 5 ++- 6 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/SharpIDE.Photino/Components/CodeViewer.razor diff --git a/src/SharpIDE.Photino/Components/CodeViewer.razor b/src/SharpIDE.Photino/Components/CodeViewer.razor new file mode 100644 index 0000000..9932c86 --- /dev/null +++ b/src/SharpIDE.Photino/Components/CodeViewer.razor @@ -0,0 +1,39 @@ + + + + +@code { + [Parameter, EditorRequired] + public string FilePath { get; set; } = null!; + + private string? _fileContent; + + private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor) + { + return new StandaloneEditorConstructionOptions + { + AutomaticLayout = true, + Language = "csharp", + Theme = "vs-dark", + ScrollBeyondLastLine = false, + FontSize = 18, + Value = _fileContent + }; + } + + protected override async Task OnInitializedAsync() + { + var fileInfo = new FileInfo(FilePath); + if (!fileInfo.Exists) + { + throw new FileNotFoundException($"File not found: {FilePath}"); + } + var fileContent = await File.ReadAllTextAsync(FilePath); + _fileContent = fileContent; + } + +} diff --git a/src/SharpIDE.Photino/Layout/MainLayout.razor b/src/SharpIDE.Photino/Layout/MainLayout.razor index 04f7c7e..cf970f9 100644 --- a/src/SharpIDE.Photino/Layout/MainLayout.razor +++ b/src/SharpIDE.Photino/Layout/MainLayout.razor @@ -1,6 +1,6 @@ @inherits LayoutComponentBase - + @@ -14,7 +14,7 @@ @* *@ - + @Body diff --git a/src/SharpIDE.Photino/Pages/Home.razor b/src/SharpIDE.Photino/Pages/Home.razor index 857348a..e82cc8c 100644 --- a/src/SharpIDE.Photino/Pages/Home.razor +++ b/src/SharpIDE.Photino/Pages/Home.razor @@ -1,6 +1,6 @@ @page "/" -Welcome to a new Photino Blazor app! + @code { diff --git a/src/SharpIDE.Photino/SharpIDE.Photino.csproj b/src/SharpIDE.Photino/SharpIDE.Photino.csproj index 7f3a4df..7622ead 100644 --- a/src/SharpIDE.Photino/SharpIDE.Photino.csproj +++ b/src/SharpIDE.Photino/SharpIDE.Photino.csproj @@ -17,6 +17,7 @@ + diff --git a/src/SharpIDE.Photino/_Imports.razor b/src/SharpIDE.Photino/_Imports.razor index df8c6af..7863d5f 100644 --- a/src/SharpIDE.Photino/_Imports.razor +++ b/src/SharpIDE.Photino/_Imports.razor @@ -10,3 +10,6 @@ @using MudBlazor @using SharpIDE.Photino.Layout @using SharpIDE.Photino.Components +@using BlazorMonaco +@using BlazorMonaco.Editor +@using BlazorMonaco.Languages diff --git a/src/SharpIDE.Photino/wwwroot/index.html b/src/SharpIDE.Photino/wwwroot/index.html index 71f1cae..d4eb76d 100644 --- a/src/SharpIDE.Photino/wwwroot/index.html +++ b/src/SharpIDE.Photino/wwwroot/index.html @@ -18,7 +18,10 @@ 🗙 - + + + +