78 lines
2.1 KiB
Plaintext
78 lines
2.1 KiB
Plaintext
@using MudBlazor
|
|
|
|
<MudDialog>
|
|
<TitleContent>
|
|
<MudText Typo="Typo.h6">Rename @ItemType</MudText>
|
|
</TitleContent>
|
|
<DialogContent>
|
|
<MudTextField @bind-Value="NewName"
|
|
Label="@LabelText"
|
|
Placeholder="Enter new name"
|
|
Required="true"
|
|
RequiredError="Name is required"
|
|
HelperText="@HelperText"
|
|
Variant="Variant.Outlined"
|
|
FullWidth="true"
|
|
@onkeydown="HandleKeyDown" />
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton OnClick="Cancel">Cancel</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="Submit">Rename</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
[CascadingParameter] IMudDialogInstance Dialog { get; set; } = null!;
|
|
[Parameter] public string CurrentName { get; set; } = string.Empty;
|
|
[Parameter] public string ItemType { get; set; } = "Item";
|
|
[Parameter] public bool RequireCsExtension { get; set; } = false;
|
|
|
|
private string NewName { get; set; } = string.Empty;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
NewName = CurrentName;
|
|
}
|
|
|
|
private string LabelText => $"{ItemType} Name";
|
|
private string HelperText => RequireCsExtension ? "File must have .cs extension" : "";
|
|
|
|
private void Cancel() => Dialog.Cancel();
|
|
|
|
private void Submit()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(NewName))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var name = NewName.Trim();
|
|
|
|
if (RequireCsExtension && !name.EndsWith(".cs", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
name += ".cs";
|
|
}
|
|
|
|
if (name == CurrentName)
|
|
{
|
|
Cancel();
|
|
return;
|
|
}
|
|
|
|
Dialog.Close(DialogResult.Ok(name));
|
|
}
|
|
|
|
private void HandleKeyDown(KeyboardEventArgs e)
|
|
{
|
|
if (e.Key == "Enter")
|
|
{
|
|
Submit();
|
|
}
|
|
else if (e.Key == "Escape")
|
|
{
|
|
Cancel();
|
|
}
|
|
}
|
|
}
|
|
|