diff --git a/newIDE/app/src/EventsFunctionsExtensionEditor/PropertyListEditor/EventsBasedEntityPropertyTreeViewItemContent.js b/newIDE/app/src/EventsFunctionsExtensionEditor/PropertyListEditor/EventsBasedEntityPropertyTreeViewItemContent.js index e4e44083218a..16ff941c2dec 100644 --- a/newIDE/app/src/EventsFunctionsExtensionEditor/PropertyListEditor/EventsBasedEntityPropertyTreeViewItemContent.js +++ b/newIDE/app/src/EventsFunctionsExtensionEditor/PropertyListEditor/EventsBasedEntityPropertyTreeViewItemContent.js @@ -102,7 +102,24 @@ export const pasteProperties = async ( index++; const groupName = property.getGroup(); unserializeFromJSObject(property, serializedProperty); - property.setGroup(groupName); + // Try to rebuild the folder structure when several properties are paste at once. + if ( + propertyContents.length > 1 && + parentFolder === properties.getRootFolder() && + property.getGroup() + ) { + const root = properties.getRootFolder(); + const folder = root.getOrCreateChildFolder(property.getGroup()); + properties + .getRootFolder() + .movePropertyFolderOrPropertyToAnotherFolder( + root.getPropertyChild(property.getName()), + folder, + folder.getChildrenCount() + ); + } else { + property.setGroup(groupName); + } if (!firstAddedPropertyName) { firstAddedPropertyName = name; } diff --git a/newIDE/app/src/EventsFunctionsExtensionEditor/PropertyListEditor/index.js b/newIDE/app/src/EventsFunctionsExtensionEditor/PropertyListEditor/index.js index 31264bd770b6..bf80506c613d 100644 --- a/newIDE/app/src/EventsFunctionsExtensionEditor/PropertyListEditor/index.js +++ b/newIDE/app/src/EventsFunctionsExtensionEditor/PropertyListEditor/index.js @@ -34,6 +34,8 @@ import { EventsBasedEntityPropertyTreeViewItemContent, getEventsBasedEntityPropertyTreeViewItemId, type EventsBasedEntityPropertyTreeViewItemProps, + PROPERTIES_CLIPBOARD_KIND, + pasteProperties, } from './EventsBasedEntityPropertyTreeViewItemContent'; import { EventsBasedEntityPropertyFolderTreeViewItemContent, @@ -53,6 +55,8 @@ import { getFoldersAscendanceWithoutRootFolder, enumerateFoldersInContainer, } from './EnumeratePropertyFolderOrProperty'; +import Clipboard from '../../Utils/Clipboard'; +import { serializeToJSObject } from '../../Utils/Serializer'; const configurationItemId = 'events-based-entity-configuration'; export const propertiesRootFolderId = 'properties'; @@ -805,6 +809,46 @@ const PropertyListEditor = React.forwardRef( ] ); + const copyAllProperties = React.useCallback( + (propertiesContainer: gdPropertiesContainer) => { + Clipboard.set( + PROPERTIES_CLIPBOARD_KIND, + mapFor(0, propertiesContainer.getCount(), i => { + const property = propertiesContainer.getAt(i); + return { + name: property.getName(), + serializedProperty: serializeToJSObject(property), + }; + }) + ); + }, + [] + ); + + const pastePropertiesInRoot = React.useCallback( + async (propertiesContainer: gdPropertiesContainer) => { + const hasPasteAnyProperty = await pasteProperties( + propertiesContainer, + propertiesContainer.getRootFolder(), + 0, + showPropertyOverridingConfirmation + ); + if (hasPasteAnyProperty) { + if (unsavedChanges) { + unsavedChanges.triggerUnsavedChanges(); + } + forceUpdate(); + onPropertiesUpdated(); + } + }, + [ + forceUpdate, + onPropertiesUpdated, + showPropertyOverridingConfirmation, + unsavedChanges, + ] + ); + const onMovedPropertyFolderOrPropertyToAnotherFolderInSameContainer = React.useCallback( ( propertyFolderOrProperty: gdPropertyFolderOrProperty, @@ -1010,6 +1054,15 @@ const PropertyListEditor = React.forwardRef( addFolder([properties.getRootFolder()], false), }, { type: 'separator' }, + { + label: i18n._(t`Copy all`), + click: () => copyAllProperties(properties), + }, + { + label: i18n._(t`Paste`), + click: () => pastePropertiesInRoot(properties), + }, + { type: 'separator' }, { label: i18n._(t`Expand all sub folders`), click: () => @@ -1079,9 +1132,11 @@ const PropertyListEditor = React.forwardRef( [ addFolder, addProperty, + copyAllProperties, eventsBasedObject, expandFolders, onOpenConfiguration, + pastePropertiesInRoot, properties, propertiesTreeViewItemProps, propertyFolderTreeViewItemProps,