diff --git a/newIDE/app/src/EventsFunctionsExtensionEditor/index.js b/newIDE/app/src/EventsFunctionsExtensionEditor/index.js index 18f1813726e3..4b92374e0a76 100644 --- a/newIDE/app/src/EventsFunctionsExtensionEditor/index.js +++ b/newIDE/app/src/EventsFunctionsExtensionEditor/index.js @@ -1289,11 +1289,6 @@ export default class EventsFunctionsExtensionEditor extends React.Component< ) } onDeleteEventsFunction={this._onDeleteEventsFunction} - canRename={(eventsFunction: gdEventsFunction) => { - return !gd.MetadataDeclarationHelper.isExtensionLifecycleEventsFunction( - eventsFunction.getName() - ); - }} onRenameEventsFunction={this._makeRenameFreeEventsFunction( i18n )} diff --git a/newIDE/app/src/EventsFunctionsList/EventsFunctionTreeViewItemContent.js b/newIDE/app/src/EventsFunctionsList/EventsFunctionTreeViewItemContent.js index ebd13873fda9..59c92344210a 100644 --- a/newIDE/app/src/EventsFunctionsList/EventsFunctionTreeViewItemContent.js +++ b/newIDE/app/src/EventsFunctionsList/EventsFunctionTreeViewItemContent.js @@ -45,7 +45,6 @@ export type EventsFunctionCallbacks = {| eventsFunction: gdEventsFunction, cb: (boolean) => void ) => void, - canRename: (eventsFunction: gdEventsFunction) => boolean, onRenameEventsFunction: ( eventsFunction: gdEventsFunction, newName: string, @@ -79,6 +78,22 @@ export const getEventsFunctionTreeViewItemId = ( return `function-${eventFunction.ptr}`; }; +export const canFunctionBeRenamed = ( + eventsFunction: gdEventsFunction, + containerType: 'extension' | 'behavior' | 'object' +) => { + const name = eventsFunction.getName(); + if (containerType === 'behavior') { + return !gd.MetadataDeclarationHelper.isBehaviorLifecycleEventsFunction( + name + ); + } + if (containerType === 'object') { + return !gd.MetadataDeclarationHelper.isObjectLifecycleEventsFunction(name); + } + return !gd.MetadataDeclarationHelper.isExtensionLifecycleEventsFunction(name); +}; + export class EventsFunctionTreeViewItemContent implements TreeViewItemContent { eventsFunction: gdEventsFunction; props: EventsFunctionProps; @@ -199,7 +214,20 @@ export class EventsFunctionTreeViewItemContent implements TreeViewItemContent { } edit(): void { - this.props.editName(this.getId()); + if (this.canBeRenamed()) { + this.props.editName(this.getId()); + } + } + + canBeRenamed() { + return canFunctionBeRenamed( + this.eventsFunction, + this.getEventsBasedBehavior() + ? 'behavior' + : this.getEventsBasedObject() + ? 'object' + : 'extension' + ); } buildMenuTemplate(i18n: I18nType, index: number) { @@ -207,7 +235,7 @@ export class EventsFunctionTreeViewItemContent implements TreeViewItemContent { { label: i18n._(t`Rename`), click: () => this.edit(), - enabled: this.props.canRename(this.eventsFunction), + enabled: this.canBeRenamed(), accelerator: 'F2', }, { diff --git a/newIDE/app/src/EventsFunctionsList/index.js b/newIDE/app/src/EventsFunctionsList/index.js index 8db0e6f67041..424f528cf91f 100644 --- a/newIDE/app/src/EventsFunctionsList/index.js +++ b/newIDE/app/src/EventsFunctionsList/index.js @@ -29,6 +29,7 @@ import ErrorBoundary from '../UI/ErrorBoundary'; import { EventsFunctionTreeViewItemContent, getEventsFunctionTreeViewItemId, + canFunctionBeRenamed, type EventFunctionCommonProps, type EventsFunctionCallbacks, type EventsFunctionCreationParameters, @@ -405,7 +406,6 @@ const EventsFunctionsList = React.forwardRef< unsavedChanges, onSelectEventsFunction, onDeleteEventsFunction, - canRename, onRenameEventsFunction, onAddEventsFunction, onEventsFunctionAdded, @@ -567,14 +567,22 @@ const EventsFunctionsList = React.forwardRef< eventsBasedBehavior, eventsBasedObject ); - if (canRename(eventsFunction)) { + if ( + canFunctionBeRenamed( + eventsFunction, + eventsBasedBehavior + ? 'behavior' + : eventsBasedObject + ? 'object' + : 'extension' + ) + ) { editName(functionItemId); } } ); }, [ - canRename, editName, eventsFunctionsExtension, forceUpdate, @@ -750,7 +758,6 @@ const EventsFunctionsList = React.forwardRef< scrollToItem, onSelectEventsFunction, onDeleteEventsFunction, - canRename, onRenameEventsFunction, onAddEventsFunction, onEventsFunctionAdded, @@ -772,7 +779,6 @@ const EventsFunctionsList = React.forwardRef< scrollToItem, onSelectEventsFunction, onDeleteEventsFunction, - canRename, onRenameEventsFunction, onAddEventsFunction, onEventsFunctionAdded, diff --git a/newIDE/app/src/stories/componentStories/EventsFunctionsExtensionEditor/EventsFunctionsList.stories.js b/newIDE/app/src/stories/componentStories/EventsFunctionsExtensionEditor/EventsFunctionsList.stories.js index 8c6e18faa6af..fca461000534 100644 --- a/newIDE/app/src/stories/componentStories/EventsFunctionsExtensionEditor/EventsFunctionsList.stories.js +++ b/newIDE/app/src/stories/componentStories/EventsFunctionsExtensionEditor/EventsFunctionsList.stories.js @@ -51,7 +51,6 @@ export const Default = () => ( eventsFunction.setName(newName); cb(true); }} - canRename={() => true} forceUpdateEditor={action('force editor update')} />