@@ -169,34 +169,40 @@ async function openProjectFile(targetWindow, projectFile, isDirty) {
169
169
// request the existing project file, prompting the user if needed.
170
170
// return null values if no project file was established or selected.
171
171
// usually called by the confirm-project-file IPC invocation.
172
+ //
173
+ // This method is always used in the "Save All" flow.
174
+ //
172
175
async function confirmProjectFile ( targetWindow ) {
173
176
let projectFile = _getProjectFilePath ( targetWindow ) ;
174
- let projectName = null ;
175
- let projectUuid = null ;
176
- if ( ! projectFile ) {
177
- projectFile = await _chooseProjectSaveFile ( targetWindow ) ;
178
- projectName = projectFile ? _generateProjectName ( projectFile ) : null ;
179
- projectUuid = projectFile ? _generateProjectUuid ( ) : null ;
180
- if ( projectFile ) {
181
- getLogger ( ) . debug ( 'confirmProjectFile adding %s to recent documents' , projectFile ) ;
182
- app . addRecentDocument ( projectFile ) ;
183
- }
177
+ if ( projectFile ) {
178
+ // if the project file exists, no need to worry about
179
+ // the project name and project UUID because they are
180
+ // already defined in the file.
181
+ //
182
+ return [ projectFile , null , null , false ] ;
183
+ } else {
184
+ return chooseProjectFile ( targetWindow ) ;
184
185
}
185
- return [ projectFile , projectName , projectUuid ] ;
186
186
}
187
187
188
188
// choose a new project file for save.
189
189
// return null values if no project file was established or selected.
190
190
// usually called by the choose-project-file IPC invocation.
191
+ //
192
+ // This method is used directly in the "Save As" flow and
193
+ // indirectly in the "Save All" flow.
194
+ //
191
195
async function chooseProjectFile ( targetWindow ) {
192
196
const projectFile = await _chooseProjectSaveFile ( targetWindow ) ;
193
- const projectName = projectFile ? _generateProjectName ( projectFile ) : null ;
194
- const projectUuid = projectFile ? _generateProjectUuid ( ) : null ;
197
+ let projectName = null ;
198
+ let projectUuid = null ;
199
+ let isNewFile = false ;
195
200
if ( projectFile ) {
196
- getLogger ( ) . debug ( 'chooseProjectFile adding %s to recent documents' , projectFile ) ;
197
- app . addRecentDocument ( projectFile ) ;
201
+ projectName = _generateProjectName ( projectFile ) ;
202
+ projectUuid = _generateProjectUuid ( ) ;
203
+ isNewFile = ! await fsUtils . exists ( projectFile ) ;
198
204
}
199
- return [ projectFile , projectName , projectUuid ] ;
205
+ return [ projectFile , projectName , projectUuid , isNewFile ] ;
200
206
}
201
207
202
208
// initiate the save process by sending a message to the web app.
@@ -213,7 +219,7 @@ function startSaveProjectAs(targetWindow) {
213
219
214
220
// save the specified project and model contents to the project file.
215
221
// usually invoked by the save-project IPC invocation.
216
- async function saveProject ( targetWindow , projectFile , projectContents , externalFileContents , showErrors = true ) {
222
+ async function saveProject ( targetWindow , projectFile , projectContents , externalFileContents , isNewFile , showErrors = true ) {
217
223
// the result will contain only sections that were updated due to save, such as model.archiveFiles
218
224
const saveResult = {
219
225
isProjectFileSaved : false ,
@@ -237,6 +243,10 @@ async function saveProject(targetWindow, projectFile, projectContents, externalF
237
243
if ( saveResult . isProjectFileSaved ) {
238
244
const wktWindow = require ( './wktWindow' ) ;
239
245
wktWindow . setTitleFileName ( targetWindow , projectFile , false ) ;
246
+ if ( isNewFile ) {
247
+ app . addRecentDocument ( projectFile ) ;
248
+ }
249
+
240
250
try {
241
251
saveResult [ 'model' ] = await _saveExternalFileContents ( _getProjectDirectory ( targetWindow ) , externalFileContents ) ;
242
252
saveResult . areModelFilesSaved = true ;
0 commit comments