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

adopt new event for when editor layout changes

上级 53042122
......@@ -315,10 +315,12 @@ export class TestEditorGroupService implements IEditorGroupService {
private _onEditorsChanged: Emitter<void>;
private _onEditorOpenFail: Emitter<IEditorInput>;
private _onEditorsMoved: Emitter<void>;
private _onGroupOrientationChanged: Emitter<void>;
constructor(callback?: (method: string) => void) {
this._onEditorsMoved = new Emitter<void>();
this._onEditorsChanged = new Emitter<void>();
this._onGroupOrientationChanged = new Emitter<void>();
this._onEditorOpenFail = new Emitter<IEditorInput>();
let services = new ServiceCollection();
......@@ -350,6 +352,10 @@ export class TestEditorGroupService implements IEditorGroupService {
return this._onEditorsMoved.event;
}
public get onGroupOrientationChanged(): Event<void> {
return this._onGroupOrientationChanged.event;
}
public focusGroup(group: IEditorGroup): void;
public focusGroup(position: Position): void;
public focusGroup(arg1: any): void {
......
......@@ -33,12 +33,19 @@ export class ToggleEditorLayoutAction extends Action {
this.class = 'toggle-editor-layout';
this.updateEnablement();
this.updateLabel();
this.registerListeners();
}
private registerListeners(): void {
this.toDispose.push(this.editorGroupService.onEditorsChanged(() => this.updateEnablement()));
this.toDispose.push(this.editorGroupService.onGroupOrientationChanged(() => this.updateLabel()));
}
private updateLabel(): void {
const editorGroupLayoutVertical = (this.editorGroupService.getGroupOrientation() !== 'horizontal');
this.label = editorGroupLayoutVertical ? nls.localize('horizontalLayout', "Horizontal Editor Group Layout") : nls.localize('verticalLayout', "Vertical Editor Group Layout");
}
private updateEnablement(): void {
......
......@@ -18,7 +18,6 @@ import { IThemeService } from 'vs/workbench/services/themes/common/themeService'
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
const DEFAULT_MIN_SIDEBAR_PART_WIDTH = 170;
const DEFAULT_MIN_PANEL_PART_HEIGHT = 77;
......@@ -82,7 +81,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
private startPanelHeight: number;
private panelHeight: number;
private panelWidth: number;
private layoutEditorsVertically: boolean;
private layoutEditorGroupsVertically: boolean;
// Take parts as an object bag since instatation service does not have typings for constructors with 9+ arguments
constructor(
......@@ -101,7 +100,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
@IEventService eventService: IEventService,
@IContextViewService private contextViewService: IContextViewService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IPartService private partService: IPartService,
@IConfigurationService configurationService: IConfigurationService,
@IViewletService private viewletService: IViewletService,
......@@ -131,11 +130,11 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
this.sidebarWidth = this.storageService.getInteger(WorkbenchLayout.sashXWidthSettingsKey, StorageScope.GLOBAL, -1);
this.panelHeight = this.storageService.getInteger(WorkbenchLayout.sashYHeightSettingsKey, StorageScope.GLOBAL, 0);
this.onDidUpdateConfiguration(configurationService.getConfiguration<IWorkbenchEditorConfiguration>(), false);
this.layoutEditorGroupsVertically = (this.editorGroupService.getGroupOrientation() !== 'horizontal');
this.toUnbind.push(themeService.onDidColorThemeChange(_ => this.relayout()));
this.toUnbind.push(editorGroupService.onEditorsChanged(() => this.onEditorsChanged()));
this.toUnbind.push(configurationService.onDidUpdateConfiguration(e => this.onDidUpdateConfiguration(e.config, true)));
this.toUnbind.push(editorGroupService.onGroupOrientationChanged(e => this.onGroupOrientationChanged()));
this.registerSashListeners();
}
......@@ -264,8 +263,8 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
if (this.workbenchSize && (this.sidebarWidth || this.panelHeight)) {
let visibleEditors = this.editorService.getVisibleEditors().length;
if (visibleEditors > 1) {
const sidebarOverflow = this.layoutEditorsVertically && (this.workbenchSize.width - this.sidebarWidth < visibleEditors * DEFAULT_MIN_EDITOR_PART_WIDTH);
const panelOverflow = !this.layoutEditorsVertically && (this.workbenchSize.height - this.panelHeight < visibleEditors * DEFAULT_MIN_EDITOR_PART_HEIGHT);
const sidebarOverflow = this.layoutEditorGroupsVertically && (this.workbenchSize.width - this.sidebarWidth < visibleEditors * DEFAULT_MIN_EDITOR_PART_WIDTH);
const panelOverflow = !this.layoutEditorGroupsVertically && (this.workbenchSize.height - this.panelHeight < visibleEditors * DEFAULT_MIN_EDITOR_PART_HEIGHT);
if (sidebarOverflow || panelOverflow) {
this.layout();
......@@ -274,16 +273,11 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
}
}
private onDidUpdateConfiguration(config: IWorkbenchEditorConfiguration, relayout: boolean): void {
let newLayoutEditorsVertically: boolean;
if (config.workbench && config.workbench.editor) {
newLayoutEditorsVertically = (config.workbench.editor.sideBySideLayout !== 'horizontal');
} else {
newLayoutEditorsVertically = true;
}
private onGroupOrientationChanged(): void {
const newLayoutEditorGroupsVertically = (this.editorGroupService.getGroupOrientation() !== 'horizontal');
const doLayout = relayout && (this.layoutEditorsVertically !== newLayoutEditorsVertically);
this.layoutEditorsVertically = newLayoutEditorsVertically;
const doLayout = this.layoutEditorGroupsVertically !== newLayoutEditorGroupsVertically;
this.layoutEditorGroupsVertically = newLayoutEditorGroupsVertically;
if (doLayout) {
this.layout();
......@@ -417,7 +411,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
let editorMinHeight = this.computedStyles.editor.minHeight;
let visibleEditorCount = this.editorService.getVisibleEditors().length;
if (visibleEditorCount > 1) {
if (this.layoutEditorsVertically) {
if (this.layoutEditorGroupsVertically) {
editorMinWidth *= visibleEditorCount; // when editors layout vertically, multiply the min editor width by number of visible editors
} else {
editorMinHeight *= visibleEditorCount; // when editors layout horizontally, multiply the min editor height by number of visible editors
......
......@@ -16,7 +16,6 @@ import { IPartService } from 'vs/workbench/services/part/common/partService';
import { Position, IEditor, Direction, IResourceInput, IEditorInput } from 'vs/platform/editor/common/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IEditorGroupService, GroupArrangement } from 'vs/workbench/services/group/common/groupService';
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
......@@ -412,7 +411,7 @@ export class OpenToSideAction extends Action {
constructor(
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IConfigurationService private configurationService: IConfigurationService
@IEditorGroupService private editorGroupService: IEditorGroupService
) {
super(OpenToSideAction.OPEN_TO_SIDE_ID, OpenToSideAction.OPEN_TO_SIDE_LABEL);
......@@ -421,9 +420,9 @@ export class OpenToSideAction extends Action {
}
public updateClass(): void {
const editorLayoutVertical = this.configurationService.lookup('workbench.editor.sideBySideLayout').value !== 'horizontal';
const editorGroupLayoutVertical = (this.editorGroupService.getGroupOrientation() !== 'horizontal');
this.class = editorLayoutVertical ? 'quick-open-sidebyside-vertical' : 'quick-open-sidebyside-horizontal';
this.class = editorGroupLayoutVertical ? 'quick-open-sidebyside-vertical' : 'quick-open-sidebyside-horizontal';
}
private updateEnablement(): void {
......
......@@ -86,11 +86,11 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
private memento: any;
private stacks: EditorStacksModel;
private previewEditors: boolean;
private layoutVertically: boolean;
private _onEditorsChanged: Emitter<void>;
private _onEditorsMoved: Emitter<void>;
private _onEditorOpenFail: Emitter<EditorInput>;
private _onGroupOrientationChanged: Emitter<void>;
// The following data structures are partitioned into array of Position as provided by Services.POSITION array
private visibleEditors: BaseEditor[];
......@@ -115,6 +115,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
this._onEditorsChanged = new Emitter<void>();
this._onEditorsMoved = new Emitter<void>();
this._onEditorOpenFail = new Emitter<EditorInput>();
this._onGroupOrientationChanged = new Emitter<void>();
this.visibleEditors = [];
......@@ -134,7 +135,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
const editorConfig = config.workbench.editor;
this.previewEditors = editorConfig.enablePreview;
this.layoutVertically = editorConfig.sideBySideLayout !== 'horizontal';
this.telemetryService.publicLog('workbenchEditorConfiguration', editorConfig);
}
......@@ -161,14 +161,8 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
}
});
}
this.previewEditors = newPreviewEditors;
// Rename groups when layout changes
const newLayoutVertically = editorConfig.sideBySideLayout !== 'horizontal';
if (newLayoutVertically !== this.layoutVertically) {
this.layoutVertically = newLayoutVertically;
this.renameGroups();
}
this.previewEditors = newPreviewEditors;
}
}
......@@ -195,6 +189,10 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
return this._onEditorOpenFail.event;
}
public get onGroupOrientationChanged(): Event<void> {
return this._onGroupOrientationChanged.event;
}
public openEditor(input: EditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise<BaseEditor>;
public openEditor(input: EditorInput, options?: EditorOptions, position?: Position, ratio?: number[]): TPromise<BaseEditor>;
public openEditor(input: EditorInput, options?: EditorOptions, arg3?: any, ratio?: number[]): TPromise<BaseEditor> {
......@@ -806,6 +804,10 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
public setGroupOrientation(orientation: GroupOrientation): void {
this.sideBySideControl.setGroupOrientation(orientation);
this._onGroupOrientationChanged.fire();
// Rename groups when layout changes
this.renameGroups();
}
public getGroupOrientation(): GroupOrientation {
......@@ -1352,23 +1354,24 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
private renameGroups(): void {
const groups = this.stacks.groups;
if (groups.length > 0) {
const layoutVertically = (this.sideBySideControl.getGroupOrientation() !== 'horizontal');
// ONE | TWO | THREE
if (groups.length > 2) {
this.stacks.renameGroup(this.stacks.groupAt(Position.ONE), this.layoutVertically ? EditorPart.GROUP_LEFT : EditorPart.GROUP_TOP);
this.stacks.renameGroup(this.stacks.groupAt(Position.TWO), this.layoutVertically ? EditorPart.GROUP_CENTER : EditorPart.GROUP_MIDDLE);
this.stacks.renameGroup(this.stacks.groupAt(Position.THREE), this.layoutVertically ? EditorPart.GROUP_RIGHT : EditorPart.GROUP_BOTTOM);
this.stacks.renameGroup(this.stacks.groupAt(Position.ONE), layoutVertically ? EditorPart.GROUP_LEFT : EditorPart.GROUP_TOP);
this.stacks.renameGroup(this.stacks.groupAt(Position.TWO), layoutVertically ? EditorPart.GROUP_CENTER : EditorPart.GROUP_MIDDLE);
this.stacks.renameGroup(this.stacks.groupAt(Position.THREE), layoutVertically ? EditorPart.GROUP_RIGHT : EditorPart.GROUP_BOTTOM);
}
// ONE | TWO
else if (groups.length > 1) {
this.stacks.renameGroup(this.stacks.groupAt(Position.ONE), this.layoutVertically ? EditorPart.GROUP_LEFT : EditorPart.GROUP_TOP);
this.stacks.renameGroup(this.stacks.groupAt(Position.TWO), this.layoutVertically ? EditorPart.GROUP_RIGHT : EditorPart.GROUP_BOTTOM);
this.stacks.renameGroup(this.stacks.groupAt(Position.ONE), layoutVertically ? EditorPart.GROUP_LEFT : EditorPart.GROUP_TOP);
this.stacks.renameGroup(this.stacks.groupAt(Position.TWO), layoutVertically ? EditorPart.GROUP_RIGHT : EditorPart.GROUP_BOTTOM);
}
// ONE
else {
this.stacks.renameGroup(this.stacks.groupAt(Position.ONE), this.layoutVertically ? EditorPart.GROUP_LEFT : EditorPart.GROUP_TOP);
this.stacks.renameGroup(this.stacks.groupAt(Position.ONE), layoutVertically ? EditorPart.GROUP_LEFT : EditorPart.GROUP_TOP);
}
}
}
......
......@@ -41,6 +41,11 @@ export interface IEditorGroupService {
*/
onEditorsMoved: Event<void>;
/**
* Emitted when the editor group orientation was changed.
*/
onGroupOrientationChanged: Event<void>;
/**
* Keyboard focus the editor group at the provided position.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册