From 475ef08ee2dbf6016b4a5e19b7c3987bf33e9f27 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Tue, 21 Oct 2025 19:21:19 +1000 Subject: [PATCH] refactor --- .../SolutionExplorerPanel.Clipboard.cs | 60 +++++++++++++++++++ .../SolutionExplorerPanel.Clipboard.cs.uid | 1 + .../SolutionExplorer/SolutionExplorerPanel.cs | 38 +----------- 3 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.Clipboard.cs create mode 100644 src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.Clipboard.cs.uid 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(); } }