ide create new cs file dialog v1
This commit is contained in:
@@ -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<Texture2D>("uid://do0edciarrnp0");
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
_nameLineEdit = GetNode<LineEdit>("%CSharpFileNameLineEdit");
|
||||||
|
_nameLineEdit.GrabFocus();
|
||||||
|
_nameLineEdit.SelectAll();
|
||||||
|
_fileTypeItemList = GetNode<ItemList>("%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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://celjpet3ik464
|
||||||
@@ -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
|
||||||
@@ -75,6 +75,7 @@ public partial class SolutionExplorerPanel
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly PackedScene _newDirectoryDialogScene = GD.Load<PackedScene>("uid://bgi4u18y8pt4x");
|
private readonly PackedScene _newDirectoryDialogScene = GD.Load<PackedScene>("uid://bgi4u18y8pt4x");
|
||||||
|
private readonly PackedScene _newCsharpFileDialogScene = GD.Load<PackedScene>("uid://chnb7gmcdg0ww");
|
||||||
private void OnCreateNewSubmenuPressed(long id, SharpIdeFolder folder)
|
private void OnCreateNewSubmenuPressed(long id, SharpIdeFolder folder)
|
||||||
{
|
{
|
||||||
var actionId = (CreateNewSubmenuOptions)id;
|
var actionId = (CreateNewSubmenuOptions)id;
|
||||||
@@ -87,7 +88,10 @@ public partial class SolutionExplorerPanel
|
|||||||
}
|
}
|
||||||
else if (actionId is CreateNewSubmenuOptions.CSharpFile)
|
else if (actionId is CreateNewSubmenuOptions.CSharpFile)
|
||||||
{
|
{
|
||||||
//OpenCreateNewCSharpFileDialog(folder);
|
var newCsharpFileDialog = _newCsharpFileDialogScene.Instantiate<NewCsharpFileDialog>();
|
||||||
|
newCsharpFileDialog.ParentFolder = folder;
|
||||||
|
AddChild(newCsharpFileDialog);
|
||||||
|
newCsharpFileDialog.PopupCentered();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user