提交 13a24e5c 编写于 作者: B Benjamin Pasero

Simplify context menu actions on editor/group actions (fixes #6596)

上级 29507354
......@@ -34,7 +34,7 @@ import {QuickOpenAction} from 'vs/workbench/browser/quickopen';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {ShowEditorsInLeftGroupAction, ShowEditorsInCenterGroupAction, ShowEditorsInRightGroupAction, CloseEditorsInGroupAction, CloseEditorsInOtherGroupsAction, CloseAllEditorsAction, MoveGroupLeftAction, MoveGroupRightAction, SplitEditorAction, CloseEditorAction} from 'vs/workbench/browser/parts/editor/editorActions';
import {ShowEditorsInLeftGroupAction, ShowEditorsInCenterGroupAction, ShowEditorsInRightGroupAction, CloseEditorsInGroupAction, MoveGroupLeftAction, MoveGroupRightAction, SplitEditorAction, CloseEditorAction} from 'vs/workbench/browser/parts/editor/editorActions';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
export enum Rochade {
......@@ -128,8 +128,6 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
private moveGroupLeftActions: MoveGroupLeftAction[];
private moveGroupRightActions: MoveGroupRightAction[];
private closeEditorsInGroupActions: CloseEditorsInGroupAction[];
private closeEditorsInOtherGroupsActions: CloseEditorsInOtherGroupsAction[];
private closeAllEditorsAction: CloseAllEditorsAction;
private splitEditorAction: SplitEditorAction;
private leftSash: Sash;
......@@ -211,19 +209,13 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
this.splitEditorAction = this.instantiationService.createInstance(SplitEditorAction, SplitEditorAction.ID, SplitEditorAction.LABEL);
// Move Group Left
this.moveGroupLeftActions = POSITIONS.map((position) => this.instantiationService.createInstance(MoveGroupLeftAction, MoveGroupLeftAction.ID, MoveGroupLeftAction.LABEL));
this.moveGroupLeftActions = POSITIONS.map((position) => this.instantiationService.createInstance(MoveGroupLeftAction, MoveGroupLeftAction.ID, nls.localize('moveLeft', "Move Left")));
// Move Group Right
this.moveGroupRightActions = POSITIONS.map((position) => this.instantiationService.createInstance(MoveGroupRightAction, MoveGroupRightAction.ID, MoveGroupRightAction.LABEL));
this.moveGroupRightActions = POSITIONS.map((position) => this.instantiationService.createInstance(MoveGroupRightAction, MoveGroupRightAction.ID, nls.localize('moveRight', "Move Right")));
// Close All Editors in Group
this.closeEditorsInGroupActions = POSITIONS.map((position) => this.instantiationService.createInstance(CloseEditorsInGroupAction, CloseEditorsInGroupAction.ID, CloseEditorsInGroupAction.LABEL));
// Close Editors in Other Groups
this.closeEditorsInOtherGroupsActions = POSITIONS.map((position) => this.instantiationService.createInstance(CloseEditorsInOtherGroupsAction, CloseEditorsInOtherGroupsAction.ID, CloseEditorsInOtherGroupsAction.LABEL));
// Close All Editors
this.closeAllEditorsAction = this.instantiationService.createInstance(CloseAllEditorsAction, CloseAllEditorsAction.ID, CloseAllEditorsAction.LABEL);
this.closeEditorsInGroupActions = POSITIONS.map((position) => this.instantiationService.createInstance(CloseEditorsInGroupAction, CloseEditorsInGroupAction.ID, nls.localize('closeAll', "Close All")));
}
private initStyles(): void {
......@@ -1374,10 +1366,7 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
this.moveGroupLeftActions[position],
this.moveGroupRightActions[position],
new Separator(),
this.closeEditorsInGroupActions[position],
this.closeEditorsInOtherGroupsActions[position],
new Separator(),
this.closeAllEditorsAction
this.closeEditorsInGroupActions[position]
];
}
......@@ -1390,9 +1379,6 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
this.moveGroupRightActions[Position.LEFT].enabled = this.getVisibleEditorCount() > 1;
this.moveGroupRightActions[Position.CENTER].enabled = this.getVisibleEditorCount() > 2;
this.moveGroupRightActions[Position.RIGHT].enabled = false;
// Close Editors in Other Groups
POSITIONS.map((position) => this.closeEditorsInOtherGroupsActions[position].enabled = this.getVisibleEditorCount() > 1);
}
public clearTitleArea(position: Position): void {
......@@ -1755,7 +1741,7 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
});
// Actions
[this.splitEditorAction, this.closeAllEditorsAction, ...this.closeEditorActions, ...this.moveGroupLeftActions, ...this.moveGroupRightActions, ...this.closeEditorsInGroupActions, ...this.closeEditorsInOtherGroupsActions].forEach((action) => {
[this.splitEditorAction, ...this.closeEditorActions, ...this.moveGroupLeftActions, ...this.moveGroupRightActions, ...this.closeEditorsInGroupActions].forEach((action) => {
action.dispose();
});
......
......@@ -20,7 +20,7 @@ import {IMouseEvent, DragMouseEvent} from 'vs/base/browser/mouseEvent';
import {IResourceInput} from 'vs/platform/editor/common/editor';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IContextMenuService, ContextSubMenu} from 'vs/platform/contextview/browser/contextView';
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {EditorOptions, EditorInput, UntitledEditorInput} from 'vs/workbench/common/editor';
import {ITextFileService, AutoSaveMode, FileEditorInput, asFileResource} from 'vs/workbench/parts/files/common/files';
......@@ -30,7 +30,7 @@ import {keybindingForAction, SaveFileAction, RevertFileAction, SaveFileAsAction,
import {CopyPathAction, RevealInOSAction} from 'vs/workbench/parts/files/electron-browser/electronFileActions';
import {OpenConsoleAction} from 'vs/workbench/parts/execution/electron-browser/terminal.contribution';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {CloseOtherEditorsInGroupAction, CloseEditorsInOtherGroupsAction, CloseEditorAction, CloseAllEditorsAction, CloseAllEditorsInGroupAction} from 'vs/workbench/browser/parts/editor/editorActions';
import {CloseOtherEditorsInGroupAction, CloseEditorAction, CloseAllEditorsInGroupAction} from 'vs/workbench/browser/parts/editor/editorActions';
const $ = dom.emmet;
......@@ -383,16 +383,14 @@ export class ActionProvider implements IActionProvider {
public getSecondaryActions(tree: ITree, element: any): TPromise<IAction[]> {
const result = [];
const autoSaveEnabled = this.textFileService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY;
const multipleGroups = this.model.groups.length > 1;
const closeActions = [];
if (element instanceof EditorGroup) {
if (!autoSaveEnabled) {
result.push(this.instantiationService.createInstance(SaveAllInGroupAction, SaveAllInGroupAction.ID, SaveAllInGroupAction.LABEL));
result.push(this.instantiationService.createInstance(SaveAllInGroupAction, SaveAllInGroupAction.ID, nls.localize('saveAll', "Save All")));
result.push(new Separator());
}
closeActions.push(this.instantiationService.createInstance(CloseAllEditorsInGroupAction, CloseAllEditorsInGroupAction.ID, CloseAllEditorsInGroupAction.LABEL));
result.push(this.instantiationService.createInstance(CloseAllEditorsInGroupAction, CloseAllEditorsInGroupAction.ID, nls.localize('closeAll', "Close All")));
} else {
const openEditor = <OpenEditor>element;
const resource = openEditor.getResource();
......@@ -410,12 +408,12 @@ export class ActionProvider implements IActionProvider {
result.push(this.instantiationService.createInstance(CopyPathAction, resource));
// Files: Save / Revert
if (!autoSaveEnabled && openEditor.isDirty()) {
if (!autoSaveEnabled) {
result.push(new Separator());
const saveAction = this.instantiationService.createInstance(SaveFileAction, SaveFileAction.ID, SaveFileAction.LABEL);
saveAction.setResource(resource);
saveAction.enabled = true;
saveAction.enabled = openEditor.isDirty();
result.push(saveAction);
const revertAction = this.instantiationService.createInstance(RevertFileAction, RevertFileAction.ID, RevertFileAction.LABEL);
......@@ -451,23 +449,13 @@ export class ActionProvider implements IActionProvider {
result.push(new Separator());
}
closeActions.push(this.instantiationService.createInstance(CloseEditorAction, CloseEditorAction.ID, CloseEditorAction.LABEL));
closeActions.push(new Separator());
const closeOtherEditorsInGroupAction = this.instantiationService.createInstance(CloseOtherEditorsInGroupAction, CloseOtherEditorsInGroupAction.ID, CloseOtherEditorsInGroupAction.LABEL);
result.push(this.instantiationService.createInstance(CloseEditorAction, CloseEditorAction.ID, nls.localize('close', "Close")));
const closeOtherEditorsInGroupAction = this.instantiationService.createInstance(CloseOtherEditorsInGroupAction, CloseOtherEditorsInGroupAction.ID, nls.localize('closeOthers', "Close Others"));
closeOtherEditorsInGroupAction.enabled = openEditor.editorGroup.count > 1;
closeActions.push(closeOtherEditorsInGroupAction);
closeActions.push(this.instantiationService.createInstance(CloseAllEditorsInGroupAction, CloseAllEditorsInGroupAction.ID, CloseAllEditorsInGroupAction.LABEL));
closeActions.push(new Separator());
result.push(closeOtherEditorsInGroupAction);
result.push(this.instantiationService.createInstance(CloseAllEditorsInGroupAction, CloseAllEditorsInGroupAction.ID, nls.localize('closeAll', "Close All")));
}
const closeEditorInOtherGroupsAction = this.instantiationService.createInstance(CloseEditorsInOtherGroupsAction, CloseEditorsInOtherGroupsAction.ID, CloseEditorsInOtherGroupsAction.LABEL);
closeEditorInOtherGroupsAction.enabled = multipleGroups;
closeActions.push(closeEditorInOtherGroupsAction);
closeActions.push(new Separator());
closeActions.push(this.instantiationService.createInstance(CloseAllEditorsAction, CloseAllEditorsAction.ID, CloseAllEditorsAction.LABEL));
result.push(new ContextSubMenu(nls.localize('close', "Close"), closeActions));
return TPromise.as(result);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册