move directories in sln explorer
This commit is contained in:
@@ -70,7 +70,8 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS
|
|||||||
|
|
||||||
var parentFolderOrProject = (IFolderOrProject)folderToMove.Parent;
|
var parentFolderOrProject = (IFolderOrProject)folderToMove.Parent;
|
||||||
parentFolderOrProject.Folders.Remove(folderToMove);
|
parentFolderOrProject.Folders.Remove(folderToMove);
|
||||||
destinationParentNode.Folders.Add(folderToMove);
|
var insertionIndex = GetInsertionPosition(destinationParentNode, folderToMove);
|
||||||
|
destinationParentNode.Folders.Insert(insertionIndex, folderToMove);
|
||||||
folderToMove.Parent = destinationParentNode;
|
folderToMove.Parent = destinationParentNode;
|
||||||
folderToMove.Path = newFolderPath;
|
folderToMove.Path = newFolderPath;
|
||||||
|
|
||||||
@@ -103,6 +104,11 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS
|
|||||||
folder.Name = renamedFolderName;
|
folder.Name = renamedFolderName;
|
||||||
folder.Path = Path.Combine(Path.GetDirectoryName(oldFolderPath)!, renamedFolderName);
|
folder.Path = Path.Combine(Path.GetDirectoryName(oldFolderPath)!, renamedFolderName);
|
||||||
|
|
||||||
|
var parentFolderOrProject = (IFolderOrProject)folder.Parent;
|
||||||
|
var currentPosition = parentFolderOrProject.Folders.IndexOf(folder);
|
||||||
|
var insertionPosition = GetMovePosition(parentFolderOrProject, folder);
|
||||||
|
parentFolderOrProject.Files.Move(currentPosition, insertionPosition);
|
||||||
|
|
||||||
var stack = new Stack<SharpIdeFolder>();
|
var stack = new Stack<SharpIdeFolder>();
|
||||||
stack.Push(folder);
|
stack.Push(folder);
|
||||||
|
|
||||||
@@ -157,11 +163,18 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS
|
|||||||
return correctInsertionPosition;
|
return correctInsertionPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetMovePosition(IFolderOrProject parentNode, SharpIdeFile sharpIdeFile)
|
private static int GetMovePosition(IFolderOrProject parentNode, IFileOrFolder fileOrFolder)
|
||||||
{
|
{
|
||||||
var correctInsertionPosition = parentNode.Files.list
|
var correctInsertionPosition = fileOrFolder switch
|
||||||
.FindAll(x => x != sharpIdeFile) // TODO: Investigate allocations
|
{
|
||||||
.BinarySearch(sharpIdeFile, SharpIdeFileComparer.Instance);
|
SharpIdeFile f => parentNode.Files.list
|
||||||
|
.FindAll(x => x != f) // TODO: Investigate allocations
|
||||||
|
.BinarySearch(f, SharpIdeFileComparer.Instance),
|
||||||
|
SharpIdeFolder d => parentNode.Folders.list
|
||||||
|
.FindAll(x => x != d) // TODO: Investigate allocations
|
||||||
|
.BinarySearch(d, SharpIdeFolderComparer.Instance),
|
||||||
|
_ => throw new InvalidOperationException("Unknown file or folder type")
|
||||||
|
};
|
||||||
|
|
||||||
if (correctInsertionPosition < 0)
|
if (correctInsertionPosition < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user