diff --git a/src/vs/workbench/browser/actions/layoutActions.ts b/src/vs/workbench/browser/actions/layoutActions.ts index e728b33e2caff..d794a97e45406 100644 --- a/src/vs/workbench/browser/actions/layoutActions.ts +++ b/src/vs/workbench/browser/actions/layoutActions.ts @@ -21,7 +21,7 @@ import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/b import { ToggleAuxiliaryBarAction } from 'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions'; import { TogglePanelAction } from 'vs/workbench/browser/parts/panel/panelActions'; import { ICommandService } from 'vs/platform/commands/common/commands'; -import { AuxiliaryBarVisibleContext, PanelAlignmentContext, PanelVisibleContext, SideBarVisibleContext, FocusedViewContext, InEditorZenModeContext, IsCenteredLayoutContext, EditorAreaVisibleContext, IsFullscreenContext, PanelPositionContext } from 'vs/workbench/common/contextkeys'; +import { AuxiliaryBarVisibleContext, PanelAlignmentContext, PanelVisibleContext, SideBarVisibleContext, FocusedViewContext, InEditorZenModeContext, IsCenteredLayoutContext, EditorAreaVisibleContext, IsFullscreenContext, PanelPositionContext, IsAuxiliaryWindowFocusedContext } from 'vs/workbench/common/contextkeys'; import { Codicon } from 'vs/base/common/codicons'; import { ThemeIcon } from 'vs/base/common/themables'; import { DisposableStore } from 'vs/base/common/lifecycle'; @@ -81,6 +81,7 @@ registerAction2(class extends Action2 { mnemonicTitle: localize({ key: 'miToggleCenteredLayout', comment: ['&& denotes a mnemonic'] }, "&&Centered Layout"), original: 'Toggle Centered Layout' }, + precondition: IsAuxiliaryWindowFocusedContext.toNegated(), category: Categories.View, f1: true, toggled: IsCenteredLayoutContext, @@ -95,7 +96,7 @@ registerAction2(class extends Action2 { run(accessor: ServicesAccessor): void { const layoutService = accessor.get(IWorkbenchLayoutService); - layoutService.centerEditorLayout(!layoutService.isEditorLayoutCentered()); + layoutService.centerMainEditorLayout(!layoutService.isMainEditorLayoutCentered()); } }); diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index 70c3e2d19e013..cdb85f4248603 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -335,7 +335,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi this._register(this.editorGroupService.mainPart.onDidActivateGroup(showEditorIfHidden)); // Revalidate center layout when active editor changes: diff editor quits centered mode. - this._register(this.editorService.onDidActiveEditorChange(() => this.centerEditorLayout(this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED)))); + this._register(this.mainPartEditorService.onDidActiveEditorChange(() => this.centerMainEditorLayout(this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED)))); }); // Configuration changes @@ -358,8 +358,8 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi this._register(onDidChangeFullscreen(() => this.onFullscreenChanged())); // Group changes - this._register(this.editorGroupService.onDidAddGroup(() => this.centerEditorLayout(this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED)))); - this._register(this.editorGroupService.onDidRemoveGroup(() => this.centerEditorLayout(this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED)))); + this._register(this.editorGroupService.mainPart.onDidAddGroup(() => this.centerMainEditorLayout(this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED)))); + this._register(this.editorGroupService.mainPart.onDidRemoveGroup(() => this.centerMainEditorLayout(this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED)))); // Prevent workbench from scrolling #55456 this._register(addDisposableListener(this.mainContainer, EventType.SCROLL, () => this.mainContainer.scrollTop = 0)); @@ -485,7 +485,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi // Centered Layout this.editorGroupService.mainPart.whenRestored.then(() => { - this.centerEditorLayout(this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED), skipLayout); + this.centerMainEditorLayout(this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED), skipLayout); }); } @@ -1047,9 +1047,9 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi this.toggleZenMode(false, true); } - // Restore Editor Center Mode + // Restore Main Editor Center Mode if (this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED)) { - this.centerEditorLayout(true, true); + this.centerMainEditorLayout(true, true); } // Await for promises that we recorded to update @@ -1320,7 +1320,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi if (!restoring) { zenModeExitInfo.transitionedToFullScreen = toggleFullScreen; - zenModeExitInfo.transitionedToCenteredEditorLayout = !this.isEditorLayoutCentered() && config.centerLayout; + zenModeExitInfo.transitionedToCenteredEditorLayout = !this.isMainEditorLayoutCentered() && config.centerLayout; zenModeExitInfo.handleNotificationsDoNotDisturbMode = !this.notificationService.doNotDisturbMode; zenModeExitInfo.wasVisible.sideBar = this.isVisible(Parts.SIDEBAR_PART); zenModeExitInfo.wasVisible.panel = this.isVisible(Parts.PANEL_PART); @@ -1362,7 +1362,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi })); if (config.centerLayout) { - this.centerEditorLayout(true, true); + this.centerMainEditorLayout(true, true); } } @@ -1389,7 +1389,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi } if (zenModeExitInfo.transitionedToCenteredEditorLayout) { - this.centerEditorLayout(false, true); + this.centerMainEditorLayout(false, true); } if (zenModeExitInfo.handleNotificationsDoNotDisturbMode) { @@ -1530,32 +1530,32 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi } } - isEditorLayoutCentered(): boolean { + isMainEditorLayoutCentered(): boolean { return this.stateModel.getRuntimeValue(LayoutStateKeys.EDITOR_CENTERED); } - centerEditorLayout(active: boolean, skipLayout?: boolean): void { + centerMainEditorLayout(active: boolean, skipLayout?: boolean): void { this.stateModel.setRuntimeValue(LayoutStateKeys.EDITOR_CENTERED, active); - const activeEditor = this.editorService.activeEditor; + const activeMainEditor = this.mainPartEditorService.activeEditor; let isEditorComplex = false; - if (activeEditor instanceof DiffEditorInput) { + if (activeMainEditor instanceof DiffEditorInput) { isEditorComplex = this.configurationService.getValue('diffEditor.renderSideBySide'); - } else if (activeEditor?.hasCapability(EditorInputCapabilities.MultipleEditors)) { + } else if (activeMainEditor?.hasCapability(EditorInputCapabilities.MultipleEditors)) { isEditorComplex = true; } const isCenteredLayoutAutoResizing = this.configurationService.getValue('workbench.editor.centeredLayoutAutoResize'); if ( isCenteredLayoutAutoResizing && - (this.editorGroupService.groups.length > 1 || isEditorComplex) + (this.editorGroupService.mainPart.groups.length > 1 || isEditorComplex) ) { active = false; // disable centered layout for complex editors or when there is more than one group } - if (this.editorGroupService.isLayoutCentered() !== active) { - this.editorGroupService.centerLayout(active); + if (this.editorGroupService.mainPart.isLayoutCentered() !== active) { + this.editorGroupService.mainPart.centerLayout(active); if (!skipLayout) { this.layout(); @@ -1877,7 +1877,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi } if (focusEditor) { - this.editorGroupService.activeGroup.focus(); // Pass focus to editor group if panel part is now hidden + this.editorGroupService.mainPart.activeGroup.focus(); // Pass focus to editor group if panel part is now hidden } } diff --git a/src/vs/workbench/browser/parts/editor/editorParts.ts b/src/vs/workbench/browser/parts/editor/editorParts.ts index 1aca6661bfffb..e3f94ab4b8c68 100644 --- a/src/vs/workbench/browser/parts/editor/editorParts.ts +++ b/src/vs/workbench/browser/parts/editor/editorParts.ts @@ -297,14 +297,6 @@ export class EditorParts extends Disposable implements IEditorGroupsService, IEd return this.activePart.getLayout(); } - centerLayout(active: boolean): void { - this.activePart.centerLayout(active); - } - - isLayoutCentered(): boolean { - return this.activePart.isLayoutCentered(); - } - get orientation() { return this.activePart.orientation; } diff --git a/src/vs/workbench/services/editor/common/editorGroupsService.ts b/src/vs/workbench/services/editor/common/editorGroupsService.ts index 541a26d23d06c..fb3ef58c89cc6 100644 --- a/src/vs/workbench/services/editor/common/editorGroupsService.ts +++ b/src/vs/workbench/services/editor/common/editorGroupsService.ts @@ -301,16 +301,6 @@ export interface IEditorGroupsContainer { */ getLayout(): EditorGroupLayout; - /** - * Enable or disable centered editor layout. - */ - centerLayout(active: boolean): void; - - /** - * Find out if the editor layout is currently centered. - */ - isLayoutCentered(): boolean; - /** * Sets the orientation of the root group to be either vertical or horizontal. */ @@ -462,6 +452,16 @@ export interface IEditorPart extends IEditorGroupsContainer { * from a previous session. */ readonly hasRestorableState: boolean; + + /** + * Enable or disable centered editor layout. + */ + centerLayout(active: boolean): void; + + /** + * Find out if the editor layout is currently centered. + */ + isLayoutCentered(): boolean; } export interface IAuxiliaryEditorPart extends IEditorPart { diff --git a/src/vs/workbench/services/layout/browser/layoutService.ts b/src/vs/workbench/services/layout/browser/layoutService.ts index aa2055c883088..5ade4d87621da 100644 --- a/src/vs/workbench/services/layout/browser/layoutService.ts +++ b/src/vs/workbench/services/layout/browser/layoutService.ts @@ -256,14 +256,14 @@ export interface IWorkbenchLayoutService extends ILayoutService { toggleZenMode(): void; /** - * Returns whether the centered editor layout is active. + * Returns whether the centered editor layout is active on the main editor part. */ - isEditorLayoutCentered(): boolean; + isMainEditorLayoutCentered(): boolean; /** - * Sets the workbench in and out of centered editor layout. + * Sets the main editor part in and out of centered layout. */ - centerEditorLayout(active: boolean): void; + centerMainEditorLayout(active: boolean): void; /** * Resizes currently focused part on main access diff --git a/src/vs/workbench/test/browser/workbenchTestServices.ts b/src/vs/workbench/test/browser/workbenchTestServices.ts index 8e4b1bb39049b..170d5d05d986e 100644 --- a/src/vs/workbench/test/browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/browser/workbenchTestServices.ts @@ -649,8 +649,8 @@ export class TestLayoutService implements IWorkbenchLayoutService { removeClass(_clazz: string): void { } getMaximumEditorDimensions(): IDimension { throw new Error('not implemented'); } toggleZenMode(): void { } - isEditorLayoutCentered(): boolean { return false; } - centerEditorLayout(_active: boolean): void { } + isMainEditorLayoutCentered(): boolean { return false; } + centerMainEditorLayout(_active: boolean): void { } resizePart(_part: Parts, _sizeChangeWidth: number, _sizeChangeHeight: number): void { } registerPart(part: Part): void { } isWindowMaximized() { return false; }