Files
I150/srcs/RobotNet10/Components/RobotNet10.ScriptEditor/Dialogs/CreateFileDialog.razor
2026-07-03 16:37:12 +07:00

61 lines
1.6 KiB
Plaintext

@using MudBlazor
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">Create New File</MudText>
</TitleContent>
<DialogContent>
<MudTextField @bind-Value="FileName"
Label="File Name"
Placeholder="Enter file name (e.g., MyFile.cs)"
Required="true"
RequiredError="File name is required"
HelperText="File must have .cs extension"
Variant="Variant.Outlined"
FullWidth="true"
@onkeydown="HandleKeyDown" />
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="Submit">Create</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter] IMudDialogInstance Dialog { get; set; } = null!;
private string FileName { get; set; } = string.Empty;
private void Cancel() => Dialog.Cancel();
private void Submit()
{
if (string.IsNullOrWhiteSpace(FileName))
{
return;
}
// Ensure .cs extension
var name = FileName.Trim();
if (!name.EndsWith(".cs", StringComparison.OrdinalIgnoreCase))
{
name += ".cs";
}
Dialog.Close(DialogResult.Ok(name));
}
private void HandleKeyDown(KeyboardEventArgs e)
{
if (e.Key == "Enter")
{
Submit();
}
else if (e.Key == "Escape")
{
Cancel();
}
}
}