Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aux window - use layoutservice for containers #196531

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/vs/platform/layout/browser/layoutService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export interface ILayoutService {

readonly _serviceBrand: undefined;

/**
* An event that is emitted when the container is layed out. The
* event carries the dimensions of the container as part of it.
*/
readonly onDidLayout: Event<IDimension>;

/**
* The dimensions of the container.
*/
Expand Down Expand Up @@ -64,12 +70,6 @@ export interface ILayoutService {
*/
readonly offset: ILayoutOffsetInfo;

/**
* An event that is emitted when the container is layed out. The
* event carries the dimensions of the container as part of it.
*/
readonly onDidLayout: Event<IDimension>;

/**
* Focus the primary component of the container.
*/
Expand Down
13 changes: 6 additions & 7 deletions src/vs/workbench/browser/actions/textInputActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle
import { isNative } from 'vs/base/common/platform';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { IAuxiliaryWindowService } from 'vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService';
import { Event } from 'vs/base/common/event';

export class TextInputActionsProvider extends Disposable implements IWorkbenchContribution {

Expand All @@ -24,8 +24,7 @@ export class TextInputActionsProvider extends Disposable implements IWorkbenchCo
constructor(
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
@IContextMenuService private readonly contextMenuService: IContextMenuService,
@IClipboardService private readonly clipboardService: IClipboardService,
@IAuxiliaryWindowService private readonly auxiliaryWindowService: IAuxiliaryWindowService
@IClipboardService private readonly clipboardService: IClipboardService
) {
super();

Expand Down Expand Up @@ -78,10 +77,10 @@ export class TextInputActionsProvider extends Disposable implements IWorkbenchCo
private registerListeners(): void {

// Context menu support in input/textarea
this._register(addDisposableListener(this.layoutService.container, 'contextmenu', e => this.onContextMenu(e)));
this._register(this.auxiliaryWindowService.onDidOpenAuxiliaryWindow(({ window, disposables }) => {
disposables.add(addDisposableListener(window.container, 'contextmenu', e => this.onContextMenu(e)));
}));
this._register(Event.runAndSubscribe(this.layoutService.onDidAddContainer, container => {
const listener = addDisposableListener(container, 'contextmenu', e => this.onContextMenu(e));
this._register(Event.filter(this.layoutService.onDidRemoveContainer, removed => removed === container, this._store)(() => listener.dispose()));
}, this.layoutService.container));
}

private onContextMenu(e: MouseEvent): void {
Expand Down
18 changes: 17 additions & 1 deletion src/vs/workbench/browser/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
import { EventType, addDisposableListener, getClientArea, Dimension, position, size, IDimension, isAncestorUsingFlowTo, computeScreenAwareSize, getActiveDocument, getWindows, getActiveWindow } from 'vs/base/browser/dom';
import { onDidChangeFullscreen, isFullscreen, isWCOEnabled } from 'vs/base/browser/browser';
Expand Down Expand Up @@ -47,6 +47,7 @@ import { IBannerService } from 'vs/workbench/services/banner/browser/bannerServi
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
import { AuxiliaryBarPart } from 'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarPart';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IAuxiliaryWindowService } from 'vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService';

//#region Layout Implementation

Expand Down Expand Up @@ -147,6 +148,12 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
private readonly _onDidLayout = this._register(new Emitter<IDimension>());
readonly onDidLayout = this._onDidLayout.event;

private readonly _onDidAddContainer = this._register(new Emitter<HTMLElement>());
readonly onDidAddContainer = this._onDidAddContainer.event;

private readonly _onDidRemoveContainer = this._register(new Emitter<HTMLElement>());
readonly onDidRemoveContainer = this._onDidRemoveContainer.event;

//#endregion

//#region Properties
Expand Down Expand Up @@ -227,6 +234,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
private statusBarService!: IStatusbarService;
private logService!: ILogService;
private telemetryService!: ITelemetryService;
private auxiliaryWindowService!: IAuxiliaryWindowService;

private state!: ILayoutState;
private stateModel!: LayoutStateModel;
Expand All @@ -252,6 +260,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
this.extensionService = accessor.get(IExtensionService);
this.logService = accessor.get(ILogService);
this.telemetryService = accessor.get(ITelemetryService);
this.auxiliaryWindowService = accessor.get(IAuxiliaryWindowService);

// Parts
this.editorService = accessor.get(IEditorService);
Expand Down Expand Up @@ -332,6 +341,13 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
if (isWeb && typeof (navigator as any).windowControlsOverlay === 'object') {
this._register(addDisposableListener((navigator as any).windowControlsOverlay, 'geometrychange', () => this.onDidChangeWCO()));
}

// Auxiliary windows
this._register(this.auxiliaryWindowService.onDidOpenAuxiliaryWindow(({ window, disposables }) => {
this._onDidAddContainer.fire(window.container);

disposables.add(toDisposable(() => this._onDidRemoveContainer.fire(window.container)));
}));
}

private onMenubarToggled(visible: boolean): void {
Expand Down
27 changes: 11 additions & 16 deletions src/vs/workbench/services/history/browser/historyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { IPathService } from 'vs/workbench/services/path/common/pathService';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { ILifecycleService, LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
import { IAuxiliaryWindowService } from 'vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService';

export class HistoryService extends Disposable implements IHistoryService {

Expand All @@ -58,8 +57,7 @@ export class HistoryService extends Disposable implements IHistoryService {
@IWorkspacesService private readonly workspacesService: IWorkspacesService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IAuxiliaryWindowService private readonly auxiliaryWindowService: IAuxiliaryWindowService
@IContextKeyService private readonly contextKeyService: IContextKeyService
) {
super();

Expand Down Expand Up @@ -113,14 +111,16 @@ export class HistoryService extends Disposable implements IHistoryService {
mouseBackForwardSupportListener.clear();

if (this.configurationService.getValue(HistoryService.MOUSE_NAVIGATION_SETTING)) {
this.doRegisterMouseNavigationListener(this.layoutService.container, mouseBackForwardSupportListener);

this._register(this.auxiliaryWindowService.onDidOpenAuxiliaryWindow(({ window, disposables }) => {
const listenerDisposables = new DisposableStore();
mouseBackForwardSupportListener.add(listenerDisposables);
disposables.add(listenerDisposables);
this.doRegisterMouseNavigationListener(window.container, listenerDisposables);
}));

this._register(Event.runAndSubscribe(this.layoutService.onDidAddContainer, container => {
const disposables = new DisposableStore();
disposables.add(addDisposableListener(container, EventType.MOUSE_DOWN, e => this.onMouseDownOrUp(e, true)));
disposables.add(addDisposableListener(container, EventType.MOUSE_UP, e => this.onMouseDownOrUp(e, false)));

this._register(Event.filter(this.layoutService.onDidRemoveContainer, removed => removed === container, this._store)(() => disposables.dispose()));

mouseBackForwardSupportListener.add(disposables);
}, this.layoutService.container));
}
};

Expand All @@ -133,11 +133,6 @@ export class HistoryService extends Disposable implements IHistoryService {
handleMouseBackForwardSupport();
}

private doRegisterMouseNavigationListener(container: HTMLElement, disposables: DisposableStore): void {
disposables.add(addDisposableListener(container, EventType.MOUSE_DOWN, e => this.onMouseDownOrUp(e, true)));
disposables.add(addDisposableListener(container, EventType.MOUSE_UP, e => this.onMouseDownOrUp(e, false)));
}

private onMouseDownOrUp(event: MouseEvent, isMouseDown: boolean): void {

// Support to navigate in history when mouse buttons 4/5 are pressed
Expand Down
12 changes: 12 additions & 0 deletions src/vs/workbench/services/layout/browser/layoutService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ export interface IWorkbenchLayoutService extends ILayoutService {
*/
readonly onDidChangeNotificationsVisibility: Event<boolean>;

/**
* An event that is emitted when a new container is added. This
* can happen in multi-window environments.
*/
readonly onDidAddContainer: Event<HTMLElement>;

/**
* An event that is emitted when a container is removed. This
* can happen in multi-window environments.
*/
readonly onDidRemoveContainer: Event<HTMLElement>;

/**
* True if a default layout with default editors was applied at startup
*/
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/test/browser/workbenchTestServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ export class TestLayoutService implements IWorkbenchLayoutService {
onDidChangePartVisibility: Event<void> = Event.None;
onDidLayout = Event.None;
onDidChangeNotificationsVisibility = Event.None;
onDidAddContainer = Event.None;
onDidRemoveContainer = Event.None;

layout(): void { }
isRestored(): boolean { return true; }
Expand Down