File name heading
This commit is contained in:
@@ -1,16 +1,23 @@
|
|||||||
|
<MudText>
|
||||||
|
@Path.GetFileName(FilePath)
|
||||||
|
@if (_unsavedEdits)
|
||||||
|
{
|
||||||
|
<span>*</span>
|
||||||
|
}
|
||||||
|
</MudText>
|
||||||
<style>
|
<style>
|
||||||
#my-editor-id {
|
#my-editor-id {
|
||||||
height: calc(100vh - 100px);
|
height: calc(100vh - 100px);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<StandaloneCodeEditor Id="my-editor-id" ConstructionOptions="@EditorConstructionOptions" />
|
<StandaloneCodeEditor Id="my-editor-id" ConstructionOptions="@EditorConstructionOptions" OnDidChangeModelContent="evnt => _unsavedEdits = true" OnDidBlurEditorText="@SaveFileToDisk" />
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[Parameter, EditorRequired]
|
[Parameter, EditorRequired]
|
||||||
public string FilePath { get; set; } = null!;
|
public string FilePath { get; set; } = null!;
|
||||||
|
|
||||||
private string? _fileContent;
|
private string? _fileContent;
|
||||||
|
private bool _unsavedEdits = false;
|
||||||
|
|
||||||
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
||||||
{
|
{
|
||||||
@@ -36,4 +43,17 @@
|
|||||||
_fileContent = fileContent;
|
_fileContent = fileContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task SaveFileToDisk(object obj)
|
||||||
|
{
|
||||||
|
if (_unsavedEdits is false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var editor = obj as StandaloneCodeEditor;
|
||||||
|
ArgumentNullException.ThrowIfNull(editor, nameof(editor));
|
||||||
|
var editorTextValue = await editor.GetValue();
|
||||||
|
await File.WriteAllTextAsync(FilePath, editorTextValue);
|
||||||
|
_unsavedEdits = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user