提交 8e1a2546 编写于 作者: B Benjamin Pasero

editors 💄

上级 8252d8af
......@@ -646,8 +646,7 @@ export abstract class BaseCloseAllAction extends Action {
let saveOrRevert: boolean;
if (confirm === ConfirmResult.DONT_SAVE) {
await this.editorService.revertAll({ soft: true });
saveOrRevert = true;
saveOrRevert = await this.editorService.revertAll({ soft: true });
} else {
saveOrRevert = await this.editorService.saveAll({ reason: SaveReason.EXPLICIT, includeUntitled: true });
}
......
......@@ -26,7 +26,7 @@ import { Schemas } from 'vs/base/common/network';
import { WorkspaceFolderCountContext, IsWebContext } from 'vs/workbench/browser/contextkeys';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { OpenFileFolderAction, OpenFileAction, OpenFolderAction, OpenWorkspaceAction } from 'vs/workbench/browser/actions/workspaceActions';
import { ActiveEditorIsSaveableContext, DirtyWorkingCopiesContext } from 'vs/workbench/common/editor';
import { ActiveEditorIsSaveableContext, DirtyWorkingCopiesContext, ActiveEditorContext } from 'vs/workbench/common/editor';
import { SidebarFocusContext } from 'vs/workbench/common/viewlet';
import { registerAndGetAmdImageURL } from 'vs/base/common/amd';
......@@ -590,7 +590,8 @@ MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
command: {
id: SAVE_FILE_AS_COMMAND_ID,
title: nls.localize({ key: 'miSaveAs', comment: ['&& denotes a mnemonic'] }, "Save &&As..."),
precondition: ContextKeyExpr.or(ActiveEditorIsSaveableContext, ContextKeyExpr.and(ExplorerViewletVisibleContext, SidebarFocusContext))
// ActiveEditorContext is not 100% correct, but we lack a context for indicating "Save As..." support
precondition: ContextKeyExpr.or(ActiveEditorContext, ContextKeyExpr.and(ExplorerViewletVisibleContext, SidebarFocusContext))
},
order: 2
});
......
......@@ -712,31 +712,27 @@ export class EditorService extends Disposable implements EditorServiceImpl {
}
saveAll(options?: ISaveAllEditorsOptions): Promise<boolean> {
// Save each editor in MRU order
const editors: IEditorIdentifier[] = [];
this.forEachDirtySaveableEditor(!!options?.includeUntitled, ({ groupId, editor }) => editors.push({ groupId, editor }));
return this.save(editors, options);
return this.save(this.getSaveableEditors(!!options?.includeUntitled), options);
}
async revertAll(options?: IRevertOptions): Promise<void> {
// Revert each editor in MRU order
const reverts: Promise<boolean>[] = [];
this.forEachDirtySaveableEditor(true /* include untitled */, ({ editor }) => reverts.push(editor.revert(options)));
async revertAll(options?: IRevertOptions): Promise<boolean> {
const result = await Promise.all(this.getSaveableEditors(true /* include untitled */).map(async ({ editor }) => editor.revert(options)));
await Promise.all(reverts);
return result.every(success => !!success);
}
private forEachDirtySaveableEditor(includeUntitled: boolean, callback: (editor: IEditorIdentifier) => void): void {
private getSaveableEditors(includeUntitled: boolean): IEditorIdentifier[] {
const editors: IEditorIdentifier[] = [];
for (const group of this.editorGroupService.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE)) {
for (const editor of group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE)) {
if (editor.isDirty() && !editor.isReadonly() && (!editor.isUntitled() || includeUntitled)) {
callback({ groupId: group.id, editor });
editors.push({ groupId: group.id, editor });
}
}
}
return editors;
}
//#endregion
......
......@@ -215,5 +215,5 @@ export interface IEditorService {
/**
* Reverts all editors.
*/
revertAll(options?: IRevertOptions): Promise<void>;
revertAll(options?: IRevertOptions): Promise<boolean>;
}
......@@ -930,7 +930,7 @@ export class TestEditorService implements EditorServiceImpl {
throw new Error('Method not implemented.');
}
revertAll(options?: IRevertOptions): Promise<void> {
revertAll(options?: IRevertOptions): Promise<boolean> {
throw new Error('Method not implemented.');
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册