11/**
22 * @license
3- * Copyright (c) 2021, Oracle and/or its affiliates.
3+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates.
44 * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55 */
66const { app, dialog} = require ( 'electron' ) ;
@@ -91,7 +91,15 @@ async function openProject(targetWindow) {
9191 return ;
9292 }
9393
94- await openProjectFile ( targetWindow , openResponse . filePaths [ 0 ] ) ;
94+ const projectFileName = openResponse . filePaths [ 0 ] ;
95+ await openProjectFile ( targetWindow , projectFileName )
96+ . catch ( err => {
97+ dialog . showErrorBox (
98+ i18n . t ( 'dialog-openProjectFileErrorTitle' ) ,
99+ i18n . t ( 'dialog-openProjectFileErrorMessage' , { projectFileName : projectFileName , err : err } ) ,
100+ ) ;
101+ getLogger ( ) . error ( 'Failed to open project file %s: %s' , projectFileName , err ) ;
102+ } ) ;
95103}
96104
97105async function openProjectFile ( targetWindow , projectFile ) {
@@ -133,12 +141,29 @@ async function confirmProjectFile(targetWindow) {
133141 return [ projectFile , projectName , projectUuid ] ;
134142}
135143
144+ // choose a new project file for save.
145+ // return null values if no project file was established or selected.
146+ // usually called by the choose-project-file IPC invocation.
147+ async function chooseProjectFile ( targetWindow ) {
148+ const projectFile = await _chooseProjectSaveFile ( targetWindow ) ;
149+ const projectName = projectFile ? _generateProjectName ( projectFile ) : null ;
150+ const projectUuid = projectFile ? _generateProjectUuid ( ) : null ;
151+ app . addRecentDocument ( projectFile ) ;
152+ return [ projectFile , projectName , projectUuid ] ;
153+ }
154+
136155// initiate the save process by sending a message to the web app.
137156// usually called from a menu click.
138157function startSaveProject ( targetWindow ) {
139158 sendToWindow ( targetWindow , 'start-save-project' ) ;
140159}
141160
161+ // initiate the save-as process by sending a message to the web app.
162+ // usually called from a menu click.
163+ function startSaveProjectAs ( targetWindow ) {
164+ sendToWindow ( targetWindow , 'start-save-project-as' ) ;
165+ }
166+
142167// save the specified project and model contents to the project file.
143168// usually invoked by the save-project IPC invocation.
144169async function saveProject ( targetWindow , projectFile , projectContents , externalFileContents ) {
@@ -254,6 +279,21 @@ async function promptSaveBeforeClose(targetWindow) {
254279 return responses [ result . response ] ;
255280}
256281
282+ // export the archive file to the default location for a different project file
283+ async function exportArchiveFile ( targetWindow , archivePath , projectFile ) {
284+ if ( ! path . isAbsolute ( archivePath ) ) {
285+ const sourceProjectDir = _getProjectDirectory ( targetWindow ) ;
286+ archivePath = path . join ( sourceProjectDir , archivePath ) ;
287+ }
288+
289+ const targetDirectoryName = _getDefaultModelsDirectoryName ( projectFile ) ;
290+ const targetPath = path . join ( path . dirname ( projectFile ) , targetDirectoryName , 'archive.zip' ) ;
291+ await mkdir ( path . dirname ( targetPath ) , { recursive : true } ) ;
292+
293+ getLogger ( ) . debug ( 'Copying archive ' + archivePath + ' to ' + targetPath ) ;
294+ await copyFile ( archivePath , targetPath ) ;
295+ }
296+
257297// Private helper methods
258298//
259299async function _createNewProjectFile ( targetWindow , projectFileName ) {
@@ -765,6 +805,10 @@ function _getProjectFilePath(targetWindow) {
765805
766806function _getDefaultModelsPath ( targetWindow ) {
767807 const projectFilePath = _getProjectFilePath ( targetWindow ) ;
808+ return _getDefaultModelsDirectoryName ( projectFilePath ) ;
809+ }
810+
811+ function _getDefaultModelsDirectoryName ( projectFilePath ) {
768812 const projectFilePrefix = path . basename ( projectFilePath , path . extname ( projectFilePath ) ) ;
769813 return projectFilePrefix + '-models' ;
770814}
@@ -809,12 +853,14 @@ function getProjectFileName(dialogReturnedFileName) {
809853module . exports = {
810854 chooseArchiveFile,
811855 chooseModelFile,
856+ chooseProjectFile,
812857 chooseVariableFile,
813858 closeProject,
814859 confirmProjectFile,
815860 createNewProject,
816861 getModelFileContent,
817862 getWindowForProject,
863+ exportArchiveFile,
818864 isWktProjectFile,
819865 openProject,
820866 openProjectFile,
@@ -825,5 +871,6 @@ module.exports = {
825871 sendProjectOpened,
826872 showExistingProjectWindow,
827873 startCloseProject,
828- startSaveProject
874+ startSaveProject,
875+ startSaveProjectAs
829876} ;
0 commit comments