@@ -9,7 +9,7 @@ import nls = require('vs/nls');
99import { Action } from 'vs/base/common/actions' ;
1010import { mixin } from 'vs/base/common/objects' ;
1111import { getCodeEditor } from 'vs/editor/common/services/codeEditorService' ;
12- import { EditorInput , getUntitledOrFileResource , TextEditorOptions , EditorOptions , IEditorIdentifier , IEditorContext , ActiveEditorMoveArguments , ActiveEditorMovePositioning , EditorCommands } from 'vs/workbench/common/editor' ;
12+ import { EditorInput , getUntitledOrFileResource , TextEditorOptions , EditorOptions , IEditorIdentifier , IEditorContext , ActiveEditorMoveArguments , ActiveEditorMovePositioning , EditorCommands , ConfirmResult } from 'vs/workbench/common/editor' ;
1313import { QuickOpenEntryGroup } from 'vs/base/parts/quickopen/browser/quickOpenModel' ;
1414import { EditorQuickOpenEntry , EditorQuickOpenEntryGroup , IEditorQuickOpenEntry , QuickOpenAction } from 'vs/workbench/browser/quickopen' ;
1515import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService' ;
@@ -21,6 +21,7 @@ import { IHistoryService } from 'vs/workbench/services/history/common/history';
2121import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
2222import { IEditorGroupService , GroupArrangement } from 'vs/workbench/services/group/common/groupService' ;
2323import { ICommandService } from 'vs/platform/commands/common/commands' ;
24+ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles' ;
2425
2526export class SplitEditorAction extends Action {
2627
@@ -565,12 +566,40 @@ export class CloseAllEditorsAction extends Action {
565566 public static ID = 'workbench.action.closeAllEditors' ;
566567 public static LABEL = nls . localize ( 'closeAllEditors' , "Close All Editors" ) ;
567568
568- constructor ( id : string , label : string , @IWorkbenchEditorService private editorService : IWorkbenchEditorService ) {
569+ constructor (
570+ id : string ,
571+ label : string ,
572+ @ITextFileService private textFileService : ITextFileService ,
573+ @IWorkbenchEditorService private editorService : IWorkbenchEditorService
574+ ) {
569575 super ( id , label , 'action-close-all-files' ) ;
570576 }
571577
572578 public run ( ) : TPromise < any > {
573- return this . editorService . closeAllEditors ( ) ;
579+
580+ // Just close all if there are no or one dirty editor
581+ if ( this . textFileService . getDirty ( ) . length < 2 ) {
582+ return this . editorService . closeAllEditors ( ) ;
583+ }
584+
585+ // Otherwise ask for combined confirmation
586+ const confirm = this . textFileService . confirmSave ( ) ;
587+ if ( confirm === ConfirmResult . CANCEL ) {
588+ return ;
589+ }
590+
591+ let saveOrRevertPromise : TPromise < boolean > ;
592+ if ( confirm === ConfirmResult . DONT_SAVE ) {
593+ saveOrRevertPromise = this . textFileService . revertAll ( ) . then ( ( ) => true ) ;
594+ } else {
595+ saveOrRevertPromise = this . textFileService . saveAll ( true ) . then ( res => res . results . every ( r => r . success ) ) ;
596+ }
597+
598+ return saveOrRevertPromise . then ( success => {
599+ if ( success ) {
600+ return this . editorService . closeAllEditors ( ) ;
601+ }
602+ } ) ;
574603 }
575604}
576605
0 commit comments