1
1
/**
2
2
* @license
3
- * Copyright (c) 2021, Oracle and/or its affiliates.
3
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates.
4
4
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
5
5
*/
6
6
const { app, dialog} = require ( 'electron' ) ;
@@ -91,7 +91,15 @@ async function openProject(targetWindow) {
91
91
return ;
92
92
}
93
93
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
+ } ) ;
95
103
}
96
104
97
105
async function openProjectFile ( targetWindow , projectFile ) {
@@ -133,12 +141,29 @@ async function confirmProjectFile(targetWindow) {
133
141
return [ projectFile , projectName , projectUuid ] ;
134
142
}
135
143
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
+
136
155
// initiate the save process by sending a message to the web app.
137
156
// usually called from a menu click.
138
157
function startSaveProject ( targetWindow ) {
139
158
sendToWindow ( targetWindow , 'start-save-project' ) ;
140
159
}
141
160
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
+
142
167
// save the specified project and model contents to the project file.
143
168
// usually invoked by the save-project IPC invocation.
144
169
async function saveProject ( targetWindow , projectFile , projectContents , externalFileContents ) {
@@ -254,6 +279,21 @@ async function promptSaveBeforeClose(targetWindow) {
254
279
return responses [ result . response ] ;
255
280
}
256
281
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
+
257
297
// Private helper methods
258
298
//
259
299
async function _createNewProjectFile ( targetWindow , projectFileName ) {
@@ -765,6 +805,10 @@ function _getProjectFilePath(targetWindow) {
765
805
766
806
function _getDefaultModelsPath ( targetWindow ) {
767
807
const projectFilePath = _getProjectFilePath ( targetWindow ) ;
808
+ return _getDefaultModelsDirectoryName ( projectFilePath ) ;
809
+ }
810
+
811
+ function _getDefaultModelsDirectoryName ( projectFilePath ) {
768
812
const projectFilePrefix = path . basename ( projectFilePath , path . extname ( projectFilePath ) ) ;
769
813
return projectFilePrefix + '-models' ;
770
814
}
@@ -809,12 +853,14 @@ function getProjectFileName(dialogReturnedFileName) {
809
853
module . exports = {
810
854
chooseArchiveFile,
811
855
chooseModelFile,
856
+ chooseProjectFile,
812
857
chooseVariableFile,
813
858
closeProject,
814
859
confirmProjectFile,
815
860
createNewProject,
816
861
getModelFileContent,
817
862
getWindowForProject,
863
+ exportArchiveFile,
818
864
isWktProjectFile,
819
865
openProject,
820
866
openProjectFile,
@@ -825,5 +871,6 @@ module.exports = {
825
871
sendProjectOpened,
826
872
showExistingProjectWindow,
827
873
startCloseProject,
828
- startSaveProject
874
+ startSaveProject,
875
+ startSaveProjectAs
829
876
} ;
0 commit comments