Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ export class SceneEditorContainer extends React.Component<RenderEditorContainerP
return project.getLayout(projectItemName);
}

saveCurrentScene = () => {
if (this.editor) this.editor.saveCurrentScene();
};

loadSceneFromFile = () => {
if (this.editor) this.editor.loadSceneFromFile();
};

saveUiSettings = () => {
const layout = this.getLayout();
const editor = this.editor;
Expand Down
17 changes: 17 additions & 0 deletions newIDE/app/src/MainFrame/MainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export type MainMenuCallbacks = {|
onOpenAskAi: () => void,
onSelectAll: () => void,
setElectronUpdateStatus: ElectronUpdateStatus => void,
onSaveScene: () => void,
onLoadScene: () => void,
|};

export type MainMenuExtraCallbacks = {|
Expand Down Expand Up @@ -81,6 +83,8 @@ export type MainMenuEvent =
| 'main-menu-open-profile'
| 'main-menu-open-ask-ai'
| 'main-menu-select-all'
| 'main-menu-save-scene'
| 'main-menu-load-scene'
| 'update-status';

const getMainMenuEventCallback = (
Expand Down Expand Up @@ -108,6 +112,8 @@ const getMainMenuEventCallback = (
'main-menu-open-profile': callbacks.onOpenProfile,
'main-menu-open-ask-ai': callbacks.onOpenAskAi,
'main-menu-select-all': callbacks.onSelectAll,
'main-menu-save-scene': callbacks.onSaveScene,
'main-menu-load-scene': callbacks.onLoadScene,
'update-status': callbacks.setElectronUpdateStatus,
};

Expand Down Expand Up @@ -188,6 +194,17 @@ export const buildMainMenuDeclarativeTemplate = ({
enabled: !!project,
},
{ type: 'separator' },
{
label: i18n._(t`Export Scene`),
onClickSendEvent: 'main-menu-save-scene',
enabled: !!project,
},
{
label: i18n._(t`Import Scene`),
onClickSendEvent: 'main-menu-load-scene',
enabled: !!project,
},
{ type: 'separator' },
{
label: i18n._(t`Close Project`),
accelerator: getElectronAccelerator(shortcutMap['CLOSE_PROJECT']),
Expand Down
48 changes: 47 additions & 1 deletion newIDE/app/src/MainFrame/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ import {
import { renderDebuggerEditorContainer } from './EditorContainers/DebuggerEditorContainer';
import { renderEventsEditorContainer } from './EditorContainers/EventsEditorContainer';
import { renderExternalEventsEditorContainer } from './EditorContainers/ExternalEventsEditorContainer';
import { renderSceneEditorContainer } from './EditorContainers/SceneEditorContainer';
import {
renderSceneEditorContainer,
SceneEditorContainer,
} from './EditorContainers/SceneEditorContainer';
import { renderExternalLayoutEditorContainer } from './EditorContainers/ExternalLayoutEditorContainer';
import { renderEventsFunctionsExtensionEditorContainer } from './EditorContainers/EventsFunctionsExtensionEditorContainer';
import { renderCustomObjectEditorContainer } from './EditorContainers/CustomObjectEditorContainer';
Expand Down Expand Up @@ -4409,6 +4412,23 @@ const MainFrame = (props: Props): React.MixedElement => {
]
);

// Automatically save the project after a scene import, so that newly
// added resources are persisted to the storage provider (e.g. cloud).
React.useEffect(
() => {
const handleSceneImported = () => {
saveProject();
};
window.addEventListener('gdevelop-scene-imported', handleSceneImported);
return () =>
window.removeEventListener(
'gdevelop-scene-imported',
handleSceneImported
);
},
[saveProject]
);

const renderSaveReminder = useSaveReminder({
onSave: saveProject,
project: currentProject,
Expand Down Expand Up @@ -5172,6 +5192,32 @@ const MainFrame = (props: Props): React.MixedElement => {
onOpenAskAi: openAskAi,
onSelectAll: selectAllInActiveEditors,
setElectronUpdateStatus: setElectronUpdateStatus,
onSaveScene: () => {
for (const paneIdentifier in state.editorTabs.panes) {
const currentTab = getCurrentTabForPane(
state.editorTabs,
paneIdentifier
);
const editorRef = currentTab ? currentTab.editorRef : null;
if (editorRef instanceof SceneEditorContainer) {
editorRef.saveCurrentScene();
return;
}
}
},
onLoadScene: () => {
for (const paneIdentifier in state.editorTabs.panes) {
const currentTab = getCurrentTabForPane(
state.editorTabs,
paneIdentifier
);
const editorRef = currentTab ? currentTab.editorRef : null;
if (editorRef instanceof SceneEditorContainer) {
editorRef.loadSceneFromFile();
return;
}
}
},
};

const isProjectOwnedBySomeoneElse =
Expand Down
Loading