From 7d379939e923fee751994827f0959a90049127aa Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Mon, 20 Oct 2025 19:35:50 +1000 Subject: [PATCH] Update NewCsharpFileDialog.cs --- .../Dialogs/NewCsharpFileDialog.cs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs index adfc9f4..b3942aa 100644 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs @@ -26,10 +26,31 @@ public partial class NewCsharpFileDialog : ConfirmationDialog _fileTypeItemList.AddItem("Record", _classIcon); _fileTypeItemList.AddItem("Struct", _classIcon); _fileTypeItemList.AddItem("Enum", _classIcon); + _fileTypeItemList.Select(0); _fileTypeItemList.ItemSelected += FileTypeItemListOnItemSelected; Confirmed += OnConfirmed; } + public override void _Input(InputEvent @event) + { + if (@event is InputEventKey { Pressed: true, Keycode: Key.Enter }) + { + OnConfirmed(); + } + else if (@event is InputEventKey { Pressed: true, Keycode: Key.Down }) + { + var selectedIndex = _fileTypeItemList.GetSelectedItems()[0]; + var nextIndex = (selectedIndex + 1) % _fileTypeItemList.GetItemCount(); + _fileTypeItemList.Select(nextIndex); + } + else if (@event is InputEventKey { Pressed: true, Keycode: Key.Up }) + { + var selectedIndex = _fileTypeItemList.GetSelectedItems()[0]; + var previousIndex = (selectedIndex - 1 + _fileTypeItemList.GetItemCount()) % _fileTypeItemList.GetItemCount(); + _fileTypeItemList.Select(previousIndex); + } + } + private void FileTypeItemListOnItemSelected(long index) { GD.Print("Selected file type index: " + index); @@ -38,7 +59,7 @@ public partial class NewCsharpFileDialog : ConfirmationDialog private void OnConfirmed() { var fileName = _nameLineEdit.Text.Trim(); - if (string.IsNullOrEmpty(fileName)) + if (IsNameInvalid(fileName)) { GD.PrintErr("File name cannot be empty."); return; @@ -53,5 +74,11 @@ public partial class NewCsharpFileDialog : ConfirmationDialog { //await _ideFileOperationsService.CreateCSharpFile(ParentFolder, fileName); }); + QueueFree(); + } + + private bool IsNameInvalid(string name) + { + return string.IsNullOrWhiteSpace(name); } } \ No newline at end of file