Skip to content

Commit 7e6dbe9

Browse files
author
Benjamin Pasero
committed
Close dirty editors: Provide fast action to save all or revert all (fixes microsoft#8009)
1 parent b978a5b commit 7e6dbe9

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

src/vs/workbench/browser/parts/editor/editorActions.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import nls = require('vs/nls');
99
import { Action } from 'vs/base/common/actions';
1010
import { mixin } from 'vs/base/common/objects';
1111
import { 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';
1313
import { QuickOpenEntryGroup } from 'vs/base/parts/quickopen/browser/quickOpenModel';
1414
import { EditorQuickOpenEntry, EditorQuickOpenEntryGroup, IEditorQuickOpenEntry, QuickOpenAction } from 'vs/workbench/browser/quickopen';
1515
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
@@ -21,6 +21,7 @@ import { IHistoryService } from 'vs/workbench/services/history/common/history';
2121
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2222
import { IEditorGroupService, GroupArrangement } from 'vs/workbench/services/group/common/groupService';
2323
import { ICommandService } from 'vs/platform/commands/common/commands';
24+
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
2425

2526
export 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

Comments
 (0)