提交 68624f14 编写于 作者: B Benjamin Pasero

grid - implement group arrangement

上级 2d4bf2d7
......@@ -120,7 +120,7 @@ export class Grid<T extends IView> implements IDisposable {
this.gridview = new GridView(container);
this.disposables.push(this.gridview);
this.gridview.onDidSashReset(this.onDidSashReset, this, this.disposables);
this.gridview.onDidSashReset(this.doResetViewSize, this, this.disposables);
this._addView(view, 0, [0]);
}
......@@ -202,6 +202,12 @@ export class Grid<T extends IView> implements IDisposable {
return getLocationOrientation(this.orientation, location);
}
resetViewSize(view: T): void {
const location = this.getViewLocation(view);
this.doResetViewSize(location);
}
private getViewLocation(view: T): number[] {
const element = this.views.get(view);
......@@ -212,7 +218,7 @@ export class Grid<T extends IView> implements IDisposable {
return getGridLocation(element);
}
private onDidSashReset(location: number[]): void {
private doResetViewSize(location: number[]): void {
if (this.sashResetSizing === Sizing.Split) {
const orientation = getLocationOrientation(this.orientation, location);
const firstViewSize = getSize(this.gridview.getViewSize(location), orientation);
......
......@@ -18,12 +18,13 @@ import { IPartService } from 'vs/workbench/services/part/common/partService';
import { Position, IEditor, Direction, IResourceInput, IEditorInput, POSITIONS } from 'vs/platform/editor/common/editor';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IEditorGroupService, GroupArrangement } from 'vs/workbench/services/group/common/groupService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
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_IN_GROUP_ONE_PREFIX, NAVIGATE_ALL_EDITORS_GROUP_PREFIX, NAVIGATE_IN_GROUP_THREE_PREFIX, NAVIGATE_IN_GROUP_TWO_PREFIX } from 'vs/workbench/browser/parts/editor/editorCommands';
import { INextEditorGroupsService, GroupDirection as SplitDirection, INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorGroupsService, GroupDirection as SplitDirection, INextEditorGroup, GroupsArrangement } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
// TODo@grid this action should be removed in favour of the split vertical/horizontal actions
export class SplitEditorAction extends Action {
......@@ -874,12 +875,12 @@ export class MinimizeOtherGroupsAction extends Action {
public static readonly ID = 'workbench.action.minimizeOtherEditors';
public static readonly LABEL = nls.localize('minimizeOtherEditorGroups', "Minimize Other Editor Groups");
constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
constructor(id: string, label: string, @INextEditorGroupsService private editorGroupService: INextEditorGroupsService) {
super(id, label);
}
public run(): TPromise<any> {
this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
return TPromise.as(false);
}
......@@ -890,12 +891,12 @@ export class EvenGroupWidthsAction extends Action {
public static readonly ID = 'workbench.action.evenEditorWidths';
public static readonly LABEL = nls.localize('evenEditorGroups', "Even Editor Group Widths");
constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
constructor(id: string, label: string, @INextEditorGroupsService private editorGroupService: INextEditorGroupsService) {
super(id, label);
}
public run(): TPromise<any> {
this.editorGroupService.arrangeGroups(GroupArrangement.EVEN);
this.editorGroupService.arrangeGroups(GroupsArrangement.EVEN);
return TPromise.as(false);
}
......@@ -909,16 +910,17 @@ export class MaximizeGroupAction extends Action {
constructor(
id: string,
label: string,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@INextEditorService private editorService: INextEditorService,
@INextEditorGroupsService private editorGroupService: INextEditorGroupsService,
@IPartService private partService: IPartService
) {
super(id, label);
}
public run(): TPromise<any> {
if (this.editorService.getActiveEditor()) {
this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
if (this.editorService.activeEditor) {
this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
return this.partService.setSideBarHidden(true);
}
......
......@@ -304,14 +304,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
//#endregion
//#region TODO@grid group arrangement
public arrangeGroups(arrangement: GroupArrangement): void {
this.editorGroupsControl.arrangeGroups(arrangement);
}
//#endregion
//#region TODO@grid group orientation
public get onGroupOrientationChanged(): Event<void> {
......@@ -1175,6 +1167,10 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
return editor;
}
public arrangeGroups(arrangement: GroupArrangement): void {
this.editorGroupsControl.arrangeGroups(arrangement);
}
private doSetInput(group: EditorGroup, editor: BaseEditor, input: EditorInput, options: EditorOptions, monitor: ProgressMonitor): TPromise<BaseEditor> {
// Emit Input-Changed Event as appropiate
......
......@@ -11,14 +11,14 @@ 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 } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorGroupsService, GroupDirection, IAddGroupOptions, GroupsArrangement } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Direction, SerializableGrid, Sizing, ISerializedGrid, Orientation, ISerializedNode } from 'vs/base/browser/ui/grid/grid';
import { GroupIdentifier, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
import { values } from 'vs/base/common/map';
import { EDITOR_GROUP_BORDER } from 'vs/workbench/common/theme';
import { distinct } from 'vs/base/common/arrays';
import { INextEditorGroupsAccessor, INextEditorGroupView, INextEditorPartOptions, getEditorPartOptions, impactsEditorPartOptions, INextEditorPartOptionsChangeEvent } from 'vs/workbench/browser/parts/editor2/editor2';
import { INextEditorGroupsAccessor, INextEditorGroupView, INextEditorPartOptions, getEditorPartOptions, impactsEditorPartOptions, INextEditorPartOptionsChangeEvent, EDITOR_MAX_DIMENSIONS, EDITOR_MIN_DIMENSIONS } from 'vs/workbench/browser/parts/editor2/editor2';
import { NextEditorGroupView } from 'vs/workbench/browser/parts/editor2/nextEditorGroupView';
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
......@@ -205,6 +205,35 @@ export class NextEditorPart extends Part implements INextEditorGroupsService, IN
return groupView;
}
arrangeGroups(arrangement: GroupsArrangement): void {
if (this.count < 2) {
return; // require at least 2 groups to show
}
// Even all group sizes
if (arrangement === GroupsArrangement.EVEN) {
this.groups.forEach(group => {
this.gridWidget.resetViewSize(group);
});
}
// Maximize the current active group
else {
this.groups.forEach(group => {
const orientation = this.gridWidget.getOrientation(group);
let newSize: number;
if (this.activeGroup === group) {
newSize = orientation === Orientation.HORIZONTAL ? EDITOR_MAX_DIMENSIONS.width : EDITOR_MAX_DIMENSIONS.height;
} else {
newSize = orientation === Orientation.HORIZONTAL ? EDITOR_MIN_DIMENSIONS.width : EDITOR_MIN_DIMENSIONS.height;
}
this.gridWidget.resizeView(group, newSize);
});
}
}
addGroup(location: INextEditorGroupView | GroupIdentifier, direction: GroupDirection, options?: IAddGroupOptions): INextEditorGroupView {
const locationView = this.assertGroupView(location);
......
......@@ -19,6 +19,20 @@ export enum GroupDirection {
RIGHT
}
export enum GroupsArrangement {
/**
* Make the current active group consume the maximum
* amount of space possible.
*/
MINIMIZE_OTHERS,
/**
* Size all groups evenly.
*/
EVEN
}
export interface IMoveEditorOptions {
index?: number;
inactive?: boolean;
......@@ -98,6 +112,11 @@ export interface INextEditorGroupsService {
*/
resizeGroup(group: INextEditorGroup | GroupIdentifier, sizeDelta: number): INextEditorGroup;
/**
* Arrange all groups according to the provided arrangement.
*/
arrangeGroups(arrangement: GroupsArrangement): void;
/**
* Add a new group to the editor area. A new group is added by splitting a provided one in
* one of the four directions.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册