提交 a40d803d 编写于 作者: B Benjamin Pasero

grid - more editor actions adoption

上级 2a7d4339
......@@ -90,7 +90,7 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
@IPartService private partService: IPartService,
@IViewletService private viewletService: IViewletService,
@IThemeService private themeService: IThemeService,
@INextEditorGroupsService private nextEditorGroupsService: INextEditorGroupsService
@INextEditorGroupsService private editorGroupService: INextEditorGroupsService
) {
super();
......@@ -124,7 +124,7 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
private onDidPreferredSizeChange(): void {
if (this.workbenchSize && (this.sidebarWidth || this.panelHeight)) {
if (this.nextEditorGroupsService.count > 1) {
if (this.editorGroupService.count > 1) {
const preferredEditorPartSize = this.parts.editor.preferredSize;
const sidebarOverflow = this.workbenchSize.width - this.sidebarWidth < preferredEditorPartSize.width;
......@@ -713,7 +713,7 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
case Parts.EDITOR_PART:
// If we have one editor we can cheat and resize sidebar with the negative delta
// If the sidebar is not visible and panel is, resize panel main axis with negative Delta
if (this.nextEditorGroupsService.count === 1) {
if (this.editorGroupService.count === 1) {
if (this.partService.isVisible(Parts.SIDEBAR_PART)) {
this.sidebarWidth = this.sidebarWidth - sizeChangePxWidth;
doLayout = true;
......@@ -726,9 +726,9 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
doLayout = true;
}
} else {
const activeGroup = this.nextEditorGroupsService.activeGroup;
const activeGroup = this.editorGroupService.activeGroup;
this.nextEditorGroupsService.resizeGroup(activeGroup, sizeChangePxWidth);
this.editorGroupService.resizeGroup(activeGroup, sizeChangePxWidth);
doLayout = false;
}
}
......
......@@ -32,7 +32,8 @@ import {
NavigateBetweenGroupsAction, FocusActiveGroupAction, FocusFirstGroupAction, FocusSecondGroupAction, FocusThirdGroupAction, EvenGroupWidthsAction, MaximizeGroupAction, MinimizeOtherGroupsAction, FocusPreviousGroup, FocusNextGroup,
toEditorQuickOpenEntry, CloseLeftEditorsInGroupAction, OpenNextEditor, OpenPreviousEditor, NavigateBackwardsAction, NavigateForwardAction, NavigateLastAction, ReopenClosedEditorAction, OpenPreviousRecentlyUsedEditorInGroupAction,
OpenPreviousEditorFromHistoryAction, ShowAllEditorsAction, ClearEditorHistoryAction, MoveEditorRightInGroupAction, OpenNextEditorInGroup, OpenPreviousEditorInGroup, OpenNextRecentlyUsedEditorAction, OpenPreviousRecentlyUsedEditorAction,
FocusLastEditorInStackAction, OpenNextRecentlyUsedEditorInGroupAction, MoveEditorToPreviousGroupAction, MoveEditorToNextGroupAction, MoveEditorToFirstGroupAction, MoveEditorToSecondGroupAction, MoveEditorToThirdGroupAction, MoveEditorLeftInGroupAction, ClearRecentFilesAction, OpenLastEditorInGroup, SplitEditorGroupHorizontalAction, SplitEditorGroupVerticalAction, RemoveActiveEditorGroupAction, ShowEditorsInActiveGroupAction
OpenNextRecentlyUsedEditorInGroupAction, MoveEditorToPreviousGroupAction, MoveEditorToNextGroupAction, MoveEditorToFirstGroupAction, MoveEditorLeftInGroupAction, ClearRecentFilesAction, OpenLastEditorInGroup,
SplitEditorGroupHorizontalAction, SplitEditorGroupVerticalAction, RemoveActiveEditorGroupAction, ShowEditorsInActiveGroupAction, MoveEditorToLastGroupAction, OpenFirstEditorInGroup, MoveGroupUpAction, MoveGroupDownAction
} from 'vs/workbench/browser/parts/editor/editorActions';
import * as editorCommands from 'vs/workbench/browser/parts/editor/editorCommands';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
......@@ -298,7 +299,8 @@ Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpen
const category = nls.localize('view', "View");
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenNextEditorInGroup, OpenNextEditorInGroup.ID, OpenNextEditorInGroup.LABEL), 'View: Open Next Editor in Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenPreviousEditorInGroup, OpenPreviousEditorInGroup.ID, OpenPreviousEditorInGroup.LABEL), 'View: Open Previous Editor in Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenLastEditorInGroup, OpenLastEditorInGroup.ID, OpenLastEditorInGroup.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_9 }), 'View: Open Last Editor in Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenLastEditorInGroup, OpenLastEditorInGroup.ID, OpenLastEditorInGroup.LABEL, { primary: KeyMod.Alt | KeyCode.KEY_0, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_0 }, secondary: [KeyMod.CtrlCmd | KeyCode.KEY_9] }), 'View: Open Last Editor in Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenFirstEditorInGroup, OpenFirstEditorInGroup.ID, OpenFirstEditorInGroup.LABEL), 'View: Open First Editor in Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenNextRecentlyUsedEditorAction, OpenNextRecentlyUsedEditorAction.ID, OpenNextRecentlyUsedEditorAction.LABEL), 'View: Open Next Recently Used Editor', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenPreviousRecentlyUsedEditorAction, OpenPreviousRecentlyUsedEditorAction.ID, OpenPreviousRecentlyUsedEditorAction.LABEL), 'View: Open Previous Recently Used Editor', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowAllEditorsAction, ShowAllEditorsAction.ID, ShowAllEditorsAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_P), mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Tab } }), 'View: Show All Editors', category);
......@@ -317,7 +319,6 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(FocusActiveGroupAction
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusFirstGroupAction, FocusFirstGroupAction.ID, FocusFirstGroupAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_1 }), 'View: Focus First Editor Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusSecondGroupAction, FocusSecondGroupAction.ID, FocusSecondGroupAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_2 }), 'View: Focus Second Editor Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusThirdGroupAction, FocusThirdGroupAction.ID, FocusThirdGroupAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_3 }), 'View: Focus Third Editor Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusLastEditorInStackAction, FocusLastEditorInStackAction.ID, FocusLastEditorInStackAction.LABEL, { primary: KeyMod.Alt | KeyCode.KEY_0, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_0 } }), 'View: Open Last Editor in Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(EvenGroupWidthsAction, EvenGroupWidthsAction.ID, EvenGroupWidthsAction.LABEL), 'View: Even Editor Group Widths', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MaximizeGroupAction, MaximizeGroupAction.ID, MaximizeGroupAction.LABEL), 'View: Maximize Editor Group and Hide Sidebar', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MinimizeOtherGroupsAction, MinimizeOtherGroupsAction.ID, MinimizeOtherGroupsAction.LABEL), 'View: Minimize Other Editor Groups', category);
......@@ -325,11 +326,12 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(MoveEditorLeftInGroupA
registry.registerWorkbenchAction(new SyncActionDescriptor(MoveEditorRightInGroupAction, MoveEditorRightInGroupAction.ID, MoveEditorRightInGroupAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.PageDown, mac: { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.RightArrow) } }), 'View: Move Editor Right', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MoveGroupLeftAction, MoveGroupLeftAction.ID, MoveGroupLeftAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.LeftArrow) }), 'View: Move Editor Group Left', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MoveGroupRightAction, MoveGroupRightAction.ID, MoveGroupRightAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.RightArrow) }), 'View: Move Editor Group Right', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MoveGroupUpAction, MoveGroupUpAction.ID, MoveGroupUpAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.UpArrow) }), 'View: Move Editor Group Up', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MoveGroupDownAction, MoveGroupDownAction.ID, MoveGroupDownAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.DownArrow) }), 'View: Move Editor Group Down', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MoveEditorToPreviousGroupAction, MoveEditorToPreviousGroupAction.ID, MoveEditorToPreviousGroupAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.LeftArrow, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.LeftArrow } }), 'View: Move Editor into Previous Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MoveEditorToNextGroupAction, MoveEditorToNextGroupAction.ID, MoveEditorToNextGroupAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.RightArrow, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.RightArrow } }), 'View: Move Editor into Next Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MoveEditorToFirstGroupAction, MoveEditorToFirstGroupAction.ID, MoveEditorToFirstGroupAction.LABEL, { primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_1, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.KEY_1 } }), 'View: Move Editor into First Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MoveEditorToSecondGroupAction, MoveEditorToSecondGroupAction.ID, MoveEditorToSecondGroupAction.LABEL, { primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_2, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.KEY_2 } }), 'View: Move Editor into Second Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MoveEditorToThirdGroupAction, MoveEditorToThirdGroupAction.ID, MoveEditorToThirdGroupAction.LABEL, { primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_3, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.KEY_3 } }), 'View: Move Editor into Third Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(MoveEditorToLastGroupAction, MoveEditorToLastGroupAction.ID, MoveEditorToLastGroupAction.LABEL, { primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_2, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.KEY_2 } }), 'View: Move Editor into Last Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusPreviousGroup, FocusPreviousGroup.ID, FocusPreviousGroup.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.LeftArrow) }), 'View: Focus Previous Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusNextGroup, FocusNextGroup.ID, FocusNextGroup.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.RightArrow) }), 'View: Focus Next Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateForwardAction, NavigateForwardAction.ID, NavigateForwardAction.LABEL, { primary: null, win: { primary: KeyMod.Alt | KeyCode.RightArrow }, mac: { primary: KeyMod.WinCtrl | KeyMod.Shift | KeyCode.US_MINUS }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_MINUS } }), 'Go Forward');
......
......@@ -20,7 +20,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 { INextEditorGroupsService, INextEditorGroup, GroupDirection } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorGroupsService, INextEditorGroup, GroupDirection, GroupLocation } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
export const MOVE_ACTIVE_EDITOR_COMMAND_ID = 'moveActiveEditor';
......@@ -38,7 +38,7 @@ export const NAVIGATE_ALL_EDITORS_GROUP_PREFIX = 'edt ';
export const NAVIGATE_IN_ACTIVE_GROUP_PREFIX = 'edt active ';
export interface ActiveEditorMoveArguments {
to?: 'first' | 'last' | 'left' | 'right' | 'up' | 'down' | 'center' | 'position';
to?: 'first' | 'last' | 'left' | 'right' | 'up' | 'down' | 'center' | 'position' | 'previous' | 'next';
by?: 'tab' | 'group';
value?: number;
}
......@@ -136,22 +136,40 @@ function moveActiveEditorToGroup(args: ActiveEditorMoveArguments, control: IEdit
switch (args.to) {
case 'left':
targetGroup = editorGroupService.findNeighbourGroup(sourceGroup, GroupDirection.LEFT);
targetGroup = editorGroupService.findGroup({ direction: GroupDirection.LEFT }, sourceGroup);
if (!targetGroup) {
targetGroup = editorGroupService.addGroup(sourceGroup, GroupDirection.LEFT);
}
break;
case 'right':
targetGroup = editorGroupService.findNeighbourGroup(sourceGroup, GroupDirection.RIGHT);
targetGroup = editorGroupService.findGroup({ direction: GroupDirection.RIGHT }, sourceGroup);
if (!targetGroup) {
targetGroup = editorGroupService.addGroup(sourceGroup, GroupDirection.RIGHT);
}
break;
case 'up':
targetGroup = editorGroupService.findNeighbourGroup(sourceGroup, GroupDirection.UP);
targetGroup = editorGroupService.findGroup({ direction: GroupDirection.UP }, sourceGroup);
if (!targetGroup) {
targetGroup = editorGroupService.addGroup(sourceGroup, GroupDirection.UP);
}
break;
case 'down':
targetGroup = editorGroupService.findNeighbourGroup(sourceGroup, GroupDirection.DOWN);
targetGroup = editorGroupService.findGroup({ direction: GroupDirection.DOWN }, sourceGroup);
if (!targetGroup) {
targetGroup = editorGroupService.addGroup(sourceGroup, GroupDirection.DOWN);
}
break;
case 'first':
targetGroup = groups[0];
targetGroup = editorGroupService.findGroup({ location: GroupLocation.FIRST }, sourceGroup);
break;
case 'last':
targetGroup = groups[groups.length - 1];
targetGroup = editorGroupService.findGroup({ location: GroupLocation.LAST }, sourceGroup);
break;
case 'previous':
targetGroup = editorGroupService.findGroup({ location: GroupLocation.PREVIOUS }, sourceGroup);
break;
case 'next':
targetGroup = editorGroupService.findGroup({ location: GroupLocation.NEXT }, sourceGroup);
break;
case 'center':
targetGroup = groups[(groups.length / 2) - 1];
......
......@@ -11,7 +11,7 @@ import { Part } from 'vs/workbench/browser/part';
import { Dimension, isAncestor, toggleClass, addClass, clearNode } from 'vs/base/browser/dom';
import { Event, Emitter, once } from 'vs/base/common/event';
import { contrastBorder, editorBackground } from 'vs/platform/theme/common/colorRegistry';
import { INextEditorGroupsService, GroupDirection, IAddGroupOptions, GroupsArrangement, GroupOrientation, IMergeGroupOptions, MergeGroupMode, ICopyEditorOptions, GroupsOrder, GroupChangeKind } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorGroupsService, GroupDirection, IAddGroupOptions, GroupsArrangement, GroupOrientation, IMergeGroupOptions, MergeGroupMode, ICopyEditorOptions, GroupsOrder, GroupChangeKind, GroupLocation, IFindGroupScope } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Direction, SerializableGrid, Sizing, ISerializedGrid, Orientation, ISerializedNode, GridBranchNode, isGridBranchNode, GridNode } from 'vs/base/browser/ui/grid/grid';
import { GroupIdentifier, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
......@@ -218,19 +218,47 @@ export class NextEditorPart extends Part implements INextEditorGroupsService, IN
return this.groupViews.get(identifier);
}
findNeighbourGroup(location: INextEditorGroupView | GroupIdentifier, direction: GroupDirection): INextEditorGroupView { // TODO@grid finding neighbour needs gridwidget support
const locationGroupView = this.assertGroupView(location);
findGroup(scope: IFindGroupScope, source: INextEditorGroupView | GroupIdentifier = this.activeGroup): INextEditorGroupView {
// by direction
if (typeof scope.direction === 'number') {
return this.doFindGroupByDirection(scope.direction, source);
}
// by location
return this.doFindGroupByLocation(scope.location, source);
}
private doFindGroupByDirection(direction: GroupDirection, source: INextEditorGroupView | GroupIdentifier): INextEditorGroupView {
const sourceGroupView = this.assertGroupView(source);
const groups = this.getGroups(GroupsOrder.GRID_APPEARANCE);
const index = groups.indexOf(locationGroupView);
const index = groups.indexOf(sourceGroupView);
const neighbourGroupView = groups[direction === GroupDirection.RIGHT || direction === GroupDirection.DOWN ? index + 1 : index - 1];
if (neighbourGroupView && this.gridWidget.getOrientation(neighbourGroupView) === this.gridWidget.getOrientation(locationGroupView)) {
return neighbourGroupView;
if (neighbourGroupView && this.gridWidget.getOrientation(neighbourGroupView) === this.gridWidget.getOrientation(sourceGroupView)) {
return neighbourGroupView; // TODO@grid finding neighbour needs gridwidget support
}
return void 0;
}
private doFindGroupByLocation(location: GroupLocation, source: INextEditorGroupView | GroupIdentifier): INextEditorGroupView {
const sourceGroupView = this.assertGroupView(source);
const groups = this.getGroups(GroupsOrder.CREATION_TIME);
const index = groups.indexOf(sourceGroupView);
switch (location) {
case GroupLocation.FIRST:
return groups[0];
case GroupLocation.LAST:
return groups[groups.length - 1];
case GroupLocation.NEXT:
return groups[index + 1];
case GroupLocation.PREVIOUS:
return groups[index - 1];
}
}
activateGroup(group: INextEditorGroupView | GroupIdentifier): INextEditorGroupView {
const groupView = this.assertGroupView(group);
this.doSetGroupActive(groupView);
......
......@@ -1200,7 +1200,7 @@ export abstract class BaseNavigationAction extends Action {
}
protected navigateAcrossEditorGroup(direction: GroupDirection): TPromise<boolean> {
const nextGroup = this.groupService.findNeighbourGroup(this.groupService.activeGroup, direction);
const nextGroup = this.groupService.findGroup({ direction });
if (nextGroup) {
this.groupService.focusGroup(nextGroup);
return TPromise.as(true);
......
......@@ -10,7 +10,7 @@ import { IAction } from 'vs/base/common/actions';
import * as dom from 'vs/base/browser/dom';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { INextEditorGroupsService, INextEditorGroup, GroupDirection, GroupChangeKind } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorGroupsService, INextEditorGroup, GroupChangeKind } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IEditorInput } from 'vs/workbench/common/editor';
......@@ -32,7 +32,7 @@ import { EditorLabel } from 'vs/workbench/browser/labels';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { TPromise } from 'vs/base/common/winjs.base';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { INextEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/nextEditorService';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
......@@ -355,14 +355,13 @@ export class OpenEditorsView extends ViewsViewletPanel {
*/
this.telemetryService.publicLog('workbenchActionExecuted', { id: 'workbench.files.openFile', from: 'openEditors' });
const groupWhereToOpen = options.sideBySide ? this.editorGroupService.findNeighbourGroup(element.groupId, GroupDirection.RIGHT) : element.groupId;
const preserveActivateGroup = options.sideBySide && options.preserveFocus; // needed for https://github.com/Microsoft/vscode/issues/42399
if (!preserveActivateGroup) {
this.editorGroupService.activateGroup(element.groupId); // needed for https://github.com/Microsoft/vscode/issues/6672
}
this.editorService.openEditor(element.editor, options, groupWhereToOpen).done(() => {
this.editorService.openEditor(element.editor, options, options.sideBySide ? SIDE_GROUP : ACTIVE_GROUP).done(editor => {
if (!preserveActivateGroup) {
this.editorGroupService.activateGroup(groupWhereToOpen);
this.editorGroupService.activateGroup(editor.group);
}
}, errors.onUnexpectedError);
}
......
......@@ -61,7 +61,7 @@ export class NextEditorService extends Disposable implements INextEditorService
private lastActiveEditor: IEditorInput;
constructor(
@INextEditorGroupsService private nextEditorGroupsService: INextEditorGroupsService,
@INextEditorGroupsService private editorGroupService: INextEditorGroupsService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IWorkspaceContextService private workspaceContextService: IWorkspaceContextService,
@IInstantiationService private instantiationService: IInstantiationService,
......@@ -77,13 +77,13 @@ export class NextEditorService extends Disposable implements INextEditorService
}
private registerListeners(): void {
this.nextEditorGroupsService.whenRestored.then(() => this.nextEditorGroupsService.groups.forEach(group => this.registerGroupListeners(group)));
this.nextEditorGroupsService.onDidActiveGroupChange(group => this.handleActiveEditorChange(group));
this.nextEditorGroupsService.onDidAddGroup(group => this.registerGroupListeners(group));
this.editorGroupService.whenRestored.then(() => this.editorGroupService.groups.forEach(group => this.registerGroupListeners(group)));
this.editorGroupService.onDidActiveGroupChange(group => this.handleActiveEditorChange(group));
this.editorGroupService.onDidAddGroup(group => this.registerGroupListeners(group));
}
private handleActiveEditorChange(group: INextEditorGroup): void {
if (group !== this.nextEditorGroupsService.activeGroup) {
if (group !== this.editorGroupService.activeGroup) {
return; // ignore if not the active group
}
......@@ -135,7 +135,7 @@ export class NextEditorService extends Disposable implements INextEditorService
}
get activeControl(): IEditor {
const activeGroup = this.nextEditorGroupsService.activeGroup;
const activeGroup = this.editorGroupService.activeGroup;
return activeGroup ? activeGroup.activeControl : void 0;
}
......@@ -154,7 +154,7 @@ export class NextEditorService extends Disposable implements INextEditorService
get editors(): IEditorInput[] {
const editors: IEditorInput[] = [];
this.nextEditorGroupsService.groups.forEach(group => {
this.editorGroupService.groups.forEach(group => {
editors.push(...group.editors);
});
......@@ -162,13 +162,13 @@ export class NextEditorService extends Disposable implements INextEditorService
}
get activeEditor(): IEditorInput {
const activeGroup = this.nextEditorGroupsService.activeGroup;
const activeGroup = this.editorGroupService.activeGroup;
return activeGroup ? activeGroup.activeEditor : void 0;
}
get visibleControls(): IEditor[] {
return coalesce(this.nextEditorGroupsService.groups.map(group => group.activeControl));
return coalesce(this.editorGroupService.groups.map(group => group.activeControl));
}
get visibleTextEditorControls(): ITextEditor[] {
......@@ -176,7 +176,7 @@ export class NextEditorService extends Disposable implements INextEditorService
}
get visibleEditors(): IEditorInput[] {
return coalesce(this.nextEditorGroupsService.groups.map(group => group.activeEditor));
return coalesce(this.editorGroupService.groups.map(group => group.activeEditor));
}
//#region preventOpenEditor()
......@@ -265,7 +265,7 @@ export class NextEditorService extends Disposable implements INextEditorService
// Group: Active Group
if (group === ACTIVE_GROUP) {
targetGroup = this.nextEditorGroupsService.activeGroup;
targetGroup = this.editorGroupService.activeGroup;
}
// Group: Side by Side
......@@ -275,12 +275,12 @@ export class NextEditorService extends Disposable implements INextEditorService
// Group: Specific Group
else if (typeof group === 'number') {
targetGroup = this.nextEditorGroupsService.getGroup(group);
targetGroup = this.editorGroupService.getGroup(group);
}
// Group: Unspecified without a specific index to open
else if (!options || typeof options.index !== 'number') {
const groupsByLastActive = this.nextEditorGroupsService.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
const groupsByLastActive = this.editorGroupService.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
// Respect option to reveal an editor if it is already visible in any group
if (options && options.revealIfVisible) {
......@@ -307,27 +307,27 @@ export class NextEditorService extends Disposable implements INextEditorService
// Fallback to active group if target not valid
if (!targetGroup) {
targetGroup = this.nextEditorGroupsService.activeGroup;
targetGroup = this.editorGroupService.activeGroup;
}
return targetGroup;
}
private findSideBySideGroup(): INextEditorGroup {
const direction = this.configurationService.getValue<'left' | 'right' | 'up' | 'down'>('workbench.editor.openSideBySideDirection');
const preferredDirection = this.configurationService.getValue<'left' | 'right' | 'up' | 'down'>('workbench.editor.openSideBySideDirection');
let groupDirection: GroupDirection;
switch (direction) {
case 'left': groupDirection = GroupDirection.LEFT; break;
case 'right': groupDirection = GroupDirection.RIGHT; break;
case 'up': groupDirection = GroupDirection.UP; break;
case 'down': groupDirection = GroupDirection.DOWN; break;
default: groupDirection = GroupDirection.RIGHT;
let direction: GroupDirection;
switch (preferredDirection) {
case 'left': direction = GroupDirection.LEFT; break;
case 'right': direction = GroupDirection.RIGHT; break;
case 'up': direction = GroupDirection.UP; break;
case 'down': direction = GroupDirection.DOWN; break;
default: direction = GroupDirection.RIGHT;
}
let neighbourGroup = this.nextEditorGroupsService.findNeighbourGroup(this.nextEditorGroupsService.activeGroup, groupDirection);
let neighbourGroup = this.editorGroupService.findGroup({ direction });
if (!neighbourGroup) {
neighbourGroup = this.nextEditorGroupsService.addGroup(this.nextEditorGroupsService.activeGroup, groupDirection);
neighbourGroup = this.editorGroupService.addGroup(this.editorGroupService.activeGroup, direction);
}
return neighbourGroup;
......@@ -398,11 +398,11 @@ export class NextEditorService extends Disposable implements INextEditorService
isOpen(editor: IEditorInput | IResourceInput | IUntitledResourceInput, group?: INextEditorGroup | GroupIdentifier): boolean {
let groups: INextEditorGroup[] = [];
if (typeof group === 'number') {
groups.push(this.nextEditorGroupsService.getGroup(group));
groups.push(this.editorGroupService.getGroup(group));
} else if (group) {
groups.push(group);
} else {
groups = [...this.nextEditorGroupsService.groups];
groups = [...this.editorGroupService.groups];
}
return groups.some(group => {
......@@ -448,7 +448,7 @@ export class NextEditorService extends Disposable implements INextEditorService
}
});
const targetGroup = typeof group === 'number' ? this.nextEditorGroupsService.getGroup(group) : group;
const targetGroup = typeof group === 'number' ? this.editorGroupService.getGroup(group) : group;
return targetGroup.replaceEditors(typedEditors);
}
......@@ -462,7 +462,7 @@ export class NextEditorService extends Disposable implements INextEditorService
return activeTextEditorControl.invokeWithinContext(fn);
}
const activeGroup = this.nextEditorGroupsService.activeGroup;
const activeGroup = this.editorGroupService.activeGroup;
if (activeGroup) {
return activeGroup.invokeWithinContext(fn);
}
......@@ -601,7 +601,7 @@ export class DelegatingWorkbenchEditorService extends NextEditorService {
private editorOpenHandler: IEditorOpenHandler;
constructor(
@INextEditorGroupsService nextEditorGroupsService: INextEditorGroupsService,
@INextEditorGroupsService editorGroupService: INextEditorGroupsService,
@IUntitledEditorService untitledEditorService: IUntitledEditorService,
@IWorkspaceContextService workspaceContextService: IWorkspaceContextService,
@IInstantiationService instantiationService: IInstantiationService,
......@@ -610,7 +610,7 @@ export class DelegatingWorkbenchEditorService extends NextEditorService {
@IConfigurationService configurationService: IConfigurationService
) {
super(
nextEditorGroupsService,
editorGroupService,
untitledEditorService,
workspaceContextService,
instantiationService,
......
......@@ -25,6 +25,18 @@ export enum GroupOrientation {
VERTICAL
}
export enum GroupLocation {
FIRST,
LAST,
NEXT,
PREVIOUS
}
export interface IFindGroupScope {
direction?: GroupDirection;
location?: GroupLocation;
}
export enum GroupsArrangement {
/**
......@@ -98,9 +110,9 @@ export enum EditorsOrder {
MOST_RECENTLY_ACTIVE,
/**
* Editors sorted by tabs order
* Editors sorted by sequential order
*/
TAB_APPEARANCE
SEQUENTIAL
}
export interface INextEditorGroupsService {
......@@ -192,13 +204,20 @@ export interface INextEditorGroupsService {
setGroupOrientation(orientation: GroupOrientation): void;
/**
* Find the closest neighbour from the provided location in the provided direction if any.
* Find a groupd in a specific scope:
* * `GroupLocation.FIRST`: the first group
* * `GroupLocation.LAST`: the last group
* * `GroupLocation.NEXT`: the next group from either the active one or `source`
* * `GroupLocation.PREVIOUS`: the previous group from either the active one or `source`
* * `GroupDirection.UP`: the next group upwards the active one or `source`
* * `GroupDirection.DOWN`: the next group downwards the active one or `source`
* * `GroupDirection.LEFT`: the next group to the left of the active one or `source`
* * `GroupDirection.RIGHT`: the next group to the right of the active one or `source`
*
* @param location the group to start from
* @param direction the direction to look up
* @returns the neighbour group or `undefined` if none.
* @param scope the scope of the group to search in
* @param source optional source to search from
*/
findNeighbourGroup(location: INextEditorGroup | GroupIdentifier, direction: GroupDirection): INextEditorGroup;
findGroup(scope: IFindGroupScope, source?: INextEditorGroup | GroupIdentifier): INextEditorGroup;
/**
* Add a new group to the editor area. A new group is added by splitting a provided one in
......
......@@ -8,7 +8,7 @@
import * as assert from 'assert';
import { NextEditorPart } from 'vs/workbench/browser/parts/editor2/nextEditorPart';
import { workbenchInstantiationService } from 'vs/workbench/test/workbenchTestServices';
import { GroupDirection, GroupsOrder, MergeGroupMode, GroupOrientation, GroupChangeKind, EditorsOrder } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { GroupDirection, GroupsOrder, MergeGroupMode, GroupOrientation, GroupChangeKind, EditorsOrder, GroupLocation } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { Dimension } from 'vs/base/browser/dom';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { INextEditorPartOptions } from 'vs/workbench/browser/parts/editor2/editor2';
......@@ -479,6 +479,8 @@ suite('Editor groups service (editor2)', () => {
return group.closeEditors([input, inputInactive]).then(() => {
assert.equal(group.isEmpty(), true);
part.dispose();
});
});
});
......@@ -501,6 +503,8 @@ suite('Editor groups service (editor2)', () => {
return group.closeEditors({ except: input2 }).then(() => {
assert.equal(group.count, 1);
assert.equal(group.getEditor(0), input2);
part.dispose();
});
});
});
......@@ -522,6 +526,8 @@ suite('Editor groups service (editor2)', () => {
return group.closeEditors({ savedOnly: true }).then(() => {
assert.equal(group.count, 0);
part.dispose();
});
});
});
......@@ -545,6 +551,8 @@ suite('Editor groups service (editor2)', () => {
assert.equal(group.count, 2);
assert.equal(group.getEditor(0), input1);
assert.equal(group.getEditor(1), input2);
part.dispose();
});
});
});
......@@ -568,6 +576,8 @@ suite('Editor groups service (editor2)', () => {
assert.equal(group.count, 2);
assert.equal(group.getEditor(0), input2);
assert.equal(group.getEditor(1), input3);
part.dispose();
});
});
});
......@@ -587,6 +597,8 @@ suite('Editor groups service (editor2)', () => {
return group.closeAllEditors().then(() => {
assert.equal(group.isEmpty(), true);
part.dispose();
});
});
});
......@@ -618,6 +630,7 @@ suite('Editor groups service (editor2)', () => {
assert.equal(group.getEditor(1), input);
editorGroupChangeListener.dispose();
part.dispose();
});
});
......@@ -642,6 +655,8 @@ suite('Editor groups service (editor2)', () => {
assert.equal(rightGroup.count, 1);
assert.equal(rightGroup.getEditor(0), inputInactive);
part.dispose();
});
});
......@@ -667,6 +682,8 @@ suite('Editor groups service (editor2)', () => {
assert.equal(rightGroup.count, 1);
assert.equal(rightGroup.getEditor(0), inputInactive);
part.dispose();
});
});
......@@ -685,25 +702,49 @@ suite('Editor groups service (editor2)', () => {
return group.replaceEditors([{ editor: input, replacement: inputInactive }]).then(() => {
assert.equal(group.count, 1);
assert.equal(group.getEditor(0), inputInactive);
part.dispose();
});
});
});
test('findNeighbour (left/right)', function () {
test('find neighbour group (left/right)', function () {
const part = createPart();
const rootGroup = part.activeGroup;
const rightGroup = part.addGroup(rootGroup, GroupDirection.RIGHT);
assert.equal(rightGroup, part.findNeighbourGroup(rootGroup, GroupDirection.RIGHT));
assert.equal(rootGroup, part.findNeighbourGroup(rightGroup, GroupDirection.LEFT));
assert.equal(rightGroup, part.findGroup({ direction: GroupDirection.RIGHT }, rootGroup));
assert.equal(rootGroup, part.findGroup({ direction: GroupDirection.LEFT }, rightGroup));
part.dispose();
});
test('findNeighbour (up/down)', function () {
test('find neighbour group (up/down)', function () {
const part = createPart();
const rootGroup = part.activeGroup;
const downGroup = part.addGroup(rootGroup, GroupDirection.DOWN);
assert.equal(downGroup, part.findNeighbourGroup(rootGroup, GroupDirection.DOWN));
assert.equal(rootGroup, part.findNeighbourGroup(downGroup, GroupDirection.UP));
assert.equal(downGroup, part.findGroup({ direction: GroupDirection.DOWN }, rootGroup));
assert.equal(rootGroup, part.findGroup({ direction: GroupDirection.UP }, downGroup));
part.dispose();
});
test('find group by location (left/right)', function () {
const part = createPart();
const rootGroup = part.activeGroup;
const rightGroup = part.addGroup(rootGroup, GroupDirection.RIGHT);
const downGroup = part.addGroup(rightGroup, GroupDirection.DOWN);
assert.equal(rootGroup, part.findGroup({ location: GroupLocation.FIRST }));
assert.equal(downGroup, part.findGroup({ location: GroupLocation.LAST }));
assert.equal(rightGroup, part.findGroup({ location: GroupLocation.NEXT }, rootGroup));
assert.equal(rootGroup, part.findGroup({ location: GroupLocation.PREVIOUS }, rightGroup));
assert.equal(downGroup, part.findGroup({ location: GroupLocation.NEXT }, rightGroup));
assert.equal(rightGroup, part.findGroup({ location: GroupLocation.PREVIOUS }, downGroup));
part.dispose();
});
});
\ No newline at end of file
......@@ -68,7 +68,7 @@ import { IExtensionPoint } from 'vs/workbench/services/extensions/common/extensi
import { IKeybindingService } from '../../platform/keybinding/common/keybinding';
import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { INextEditorGroupsService, INextEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, EditorsOrder } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorGroupsService, INextEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, EditorsOrder, IFindGroupScope } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorService, IOpenEditorOverrideHandler } from 'vs/workbench/services/editor/common/nextEditorService';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
......@@ -743,7 +743,7 @@ export class TestNextEditorGroupsService implements INextEditorGroupsService {
return null;
}
findNeighbourGroup(location: number | INextEditorGroup, direction: GroupDirection): INextEditorGroup {
findGroup(scope: IFindGroupScope, source?: number | INextEditorGroup): INextEditorGroup {
return null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册