diff --git a/Source/Editor/Content/GUI/ContentView.cs b/Source/Editor/Content/GUI/ContentView.cs index fee36bbb0..8f9bafc87 100644 --- a/Source/Editor/Content/GUI/ContentView.cs +++ b/Source/Editor/Content/GUI/ContentView.cs @@ -61,6 +61,8 @@ namespace FlaxEditor.Content.GUI private bool _isRubberBandSpanning; private Float2 _mousePressLocation; private Rectangle _rubberBandRectangle; + private bool _isCutting; + private List _cutItems = new List(); private bool _validDragOver; private DragActors _dragActors; @@ -83,9 +85,9 @@ namespace FlaxEditor.Content.GUI public event Action> OnDelete; /// - /// Called when user wants to paste the files/folders. + /// Called when user wants to paste the files/folders. Bool is for cutting. /// - public event Action OnPaste; + public event Action OnPaste; /// /// Called when user wants to duplicate the item(s). @@ -210,6 +212,15 @@ namespace FlaxEditor.Content.GUI }), new InputActionsContainer.Binding(options => options.Copy, Copy), new InputActionsContainer.Binding(options => options.Paste, Paste), + new InputActionsContainer.Binding(options => options.Cut, Cut), + new InputActionsContainer.Binding(options => options.Undo, () => + { + if (_isCutting) + { + _isCutting = false; + UpdateContentItemCut(false); + } + }), new InputActionsContainer.Binding(options => options.Duplicate, Duplicate), }); } @@ -462,6 +473,7 @@ namespace FlaxEditor.Content.GUI /// public void Duplicate() { + UpdateContentItemCut(false); OnDuplicate?.Invoke(_selection); } @@ -475,6 +487,7 @@ namespace FlaxEditor.Content.GUI var files = _selection.ConvertAll(x => x.Path).ToArray(); Clipboard.Files = files; + UpdateContentItemCut(false); } /// @@ -496,7 +509,36 @@ namespace FlaxEditor.Content.GUI if (files == null || files.Length == 0) return; - OnPaste?.Invoke(files); + OnPaste?.Invoke(files, _isCutting); + UpdateContentItemCut(false); + } + + /// + /// Cuts the items. + /// + public void Cut() + { + Copy(); + UpdateContentItemCut(true); + } + + private void UpdateContentItemCut(bool cut) + { + _isCutting = cut; + + // Add selection to cut list + if (cut) + _cutItems.AddRange(_selection); + + // Update item with if it is being cut. + foreach (var item in _cutItems) + { + item.IsBeingCut = cut; + } + + // Clean up cut items + if (!cut) + _cutItems.Clear(); } /// diff --git a/Source/Editor/Content/Items/ContentItem.cs b/Source/Editor/Content/Items/ContentItem.cs index b511c0649..259c09481 100644 --- a/Source/Editor/Content/Items/ContentItem.cs +++ b/Source/Editor/Content/Items/ContentItem.cs @@ -182,6 +182,11 @@ namespace FlaxEditor.Content /// public const int DefaultHeight = (DefaultThumbnailSize + 2 * DefaultMarginSize + DefaultTextHeight); + /// + /// Whether the item is being but. + /// + public bool IsBeingCut; + private ContentFolder _parentFolder; private bool _isMouseDown; @@ -747,6 +752,12 @@ namespace FlaxEditor.Content Render2D.PushClip(ref textRect); Render2D.DrawText(style.FontMedium, ShowFileExtension || view.ShowFileExtensions ? FileName : ShortName, textRect, style.Foreground, nameAlignment, TextAlignment.Center, TextWrapping.WrapWords, 1f, 0.95f); Render2D.PopClip(); + + if (IsBeingCut) + { + var color = style.LightBackground.AlphaMultiplied(0.5f); + Render2D.FillRectangle(clientRect, color); + } } /// diff --git a/Source/Editor/Windows/ContentWindow.ContextMenu.cs b/Source/Editor/Windows/ContentWindow.ContextMenu.cs index 4b21a2e6a..f29f97e66 100644 --- a/Source/Editor/Windows/ContentWindow.ContextMenu.cs +++ b/Source/Editor/Windows/ContentWindow.ContextMenu.cs @@ -128,11 +128,9 @@ namespace FlaxEditor.Windows else { cm.AddButton("Delete", () => Delete(item)); - cm.AddSeparator(); - cm.AddButton("Duplicate", _view.Duplicate); - + cm.AddButton("Cut", _view.Cut); cm.AddButton("Copy", _view.Copy); } diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 8d60036cb..bb7c594b3 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -741,7 +741,8 @@ namespace FlaxEditor.Windows /// Pastes the specified files. /// /// The files paths to import. - public void Paste(string[] files) + /// Whether a cutting action is occuring. + public void Paste(string[] files, bool isCutting) { var importFiles = new List(); foreach (var sourcePath in files) @@ -752,7 +753,10 @@ namespace FlaxEditor.Windows var newPath = StringUtils.NormalizePath(Path.Combine(CurrentViewFolder.Path, item.FileName)); if (sourcePath.Equals(newPath)) newPath = GetClonedAssetPath(item); - Editor.ContentDatabase.Copy(item, newPath); + if (isCutting) + Editor.ContentDatabase.Move(item, newPath); + else + Editor.ContentDatabase.Copy(item, newPath); } else importFiles.Add(sourcePath);