Skip to content

Commit cef3522

Browse files
authored
Add a duplicate action in the functions lists contextual menu. (#4085)
1 parent 49ea27f commit cef3522

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

newIDE/app/src/EventsBasedBehaviorsList/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export default class EventsBasedBehaviorsList extends React.Component<
254254
{
255255
label: i18n._(t`Paste`),
256256
enabled: Clipboard.has(EVENTS_BASED_BEHAVIOR_CLIPBOARD_KIND),
257-
click: () => this._pasteEventsBasedBehavior(index),
257+
click: () => this._pasteEventsBasedBehavior(index + 1),
258258
},
259259
];
260260
};

newIDE/app/src/EventsFunctionsList/index.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,26 @@ export default class EventsFunctionsList extends React.Component<Props, State> {
271271
this._editName(newEventsFunction);
272272
};
273273

274+
_duplicateEventsFunction = (
275+
eventsFunction: gdEventsFunction,
276+
newFunctionIndex: number
277+
) => {
278+
const { eventsFunctionsContainer } = this.props;
279+
const newName = newNameGenerator(eventsFunction.getName(), name =>
280+
eventsFunctionsContainer.hasEventsFunctionNamed(name)
281+
);
282+
const newEventsFunction = eventsFunctionsContainer.insertEventsFunction(
283+
eventsFunction,
284+
newFunctionIndex
285+
);
286+
newEventsFunction.setName(newName);
287+
this.props.onEventsFunctionAdded(newEventsFunction);
288+
289+
this._onEventsFunctionModified();
290+
this.props.onSelectEventsFunction(newEventsFunction);
291+
this._editName(newEventsFunction);
292+
};
293+
274294
_onEventsFunctionModified() {
275295
if (this.props.unsavedChanges)
276296
this.props.unsavedChanges.triggerUnsavedChanges();
@@ -315,7 +335,11 @@ export default class EventsFunctionsList extends React.Component<Props, State> {
315335
{
316336
label: i18n._(t`Paste`),
317337
enabled: Clipboard.has(EVENTS_FUNCTION_CLIPBOARD_KIND),
318-
click: () => this._pasteEventsFunction(index),
338+
click: () => this._pasteEventsFunction(index + 1),
339+
},
340+
{
341+
label: i18n._(t`Duplicate`),
342+
click: () => this._duplicateEventsFunction(eventsFunction, index + 1),
319343
},
320344
];
321345
};

0 commit comments

Comments
 (0)