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

grid - introduce and use command for predefined editor layouts

上级 cf179059
...@@ -688,8 +688,6 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr ...@@ -688,8 +688,6 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
const sizeChangePxHeight = this.workbenchSize.height * (sizeChange / 100); const sizeChangePxHeight = this.workbenchSize.height * (sizeChange / 100);
let doLayout = false; let doLayout = false;
switch (part) { switch (part) {
case Parts.SIDEBAR_PART: case Parts.SIDEBAR_PART:
this.sidebarWidth = this.sidebarWidth + sizeChangePxWidth; // Sidebar can not become smaller than MIN_PART_WIDTH this.sidebarWidth = this.sidebarWidth + sizeChangePxWidth; // Sidebar can not become smaller than MIN_PART_WIDTH
...@@ -728,8 +726,8 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr ...@@ -728,8 +726,8 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
} else { } else {
const activeGroup = this.editorGroupService.activeGroup; const activeGroup = this.editorGroupService.activeGroup;
this.editorGroupService.resizeGroup(activeGroup, sizeChangePxWidth); const activeGroupSize = this.editorGroupService.getSize(activeGroup);
doLayout = false; this.editorGroupService.setSize(activeGroup, activeGroupSize + sizeChangePxWidth);
} }
} }
......
...@@ -35,7 +35,8 @@ import { ...@@ -35,7 +35,8 @@ import {
OpenPreviousEditorInGroup, OpenNextRecentlyUsedEditorAction, OpenPreviousRecentlyUsedEditorAction, OpenNextRecentlyUsedEditorInGroupAction, MoveEditorToPreviousGroupAction, OpenPreviousEditorInGroup, OpenNextRecentlyUsedEditorAction, OpenPreviousRecentlyUsedEditorAction, OpenNextRecentlyUsedEditorInGroupAction, MoveEditorToPreviousGroupAction,
MoveEditorToNextGroupAction, MoveEditorToFirstGroupAction, MoveEditorLeftInGroupAction, ClearRecentFilesAction, OpenLastEditorInGroup, SplitEditorGroupHorizontalAction, SplitEditorGroupVerticalAction, MoveEditorToNextGroupAction, MoveEditorToFirstGroupAction, MoveEditorLeftInGroupAction, ClearRecentFilesAction, OpenLastEditorInGroup, SplitEditorGroupHorizontalAction, SplitEditorGroupVerticalAction,
ShowEditorsInActiveGroupAction, MoveEditorToLastGroupAction, OpenFirstEditorInGroup, MoveGroupUpAction, MoveGroupDownAction, FocusLastGroupAction, SplitEditorGroupLeftAction, SplitEditorGroupRightAction, ShowEditorsInActiveGroupAction, MoveEditorToLastGroupAction, OpenFirstEditorInGroup, MoveGroupUpAction, MoveGroupDownAction, FocusLastGroupAction, SplitEditorGroupLeftAction, SplitEditorGroupRightAction,
SplitEditorGroupUpAction, SplitEditorGroupDownAction, MoveEditorToLeftGroupAction, MoveEditorToRightGroupAction, MoveEditorToAboveGroupAction, MoveEditorToBelowGroupAction, CloseAllEditorGroupsAction, JoinAllGroupsAction, FocusLeftGroup, FocusAboveGroup, FocusRightGroup, FocusBelowGroup SplitEditorGroupUpAction, SplitEditorGroupDownAction, MoveEditorToLeftGroupAction, MoveEditorToRightGroupAction, MoveEditorToAboveGroupAction, MoveEditorToBelowGroupAction, CloseAllEditorGroupsAction,
JoinAllGroupsAction, FocusLeftGroup, FocusAboveGroup, FocusRightGroup, FocusBelowGroup, EditorLayoutSingleAction, EditorLayoutTwoColumnsAction, EditorLayoutThreeColumnsAction, EditorLayoutTwoByTwoGridAction, EditorLayoutTwoRowsAction, EditorLayoutThreeRowsAction, EditorLayoutThreeColumnsTopAction, EditorLayoutThreeColumnsRightAction, EditorLayoutGoldenRatioAction
} from 'vs/workbench/browser/parts/editor/editorActions'; } from 'vs/workbench/browser/parts/editor/editorActions';
import * as editorCommands from 'vs/workbench/browser/parts/editor/editorCommands'; import * as editorCommands from 'vs/workbench/browser/parts/editor/editorCommands';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
...@@ -357,6 +358,15 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateLastAction, Na ...@@ -357,6 +358,15 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateLastAction, Na
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenPreviousEditorFromHistoryAction, OpenPreviousEditorFromHistoryAction.ID, OpenPreviousEditorFromHistoryAction.LABEL), 'Open Previous Editor from History'); registry.registerWorkbenchAction(new SyncActionDescriptor(OpenPreviousEditorFromHistoryAction, OpenPreviousEditorFromHistoryAction.ID, OpenPreviousEditorFromHistoryAction.LABEL), 'Open Previous Editor from History');
registry.registerWorkbenchAction(new SyncActionDescriptor(ClearEditorHistoryAction, ClearEditorHistoryAction.ID, ClearEditorHistoryAction.LABEL), 'Clear Editor History'); registry.registerWorkbenchAction(new SyncActionDescriptor(ClearEditorHistoryAction, ClearEditorHistoryAction.ID, ClearEditorHistoryAction.LABEL), 'Clear Editor History');
registry.registerWorkbenchAction(new SyncActionDescriptor(RevertAndCloseEditorAction, RevertAndCloseEditorAction.ID, RevertAndCloseEditorAction.LABEL), 'View: Revert and Close Editor', category); registry.registerWorkbenchAction(new SyncActionDescriptor(RevertAndCloseEditorAction, RevertAndCloseEditorAction.ID, RevertAndCloseEditorAction.LABEL), 'View: Revert and Close Editor', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(EditorLayoutSingleAction, EditorLayoutSingleAction.ID, EditorLayoutSingleAction.LABEL), 'View: Single Column Editor Layout', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(EditorLayoutTwoColumnsAction, EditorLayoutTwoColumnsAction.ID, EditorLayoutTwoColumnsAction.LABEL), 'View: Two Columns Editor Layout', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(EditorLayoutThreeColumnsAction, EditorLayoutThreeColumnsAction.ID, EditorLayoutThreeColumnsAction.LABEL), 'View: Three Columns Editor Layout', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(EditorLayoutTwoRowsAction, EditorLayoutTwoRowsAction.ID, EditorLayoutTwoRowsAction.LABEL), 'View: Two Rows Editor Layout', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(EditorLayoutThreeRowsAction, EditorLayoutThreeRowsAction.ID, EditorLayoutThreeRowsAction.LABEL), 'View: Three Rows Editor Layout', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(EditorLayoutTwoByTwoGridAction, EditorLayoutTwoByTwoGridAction.ID, EditorLayoutTwoByTwoGridAction.LABEL), 'View: Grid Editor Layout (2x2)', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(EditorLayoutThreeColumnsTopAction, EditorLayoutThreeColumnsTopAction.ID, EditorLayoutThreeColumnsTopAction.LABEL), 'View: Three Columns Top Editor Layout', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(EditorLayoutThreeColumnsRightAction, EditorLayoutThreeColumnsRightAction.ID, EditorLayoutThreeColumnsRightAction.LABEL), 'View: Three Columns Right Editor Layout', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(EditorLayoutGoldenRatioAction, EditorLayoutGoldenRatioAction.ID, EditorLayoutGoldenRatioAction.LABEL), 'View: Golden Ratio Editor Layout', category);
// Register Editor Picker Actions including quick navigate support // Register Editor Picker Actions including quick navigate support
const openNextEditorKeybinding = { primary: KeyMod.CtrlCmd | KeyCode.Tab, mac: { primary: KeyMod.WinCtrl | KeyCode.Tab } }; const openNextEditorKeybinding = { primary: KeyMod.CtrlCmd | KeyCode.Tab, mac: { primary: KeyMod.WinCtrl | KeyCode.Tab } };
...@@ -406,7 +416,7 @@ MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: edi ...@@ -406,7 +416,7 @@ MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: edi
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: editorCommands.SPLIT_EDITOR_DOWN, title: nls.localize('splitDown', "Split Down") }, group: '1_split', order: 20 }); MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: editorCommands.SPLIT_EDITOR_DOWN, title: nls.localize('splitDown', "Split Down") }, group: '1_split', order: 20 });
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: editorCommands.SPLIT_EDITOR_LEFT, title: nls.localize('splitLeft', "Split Left") }, group: '1_split', order: 30 }); MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: editorCommands.SPLIT_EDITOR_LEFT, title: nls.localize('splitLeft', "Split Left") }, group: '1_split', order: 30 });
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: editorCommands.SPLIT_EDITOR_RIGHT, title: nls.localize('splitRight', "Split Right") }, group: '1_split', order: 40 }); MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: editorCommands.SPLIT_EDITOR_RIGHT, title: nls.localize('splitRight', "Split Right") }, group: '1_split', order: 40 });
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: editorCommands.CLOSE_EDITOR_GROUP_COMMAND_ID, title: nls.localize('close', "Close") }, group: '3_close', order: 10 }); MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: editorCommands.CLOSE_EDITOR_GROUP_COMMAND_ID, title: nls.localize('close', "Close") }, group: '3_close', order: 10, when: ContextKeyExpr.has('multipleEditorGroups') });
// Editor Title Context Menu // Editor Title Context Menu
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: editorCommands.CLOSE_EDITOR_COMMAND_ID, title: nls.localize('close', "Close") }, group: '1_close', order: 10 }); MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: editorCommands.CLOSE_EDITOR_COMMAND_ID, title: nls.localize('close', "Close") }, group: '1_close', order: 10 });
......
...@@ -19,12 +19,29 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; ...@@ -19,12 +19,29 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICommandService } from 'vs/platform/commands/common/commands';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IWindowsService } from 'vs/platform/windows/common/windows'; 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 } from 'vs/workbench/browser/parts/editor/editorCommands'; 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 } from 'vs/workbench/services/group/common/editorGroupsService'; import { IEditorGroupsService, IEditorGroup, GroupsArrangement, EditorsOrder, GroupLocation, GroupDirection, preferredGroupDirection, IFindGroupScope, GroupOrientation } from 'vs/workbench/services/group/common/editorGroupsService';
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IDisposable, dispose } from 'vs/base/common/lifecycle';
export class ExecuteCommandAction extends Action {
constructor(
id: string,
label: string,
private commandId: string,
private commandService: ICommandService,
private commandArgs?: any
) {
super(id, label);
}
public run(): TPromise<any> {
return this.commandService.executeCommand(this.commandId, this.commandArgs);
}
}
export class BaseSplitEditorGroupAction extends Action { export class BaseSplitEditorGroupAction extends Action {
constructor( constructor(
...@@ -153,7 +170,7 @@ export class SplitEditorGroupHorizontalAction extends BaseSplitEditorGroupAction ...@@ -153,7 +170,7 @@ export class SplitEditorGroupHorizontalAction extends BaseSplitEditorGroupAction
} }
} }
export class SplitEditorGroupLeftAction extends Action { export class SplitEditorGroupLeftAction extends ExecuteCommandAction {
public static readonly ID = SPLIT_EDITOR_LEFT; public static readonly ID = SPLIT_EDITOR_LEFT;
public static readonly LABEL = nls.localize('splitEditorGroupLeft', "Split Editor Left"); public static readonly LABEL = nls.localize('splitEditorGroupLeft', "Split Editor Left");
...@@ -161,17 +178,13 @@ export class SplitEditorGroupLeftAction extends Action { ...@@ -161,17 +178,13 @@ export class SplitEditorGroupLeftAction extends Action {
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, SPLIT_EDITOR_LEFT, commandService);
}
public run(): TPromise<any> {
return this.commandService.executeCommand(SPLIT_EDITOR_LEFT);
} }
} }
export class SplitEditorGroupRightAction extends Action { export class SplitEditorGroupRightAction extends ExecuteCommandAction {
public static readonly ID = SPLIT_EDITOR_RIGHT; public static readonly ID = SPLIT_EDITOR_RIGHT;
public static readonly LABEL = nls.localize('splitEditorGroupRight', "Split Editor Right"); public static readonly LABEL = nls.localize('splitEditorGroupRight', "Split Editor Right");
...@@ -179,17 +192,13 @@ export class SplitEditorGroupRightAction extends Action { ...@@ -179,17 +192,13 @@ export class SplitEditorGroupRightAction extends Action {
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, SPLIT_EDITOR_RIGHT, commandService);
}
public run(): TPromise<any> {
return this.commandService.executeCommand(SPLIT_EDITOR_RIGHT);
} }
} }
export class SplitEditorGroupUpAction extends Action { export class SplitEditorGroupUpAction extends ExecuteCommandAction {
public static readonly ID = SPLIT_EDITOR_UP; public static readonly ID = SPLIT_EDITOR_UP;
public static readonly LABEL = nls.localize('splitEditorGroupUp', "Split Editor Up"); public static readonly LABEL = nls.localize('splitEditorGroupUp', "Split Editor Up");
...@@ -197,17 +206,13 @@ export class SplitEditorGroupUpAction extends Action { ...@@ -197,17 +206,13 @@ export class SplitEditorGroupUpAction extends Action {
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, SPLIT_EDITOR_UP, commandService);
}
public run(): TPromise<any> {
return this.commandService.executeCommand(SPLIT_EDITOR_UP);
} }
} }
export class SplitEditorGroupDownAction extends Action { export class SplitEditorGroupDownAction extends ExecuteCommandAction {
public static readonly ID = SPLIT_EDITOR_DOWN; public static readonly ID = SPLIT_EDITOR_DOWN;
public static readonly LABEL = nls.localize('splitEditorGroupDown', "Split Editor Down"); public static readonly LABEL = nls.localize('splitEditorGroupDown', "Split Editor Down");
...@@ -215,13 +220,9 @@ export class SplitEditorGroupDownAction extends Action { ...@@ -215,13 +220,9 @@ export class SplitEditorGroupDownAction extends Action {
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, SPLIT_EDITOR_DOWN, commandService);
}
public run(): TPromise<any> {
return this.commandService.executeCommand(SPLIT_EDITOR_DOWN);
} }
} }
...@@ -274,10 +275,7 @@ export class JoinAllGroupsAction extends Action { ...@@ -274,10 +275,7 @@ export class JoinAllGroupsAction extends Action {
} }
public run(context?: IEditorIdentifier): TPromise<any> { public run(context?: IEditorIdentifier): TPromise<any> {
const firstGroup = this.editorGroupService.groups[0]; mergeAllGroups(this.editorGroupService);
while (this.editorGroupService.count > 1) {
this.editorGroupService.mergeGroup(this.editorGroupService.findGroup({ location: GroupLocation.NEXT }, firstGroup), firstGroup);
}
return TPromise.as(true); return TPromise.as(true);
} }
...@@ -1328,7 +1326,7 @@ export class ClearEditorHistoryAction extends Action { ...@@ -1328,7 +1326,7 @@ export class ClearEditorHistoryAction extends Action {
} }
} }
export class MoveEditorLeftInGroupAction extends Action { export class MoveEditorLeftInGroupAction extends ExecuteCommandAction {
public static readonly ID = 'workbench.action.moveEditorLeftInGroup'; public static readonly ID = 'workbench.action.moveEditorLeftInGroup';
public static readonly LABEL = nls.localize('moveEditorLeft', "Move Editor Left"); public static readonly LABEL = nls.localize('moveEditorLeft', "Move Editor Left");
...@@ -1336,20 +1334,13 @@ export class MoveEditorLeftInGroupAction extends Action { ...@@ -1336,20 +1334,13 @@ export class MoveEditorLeftInGroupAction extends Action {
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'left' } as ActiveEditorMoveArguments);
}
public run(): TPromise<any> {
const args: ActiveEditorMoveArguments = { to: 'left' };
this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
return TPromise.as(true);
} }
} }
export class MoveEditorRightInGroupAction extends Action { export class MoveEditorRightInGroupAction extends ExecuteCommandAction {
public static readonly ID = 'workbench.action.moveEditorRightInGroup'; public static readonly ID = 'workbench.action.moveEditorRightInGroup';
public static readonly LABEL = nls.localize('moveEditorRight', "Move Editor Right"); public static readonly LABEL = nls.localize('moveEditorRight', "Move Editor Right");
...@@ -1357,20 +1348,13 @@ export class MoveEditorRightInGroupAction extends Action { ...@@ -1357,20 +1348,13 @@ export class MoveEditorRightInGroupAction extends Action {
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'right' } as ActiveEditorMoveArguments);
}
public run(): TPromise<any> {
const args: ActiveEditorMoveArguments = { to: 'right' };
this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
return TPromise.as(true);
} }
} }
export class MoveEditorToPreviousGroupAction extends Action { export class MoveEditorToPreviousGroupAction extends ExecuteCommandAction {
public static readonly ID = 'workbench.action.moveEditorToPreviousGroup'; public static readonly ID = 'workbench.action.moveEditorToPreviousGroup';
public static readonly LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group"); public static readonly LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
...@@ -1378,20 +1362,27 @@ export class MoveEditorToPreviousGroupAction extends Action { ...@@ -1378,20 +1362,27 @@ export class MoveEditorToPreviousGroupAction extends Action {
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'previous', by: 'group' } as ActiveEditorMoveArguments);
} }
}
public run(): TPromise<any> { export class MoveEditorToNextGroupAction extends ExecuteCommandAction {
const args: ActiveEditorMoveArguments = { to: 'previous', by: 'group' };
this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
return TPromise.as(true); public static readonly ID = 'workbench.action.moveEditorToNextGroup';
public static readonly LABEL = nls.localize('moveEditorToNextGroup', "Move Editor into Next Group");
constructor(
id: string,
label: string,
@ICommandService commandService: ICommandService
) {
super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'next', by: 'group' } as ActiveEditorMoveArguments);
} }
} }
export class MoveEditorToAboveGroupAction extends Action { export class MoveEditorToAboveGroupAction extends ExecuteCommandAction {
public static readonly ID = 'workbench.action.moveEditorToAboveGroup'; public static readonly ID = 'workbench.action.moveEditorToAboveGroup';
public static readonly LABEL = nls.localize('moveEditorToAboveGroup', "Move Editor into Above Group"); public static readonly LABEL = nls.localize('moveEditorToAboveGroup', "Move Editor into Above Group");
...@@ -1399,141 +1390,204 @@ export class MoveEditorToAboveGroupAction extends Action { ...@@ -1399,141 +1390,204 @@ export class MoveEditorToAboveGroupAction extends Action {
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'up', by: 'group' } as ActiveEditorMoveArguments);
} }
}
public run(): TPromise<any> { export class MoveEditorToBelowGroupAction extends ExecuteCommandAction {
const args: ActiveEditorMoveArguments = { to: 'up', by: 'group' };
this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
return TPromise.as(true); public static readonly ID = 'workbench.action.moveEditorToBelowGroup';
public static readonly LABEL = nls.localize('moveEditorToBelowGroup', "Move Editor into Below Group");
constructor(
id: string,
label: string,
@ICommandService commandService: ICommandService
) {
super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'down', by: 'group' } as ActiveEditorMoveArguments);
} }
} }
export class MoveEditorToBelowGroupAction extends Action { export class MoveEditorToLeftGroupAction extends ExecuteCommandAction {
public static readonly ID = 'workbench.action.moveEditorToBelowGroup'; public static readonly ID = 'workbench.action.moveEditorToLeftGroup';
public static readonly LABEL = nls.localize('moveEditorToBelowGroup', "Move Editor into Below Group"); public static readonly LABEL = nls.localize('moveEditorToLeftGroup', "Move Editor into Left Group");
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'left', by: 'group' } as ActiveEditorMoveArguments);
} }
}
public run(): TPromise<any> { export class MoveEditorToRightGroupAction extends ExecuteCommandAction {
const args: ActiveEditorMoveArguments = { to: 'down', by: 'group' };
this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
return TPromise.as(true); public static readonly ID = 'workbench.action.moveEditorToRightGroup';
public static readonly LABEL = nls.localize('moveEditorToRightGroup', "Move Editor into Right Group");
constructor(
id: string,
label: string,
@ICommandService commandService: ICommandService
) {
super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'right', by: 'group' } as ActiveEditorMoveArguments);
} }
} }
export class MoveEditorToLeftGroupAction extends Action { export class MoveEditorToFirstGroupAction extends ExecuteCommandAction {
public static readonly ID = 'workbench.action.moveEditorToLeftGroup'; public static readonly ID = 'workbench.action.moveEditorToFirstGroup';
public static readonly LABEL = nls.localize('moveEditorToLeftGroup', "Move Editor into Left Group"); public static readonly LABEL = nls.localize('moveEditorToFirstGroup', "Move Editor into First Group");
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'first', by: 'group' } as ActiveEditorMoveArguments);
} }
}
public run(): TPromise<any> { export class MoveEditorToLastGroupAction extends ExecuteCommandAction {
const args: ActiveEditorMoveArguments = { to: 'left', by: 'group' };
this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
return TPromise.as(true); public static readonly ID = 'workbench.action.moveEditorToLastGroup';
public static readonly LABEL = nls.localize('moveEditorToLastGroup', "Move Editor into Last Group");
constructor(
id: string,
label: string,
@ICommandService commandService: ICommandService
) {
super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'last', by: 'group' } as ActiveEditorMoveArguments);
} }
} }
export class MoveEditorToRightGroupAction extends Action { export class EditorLayoutSingleAction extends ExecuteCommandAction {
public static readonly ID = 'workbench.action.moveEditorToRightGroup'; public static readonly ID = 'workbench.action.editorLayoutSingle';
public static readonly LABEL = nls.localize('moveEditorToRightGroup', "Move Editor into Right Group"); public static readonly LABEL = nls.localize('editorLayoutSingle', "Single Column Editor Layout");
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}] } as EditorGroupLayout);
} }
}
public run(): TPromise<any> { export class EditorLayoutTwoColumnsAction extends ExecuteCommandAction {
const args: ActiveEditorMoveArguments = { to: 'right', by: 'group' };
this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
return TPromise.as(true); public static readonly ID = 'workbench.action.editorLayoutTwoColumns';
public static readonly LABEL = nls.localize('editorLayoutTwoColumns', "Two Columns Editor Layout");
constructor(
id: string,
label: string,
@ICommandService commandService: ICommandService
) {
super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, {}], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
} }
} }
export class MoveEditorToNextGroupAction extends Action { export class EditorLayoutThreeColumnsAction extends ExecuteCommandAction {
public static readonly ID = 'workbench.action.moveEditorToNextGroup'; public static readonly ID = 'workbench.action.editorLayoutThreeColumns';
public static readonly LABEL = nls.localize('moveEditorToNextGroup', "Move Editor into Next Group"); public static readonly LABEL = nls.localize('editorLayoutThreeColumns', "Three Columns Editor Layout");
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, {}, {}], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
}
}
export class EditorLayoutTwoRowsAction extends ExecuteCommandAction {
public static readonly ID = 'workbench.action.editorLayoutTwoRows';
public static readonly LABEL = nls.localize('editorLayoutTwoRows', "Two Rows Editor Layout");
constructor(
id: string,
label: string,
@ICommandService commandService: ICommandService
) {
super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, {}], orientation: GroupOrientation.VERTICAL } as EditorGroupLayout);
} }
}
public run(): TPromise<any> { export class EditorLayoutThreeRowsAction extends ExecuteCommandAction {
const args: ActiveEditorMoveArguments = { to: 'next', by: 'group' };
this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
return TPromise.as(true); public static readonly ID = 'workbench.action.editorLayoutThreeRows';
public static readonly LABEL = nls.localize('editorLayoutThreeRows', "Three Rows Editor Layout");
constructor(
id: string,
label: string,
@ICommandService commandService: ICommandService
) {
super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, {}, {}], orientation: GroupOrientation.VERTICAL } as EditorGroupLayout);
} }
} }
export class MoveEditorToFirstGroupAction extends Action { export class EditorLayoutTwoByTwoGridAction extends ExecuteCommandAction {
public static readonly ID = 'workbench.action.moveEditorToFirstGroup'; public static readonly ID = 'workbench.action.editorLayoutTwoByTwoGrid';
public static readonly LABEL = nls.localize('moveEditorToFirstGroup', "Move Editor into First Group"); public static readonly LABEL = nls.localize('editorLayoutTwoByTwoGrid', "Grid Editor Layout (2x2)");
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{ groups: [{}, {}] }, { groups: [{}, {}] }] } as EditorGroupLayout);
} }
}
public run(): TPromise<any> { export class EditorLayoutThreeColumnsTopAction extends ExecuteCommandAction {
const args: ActiveEditorMoveArguments = { to: 'first', by: 'group' };
this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
return TPromise.as(true); public static readonly ID = 'workbench.action.editorLayoutThreeColumnsTop';
public static readonly LABEL = nls.localize('editorLayoutThreeColumnsTop', "Three Columns Top Editor Layout");
constructor(
id: string,
label: string,
@ICommandService commandService: ICommandService
) {
super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{ groups: [{}, {}, {}] }, {}], orientation: GroupOrientation.VERTICAL } as EditorGroupLayout);
} }
} }
export class MoveEditorToLastGroupAction extends Action { export class EditorLayoutThreeColumnsRightAction extends ExecuteCommandAction {
public static readonly ID = 'workbench.action.moveEditorToLastGroup'; public static readonly ID = 'workbench.action.editorLayoutThreeColumnsRight';
public static readonly LABEL = nls.localize('moveEditorToLastGroup', "Move Editor into Last Group"); public static readonly LABEL = nls.localize('editorLayoutThreeColumnsRight', "Three Columns Right Editor Layout");
constructor( constructor(
id: string, id: string,
label: string, label: string,
@ICommandService private commandService: ICommandService @ICommandService commandService: ICommandService
) { ) {
super(id, label); super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, { groups: [{}, {}, {}] }], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
} }
}
public run(): TPromise<any> { export class EditorLayoutGoldenRatioAction extends ExecuteCommandAction {
const args: ActiveEditorMoveArguments = { to: 'last', by: 'group' };
this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
return TPromise.as(true); public static readonly ID = 'workbench.action.editorLayoutGoldenRatio';
public static readonly LABEL = nls.localize('editorLayoutGoldenRatio', "Golden Ratio Editor Layout");
constructor(
id: string,
label: string,
@ICommandService commandService: ICommandService
) {
super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{ size: 0.618 }, { size: 0.382, groups: [{ size: 0.618 }, { size: 0.382 }] }], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
} }
} }
\ No newline at end of file
...@@ -19,7 +19,7 @@ import { IDiffEditorOptions } from 'vs/editor/common/config/editorOptions'; ...@@ -19,7 +19,7 @@ import { IDiffEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IListService } from 'vs/platform/list/browser/listService'; import { IListService } from 'vs/platform/list/browser/listService';
import { List } from 'vs/base/browser/ui/list/listWidget'; import { List } from 'vs/base/browser/ui/list/listWidget';
import { distinct } from 'vs/base/common/arrays'; import { distinct } from 'vs/base/common/arrays';
import { IEditorGroupsService, IEditorGroup, GroupDirection, GroupLocation, GroupsOrder, preferredGroupDirection } from 'vs/workbench/services/group/common/editorGroupsService'; import { IEditorGroupsService, IEditorGroup, GroupDirection, GroupLocation, GroupsOrder, preferredGroupDirection, GroupOrientation } from 'vs/workbench/services/group/common/editorGroupsService';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { CommandsRegistry } from 'vs/platform/commands/common/commands';
...@@ -32,6 +32,7 @@ export const CLOSE_EDITOR_GROUP_COMMAND_ID = 'workbench.action.closeEditorGroup' ...@@ -32,6 +32,7 @@ export const CLOSE_EDITOR_GROUP_COMMAND_ID = 'workbench.action.closeEditorGroup'
export const CLOSE_OTHER_EDITORS_IN_GROUP_COMMAND_ID = 'workbench.action.closeOtherEditors'; export const CLOSE_OTHER_EDITORS_IN_GROUP_COMMAND_ID = 'workbench.action.closeOtherEditors';
export const MOVE_ACTIVE_EDITOR_COMMAND_ID = 'moveActiveEditor'; export const MOVE_ACTIVE_EDITOR_COMMAND_ID = 'moveActiveEditor';
export const LAYOUT_EDITOR_GROUPS_COMMAND_ID = 'layoutEditorGroups';
export const KEEP_EDITOR_COMMAND_ID = 'workbench.action.keepEditor'; export const KEEP_EDITOR_COMMAND_ID = 'workbench.action.keepEditor';
export const SHOW_EDITORS_IN_GROUP = 'workbench.action.showEditorsInGroup'; export const SHOW_EDITORS_IN_GROUP = 'workbench.action.showEditorsInGroup';
export const TOGGLE_DIFF_INLINE_MODE = 'toggle.diff.editorMode'; export const TOGGLE_DIFF_INLINE_MODE = 'toggle.diff.editorMode';
...@@ -192,6 +193,79 @@ function moveActiveEditorToGroup(args: ActiveEditorMoveArguments, control: IEdit ...@@ -192,6 +193,79 @@ function moveActiveEditorToGroup(args: ActiveEditorMoveArguments, control: IEdit
} }
} }
function registerEditorGroupsLayoutCommand(): void {
CommandsRegistry.registerCommand(LAYOUT_EDITOR_GROUPS_COMMAND_ID, applyEditorGroupLayout);
}
export interface GroupLayoutArgument {
size?: number;
groups?: Array<GroupLayoutArgument>;
}
export interface EditorGroupLayout {
orientation: GroupOrientation;
groups: GroupLayoutArgument[];
}
function applyEditorGroupLayout(accessor: ServicesAccessor, args: EditorGroupLayout): void {
if (!args || typeof args !== 'object') {
return;
}
const editorGroupService = accessor.get(IEditorGroupsService);
// Reduce to one editor group
mergeAllGroups(editorGroupService);
// Apply orientation
if (typeof args.orientation === 'number') {
editorGroupService.setGroupOrientation(args.orientation);
}
// Build layout
function buildLayout(groups: IEditorGroup[], descriptions: GroupLayoutArgument[], direction: GroupDirection): void {
if (descriptions.length === 0) {
return; // we need at least one group to layout
}
// Add a group for each item in the description
let totalProportions = 0;
descriptions.forEach((description, index) => {
if (index > 0) {
groups.push(editorGroupService.addGroup(groups[index - 1], direction));
}
if (typeof description.size === 'number') {
totalProportions += description.size;
}
});
// Apply proportions if they are valid (sum() === 1)
if (totalProportions === 1) {
const totalSize = groups.map(group => editorGroupService.getSize(group)).reduce(((prev, cur) => prev + cur));
descriptions.forEach((description, index) => {
editorGroupService.setSize(groups[index], totalSize * description.size);
});
}
// Continue building layout if description.groups is array-type
descriptions.forEach((description, index) => {
if (Array.isArray(description.groups)) {
buildLayout([groups[index]], description.groups, direction === GroupDirection.RIGHT ? GroupDirection.DOWN : GroupDirection.RIGHT);
}
});
}
buildLayout([editorGroupService.groups[0]], args.groups, editorGroupService.orientation === GroupOrientation.HORIZONTAL ? GroupDirection.RIGHT : GroupDirection.DOWN);
}
export function mergeAllGroups(editorGroupService: IEditorGroupsService): void {
const firstGroup = editorGroupService.groups[0];
while (editorGroupService.count > 1) {
editorGroupService.mergeGroup(editorGroupService.findGroup({ location: GroupLocation.NEXT }, firstGroup), firstGroup);
}
}
function registerDiffEditorCommands(): void { function registerDiffEditorCommands(): void {
KeybindingsRegistry.registerCommandAndKeybindingRule({ KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.action.compareEditor.nextChange', id: 'workbench.action.compareEditor.nextChange',
...@@ -633,6 +707,7 @@ function isEditorIdentifier(thing: any): thing is IEditorIdentifier { ...@@ -633,6 +707,7 @@ function isEditorIdentifier(thing: any): thing is IEditorIdentifier {
export function setup(): void { export function setup(): void {
registerActiveEditorMoveCommand(); registerActiveEditorMoveCommand();
registerEditorGroupsLayoutCommand();
registerDiffEditorCommands(); registerDiffEditorCommands();
registerOpenEditorAtIndexCommands(); registerOpenEditorAtIndexCommands();
registerCloseEditorCommands(); registerCloseEditorCommands();
......
...@@ -273,13 +273,16 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro ...@@ -273,13 +273,16 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
return groupView; return groupView;
} }
resizeGroup(group: IEditorGroupView | GroupIdentifier, sizeDelta: number): IEditorGroupView { getSize(group: IEditorGroupView | GroupIdentifier): number {
const groupView = this.assertGroupView(group); const groupView = this.assertGroupView(group);
const currentSize = this.gridWidget.getViewSize(groupView);
this.gridWidget.resizeView(groupView, currentSize + sizeDelta); return this.gridWidget.getViewSize(groupView);
}
return groupView; setSize(group: IEditorGroupView | GroupIdentifier, size: number): void {
const groupView = this.assertGroupView(group);
this.gridWidget.resizeView(groupView, size);
} }
arrangeGroups(arrangement: GroupsArrangement): void { arrangeGroups(arrangement: GroupsArrangement): void {
......
...@@ -197,9 +197,14 @@ export interface IEditorGroupsService { ...@@ -197,9 +197,14 @@ export interface IEditorGroupsService {
activateGroup(group: IEditorGroup | GroupIdentifier): IEditorGroup; activateGroup(group: IEditorGroup | GroupIdentifier): IEditorGroup;
/** /**
* Resize the group given the provided size delta. * Returns the size of a group.
*/ */
resizeGroup(group: IEditorGroup | GroupIdentifier, sizeDelta: number): IEditorGroup; getSize(group: IEditorGroup | GroupIdentifier): number;
/**
* Sets the size of a group.
*/
setSize(group: IEditorGroup | GroupIdentifier, size: number): void;
/** /**
* Arrange all groups according to the provided arrangement. * Arrange all groups according to the provided arrangement.
......
...@@ -541,10 +541,12 @@ export class TestEditorGroupsService implements IEditorGroupsService { ...@@ -541,10 +541,12 @@ export class TestEditorGroupsService implements IEditorGroupsService {
return null; return null;
} }
resizeGroup(group: number | IEditorGroup, sizeDelta: number): IEditorGroup { getSize(group: number | IEditorGroup): number {
return null; return 100;
} }
setSize(group: number | IEditorGroup, size: number): void { }
arrangeGroups(arrangement: GroupsArrangement): void { } arrangeGroups(arrangement: GroupsArrangement): void { }
setGroupOrientation(orientation: any): void { } setGroupOrientation(orientation: any): void { }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册