@@ -44,27 +44,32 @@ export class NativeBackupTracker extends BackupTracker implements IWorkbenchCont
4444 // Dirty working copies need treatment on shutdown
4545 const dirtyWorkingCopies = this . workingCopyService . dirtyWorkingCopies ;
4646 if ( dirtyWorkingCopies . length ) {
47+ return this . onBeforeShutdownWithDirty ( reason , dirtyWorkingCopies ) ;
48+ }
4749
48- // If auto save is enabled, save all non-untitled working copies
49- // and then check again for dirty copies
50- if ( this . filesConfigurationService . getAutoSaveMode ( ) !== AutoSaveMode . OFF ) {
51- return this . doSaveAllBeforeShutdown ( false /* not untitled */ , SaveReason . AUTO ) . then ( ( ) => {
50+ return false ; // no veto (no dirty working copies)
51+ }
5252
53- // If we still have dirty working copies, we either have untitled ones or working copies that cannot be saved
54- const remainingDirtyWorkingCopies = this . workingCopyService . dirtyWorkingCopies ;
55- if ( remainingDirtyWorkingCopies . length ) {
56- return this . handleDirtyBeforeShutdown ( remainingDirtyWorkingCopies , reason ) ;
57- }
53+ protected async onBeforeShutdownWithDirty ( reason : ShutdownReason , workingCopies : IWorkingCopy [ ] ) : Promise < boolean > {
5854
59- return false ; // no veto (there are no remaining dirty working copies)
60- } ) ;
55+ // If auto save is enabled, save all non-untitled working copies
56+ // and then check again for dirty copies
57+ if ( this . filesConfigurationService . getAutoSaveMode ( ) !== AutoSaveMode . OFF ) {
58+
59+ // Save all files
60+ await this . doSaveAllBeforeShutdown ( false /* not untitled */ , SaveReason . AUTO ) ;
61+
62+ // If we still have dirty working copies, we either have untitled ones or working copies that cannot be saved
63+ const remainingDirtyWorkingCopies = this . workingCopyService . dirtyWorkingCopies ;
64+ if ( remainingDirtyWorkingCopies . length ) {
65+ return this . handleDirtyBeforeShutdown ( remainingDirtyWorkingCopies , reason ) ;
6166 }
6267
63- // Auto save is not enabled
64- return this . handleDirtyBeforeShutdown ( dirtyWorkingCopies , reason ) ;
68+ return false ; // no veto (there are no remaining dirty working copies)
6569 }
6670
67- return false ; // no veto (no dirty working copies)
71+ // Auto save is not enabled
72+ return this . handleDirtyBeforeShutdown ( workingCopies , reason ) ;
6873 }
6974
7075 private async handleDirtyBeforeShutdown ( workingCopies : IWorkingCopy [ ] , reason : ShutdownReason ) : Promise < boolean > {
@@ -95,14 +100,14 @@ export class NativeBackupTracker extends BackupTracker implements IWorkbenchCont
95100 try {
96101 return await this . confirmBeforeShutdown ( workingCopies . filter ( workingCopy => backups . indexOf ( workingCopy ) === - 1 ) ) ;
97102 } catch ( error ) {
98- this . showErrorDialog ( localize ( 'backupTrackerConfirmFailed' , "Editors that are dirty could not be saved or reverted." ) , error ) ;
103+ this . showErrorDialog ( localize ( 'backupTrackerConfirmFailed' , "One or many editors that are dirty could not be saved or reverted." ) , error ) ;
99104
100105 return true ; // veto (save or revert failed)
101106 }
102107 }
103108
104109 private showErrorDialog ( msg : string , error ?: Error ) : void {
105- this . dialogService . show ( Severity . Error , msg , [ localize ( 'ok' , 'OK' ) ] , { detail : localize ( 'backupErrorDetails' , "Try saving the dirty editors first and then try again." ) } ) ;
110+ this . dialogService . show ( Severity . Error , msg , [ localize ( 'ok' , 'OK' ) ] , { detail : localize ( 'backupErrorDetails' , "Try saving or reverting the dirty editors first and then try again." ) } ) ;
106111
107112 this . logService . error ( error ? `[backup tracker] ${ msg } : ${ error } ` : `[backup tracker] ${ msg } ` ) ;
108113 }
@@ -174,10 +179,10 @@ export class NativeBackupTracker extends BackupTracker implements IWorkbenchCont
174179 // Save
175180 const confirm = await this . fileDialogService . showSaveConfirm ( workingCopies . map ( workingCopy => workingCopy . name ) ) ;
176181 if ( confirm === ConfirmResult . SAVE ) {
177- const dirtyCount = this . workingCopyService . dirtyCount ;
182+ const dirtyCountBeforeSave = this . workingCopyService . dirtyCount ;
178183 await this . doSaveAllBeforeShutdown ( workingCopies , SaveReason . EXPLICIT ) ;
179184
180- const savedWorkingCopies = dirtyCount - this . workingCopyService . dirtyCount ;
185+ const savedWorkingCopies = dirtyCountBeforeSave - this . workingCopyService . dirtyCount ;
181186 if ( savedWorkingCopies < workingCopies . length ) {
182187 return true ; // veto (save failed or was canceled)
183188 }
@@ -224,7 +229,7 @@ export class NativeBackupTracker extends BackupTracker implements IWorkbenchCont
224229 }
225230 }
226231
227- private async doRevertAllBeforeShutdown ( workingCopies = this . workingCopyService . dirtyWorkingCopies ) : Promise < void > {
232+ private async doRevertAllBeforeShutdown ( workingCopies : IWorkingCopy [ ] ) : Promise < void > {
228233
229234 // Soft revert is good enough on shutdown
230235 const revertOptions = { soft : true } ;
0 commit comments