From 7fa1fedd1e164129b0ba8e45aea98d84fae458bb Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Fri, 31 Oct 2025 19:25:01 +1000 Subject: [PATCH] move folders v1 --- .../SharpIdeSolutionModificationService.cs | 2 +- .../SolutionExplorer/SolutionExplorerPanel.cs | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs b/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs index ff5f085..5541b8d 100644 --- a/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs +++ b/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs @@ -107,7 +107,7 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS var parentFolderOrProject = (IFolderOrProject)folder.Parent; var currentPosition = parentFolderOrProject.Folders.IndexOf(folder); var insertionPosition = GetMovePosition(parentFolderOrProject, folder); - if (currentPosition != insertionPosition) parentFolderOrProject.Files.Move(currentPosition, insertionPosition); + if (currentPosition != insertionPosition) parentFolderOrProject.Folders.Move(currentPosition, insertionPosition); var stack = new Stack(); stack.Push(folder); diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs index fbc4fae..4034c87 100644 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs @@ -226,6 +226,7 @@ public partial class SolutionExplorerPanel : MarginContainer .SubscribeAwait(async (innerEvent, ct) => await (innerEvent.Action switch { NotifyCollectionChangedAction.Add => this.InvokeAsync(() => innerEvent.NewItem.View.Value = CreateFolderTreeItem(_tree, projectItem, innerEvent.NewItem.Value, innerEvent.NewStartingIndex)), + NotifyCollectionChangedAction.Move => MoveTreeItem(_tree, innerEvent.NewItem.View, innerEvent.NewItem.Value, innerEvent.OldStartingIndex, innerEvent.NewStartingIndex), NotifyCollectionChangedAction.Remove => FreeTreeItem(innerEvent.OldItem.View.Value), _ => Task.CompletedTask })).AddTo(this); @@ -237,6 +238,7 @@ public partial class SolutionExplorerPanel : MarginContainer .SubscribeAwait(async (innerEvent, ct) => await (innerEvent.Action switch { NotifyCollectionChangedAction.Add => this.InvokeAsync(() => innerEvent.NewItem.View.Value = CreateFileTreeItem(_tree, projectItem, innerEvent.NewItem.Value, innerEvent.NewStartingIndex)), + NotifyCollectionChangedAction.Move => MoveTreeItem(_tree, innerEvent.NewItem.View, innerEvent.NewItem.Value, innerEvent.OldStartingIndex, innerEvent.NewStartingIndex), NotifyCollectionChangedAction.Remove => FreeTreeItem(innerEvent.OldItem.View.Value), _ => Task.CompletedTask })).AddTo(this); @@ -265,6 +267,7 @@ public partial class SolutionExplorerPanel : MarginContainer .SubscribeAwait(async (innerEvent, ct) => await (innerEvent.Action switch { NotifyCollectionChangedAction.Add => this.InvokeAsync(() => innerEvent.NewItem.View.Value = CreateFolderTreeItem(_tree, folderItem, innerEvent.NewItem.Value, innerEvent.NewStartingIndex)), + NotifyCollectionChangedAction.Move => MoveTreeItem(_tree, innerEvent.NewItem.View, innerEvent.NewItem.Value, innerEvent.OldStartingIndex, innerEvent.NewStartingIndex), NotifyCollectionChangedAction.Remove => FreeTreeItem(innerEvent.OldItem.View.Value), _ => Task.CompletedTask })).AddTo(this); @@ -310,14 +313,19 @@ public partial class SolutionExplorerPanel : MarginContainer return fileItem; } - private async Task MoveTreeItem(Tree tree, TreeItemContainer treeItemContainer, SharpIdeFile sharpIdeFile, int oldStartingIndex, int newStartingIndex) + private async Task MoveTreeItem(Tree tree, TreeItemContainer treeItemContainer, IFileOrFolder fileOrFolder, int oldStartingIndex, int newStartingIndex) { if (oldStartingIndex == newStartingIndex) throw new InvalidOperationException("Old and new starting indexes are the same"); var treeItem = treeItemContainer.Value!; - var sharpIdeParent = sharpIdeFile.Parent as IFolderOrProject; - Guard.Against.Null(sharpIdeParent, nameof(sharpIdeParent)); - var folderCount = sharpIdeParent.Folders.Count; - newStartingIndex += folderCount; + var isFile = fileOrFolder is SharpIdeFile; + if (isFile) + { + var sharpIdeParent = fileOrFolder.Parent as IFolderOrProject; + Guard.Against.Null(sharpIdeParent, nameof(sharpIdeParent)); + var folderCount = sharpIdeParent.Folders.Count; + newStartingIndex += folderCount; + } + var treeParent = treeItem.GetParent()!; await this.InvokeAsync(() => { @@ -327,7 +335,7 @@ public partial class SolutionExplorerPanel : MarginContainer newItem.SetText(0, treeItem.GetText(0)); newItem.SetIcon(0, treeItem.GetIcon(0)); newItem.SetMetadata(0, treeItem.GetMetadata(0)); - newItem.SetCustomColor(0, treeItem.GetCustomColor(0)); + if (isFile) newItem.SetCustomColor(0, treeItem.GetCustomColor(0)); treeItemContainer.Value = newItem; treeItem.Free(); });