This commit is contained in:
Matt Parker
2025-10-21 19:21:19 +10:00
parent 439a8d96f9
commit 475ef08ee2
3 changed files with 64 additions and 35 deletions

View File

@@ -0,0 +1,60 @@
using Godot;
using SharpIDE.Application.Features.SolutionDiscovery;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
using SharpIDE.Godot.Features.Problems;
namespace SharpIDE.Godot.Features.SolutionExplorer;
public partial class SolutionExplorerPanel
{
private void CopySelectedNodeToSlnExplorerClipboard()
{
var selected = _tree.GetSelected();
if (selected is null) return;
var genericMetadata = selected.GetMetadata(0).As<RefCounted?>();
if (genericMetadata is RefCountedContainer<SharpIdeFile> fileContainer)
{
_itemOnClipboard = (fileContainer.Item, ClipboardOperation.Copy);
}
}
private void CutSelectedNodeToSlnExplorerClipboard()
{
var selected = _tree.GetSelected();
if (selected is null) return;
var genericMetadata = selected.GetMetadata(0).As<RefCounted?>();
if (genericMetadata is RefCountedContainer<SharpIdeFile> fileContainer)
{
_itemOnClipboard = (fileContainer.Item, ClipboardOperation.Cut);
}
}
private void ClearSlnExplorerClipboard()
{
_itemOnClipboard = null;
}
private void CopyNodeFromClipboardToSelectedNode()
{
var selected = _tree.GetSelected();
if (selected is null || _itemOnClipboard is null) return;
var genericMetadata = selected.GetMetadata(0).As<RefCounted?>();
IFolderOrProject? folderOrProject = genericMetadata switch
{
RefCountedContainer<SharpIdeFolder> f => f.Item,
RefCountedContainer<SharpIdeProjectModel> p => p.Item,
_ => null
};
if (folderOrProject is null) return;
var (fileToPaste, operation) = _itemOnClipboard.Value;
_itemOnClipboard = null;
_ = Task.GodotRun(async () =>
{
if (operation is ClipboardOperation.Copy)
{
await _ideFileOperationsService.CopyFile(folderOrProject, fileToPaste.Path, fileToPaste.Name);
}
});
}
}

View File

@@ -0,0 +1 @@
uid://3vyxuek1gy86

View File

@@ -41,49 +41,17 @@ public partial class SolutionExplorerPanel : MarginContainer
// Copy
if (@event is InputEventKey { Pressed: true, Keycode: Key.C, CtrlPressed: true })
{
var selected = _tree.GetSelected();
if (selected is null) return;
var genericMetadata = selected.GetMetadata(0).As<RefCounted?>();
if (genericMetadata is RefCountedContainer<SharpIdeFile> fileContainer)
{
_itemOnClipboard = (fileContainer.Item, ClipboardOperation.Copy);
}
CopySelectedNodeToSlnExplorerClipboard();
}
// Cut
else if (@event is InputEventKey { Pressed: true, Keycode: Key.X, CtrlPressed: true })
{
var selected = _tree.GetSelected();
if (selected is null) return;
var genericMetadata = selected.GetMetadata(0).As<RefCounted?>();
if (genericMetadata is RefCountedContainer<SharpIdeFile> fileContainer)
{
_itemOnClipboard = (fileContainer.Item, ClipboardOperation.Cut);
}
CutSelectedNodeToSlnExplorerClipboard();
}
// Paste
else if (@event is InputEventKey { Pressed: true, Keycode: Key.V, CtrlPressed: true })
{
var selected = _tree.GetSelected();
if (selected is null || _itemOnClipboard is null) return;
var genericMetadata = selected.GetMetadata(0).As<RefCounted?>();
IFolderOrProject? folderOrProject = genericMetadata switch
{
RefCountedContainer<SharpIdeFolder> f => f.Item,
RefCountedContainer<SharpIdeProjectModel> p => p.Item,
_ => null
};
if (folderOrProject is null) return;
var (fileToPaste, operation) = _itemOnClipboard.Value;
_itemOnClipboard = null;
_ = Task.GodotRun(async () =>
{
if (operation is ClipboardOperation.Copy)
{
await _ideFileOperationsService.CopyFile(folderOrProject, fileToPaste.Path, fileToPaste.Name);
}
});
CopyNodeFromClipboardToSelectedNode();
}
}