@@ -169,34 +169,40 @@ async function openProjectFile(targetWindow, projectFile, isDirty) {
169169// request the existing project file, prompting the user if needed.
170170// return null values if no project file was established or selected.
171171// usually called by the confirm-project-file IPC invocation.
172+ //
173+ // This method is always used in the "Save All" flow.
174+ //
172175async function confirmProjectFile ( targetWindow ) {
173176 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 ) ;
184185 }
185- return [ projectFile , projectName , projectUuid ] ;
186186}
187187
188188// choose a new project file for save.
189189// return null values if no project file was established or selected.
190190// 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+ //
191195async function chooseProjectFile ( targetWindow ) {
192196 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 ;
195200 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 ) ;
198204 }
199- return [ projectFile , projectName , projectUuid ] ;
205+ return [ projectFile , projectName , projectUuid , isNewFile ] ;
200206}
201207
202208// initiate the save process by sending a message to the web app.
@@ -213,7 +219,7 @@ function startSaveProjectAs(targetWindow) {
213219
214220// save the specified project and model contents to the project file.
215221// 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 ) {
217223 // the result will contain only sections that were updated due to save, such as model.archiveFiles
218224 const saveResult = {
219225 isProjectFileSaved : false ,
@@ -237,6 +243,10 @@ async function saveProject(targetWindow, projectFile, projectContents, externalF
237243 if ( saveResult . isProjectFileSaved ) {
238244 const wktWindow = require ( './wktWindow' ) ;
239245 wktWindow . setTitleFileName ( targetWindow , projectFile , false ) ;
246+ if ( isNewFile ) {
247+ app . addRecentDocument ( projectFile ) ;
248+ }
249+
240250 try {
241251 saveResult [ 'model' ] = await _saveExternalFileContents ( _getProjectDirectory ( targetWindow ) , externalFileContents ) ;
242252 saveResult . areModelFilesSaved = true ;
0 commit comments