diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.Clipboard.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.Clipboard.cs new file mode 100644 index 0000000..55767a7 --- /dev/null +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.Clipboard.cs @@ -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(); + if (genericMetadata is RefCountedContainer fileContainer) + { + _itemOnClipboard = (fileContainer.Item, ClipboardOperation.Copy); + } + } + + private void CutSelectedNodeToSlnExplorerClipboard() + { + var selected = _tree.GetSelected(); + if (selected is null) return; + var genericMetadata = selected.GetMetadata(0).As(); + if (genericMetadata is RefCountedContainer 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(); + IFolderOrProject? folderOrProject = genericMetadata switch + { + RefCountedContainer f => f.Item, + RefCountedContainer 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); + } + }); + } +} \ No newline at end of file diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.Clipboard.cs.uid b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.Clipboard.cs.uid new file mode 100644 index 0000000..0022d64 --- /dev/null +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.Clipboard.cs.uid @@ -0,0 +1 @@ +uid://3vyxuek1gy86 diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs index b20d61f..4c4c14a 100644 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs @@ -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(); - if (genericMetadata is RefCountedContainer 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(); - if (genericMetadata is RefCountedContainer 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(); - IFolderOrProject? folderOrProject = genericMetadata switch - { - RefCountedContainer f => f.Item, - RefCountedContainer 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(); } }