Initial commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user