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

grid - let "open side by side" editor action be a command with alternative command support

上级 58e92651
......@@ -436,6 +436,51 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, { command: { id: editorCommands.
MenuRegistry.appendMenuItem(MenuId.EditorTitle, { command: { id: editorCommands.CLOSE_EDITORS_IN_GROUP_COMMAND_ID, title: nls.localize('closeAll', "Close All") }, group: '5_close', order: 10, when: ContextKeyExpr.has('config.workbench.editor.showTabs') });
MenuRegistry.appendMenuItem(MenuId.EditorTitle, { command: { id: editorCommands.CLOSE_SAVED_EDITORS_COMMAND_ID, title: nls.localize('closeAllSaved', "Close Saved") }, group: '5_close', order: 20, when: ContextKeyExpr.has('config.workbench.editor.showTabs') });
// Editor Title Menu: Split Editor
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
id: SplitEditorAction.ID,
title: nls.localize('splitEditorRight', "Split Editor Right"),
iconPath: {
dark: URI.parse(require.toUrl('vs/workbench/browser/parts/editor/media/split-editor-horizontal-inverse.svg')).fsPath,
light: URI.parse(require.toUrl('vs/workbench/browser/parts/editor/media/split-editor-horizontal.svg')).fsPath
}
},
alt: {
id: editorCommands.SPLIT_EDITOR_DOWN,
title: nls.localize('splitEditorDown', "Split Editor Down"),
iconPath: {
dark: URI.parse(require.toUrl('vs/workbench/browser/parts/editor/media/split-editor-vertical-inverse.svg')).fsPath,
light: URI.parse(require.toUrl('vs/workbench/browser/parts/editor/media/split-editor-vertical.svg')).fsPath
}
},
group: 'navigation',
when: ContextKeyExpr.not('splitEditorsVertically'),
order: Number.POSITIVE_INFINITY // at the end
});
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
id: SplitEditorAction.ID,
title: nls.localize('splitEditorDown', "Split Editor Down"),
iconPath: {
dark: URI.parse(require.toUrl('vs/workbench/browser/parts/editor/media/split-editor-vertical-inverse.svg')).fsPath,
light: URI.parse(require.toUrl('vs/workbench/browser/parts/editor/media/split-editor-vertical.svg')).fsPath
}
},
alt: {
id: editorCommands.SPLIT_EDITOR_RIGHT,
title: nls.localize('splitEditorRight', "Split Editor Right"),
iconPath: {
dark: URI.parse(require.toUrl('vs/workbench/browser/parts/editor/media/split-editor-horizontal-inverse.svg')).fsPath,
light: URI.parse(require.toUrl('vs/workbench/browser/parts/editor/media/split-editor-horizontal.svg')).fsPath
}
},
group: 'navigation',
when: ContextKeyExpr.has('splitEditorsVertically'),
order: Number.POSITIVE_INFINITY // at the end
});
// Editor Commands for Command Palette
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: editorCommands.KEEP_EDITOR_COMMAND_ID, title: nls.localize('keepEditor', "Keep Editor"), category }, when: ContextKeyExpr.has('config.workbench.editor.enablePreview') });
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: editorCommands.CLOSE_EDITORS_IN_GROUP_COMMAND_ID, title: nls.localize('closeEditorsInGroup', "Close All Editors in Group"), category } });
......
......@@ -35,7 +35,7 @@ export const DEFAULT_EDITOR_PART_OPTIONS: IEditorPartOptions = {
showIcons: true,
enablePreview: true,
openPositioning: 'right',
openSideBySideDirection: 'right',
openSideBySideDirection: 'horizontal',
closeEmptyGroups: true,
labelFormat: 'default',
iconTheme: 'vs-seti'
......
......@@ -20,7 +20,7 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IWindowsService } from 'vs/platform/windows/common/windows';
import { CLOSE_EDITOR_COMMAND_ID, NAVIGATE_ALL_EDITORS_GROUP_PREFIX, MOVE_ACTIVE_EDITOR_COMMAND_ID, NAVIGATE_IN_ACTIVE_GROUP_PREFIX, ActiveEditorMoveArguments, SPLIT_EDITOR_LEFT, SPLIT_EDITOR_RIGHT, SPLIT_EDITOR_UP, SPLIT_EDITOR_DOWN, splitEditor, LAYOUT_EDITOR_GROUPS_COMMAND_ID, EditorGroupLayout, mergeAllGroups } from 'vs/workbench/browser/parts/editor/editorCommands';
import { IEditorGroupsService, IEditorGroup, GroupsArrangement, EditorsOrder, GroupLocation, GroupDirection, preferredGroupDirection, IFindGroupScope, GroupOrientation } from 'vs/workbench/services/group/common/editorGroupsService';
import { IEditorGroupsService, IEditorGroup, GroupsArrangement, EditorsOrder, GroupLocation, GroupDirection, preferredSideBySideGroupDirection, IFindGroupScope, GroupOrientation } from 'vs/workbench/services/group/common/editorGroupsService';
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
......@@ -60,8 +60,8 @@ export class BaseSplitEditorGroupAction extends Action {
return TPromise.as(true);
}
protected splitEditor(groupId?: number, direction = this.direction): void {
splitEditor(this.editorGroupService, direction, { groupId });
protected splitEditor(groupId?: number): void {
splitEditor(this.editorGroupService, this.direction, { groupId });
}
}
......@@ -78,63 +78,25 @@ export class SplitEditorAction extends BaseSplitEditorGroupAction {
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@IConfigurationService private configurationService: IConfigurationService
) {
super(id, label, null, preferredGroupDirection(configurationService), editorGroupService);
this.updateAction();
super(id, label, null, preferredSideBySideGroupDirection(configurationService), editorGroupService);
this.registerListeners();
}
private updateAction(): void {
switch (this.direction) {
case GroupDirection.LEFT:
this.label = SplitEditorGroupLeftAction.LABEL;
this.class = 'split-editor-horizontal-action';
break;
case GroupDirection.RIGHT:
this.label = SplitEditorGroupRightAction.LABEL;
this.class = 'split-editor-horizontal-action';
break;
case GroupDirection.UP:
this.label = SplitEditorGroupUpAction.LABEL;
this.class = 'split-editor-vertical-action';
break;
case GroupDirection.DOWN:
this.label = SplitEditorGroupDownAction.LABEL;
this.class = 'split-editor-vertical-action';
break;
}
}
private registerListeners(): void {
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('workbench.editor.openSideBySideDirection')) {
this.direction = preferredGroupDirection(this.configurationService);
this.updateAction();
this.direction = preferredSideBySideGroupDirection(this.configurationService);
}
}));
}
public run(context?: IEditorIdentifier & { event?: Event }): TPromise<any> {
let direction = this.direction;
if (context && context.event instanceof MouseEvent && (context.event.altKey)) {
direction = this.alternateGroupDirection;
}
this.splitEditor(context ? context.groupId : void 0, direction);
public run(context?: IEditorIdentifier): TPromise<any> {
this.splitEditor(context ? context.groupId : void 0);
return TPromise.as(true);
}
private get alternateGroupDirection(): GroupDirection {
switch (this.direction) {
case GroupDirection.LEFT: return GroupDirection.UP;
case GroupDirection.RIGHT: return GroupDirection.DOWN;
case GroupDirection.UP: return GroupDirection.LEFT;
case GroupDirection.DOWN: return GroupDirection.RIGHT;
}
}
public dispose(): void {
super.dispose();
......@@ -152,7 +114,7 @@ export class SplitEditorGroupVerticalAction extends BaseSplitEditorGroupAction {
label: string,
@IEditorGroupsService editorGroupService: IEditorGroupsService
) {
super(id, label, 'split-editor-vertical-action', GroupDirection.DOWN, editorGroupService);
super(id, label, null, GroupDirection.DOWN, editorGroupService);
}
}
......@@ -166,7 +128,7 @@ export class SplitEditorGroupHorizontalAction extends BaseSplitEditorGroupAction
label: string,
@IEditorGroupsService editorGroupService: IEditorGroupsService
) {
super(id, label, 'split-editor-horizontal-action', GroupDirection.RIGHT, editorGroupService);
super(id, label, null, GroupDirection.RIGHT, editorGroupService);
}
}
......@@ -475,9 +437,9 @@ export class OpenToSideAction extends Action {
}
public updateClass(): void {
const preferredDirection = preferredGroupDirection(this.configurationService);
const preferredDirection = preferredSideBySideGroupDirection(this.configurationService);
this.class = (preferredDirection === GroupDirection.LEFT || preferredDirection === GroupDirection.RIGHT) ? 'quick-open-sidebyside-vertical' : 'quick-open-sidebyside-horizontal';
this.class = (preferredDirection === GroupDirection.RIGHT) ? 'quick-open-sidebyside-vertical' : 'quick-open-sidebyside-horizontal';
}
public run(context: any): TPromise<any> {
......
......@@ -19,7 +19,7 @@ import { IDiffEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IListService } from 'vs/platform/list/browser/listService';
import { List } from 'vs/base/browser/ui/list/listWidget';
import { distinct } from 'vs/base/common/arrays';
import { IEditorGroupsService, IEditorGroup, GroupDirection, GroupLocation, GroupsOrder, preferredGroupDirection, GroupOrientation } from 'vs/workbench/services/group/common/editorGroupsService';
import { IEditorGroupsService, IEditorGroup, GroupDirection, GroupLocation, GroupsOrder, preferredSideBySideGroupDirection, GroupOrientation } from 'vs/workbench/services/group/common/editorGroupsService';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
......@@ -455,7 +455,7 @@ function registerFocusEditorGroupAtIndexCommands(): void {
}
// Group does not exist: create new by splitting the active one of the last group
const direction = preferredGroupDirection(configurationService);
const direction = preferredSideBySideGroupDirection(configurationService);
const lastGroup = editorGroupService.findGroup({ location: GroupLocation.LAST });
const newGroup = editorGroupService.addGroup(lastGroup, direction);
......
......@@ -70,24 +70,6 @@
background: url('close-inverse.svg') center center no-repeat;
}
.monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-horizontal-action {
background: url('split-editor-horizontal.svg') center center no-repeat;
}
.vs-dark .monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-horizontal-action,
.hc-black .monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-horizontal-action {
background: url('split-editor-horizontal-inverse.svg') center center no-repeat;
}
.monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-vertical-action {
background: url('split-editor-vertical.svg') center center no-repeat;
}
.vs-dark .monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-vertical-action,
.hc-black .monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-vertical-action {
background: url('split-editor-vertical-inverse.svg') center center no-repeat;
}
/* Drag and Drop Feedback */
.monaco-editor-group-drag-image {
......
......@@ -23,7 +23,7 @@ import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { CloseOneEditorAction, SplitEditorAction } from 'vs/workbench/browser/parts/editor/editorActions';
import { CloseOneEditorAction } from 'vs/workbench/browser/parts/editor/editorActions';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { createActionItem, fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
import { IMenuService, MenuId, IMenu, ExecuteCommandAction } from 'vs/platform/actions/common/actions';
......@@ -61,8 +61,6 @@ export abstract class TitleControl extends Themable {
private resourceContext: ResourceContextKey;
private editorToolBarMenuDisposables: IDisposable[] = [];
private splitEditorAction: SplitEditorAction;
private contextMenu: IMenu;
constructor(
......@@ -86,7 +84,6 @@ export abstract class TitleControl extends Themable {
this.contextMenu = this._register(this.menuService.createMenu(MenuId.EditorTitleContext, this.contextKeyService));
this.closeOneEditorAction = this._register(this.instantiationService.createInstance(CloseOneEditorAction, CloseOneEditorAction.ID, CloseOneEditorAction.LABEL));
this.splitEditorAction = this._register(this.instantiationService.createInstance(SplitEditorAction, SplitEditorAction.ID, SplitEditorAction.LABEL));
this.create(parent);
this.registerListeners();
......@@ -197,7 +194,6 @@ export abstract class TitleControl extends Themable {
// Primary actions only for the active group
if (isGroupActive) {
primaryEditorActions = prepareActions(editorActions.primary);
primaryEditorActions.push(this.splitEditorAction);
}
secondaryEditorActions = prepareActions(editorActions.secondary);
......
......@@ -28,6 +28,7 @@ export const ActiveEditorGroupEmptyContext = new RawContextKey<boolean>('activeE
export const MultipleEditorGroupsContext = new RawContextKey<boolean>('multipleEditorGroups', false);
export const SingleEditorGroupsContext = MultipleEditorGroupsContext.toNegated();
export const InEditorZenModeContext = new RawContextKey<boolean>('inZenMode', false);
export const SplitEditorsVertically = new RawContextKey<boolean>('splitEditorsVertically', false);
/**
* Text diff editor id.
......@@ -946,7 +947,7 @@ export interface IWorkbenchEditorPartConfiguration {
enablePreviewFromQuickOpen?: boolean;
closeOnFileDelete?: boolean;
openPositioning?: 'left' | 'right' | 'first' | 'last';
openSideBySideDirection?: 'left' | 'right' | 'up' | 'down';
openSideBySideDirection?: 'horizontal' | 'vertical';
closeEmptyGroups?: boolean;
revealIfOpen?: boolean;
swipeToNavigate?: boolean;
......
......@@ -218,9 +218,9 @@ configurationRegistry.registerConfiguration({
},
'workbench.editor.openSideBySideDirection': {
'type': 'string',
'enum': ['left', 'right', 'up', 'down'],
'default': 'right',
'description': nls.localize('sideBySideDirection', "Controls the default direction of editors that are opened side by side (e.g. from the explorer). By default, editors will open on the rigth hand side of the currently active one.")
'enum': ['horizontal', 'vertical'],
'default': 'horizontal',
'description': nls.localize('sideBySideDirection', "Controls the default direction of editors that are opened side by side (e.g. from the explorer). By default, editors will open horizontally on the rigth hand side of the currently active one. If changed to open vertically, the editors will open below the currently active one.")
},
'workbench.editor.closeEmptyGroups': {
'type': 'boolean',
......
......@@ -23,7 +23,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform';
import { IResourceInput } from 'vs/platform/editor/common/editor';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { IEditorInputFactoryRegistry, Extensions as EditorExtensions, TextCompareEditorVisibleContext, TEXT_DIFF_EDITOR_ID, EditorsVisibleContext, InEditorZenModeContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, IUntitledResourceInput, IResourceDiffInput } from 'vs/workbench/common/editor';
import { IEditorInputFactoryRegistry, Extensions as EditorExtensions, TextCompareEditorVisibleContext, TEXT_DIFF_EDITOR_ID, EditorsVisibleContext, InEditorZenModeContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, IUntitledResourceInput, IResourceDiffInput, SplitEditorsVertically } from 'vs/workbench/common/editor';
import { HistoryService } from 'vs/workbench/services/history/electron-browser/history';
import { ActivitybarPart } from 'vs/workbench/browser/parts/activitybar/activitybarPart';
import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
......@@ -108,7 +108,7 @@ import { registerWindowDriver } from 'vs/platform/driver/electron-browser/driver
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { PreferencesService } from 'vs/workbench/services/preferences/browser/preferencesService';
import { IEditorService, IResourceEditor } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupsService, GroupDirection } from 'vs/workbench/services/group/common/editorGroupsService';
import { IEditorGroupsService, GroupDirection, preferredSideBySideGroupDirection } from 'vs/workbench/services/group/common/editorGroupsService';
import { EditorService } from 'vs/workbench/services/editor/browser/editorService';
import { IExtensionUrlHandler, ExtensionUrlHandler } from 'vs/platform/url/electron-browser/inactiveExtensionUrlHandler';
......@@ -621,6 +621,21 @@ export class Workbench extends Disposable implements IPartService {
this._register(this.configurationService.onDidChangeWorkspaceFolders(() => {
workspaceFolderCountContext.set(this.configurationService.getWorkspace().folders.length);
}));
const splitEditorsVerticallyContext = SplitEditorsVertically.bindTo(this.contextKeyService);
const updateSplitEditorsVerticallyContext = () => {
const direction = preferredSideBySideGroupDirection(this.configurationService);
splitEditorsVerticallyContext.set(direction === GroupDirection.DOWN);
};
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('workbench.editor.openSideBySideDirection')) {
updateSplitEditorsVerticallyContext();
}
}));
updateSplitEditorsVerticallyContext();
}
private restoreParts(): TPromise<IWorkbenchStartedInfo> {
......
......@@ -24,7 +24,7 @@ import { basename } from 'vs/base/common/paths';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { localize } from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
import { IEditorGroupsService, IEditorGroup, GroupsOrder, IEditorReplacement, GroupChangeKind, preferredGroupDirection } from 'vs/workbench/services/group/common/editorGroupsService';
import { IEditorGroupsService, IEditorGroup, GroupsOrder, IEditorReplacement, GroupChangeKind, preferredSideBySideGroupDirection } from 'vs/workbench/services/group/common/editorGroupsService';
import { IEditorService, IResourceEditor, ACTIVE_GROUP_TYPE, SIDE_GROUP_TYPE, SIDE_GROUP, ACTIVE_GROUP, IResourceEditorReplacement, IOpenEditorOverrideHandler } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Disposable, IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
......@@ -302,7 +302,7 @@ export class EditorService extends Disposable implements IEditorService {
}
private findSideBySideGroup(): IEditorGroup {
const direction = preferredGroupDirection(this.configurationService);
const direction = preferredSideBySideGroupDirection(this.configurationService);
let neighbourGroup = this.editorGroupService.findGroup({ direction });
if (!neighbourGroup) {
......
......@@ -21,16 +21,14 @@ export enum GroupDirection {
RIGHT
}
export function preferredGroupDirection(configurationService: IConfigurationService): GroupDirection {
const openSideBySideDirection = configurationService.getValue<'left' | 'right' | 'up' | 'down'>('workbench.editor.openSideBySideDirection');
switch (openSideBySideDirection) {
case 'left': return GroupDirection.LEFT;
case 'right': return GroupDirection.RIGHT;
case 'up': return GroupDirection.UP;
case 'down': return GroupDirection.DOWN;
default: return GroupDirection.RIGHT;
export function preferredSideBySideGroupDirection(configurationService: IConfigurationService): GroupDirection.DOWN | GroupDirection.RIGHT {
const openSideBySideDirection = configurationService.getValue<'horizontal' | 'vertical'>('workbench.editor.openSideBySideDirection');
if (openSideBySideDirection === 'vertical') {
return GroupDirection.DOWN;
}
return GroupDirection.RIGHT;
}
export enum GroupOrientation {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册