diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs new file mode 100644 index 0000000..adfc9f4 --- /dev/null +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs @@ -0,0 +1,57 @@ +using Godot; +using SharpIDE.Application.Features.FileWatching; +using SharpIDE.Application.Features.SolutionDiscovery; + +namespace SharpIDE.Godot.Features.SolutionExplorer.ContextMenus.Dialogs; + +public partial class NewCsharpFileDialog : ConfirmationDialog +{ + private LineEdit _nameLineEdit = null!; + private ItemList _fileTypeItemList = null!; + + public SharpIdeFolder ParentFolder { get; set; } = null!; + + [Inject] private readonly IdeFileOperationsService _ideFileOperationsService = null!; + + private Texture2D _classIcon = GD.Load("uid://do0edciarrnp0"); + + public override void _Ready() + { + _nameLineEdit = GetNode("%CSharpFileNameLineEdit"); + _nameLineEdit.GrabFocus(); + _nameLineEdit.SelectAll(); + _fileTypeItemList = GetNode("%FileTypeItemList"); + _fileTypeItemList.AddItem("Class", _classIcon); + _fileTypeItemList.AddItem("Interface", _classIcon); + _fileTypeItemList.AddItem("Record", _classIcon); + _fileTypeItemList.AddItem("Struct", _classIcon); + _fileTypeItemList.AddItem("Enum", _classIcon); + _fileTypeItemList.ItemSelected += FileTypeItemListOnItemSelected; + Confirmed += OnConfirmed; + } + + private void FileTypeItemListOnItemSelected(long index) + { + GD.Print("Selected file type index: " + index); + } + + private void OnConfirmed() + { + var fileName = _nameLineEdit.Text.Trim(); + if (string.IsNullOrEmpty(fileName)) + { + GD.PrintErr("File name cannot be empty."); + return; + } + + if (!fileName.EndsWith(".cs")) + { + fileName += ".cs"; + } + + _ = Task.GodotRun(async () => + { + //await _ideFileOperationsService.CreateCSharpFile(ParentFolder, fileName); + }); + } +} \ No newline at end of file diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs.uid b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs.uid new file mode 100644 index 0000000..69c6415 --- /dev/null +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs.uid @@ -0,0 +1 @@ +uid://celjpet3ik464 diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.tscn b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.tscn new file mode 100644 index 0000000..f9817be --- /dev/null +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.tscn @@ -0,0 +1,28 @@ +[gd_scene load_steps=2 format=3 uid="uid://chnb7gmcdg0ww"] + +[ext_resource type="Script" uid="uid://celjpet3ik464" path="res://Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs" id="1_fod37"] + +[node name="NewCsharpFileDialog" type="ConfirmationDialog"] +oversampling_override = 1.0 +title = "Create new C# file" +size = Vector2i(350, 230) +visible = true +script = ExtResource("1_fod37") + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +offset_left = 8.0 +offset_top = 8.0 +offset_right = 342.0 +offset_bottom = 181.0 + +[node name="CSharpFileNameLineEdit" type="LineEdit" parent="VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +placeholder_text = "Name" + +[node name="FileTypeItemList" type="ItemList" parent="VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_vertical = 3 +allow_search = false +auto_height = true diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FolderContextMenu.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FolderContextMenu.cs index 78945da..985f415 100644 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FolderContextMenu.cs +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FolderContextMenu.cs @@ -75,6 +75,7 @@ public partial class SolutionExplorerPanel } private readonly PackedScene _newDirectoryDialogScene = GD.Load("uid://bgi4u18y8pt4x"); + private readonly PackedScene _newCsharpFileDialogScene = GD.Load("uid://chnb7gmcdg0ww"); private void OnCreateNewSubmenuPressed(long id, SharpIdeFolder folder) { var actionId = (CreateNewSubmenuOptions)id; @@ -87,7 +88,10 @@ public partial class SolutionExplorerPanel } else if (actionId is CreateNewSubmenuOptions.CSharpFile) { - //OpenCreateNewCSharpFileDialog(folder); + var newCsharpFileDialog = _newCsharpFileDialogScene.Instantiate(); + newCsharpFileDialog.ParentFolder = folder; + AddChild(newCsharpFileDialog); + newCsharpFileDialog.PopupCentered(); } } } \ No newline at end of file