Add cutting of content items.
This commit is contained in:
@@ -61,6 +61,8 @@ namespace FlaxEditor.Content.GUI
|
||||
private bool _isRubberBandSpanning;
|
||||
private Float2 _mousePressLocation;
|
||||
private Rectangle _rubberBandRectangle;
|
||||
private bool _isCutting;
|
||||
private List<ContentItem> _cutItems = new List<ContentItem>();
|
||||
|
||||
private bool _validDragOver;
|
||||
private DragActors _dragActors;
|
||||
@@ -83,9 +85,9 @@ namespace FlaxEditor.Content.GUI
|
||||
public event Action<List<ContentItem>> OnDelete;
|
||||
|
||||
/// <summary>
|
||||
/// Called when user wants to paste the files/folders.
|
||||
/// Called when user wants to paste the files/folders. Bool is for cutting.
|
||||
/// </summary>
|
||||
public event Action<string[]> OnPaste;
|
||||
public event Action<string[], bool> OnPaste;
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -496,7 +509,36 @@ namespace FlaxEditor.Content.GUI
|
||||
if (files == null || files.Length == 0)
|
||||
return;
|
||||
|
||||
OnPaste?.Invoke(files);
|
||||
OnPaste?.Invoke(files, _isCutting);
|
||||
UpdateContentItemCut(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cuts the items.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -182,6 +182,11 @@ namespace FlaxEditor.Content
|
||||
/// </summary>
|
||||
public const int DefaultHeight = (DefaultThumbnailSize + 2 * DefaultMarginSize + DefaultTextHeight);
|
||||
|
||||
/// <summary>
|
||||
/// Whether the item is being but.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -741,7 +741,8 @@ namespace FlaxEditor.Windows
|
||||
/// Pastes the specified files.
|
||||
/// </summary>
|
||||
/// <param name="files">The files paths to import.</param>
|
||||
public void Paste(string[] files)
|
||||
/// <param name="isCutting">Whether a cutting action is occuring.</param>
|
||||
public void Paste(string[] files, bool isCutting)
|
||||
{
|
||||
var importFiles = new List<string>();
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user