add new file and dir to project
This commit is contained in:
@@ -39,14 +39,14 @@ public class IdeFileExternalChangeHandler
|
||||
return;
|
||||
}
|
||||
var containingFolderPath = Path.GetDirectoryName(folderPath)!;
|
||||
var containingFolder = SolutionModel.AllFolders.SingleOrDefault(f => f.Path == containingFolderPath);
|
||||
if (containingFolder is null)
|
||||
var containingFolderOrProject = (IFolderOrProject?)SolutionModel.AllFolders.SingleOrDefault(f => f.ChildNodeBasePath == containingFolderPath) ?? SolutionModel.AllProjects.SingleOrDefault(s => s.ChildNodeBasePath == containingFolderPath);
|
||||
if (containingFolderOrProject is null)
|
||||
{
|
||||
Console.WriteLine($"Error - Containing Folder of {folderPath} does not exist");
|
||||
Console.WriteLine($"Error - Containing Folder or Project of {folderPath} does not exist");
|
||||
return;
|
||||
}
|
||||
var folderName = Path.GetFileName(folderPath);
|
||||
await _sharpIdeSolutionModificationService.AddDirectory(containingFolder, folderName);
|
||||
await _sharpIdeSolutionModificationService.AddDirectory(containingFolderOrProject, folderName);
|
||||
}
|
||||
|
||||
private async Task OnFileCreated(string filePath)
|
||||
@@ -61,7 +61,7 @@ public class IdeFileExternalChangeHandler
|
||||
// If sharpIdeFile is null, it means the file was created externally, and we need to create it and add it to the solution model
|
||||
var createdFileDirectory = Path.GetDirectoryName(filePath)!;
|
||||
|
||||
var containingFolderOrProject = (IFolderOrProject?)SolutionModel.AllFolders.SingleOrDefault(f => f.Path == createdFileDirectory) ?? SolutionModel.AllProjects.SingleOrDefault(s => s.FilePath == createdFileDirectory);
|
||||
var containingFolderOrProject = (IFolderOrProject?)SolutionModel.AllFolders.SingleOrDefault(f => f.ChildNodeBasePath == createdFileDirectory) ?? SolutionModel.AllProjects.SingleOrDefault(s => s.ChildNodeBasePath == createdFileDirectory);
|
||||
if (containingFolderOrProject is null)
|
||||
{
|
||||
Console.WriteLine($"Error - Containing Folder or Project of {filePath} does not exist");
|
||||
|
||||
@@ -7,11 +7,11 @@ public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpI
|
||||
{
|
||||
private readonly SharpIdeSolutionModificationService _sharpIdeSolutionModificationService = sharpIdeSolutionModificationService;
|
||||
|
||||
public async Task CreateDirectory(SharpIdeFolder parentFolder, string newDirectoryName)
|
||||
public async Task CreateDirectory(IFolderOrProject parentNode, string newDirectoryName)
|
||||
{
|
||||
var newDirectoryPath = Path.Combine(parentFolder.Path, newDirectoryName);
|
||||
var newDirectoryPath = Path.Combine(parentNode.ChildNodeBasePath, newDirectoryName);
|
||||
Directory.CreateDirectory(newDirectoryPath);
|
||||
var newFolder = await _sharpIdeSolutionModificationService.AddDirectory(parentFolder, newDirectoryName);
|
||||
var newFolder = await _sharpIdeSolutionModificationService.AddDirectory(parentNode, newDirectoryName);
|
||||
}
|
||||
|
||||
public async Task DeleteDirectory(SharpIdeFolder folder)
|
||||
|
||||
@@ -13,9 +13,9 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS
|
||||
public SharpIdeSolutionModel SolutionModel { get; set; } = null!;
|
||||
|
||||
/// The directory must already exist on disk
|
||||
public async Task<SharpIdeFolder> AddDirectory(SharpIdeFolder parentFolder, string directoryName)
|
||||
public async Task<SharpIdeFolder> AddDirectory(IFolderOrProject parentFolder, string directoryName)
|
||||
{
|
||||
var addedDirectoryPath = Path.Combine(parentFolder.Path, directoryName);
|
||||
var addedDirectoryPath = Path.Combine(parentFolder.ChildNodeBasePath, directoryName);
|
||||
var allFiles = new ConcurrentBag<SharpIdeFile>();
|
||||
var allFolders = new ConcurrentBag<SharpIdeFolder>();
|
||||
var sharpIdeFolder = new SharpIdeFolder(new DirectoryInfo(addedDirectoryPath), parentFolder, allFiles, allFolders);
|
||||
|
||||
@@ -9,6 +9,7 @@ public class SharpIdeFolder : ISharpIdeNode, IExpandableSharpIdeNode, IChildShar
|
||||
{
|
||||
public required IExpandableSharpIdeNode Parent { get; set; }
|
||||
public required string Path { get; set; }
|
||||
public string ChildNodeBasePath => Path;
|
||||
public required string Name { get; set; }
|
||||
public ObservableHashSet<SharpIdeFile> Files { get; init; }
|
||||
public ObservableHashSet<SharpIdeFolder> Folders { get; init; }
|
||||
|
||||
@@ -20,6 +20,7 @@ public interface IFolderOrProject : IExpandableSharpIdeNode, IChildSharpIdeNode
|
||||
public ObservableHashSet<SharpIdeFolder> Folders { get; init; }
|
||||
public ObservableHashSet<SharpIdeFile> Files { get; init; }
|
||||
public string Name { get; set; }
|
||||
public string ChildNodeBasePath { get; }
|
||||
}
|
||||
public interface IChildSharpIdeNode
|
||||
{
|
||||
@@ -89,6 +90,7 @@ public class SharpIdeProjectModel : ISharpIdeNode, IExpandableSharpIdeNode, IChi
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public required string FilePath { get; set; }
|
||||
public string ChildNodeBasePath => Path.GetDirectoryName(FilePath)!;
|
||||
public required ObservableHashSet<SharpIdeFolder> Folders { get; init; }
|
||||
public required ObservableHashSet<SharpIdeFile> Files { get; init; }
|
||||
public bool Expanded { get; set; }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Godot;
|
||||
using SharpIDE.Application.Features.FileWatching;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
|
||||
namespace SharpIDE.Godot.Features.SolutionExplorer.ContextMenus.Dialogs;
|
||||
|
||||
@@ -8,7 +8,7 @@ public partial class NewDirectoryDialog : ConfirmationDialog
|
||||
{
|
||||
private LineEdit _nameLineEdit = null!;
|
||||
|
||||
public SharpIdeFolder ParentFolder { get; set; } = null!;
|
||||
public IFolderOrProject ParentFolder { get; set; } = null!;
|
||||
|
||||
[Inject] private readonly IdeFileOperationsService _ideFileOperationsService = null!;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Godot;
|
||||
using SharpIDE.Application.Features.FileWatching;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
using SharpIDE.Godot.Features.SolutionExplorer.ContextMenus.Dialogs;
|
||||
|
||||
namespace SharpIDE.Godot.Features.SolutionExplorer;
|
||||
@@ -76,7 +77,7 @@ public partial class SolutionExplorerPanel
|
||||
|
||||
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, IFolderOrProject folder)
|
||||
{
|
||||
var actionId = (CreateNewSubmenuOptions)id;
|
||||
if (actionId is CreateNewSubmenuOptions.Directory)
|
||||
|
||||
@@ -11,11 +11,18 @@ namespace SharpIDE.Godot.Features.SolutionExplorer;
|
||||
|
||||
file enum ProjectContextMenuOptions
|
||||
{
|
||||
Run = 0,
|
||||
Build = 1,
|
||||
Rebuild = 2,
|
||||
Clean = 3,
|
||||
Restore = 4
|
||||
CreateNew = 0,
|
||||
Run = 1,
|
||||
Build = 2,
|
||||
Rebuild = 3,
|
||||
Clean = 4,
|
||||
Restore = 5
|
||||
}
|
||||
|
||||
file enum CreateNewSubmenuOptions
|
||||
{
|
||||
Directory = 1,
|
||||
CSharpFile = 2
|
||||
}
|
||||
|
||||
public partial class SolutionExplorerPanel
|
||||
@@ -29,6 +36,13 @@ public partial class SolutionExplorerPanel
|
||||
{
|
||||
var menu = new PopupMenu();
|
||||
AddChild(menu);
|
||||
var createNewSubmenu = new PopupMenu();
|
||||
menu.AddSubmenuNodeItem("Add", createNewSubmenu, (int)ProjectContextMenuOptions.CreateNew);
|
||||
menu.AddSeparator();
|
||||
createNewSubmenu.AddItem("Directory", (int)CreateNewSubmenuOptions.Directory);
|
||||
createNewSubmenu.AddItem("C# File", (int)CreateNewSubmenuOptions.CSharpFile);
|
||||
createNewSubmenu.IdPressed += id => OnCreateNewSubmenuPressed(id, project);
|
||||
|
||||
menu.AddIconItem(_runIcon, "Run", (int)ProjectContextMenuOptions.Run);
|
||||
menu.SetItemIconMaxWidth((int)ProjectContextMenuOptions.Run, 20);
|
||||
menu.AddSeparator();
|
||||
|
||||
Reference in New Issue
Block a user