diff --git a/Source/Editor/CustomEditors/Editors/CollectionEditor.cs b/Source/Editor/CustomEditors/Editors/CollectionEditor.cs index cfc11d5a5..50b3e47d5 100644 --- a/Source/Editor/CustomEditors/Editors/CollectionEditor.cs +++ b/Source/Editor/CustomEditors/Editors/CollectionEditor.cs @@ -70,7 +70,9 @@ namespace FlaxEditor.CustomEditors.Editors menu.ItemsContainer.RemoveChildren(); menu.AddButton("Copy", linkedEditor.Copy); - var b = menu.AddButton("Paste", linkedEditor.Paste); + var b = menu.AddButton("Duplicate", () => Editor.Duplicate(Index)); + b.Enabled = linkedEditor.CanPaste && !Editor._readOnly; + b = menu.AddButton("Paste", linkedEditor.Paste); b.Enabled = linkedEditor.CanPaste && !Editor._readOnly; menu.AddSeparator(); @@ -404,8 +406,10 @@ namespace FlaxEditor.CustomEditors.Editors var menu = new ContextMenu(); menu.AddButton("Copy", linkedEditor.Copy); + var b = menu.AddButton("Duplicate", () => Editor.Duplicate(Index)); + b.Enabled = linkedEditor.CanPaste && !Editor._readOnly; var paste = menu.AddButton("Paste", linkedEditor.Paste); - paste.Enabled = linkedEditor.CanPaste; + paste.Enabled = linkedEditor.CanPaste && !Editor._readOnly; if (_canReorder) { @@ -741,6 +745,25 @@ namespace FlaxEditor.CustomEditors.Editors cloned[srcIndex] = tmp; SetValue(cloned); } + + /// + /// Duplicates the list item. + /// + /// The index to duplicate. + public void Duplicate(int index) + { + if (IsSetBlocked) + return; + + var count = Count; + Resize(count + 1); + RefreshInternal(); // Force update values. + Shift(count, index + 1); + RefreshInternal(); // Force update values. + var cloned = CloneValues(); + cloned[index + 1] = Utilities.Utils.CloneValue(cloned[index]); + SetValue(cloned); + } /// /// Shifts the specified item at the given index and moves it through the list to the other item. It supports undo.