Skip to content

Commit

Permalink
aux window - limit centered layout to main part for now
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Nov 17, 2023
1 parent cb33247 commit a76b835
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 44 deletions.
5 changes: 3 additions & 2 deletions src/vs/workbench/browser/actions/layoutActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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());
}
});

Expand Down
36 changes: 18 additions & 18 deletions src/vs/workbench/browser/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1362,7 +1362,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
}));

if (config.centerLayout) {
this.centerEditorLayout(true, true);
this.centerMainEditorLayout(true, true);
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/vs/workbench/browser/parts/editor/editorParts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
20 changes: 10 additions & 10 deletions src/vs/workbench/services/editor/common/editorGroupsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/services/layout/browser/layoutService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/test/browser/workbenchTestServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit a76b835

Please sign in to comment.