mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Fix custom object editor not closed when the extension is renamed (#7066)
This commit is contained in:
@@ -78,6 +78,11 @@ type Props = {|
|
||||
onOpenCustomObjectEditor: gdEventsBasedObject => void,
|
||||
hotReloadPreviewButtonProps: HotReloadPreviewButtonProps,
|
||||
onEventsBasedObjectChildrenEdited: () => void,
|
||||
onRenamedEventsBasedObject: (
|
||||
eventsFunctionsExtension: gdEventsFunctionsExtension,
|
||||
oldName: string,
|
||||
newName: string
|
||||
) => void,
|
||||
|};
|
||||
|
||||
type State = {|
|
||||
@@ -667,7 +672,12 @@ export default class EventsFunctionsExtensionEditor extends React.Component<
|
||||
newName: string,
|
||||
done: boolean => void
|
||||
) => {
|
||||
const { project, eventsFunctionsExtension } = this.props;
|
||||
const {
|
||||
project,
|
||||
eventsFunctionsExtension,
|
||||
onRenamedEventsBasedObject,
|
||||
} = this.props;
|
||||
const oldName = eventsBasedObject.getName();
|
||||
const safeAndUniqueNewName = newNameGenerator(
|
||||
gd.Project.getSafeName(newName),
|
||||
tentativeNewName => {
|
||||
@@ -690,6 +700,11 @@ export default class EventsFunctionsExtensionEditor extends React.Component<
|
||||
eventsBasedObject.setName(safeAndUniqueNewName);
|
||||
|
||||
done(true);
|
||||
onRenamedEventsBasedObject(
|
||||
eventsFunctionsExtension,
|
||||
oldName,
|
||||
safeAndUniqueNewName
|
||||
);
|
||||
};
|
||||
|
||||
_onEventsBasedBehaviorPasted = (
|
||||
|
@@ -76,6 +76,11 @@ export type RenderEditorContainerProps = {|
|
||||
| 'extension-events-editor'
|
||||
| 'external-events-editor'
|
||||
) => void,
|
||||
onRenamedEventsBasedObject: (
|
||||
eventsFunctionsExtension: gdEventsFunctionsExtension,
|
||||
oldName: string,
|
||||
newName: string
|
||||
) => void,
|
||||
|
||||
// Project opening
|
||||
canOpen: boolean,
|
||||
|
@@ -118,7 +118,9 @@ export class CustomObjectEditorContainer extends React.Component<RenderEditorCon
|
||||
getEventsFunctionsExtension(): ?gdEventsFunctionsExtension {
|
||||
const { project, projectItemName } = this.props;
|
||||
if (!project || !projectItemName) return null;
|
||||
const extensionName = projectItemName.split('::')[0]; //TODO
|
||||
const extensionName = gd.PlatformExtension.getExtensionFromFullObjectType(
|
||||
projectItemName
|
||||
);
|
||||
|
||||
if (!project.hasEventsFunctionsExtensionNamed(extensionName)) {
|
||||
return null;
|
||||
@@ -126,6 +128,13 @@ export class CustomObjectEditorContainer extends React.Component<RenderEditorCon
|
||||
return project.getEventsFunctionsExtension(extensionName);
|
||||
}
|
||||
|
||||
getEventsFunctionsExtensionName(): ?string {
|
||||
const { project, projectItemName } = this.props;
|
||||
if (!project || !projectItemName) return null;
|
||||
|
||||
return gd.PlatformExtension.getExtensionFromFullObjectType(projectItemName);
|
||||
}
|
||||
|
||||
getEventsBasedObject(): ?gdEventsBasedObject {
|
||||
const { project, projectItemName } = this.props;
|
||||
if (!project || !projectItemName) return null;
|
||||
@@ -133,7 +142,9 @@ export class CustomObjectEditorContainer extends React.Component<RenderEditorCon
|
||||
const extension = this.getEventsFunctionsExtension();
|
||||
if (!extension) return null;
|
||||
|
||||
const eventsBasedObjectName = projectItemName.split('::')[1];
|
||||
const eventsBasedObjectName = gd.PlatformExtension.getObjectNameFromFullObjectType(
|
||||
projectItemName
|
||||
);
|
||||
|
||||
if (!extension.getEventsBasedObjects().has(eventsBasedObjectName)) {
|
||||
return null;
|
||||
@@ -141,6 +152,18 @@ export class CustomObjectEditorContainer extends React.Component<RenderEditorCon
|
||||
return extension.getEventsBasedObjects().get(eventsBasedObjectName);
|
||||
}
|
||||
|
||||
getEventsBasedObjectName(): ?string {
|
||||
const { project, projectItemName } = this.props;
|
||||
if (!project || !projectItemName) return null;
|
||||
|
||||
const extension = this.getEventsFunctionsExtension();
|
||||
if (!extension) return null;
|
||||
|
||||
return gd.PlatformExtension.getObjectNameFromFullObjectType(
|
||||
projectItemName
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { project, isActive } = this.props;
|
||||
if (!project) return null;
|
||||
|
@@ -176,6 +176,7 @@ export class EventsFunctionsExtensionEditorContainer extends React.Component<Ren
|
||||
onEventsBasedObjectChildrenEdited={
|
||||
this.props.onEventsBasedObjectChildrenEdited
|
||||
}
|
||||
onRenamedEventsBasedObject={this.props.onRenamedEventsBasedObject}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
@@ -340,14 +340,36 @@ export const closeEventsFunctionsExtensionTabs = (
|
||||
) => {
|
||||
return closeTabsExceptIf(state, editorTab => {
|
||||
const editor = editorTab.editorRef;
|
||||
if (editor instanceof EventsFunctionsExtensionEditorContainer) {
|
||||
if (
|
||||
editor instanceof EventsFunctionsExtensionEditorContainer ||
|
||||
editor instanceof CustomObjectEditorContainer
|
||||
) {
|
||||
return (
|
||||
!editor.getEventsFunctionsExtensionName() ||
|
||||
editor.getEventsFunctionsExtensionName() !==
|
||||
eventsFunctionsExtensionName
|
||||
);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
export const closeCustomObjectTab = (
|
||||
state: EditorTabsState,
|
||||
eventsFunctionsExtensionName: string,
|
||||
eventsBasedObjectName: string
|
||||
) => {
|
||||
return closeTabsExceptIf(state, editorTab => {
|
||||
const editor = editorTab.editorRef;
|
||||
if (editor instanceof CustomObjectEditorContainer) {
|
||||
return (
|
||||
(!editor.getEventsFunctionsExtensionName() ||
|
||||
editor.getEventsFunctionsExtensionName() !==
|
||||
eventsFunctionsExtensionName) &&
|
||||
(!editor.getEventsBasedObjectName() ||
|
||||
editor.getEventsBasedObjectName() !== eventsBasedObjectName)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
@@ -39,6 +39,7 @@ import {
|
||||
closeExternalLayoutTabs,
|
||||
closeExternalEventsTabs,
|
||||
closeEventsFunctionsExtensionTabs,
|
||||
closeCustomObjectTab,
|
||||
saveUiSettings,
|
||||
type EditorTabsState,
|
||||
type EditorTab,
|
||||
@@ -1474,6 +1475,7 @@ const MainFrame = (props: Props) => {
|
||||
oldName
|
||||
);
|
||||
|
||||
// TODO Replace the tabs instead on closing them.
|
||||
setState(state => ({
|
||||
...state,
|
||||
editorTabs: closeEventsFunctionsExtensionTabs(state.editorTabs, oldName),
|
||||
@@ -1485,6 +1487,22 @@ const MainFrame = (props: Props) => {
|
||||
});
|
||||
};
|
||||
|
||||
const onRenamedEventsBasedObject = (
|
||||
eventsFunctionsExtension: gdEventsFunctionsExtension,
|
||||
oldName: string,
|
||||
newName: string
|
||||
) => {
|
||||
// TODO Replace the tabs instead on closing them.
|
||||
setState(state => ({
|
||||
...state,
|
||||
editorTabs: closeCustomObjectTab(
|
||||
state.editorTabs,
|
||||
eventsFunctionsExtension.getName(),
|
||||
oldName
|
||||
),
|
||||
}));
|
||||
};
|
||||
|
||||
const setPreviewedLayout = (
|
||||
previewLayoutName: ?string,
|
||||
previewExternalLayoutName?: ?string
|
||||
@@ -3561,6 +3579,7 @@ const MainFrame = (props: Props) => {
|
||||
onCreateEventsFunction,
|
||||
openInstructionOrExpression,
|
||||
onOpenCustomObjectEditor: openCustomObjectEditor,
|
||||
onRenamedEventsBasedObject: onRenamedEventsBasedObject,
|
||||
openObjectEvents,
|
||||
unsavedChanges: unsavedChanges,
|
||||
canOpen: !!props.storageProviders.filter(
|
||||
|
@@ -35,6 +35,7 @@ export const Default = () => (
|
||||
initiallyFocusedObjectName={null}
|
||||
onCreateEventsFunction={action('on create events function')}
|
||||
onOpenCustomObjectEditor={action('onOpenCustomObjectEditor')}
|
||||
onRenamedEventsBasedObject={action('onRenamedEventsBasedObject')}
|
||||
onEventsBasedObjectChildrenEdited={action(
|
||||
'onEventsBasedObjectChildrenEdited'
|
||||
)}
|
||||
@@ -66,6 +67,7 @@ export const WithObjectEditor = () => {
|
||||
initiallyFocusedObjectName={null}
|
||||
onCreateEventsFunction={action('on create events function')}
|
||||
onOpenCustomObjectEditor={action('onOpenCustomObjectEditor')}
|
||||
onRenamedEventsBasedObject={action('onRenamedEventsBasedObject')}
|
||||
onEventsBasedObjectChildrenEdited={action(
|
||||
'onEventsBasedObjectChildrenEdited'
|
||||
)}
|
||||
|
Reference in New Issue
Block a user