Add folder via dialog

This commit is contained in:
Matt Parker
2025-10-20 00:09:24 +10:00
parent 681e07586e
commit e379d064f3
5 changed files with 26 additions and 7 deletions

View File

@@ -24,7 +24,7 @@ public class IdeFileExternalChangeHandler
var sharpIdeFolder = SolutionModel.AllFolders.SingleOrDefault(f => f.Path == folderPath); var sharpIdeFolder = SolutionModel.AllFolders.SingleOrDefault(f => f.Path == folderPath);
if (sharpIdeFolder is not null) if (sharpIdeFolder is not null)
{ {
Console.WriteLine($"Error - Folder {folderPath} already exists"); //Console.WriteLine($"Error - Folder {folderPath} already exists");
return; return;
} }
var containingFolderPath = Path.GetDirectoryName(folderPath)!; var containingFolderPath = Path.GetDirectoryName(folderPath)!;
@@ -34,7 +34,8 @@ public class IdeFileExternalChangeHandler
Console.WriteLine($"Error - Containing Folder of {folderPath} does not exist"); Console.WriteLine($"Error - Containing Folder of {folderPath} does not exist");
return; return;
} }
await _sharpIdeSolutionModificationService.CreateDirectory(containingFolder, folderPath); var folderName = Path.GetFileName(folderPath);
await _sharpIdeSolutionModificationService.AddDirectory(containingFolder, folderName);
} }
private async Task OnFileCreated(string filePath) private async Task OnFileCreated(string filePath)

View File

@@ -6,9 +6,10 @@ public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpI
{ {
private readonly SharpIdeSolutionModificationService _sharpIdeSolutionModificationService = sharpIdeSolutionModificationService; private readonly SharpIdeSolutionModificationService _sharpIdeSolutionModificationService = sharpIdeSolutionModificationService;
public async Task CreateDirectory(SharpIdeFolder parentFolder, string directoryPath) public async Task CreateDirectory(SharpIdeFolder parentFolder, string newDirectoryName)
{ {
var newFolder = await _sharpIdeSolutionModificationService.CreateDirectory(parentFolder, directoryPath); var newDirectoryPath = Path.Combine(parentFolder.Path, newDirectoryName);
Directory.CreateDirectory(directoryPath); Directory.CreateDirectory(newDirectoryPath);
var newFolder = await _sharpIdeSolutionModificationService.AddDirectory(parentFolder, newDirectoryName);
} }
} }

View File

@@ -7,10 +7,12 @@ public class SharpIdeSolutionModificationService
{ {
public SharpIdeSolutionModel SolutionModel { get; set; } = null!; public SharpIdeSolutionModel SolutionModel { get; set; } = null!;
public async Task<SharpIdeFolder> CreateDirectory(SharpIdeFolder parentFolder, string directoryPath) /// The directory must already exist on disk
public async Task<SharpIdeFolder> AddDirectory(SharpIdeFolder parentFolder, string directoryName)
{ {
// Passing [] to allFiles and allFolders, as we assume that a brand new folder has no subfolders or files yet // Passing [] to allFiles and allFolders, as we assume that a brand new folder has no subfolders or files yet
var sharpIdeFolder = new SharpIdeFolder(new DirectoryInfo(directoryPath), parentFolder, [], []); var addedDirectoryPath = Path.Combine(parentFolder.Path, directoryName);
var sharpIdeFolder = new SharpIdeFolder(new DirectoryInfo(addedDirectoryPath), parentFolder, [], []);
parentFolder.Folders.Add(sharpIdeFolder); parentFolder.Folders.Add(sharpIdeFolder);
SolutionModel.AllFolders.Add(sharpIdeFolder); SolutionModel.AllFolders.Add(sharpIdeFolder);
return sharpIdeFolder; return sharpIdeFolder;

View File

@@ -1,4 +1,5 @@
using Godot; using Godot;
using SharpIDE.Application.Features.FileWatching;
using SharpIDE.Application.Features.SolutionDiscovery; using SharpIDE.Application.Features.SolutionDiscovery;
namespace SharpIDE.Godot.Features.SolutionExplorer.ContextMenus.Dialogs; namespace SharpIDE.Godot.Features.SolutionExplorer.ContextMenus.Dialogs;
@@ -9,6 +10,8 @@ public partial class NewDirectoryDialog : ConfirmationDialog
public SharpIdeFolder ParentFolder { get; set; } = null!; public SharpIdeFolder ParentFolder { get; set; } = null!;
[Inject] private readonly IdeFileOperationsService _ideFileOperationsService = null!;
public override void _Ready() public override void _Ready()
{ {
_nameLineEdit = GetNode<LineEdit>("%DirectoryNameLineEdit"); _nameLineEdit = GetNode<LineEdit>("%DirectoryNameLineEdit");
@@ -20,5 +23,15 @@ public partial class NewDirectoryDialog : ConfirmationDialog
private void OnConfirmed() private void OnConfirmed()
{ {
var directoryName = _nameLineEdit.Text.Trim(); var directoryName = _nameLineEdit.Text.Trim();
if (string.IsNullOrEmpty(directoryName))
{
GD.PrintErr("Directory name cannot be empty.");
return;
}
_ = Task.GodotRun(async () =>
{
await _ideFileOperationsService.CreateDirectory(ParentFolder, directoryName);
});
} }
} }

View File

@@ -44,6 +44,7 @@ public partial class IdeRoot : Control
[Inject] private readonly BuildService _buildService = null!; [Inject] private readonly BuildService _buildService = null!;
[Inject] private readonly IdeOpenTabsFileManager _openTabsFileManager = null!; [Inject] private readonly IdeOpenTabsFileManager _openTabsFileManager = null!;
[Inject] private readonly RoslynAnalysis _roslynAnalysis = null!; [Inject] private readonly RoslynAnalysis _roslynAnalysis = null!;
[Inject] private readonly SharpIdeSolutionModificationService _sharpIdeSolutionModificationService = null!;
public override void _EnterTree() public override void _EnterTree()
{ {
@@ -141,6 +142,7 @@ public partial class IdeRoot : Control
_searchAllFilesWindow.Solution = solutionModel; _searchAllFilesWindow.Solution = solutionModel;
_fileExternalChangeHandler.SolutionModel = solutionModel; _fileExternalChangeHandler.SolutionModel = solutionModel;
_fileChangedService.SolutionModel = solutionModel; _fileChangedService.SolutionModel = solutionModel;
_sharpIdeSolutionModificationService.SolutionModel = solutionModel;
Callable.From(_solutionExplorerPanel.BindToSolution).CallDeferred(); Callable.From(_solutionExplorerPanel.BindToSolution).CallDeferred();
_roslynAnalysis.StartSolutionAnalysis(solutionModel); _roslynAnalysis.StartSolutionAnalysis(solutionModel);
_fileWatcher.StartWatching(solutionModel); _fileWatcher.StartWatching(solutionModel);