cut and paste files
This commit is contained in:
@@ -57,6 +57,15 @@ public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpI
|
||||
return sharpIdeFile;
|
||||
}
|
||||
|
||||
public async Task<SharpIdeFile> MoveFile(IFolderOrProject destinationParentNode, SharpIdeFile fileToMove)
|
||||
{
|
||||
var newFilePath = Path.Combine(destinationParentNode.ChildNodeBasePath, fileToMove.Name);
|
||||
if (File.Exists(newFilePath)) throw new InvalidOperationException($"File {newFilePath} already exists.");
|
||||
File.Move(fileToMove.Path, newFilePath);
|
||||
var sharpIdeFile = await _sharpIdeSolutionModificationService.MoveFile(destinationParentNode, fileToMove);
|
||||
return sharpIdeFile;
|
||||
}
|
||||
|
||||
private static string GetFileParentNodePath(IFolderOrProject parentNode) => parentNode switch
|
||||
{
|
||||
SharpIdeFolder folder => folder.Path,
|
||||
|
||||
@@ -110,4 +110,17 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS
|
||||
SolutionModel.AllFiles.Remove(file);
|
||||
await _fileChangedService.SharpIdeFileRemoved(file);
|
||||
}
|
||||
|
||||
public async Task<SharpIdeFile> MoveFile(IFolderOrProject destinationParentNode, SharpIdeFile fileToMove)
|
||||
{
|
||||
var oldPath = fileToMove.Path;
|
||||
var newFilePath = Path.Combine(destinationParentNode.ChildNodeBasePath, fileToMove.Name);
|
||||
var parentFolderOrProject = (IFolderOrProject)fileToMove.Parent;
|
||||
parentFolderOrProject.Files.Remove(fileToMove);
|
||||
destinationParentNode.Files.Add(fileToMove);
|
||||
fileToMove.Parent = destinationParentNode;
|
||||
fileToMove.Path = newFilePath;
|
||||
await _fileChangedService.SharpIdeFileMoved(fileToMove, oldPath);
|
||||
return fileToMove;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public partial class SolutionExplorerPanel
|
||||
.OfType<RefCountedContainer<SharpIdeFile>>()
|
||||
.Select(s => s.Item)
|
||||
.ToList(),
|
||||
ClipboardOperation.Copy);
|
||||
clipboardOperation);
|
||||
}
|
||||
|
||||
private List<TreeItem> GetSelectedTreeItems()
|
||||
@@ -75,6 +75,14 @@ public partial class SolutionExplorerPanel
|
||||
await _ideFileOperationsService.CopyFile(folderOrProject, fileToPaste.Path, fileToPaste.Name);
|
||||
}
|
||||
}
|
||||
// This will blow up if cutting a file into a directory that already has a file with the same name, but I don't really want to handle renaming cut-pasted files for MVP
|
||||
else if (operation is ClipboardOperation.Cut)
|
||||
{
|
||||
foreach (var fileToPaste in filesToPaste)
|
||||
{
|
||||
await _ideFileOperationsService.MoveFile(folderOrProject, fileToPaste);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user