From 9eada905f9be78296ee4aeafcb70fbb021992faa Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Mon, 18 Nov 2024 11:28:40 +0100 Subject: [PATCH] Add "Create new folder" menu item inside "Move to folder" menu (#7172) --- .../ObjectFolderTreeViewItemContent.js | 48 ++++++++++++------- .../ObjectsList/ObjectTreeViewItemContent.js | 43 ++++++++++++----- newIDE/app/src/ObjectsList/index.js | 2 + 3 files changed, 64 insertions(+), 29 deletions(-) diff --git a/newIDE/app/src/ObjectsList/ObjectFolderTreeViewItemContent.js b/newIDE/app/src/ObjectsList/ObjectFolderTreeViewItemContent.js index eaf18dd624f8..da1299af40e0 100644 --- a/newIDE/app/src/ObjectsList/ObjectFolderTreeViewItemContent.js +++ b/newIDE/app/src/ObjectsList/ObjectFolderTreeViewItemContent.js @@ -234,24 +234,38 @@ export class ObjectFolderTreeViewItemContent implements TreeViewItemContent { }, { label: i18n._('Move to folder'), - submenu: filteredFolderAndPathsInContainer.map(({ folder, path }) => ({ - label: path, - enabled: folder !== this.objectFolder.getParent(), - click: () => { - if (folder === this.objectFolder.getParent()) return; - this.objectFolder - .getParent() - .moveObjectFolderOrObjectToAnotherFolder( - this.objectFolder, - folder, - 0 - ); - onMovedObjectFolderOrObjectToAnotherFolderInSameContainer({ - objectFolderOrObject: folder, - global: this._isGlobal, - }); + submenu: [ + ...filteredFolderAndPathsInContainer.map(({ folder, path }) => ({ + label: path, + enabled: folder !== this.objectFolder.getParent(), + click: () => { + if (folder === this.objectFolder.getParent()) return; + this.objectFolder + .getParent() + .moveObjectFolderOrObjectToAnotherFolder( + this.objectFolder, + folder, + 0 + ); + onMovedObjectFolderOrObjectToAnotherFolderInSameContainer({ + objectFolderOrObject: folder, + global: this._isGlobal, + }); + }, + })), + + { type: 'separator' }, + { + label: i18n._(t`Create new folder...`), + click: () => + addFolder([ + { + objectFolderOrObject: this.objectFolder.getParent(), + global: this._isGlobal, + }, + ]), }, - })), + ], }, ...renderQuickCustomizationMenuItems({ i18n, diff --git a/newIDE/app/src/ObjectsList/ObjectTreeViewItemContent.js b/newIDE/app/src/ObjectsList/ObjectTreeViewItemContent.js index aebb1828542e..54bc28298826 100644 --- a/newIDE/app/src/ObjectsList/ObjectTreeViewItemContent.js +++ b/newIDE/app/src/ObjectsList/ObjectTreeViewItemContent.js @@ -79,6 +79,7 @@ export type ObjectTreeViewItemProps = {| selectObjectFolderOrObjectWithContext: ( objectFolderOrObjectWithContext: ?ObjectFolderOrObjectWithContext ) => void, + addFolder: (items: Array) => void, forceUpdateList: () => void, forceUpdate: () => void, |}; @@ -280,6 +281,7 @@ export class ObjectTreeViewItemContent implements TreeViewItemContent { setAsGlobalObject, onOpenEventBasedObjectEditor, selectObjectFolderOrObjectWithContext, + addFolder, } = this.props; const container = this._isGlobal @@ -390,19 +392,36 @@ export class ObjectTreeViewItemContent implements TreeViewItemContent { }, { label: i18n._('Move to folder'), - submenu: folderAndPathsInContainer.map(({ folder, path }) => ({ - label: path, - enabled: folder !== this.object.getParent(), - click: () => { - this.object - .getParent() - .moveObjectFolderOrObjectToAnotherFolder(this.object, folder, 0); - onMovedObjectFolderOrObjectToAnotherFolderInSameContainer({ - objectFolderOrObject: folder, - global: this._isGlobal, - }); + submenu: [ + ...folderAndPathsInContainer.map(({ folder, path }) => ({ + label: path, + enabled: folder !== this.object.getParent(), + click: () => { + this.object + .getParent() + .moveObjectFolderOrObjectToAnotherFolder( + this.object, + folder, + 0 + ); + onMovedObjectFolderOrObjectToAnotherFolderInSameContainer({ + objectFolderOrObject: folder, + global: this._isGlobal, + }); + }, + })), + { type: 'separator' }, + { + label: i18n._(t`Create new folder...`), + click: () => + addFolder([ + { + objectFolderOrObject: this.object.getParent(), + global: this._isGlobal, + }, + ]), }, - })), + ], }, { type: 'separator' }, { diff --git a/newIDE/app/src/ObjectsList/index.js b/newIDE/app/src/ObjectsList/index.js index 4dcf0e07b605..be0393285f46 100644 --- a/newIDE/app/src/ObjectsList/index.js +++ b/newIDE/app/src/ObjectsList/index.js @@ -947,6 +947,7 @@ const ObjectsList = React.forwardRef( getThumbnail, showDeleteConfirmation, selectObjectFolderOrObjectWithContext, + addFolder, forceUpdateList, forceUpdate, }), @@ -972,6 +973,7 @@ const ObjectsList = React.forwardRef( getThumbnail, showDeleteConfirmation, selectObjectFolderOrObjectWithContext, + addFolder, forceUpdateList, forceUpdate, ]