Skip to content

Commit ac40d17

Browse files
authored
debt - inline context menu contribution into windows (microsoft#269672)
* debt - inline context menu contribution into windows * fix compile * tweaks
1 parent 3a1b1ed commit ac40d17

8 files changed

Lines changed: 71 additions & 62 deletions

File tree

src/vs/workbench/browser/window.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { createSingleCallFunction } from '../../base/common/functional.js';
3232
import { IConfigurationService } from '../../platform/configuration/common/configuration.js';
3333
import { IWorkbenchEnvironmentService } from '../services/environment/common/environmentService.js';
3434
import { MarkdownString } from '../../base/common/htmlContent.js';
35+
import { IContextMenuService } from '../../platform/contextview/browser/contextView.js';
3536

3637
export abstract class BaseWindow extends Disposable {
3738

@@ -42,14 +43,17 @@ export abstract class BaseWindow extends Disposable {
4243
targetWindow: CodeWindow,
4344
dom = { getWindowsCount, getWindows }, /* for testing */
4445
@IHostService protected readonly hostService: IHostService,
45-
@IWorkbenchEnvironmentService protected readonly environmentService: IWorkbenchEnvironmentService
46+
@IWorkbenchEnvironmentService protected readonly environmentService: IWorkbenchEnvironmentService,
47+
@IContextMenuService protected readonly contextMenuService: IContextMenuService,
48+
@IWorkbenchLayoutService protected readonly layoutService: IWorkbenchLayoutService,
4649
) {
4750
super();
4851

4952
this.enableWindowFocusOnElementFocus(targetWindow);
5053
this.enableMultiWindowAwareTimeout(targetWindow, dom);
5154

5255
this.registerFullScreenListeners(targetWindow.vscodeWindowId);
56+
this.registerContextMenuListeners(targetWindow);
5357
}
5458

5559
//#region focus handling in multi-window applications
@@ -171,17 +175,6 @@ export abstract class BaseWindow extends Disposable {
171175

172176
//#endregion
173177

174-
private registerFullScreenListeners(targetWindowId: number): void {
175-
this._register(this.hostService.onDidChangeFullScreen(({ windowId, fullscreen }) => {
176-
if (windowId === targetWindowId) {
177-
const targetWindow = getWindowById(targetWindowId);
178-
if (targetWindow) {
179-
setFullscreen(fullscreen, targetWindow.window);
180-
}
181-
}
182-
}));
183-
}
184-
185178
//#region Confirm on Shutdown
186179

187180
static async confirmOnShutdown(accessor: ServicesAccessor, reason: ShutdownReason): Promise<boolean> {
@@ -212,6 +205,29 @@ export abstract class BaseWindow extends Disposable {
212205
}
213206

214207
//#endregion
208+
209+
private registerFullScreenListeners(targetWindowId: number): void {
210+
this._register(this.hostService.onDidChangeFullScreen(({ windowId, fullscreen }) => {
211+
if (windowId === targetWindowId) {
212+
const targetWindow = getWindowById(targetWindowId);
213+
if (targetWindow) {
214+
setFullscreen(fullscreen, targetWindow.window);
215+
}
216+
}
217+
}));
218+
}
219+
220+
private registerContextMenuListeners(targetWindow: Window): void {
221+
if (targetWindow !== mainWindow) {
222+
// we only need to listen in the main window as the code
223+
// will go by the active container and update accordingly
224+
return;
225+
}
226+
227+
const update = (visible: boolean) => this.layoutService.activeContainer.classList.toggle('context-menu-visible', visible);
228+
this._register(this.contextMenuService.onDidShowContextMenu(() => update(true)));
229+
this._register(this.contextMenuService.onDidHideContextMenu(() => update(false)));
230+
}
215231
}
216232

217233
export class BrowserWindow extends BaseWindow {
@@ -223,11 +239,12 @@ export class BrowserWindow extends BaseWindow {
223239
@ILabelService private readonly labelService: ILabelService,
224240
@IProductService private readonly productService: IProductService,
225241
@IBrowserWorkbenchEnvironmentService private readonly browserEnvironmentService: IBrowserWorkbenchEnvironmentService,
226-
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
242+
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService,
227243
@IInstantiationService private readonly instantiationService: IInstantiationService,
228-
@IHostService hostService: IHostService
244+
@IHostService hostService: IHostService,
245+
@IContextMenuService contextMenuService: IContextMenuService,
229246
) {
230-
super(mainWindow, undefined, hostService, browserEnvironmentService);
247+
super(mainWindow, undefined, hostService, browserEnvironmentService, contextMenuService, layoutService);
231248

232249
this.registerListeners();
233250
this.create();

src/vs/workbench/contrib/contextmenu/browser/contextmenu.contribution.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/vs/workbench/electron-browser/window.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import { getWorkbenchContribution } from '../common/contributions.js';
7979
import { DynamicWorkbenchSecurityConfiguration } from '../common/configuration.js';
8080
import { nativeHoverDelegate } from '../../platform/hover/browser/hover.js';
8181
import { WINDOW_ACTIVE_BORDER, WINDOW_INACTIVE_BORDER } from '../common/theme.js';
82+
import { IContextMenuService } from '../../platform/contextview/browser/contextView.js';
8283

8384
export class NativeWindow extends BaseWindow {
8485

@@ -111,7 +112,7 @@ export class NativeWindow extends BaseWindow {
111112
@IOpenerService private readonly openerService: IOpenerService,
112113
@INativeHostService private readonly nativeHostService: INativeHostService,
113114
@ITunnelService private readonly tunnelService: ITunnelService,
114-
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
115+
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService,
115116
@IWorkingCopyService private readonly workingCopyService: IWorkingCopyService,
116117
@IFilesConfigurationService private readonly filesConfigurationService: IFilesConfigurationService,
117118
@IProductService private readonly productService: IProductService,
@@ -127,9 +128,10 @@ export class NativeWindow extends BaseWindow {
127128
@IUriIdentityService private readonly uriIdentityService: IUriIdentityService,
128129
@IPreferencesService private readonly preferencesService: IPreferencesService,
129130
@IUtilityProcessWorkerWorkbenchService private readonly utilityProcessWorkerWorkbenchService: IUtilityProcessWorkerWorkbenchService,
130-
@IHostService hostService: IHostService
131+
@IHostService hostService: IHostService,
132+
@IContextMenuService contextMenuService: IContextMenuService,
131133
) {
132-
super(mainWindow, undefined, hostService, nativeEnvironmentService);
134+
super(mainWindow, undefined, hostService, nativeEnvironmentService, contextMenuService, layoutService);
133135

134136
this.configuredWindowZoomLevel = this.resolveConfiguredWindowZoomLevel();
135137

src/vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { isFirefox, isWeb } from '../../../../base/common/platform.js';
1818
import Severity from '../../../../base/common/severity.js';
1919
import { localize } from '../../../../nls.js';
2020
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
21+
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';
2122
import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
2223
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
2324
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
@@ -117,9 +118,11 @@ export class AuxiliaryWindow extends BaseWindow implements IAuxiliaryWindow {
117118
stylesHaveLoaded: Barrier,
118119
@IConfigurationService private readonly configurationService: IConfigurationService,
119120
@IHostService hostService: IHostService,
120-
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService
121+
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
122+
@IContextMenuService contextMenuService: IContextMenuService,
123+
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService
121124
) {
122-
super(window, undefined, hostService, environmentService);
125+
super(window, undefined, hostService, environmentService, contextMenuService, layoutService);
123126

124127
this.whenStylesHaveLoaded = stylesHaveLoaded.wait().then(() => undefined);
125128

@@ -247,12 +250,13 @@ export class BrowserAuxiliaryWindowService extends Disposable implements IAuxili
247250
private readonly windows = new Map<number, IAuxiliaryWindow>();
248251

249252
constructor(
250-
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
253+
@IWorkbenchLayoutService protected readonly layoutService: IWorkbenchLayoutService,
251254
@IDialogService protected readonly dialogService: IDialogService,
252255
@IConfigurationService protected readonly configurationService: IConfigurationService,
253256
@ITelemetryService private readonly telemetryService: ITelemetryService,
254257
@IHostService protected readonly hostService: IHostService,
255-
@IWorkbenchEnvironmentService protected readonly environmentService: IWorkbenchEnvironmentService
258+
@IWorkbenchEnvironmentService protected readonly environmentService: IWorkbenchEnvironmentService,
259+
@IContextMenuService protected readonly contextMenuService: IContextMenuService,
256260
) {
257261
super();
258262
}
@@ -308,7 +312,7 @@ export class BrowserAuxiliaryWindowService extends Disposable implements IAuxili
308312
}
309313

310314
protected createAuxiliaryWindow(targetWindow: CodeWindow, container: HTMLElement, stylesLoaded: Barrier): AuxiliaryWindow {
311-
return new AuxiliaryWindow(targetWindow, container, stylesLoaded, this.configurationService, this.hostService, this.environmentService);
315+
return new AuxiliaryWindow(targetWindow, container, stylesLoaded, this.configurationService, this.hostService, this.environmentService, this.contextMenuService, this.layoutService);
312316
}
313317

314318
private async openWindow(options?: IAuxiliaryWindowOpenOptions): Promise<Window | undefined> {

src/vs/workbench/services/auxiliaryWindow/electron-browser/auxiliaryWindowService.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { getZoomLevel, isFullscreen, setFullscreen } from '../../../../base/brow
2424
import { getActiveWindow } from '../../../../base/browser/dom.js';
2525
import { IWorkbenchEnvironmentService } from '../../environment/common/environmentService.js';
2626
import { isMacintosh } from '../../../../base/common/platform.js';
27+
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';
2728

2829
type NativeCodeWindow = CodeWindow & {
2930
readonly vscode: ISandboxGlobals;
@@ -45,9 +46,11 @@ export class NativeAuxiliaryWindow extends AuxiliaryWindow {
4546
@IInstantiationService private readonly instantiationService: IInstantiationService,
4647
@IHostService hostService: IHostService,
4748
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
48-
@IDialogService private readonly dialogService: IDialogService
49+
@IDialogService private readonly dialogService: IDialogService,
50+
@IContextMenuService contextMenuService: IContextMenuService,
51+
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService
4952
) {
50-
super(window, container, stylesHaveLoaded, configurationService, hostService, environmentService);
53+
super(window, container, stylesHaveLoaded, configurationService, hostService, environmentService, contextMenuService, layoutService);
5154

5255
if (!isMacintosh) {
5356
// For now, limit this to platforms that have clear maximised
@@ -143,9 +146,10 @@ export class NativeAuxiliaryWindowService extends BrowserAuxiliaryWindowService
143146
@IInstantiationService private readonly instantiationService: IInstantiationService,
144147
@ITelemetryService telemetryService: ITelemetryService,
145148
@IHostService hostService: IHostService,
146-
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService
149+
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
150+
@IContextMenuService contextMenuService: IContextMenuService,
147151
) {
148-
super(layoutService, dialogService, configurationService, telemetryService, hostService, environmentService);
152+
super(layoutService, dialogService, configurationService, telemetryService, hostService, environmentService, contextMenuService);
149153
}
150154

151155
protected override async resolveWindowId(auxiliaryWindow: NativeCodeWindow): Promise<number> {
@@ -172,7 +176,7 @@ export class NativeAuxiliaryWindowService extends BrowserAuxiliaryWindowService
172176
}
173177

174178
protected override createAuxiliaryWindow(targetWindow: CodeWindow, container: HTMLElement, stylesHaveLoaded: Barrier): AuxiliaryWindow {
175-
return new NativeAuxiliaryWindow(targetWindow, container, stylesHaveLoaded, this.configurationService, this.nativeHostService, this.instantiationService, this.hostService, this.environmentService, this.dialogService);
179+
return new NativeAuxiliaryWindow(targetWindow, container, stylesHaveLoaded, this.configurationService, this.nativeHostService, this.instantiationService, this.hostService, this.environmentService, this.dialogService, this.contextMenuService, this.layoutService);
176180
}
177181
}
178182

src/vs/workbench/test/browser/window.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { DisposableStore } from '../../../base/common/lifecycle.js';
1010
import { runWithFakedTimers } from '../../../base/test/common/timeTravelScheduler.js';
1111
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../base/test/common/utils.js';
1212
import { BaseWindow } from '../../browser/window.js';
13-
import { TestEnvironmentService, TestHostService } from './workbenchTestServices.js';
13+
import { TestContextMenuService, TestEnvironmentService, TestHostService, TestLayoutService } from './workbenchTestServices.js';
1414

1515
suite('Window', () => {
1616

@@ -19,7 +19,7 @@ suite('Window', () => {
1919
class TestWindow extends BaseWindow {
2020

2121
constructor(window: CodeWindow, dom: { getWindowsCount: () => number; getWindows: () => Iterable<IRegisteredCodeWindow> }) {
22-
super(window, dom, new TestHostService(), TestEnvironmentService);
22+
super(window, dom, new TestHostService(), TestEnvironmentService, new TestContextMenuService(), new TestLayoutService());
2323
}
2424

2525
protected override enableWindowFocusOnElementFocus(): void { }

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { IContextMenuDelegate } from '../../../base/browser/contextmenu.js';
67
import { IDimension } from '../../../base/browser/dom.js';
78
import { Direction, IViewSize } from '../../../base/browser/ui/grid/grid.js';
89
import { mainWindow } from '../../../base/browser/window.js';
@@ -58,7 +59,7 @@ import { ConfigurationTarget, IConfigurationService, IConfigurationValue } from
5859
import { TestConfigurationService } from '../../../platform/configuration/test/common/testConfigurationService.js';
5960
import { ContextKeyValue, IContextKeyService } from '../../../platform/contextkey/common/contextkey.js';
6061
import { ContextMenuService } from '../../../platform/contextview/browser/contextMenuService.js';
61-
import { IContextMenuService, IContextViewService } from '../../../platform/contextview/browser/contextView.js';
62+
import { IContextMenuMenuDelegate, IContextMenuService, IContextViewService } from '../../../platform/contextview/browser/contextView.js';
6263
import { ContextViewService } from '../../../platform/contextview/browser/contextViewService.js';
6364
import { IDiagnosticInfo, IDiagnosticInfoOptions } from '../../../platform/diagnostics/common/diagnostics.js';
6465
import { ConfirmResult, IDialogService, IFileDialogService, IOpenDialogOptions, IPickAndOpenOptions, ISaveDialogOptions } from '../../../platform/dialogs/common/dialogs.js';
@@ -2196,3 +2197,15 @@ export class TestChatEntitlementService implements IChatEntitlementService {
21962197
onDidChangeAnonymous = Event.None;
21972198
readonly anonymousObs = observableValue({}, false);
21982199
}
2200+
2201+
export class TestContextMenuService implements IContextMenuService {
2202+
2203+
_serviceBrand: undefined;
2204+
2205+
readonly onDidShowContextMenu = Event.None;
2206+
readonly onDidHideContextMenu = Event.None;
2207+
2208+
showContextMenu(delegate: IContextMenuDelegate | IContextMenuMenuDelegate): void {
2209+
throw new Error('Method not implemented.');
2210+
}
2211+
}

src/vs/workbench/workbench.common.main.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ import './contrib/preferences/browser/preferencesSearch.js';
195195
// Performance
196196
import './contrib/performance/browser/performance.contribution.js';
197197

198-
// Context Menus
199-
import './contrib/contextmenu/browser/contextmenu.contribution.js';
200-
201198
// Notebook
202199
import './contrib/notebook/browser/notebook.contribution.js';
203200

0 commit comments

Comments
 (0)