Skip to content

Commit c4de96c

Browse files
author
Benjamin Pasero
committed
debt - declarative context menu service
1 parent 9b849d9 commit c4de96c

5 files changed

Lines changed: 49 additions & 13 deletions

File tree

src/vs/platform/contextview/browser/contextMenuHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class ContextMenuHandler {
2828
private block: HTMLElement | null;
2929

3030
constructor(
31-
element: HTMLElement,
31+
element: HTMLElement | null,
3232
private contextViewService: IContextViewService,
3333
private telemetryService: ITelemetryService,
3434
private notificationService: INotificationService,

src/vs/platform/contextview/browser/contextMenuService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class ContextMenuService extends Disposable implements IContextMenuServic
2222
private contextMenuHandler: ContextMenuHandler;
2323

2424
constructor(
25-
container: HTMLElement,
25+
container: HTMLElement | null,
2626
@ITelemetryService telemetryService: ITelemetryService,
2727
@INotificationService notificationService: INotificationService,
2828
@IContextViewService contextViewService: IContextViewService,

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { getServices } from 'vs/platform/instantiation/common/extensions';
2929
import { Position, Parts, IWorkbenchLayoutService, ILayoutOptions } from 'vs/workbench/services/layout/browser/layoutService';
3030
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
3131
import { IStorageService, StorageScope, IWillSaveStateEvent, WillSaveStateReason } from 'vs/platform/storage/common/storage';
32-
import { ContextMenuService as HTMLContextMenuService } from 'vs/platform/contextview/browser/contextMenuService';
3332
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
3433
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
3534
import { IFileService } from 'vs/platform/files/common/files';
@@ -40,7 +39,7 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
4039
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
4140
import { LifecyclePhase, StartupKind, ILifecycleService, WillShutdownEvent } from 'vs/platform/lifecycle/common/lifecycle';
4241
import { IWindowService, IWindowConfiguration, IPath, MenuBarVisibility, getTitleBarStyle, IWindowsService } from 'vs/platform/windows/common/windows';
43-
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
42+
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
4443
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
4544
import { INotificationService } from 'vs/platform/notification/common/notification';
4645
import { NotificationService } from 'vs/workbench/services/notification/common/notificationService';
@@ -91,7 +90,6 @@ import { LocalizationsChannelClient } from 'vs/platform/localizations/node/local
9190
import { ProductService } from 'vs/platform/product/node/productService';
9291

9392
// import@electron-browser
94-
import { ContextMenuService as NativeContextMenuService } from 'vs/workbench/services/contextmenu/electron-browser/contextmenuService';
9593
import { LifecycleService } from 'vs/platform/lifecycle/electron-browser/lifecycleService';
9694
import { WindowService } from 'vs/platform/windows/electron-browser/windowService';
9795
import { RemoteAuthorityResolverService } from 'vs/platform/remote/electron-browser/remoteAuthorityResolverService';
@@ -369,13 +367,6 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
369367
// Context view service
370368
serviceCollection.set(IContextViewService, new SyncDescriptor(ContextViewService, [this.workbench], true));
371369

372-
// Use themable context menus when custom titlebar is enabled to match custom menubar
373-
if (!isMacintosh && getTitleBarStyle(this.configurationService, this.environmentService) === 'custom') {
374-
serviceCollection.set(IContextMenuService, new SyncDescriptor(HTMLContextMenuService, [null]));
375-
} else {
376-
serviceCollection.set(IContextMenuService, new SyncDescriptor(NativeContextMenuService));
377-
}
378-
379370
// Contributed services
380371
const contributedServices = getServices();
381372
for (let contributedService of contributedServices) {

src/vs/workbench/services/contextmenu/electron-browser/contextmenuService.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { IAction, IActionRunner, ActionRunner } from 'vs/base/common/actions';
77
import { Separator } from 'vs/base/browser/ui/actionbar/actionbar';
88
import * as dom from 'vs/base/browser/dom';
9-
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
9+
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
1010
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1111
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1212
import { webFrame } from 'electron';
@@ -18,11 +18,53 @@ import { once } from 'vs/base/common/functional';
1818
import { Disposable } from 'vs/base/common/lifecycle';
1919
import { IContextMenuItem } from 'vs/base/parts/contextmenu/common/contextmenu';
2020
import { popup } from 'vs/base/parts/contextmenu/electron-browser/contextmenu';
21+
import { getTitleBarStyle } from 'vs/platform/windows/common/windows';
22+
import { isMacintosh } from 'vs/base/common/platform';
23+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
24+
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
25+
import { ContextMenuService as HTMLContextMenuService } from 'vs/platform/contextview/browser/contextMenuService';
26+
import { IThemeService } from 'vs/platform/theme/common/themeService';
27+
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
2128

2229
export class ContextMenuService extends Disposable implements IContextMenuService {
2330

2431
_serviceBrand: any;
2532

33+
get onDidContextMenu(): Event<void> { return this.impl.onDidContextMenu; }
34+
35+
private impl: IContextMenuService;
36+
37+
constructor(
38+
@INotificationService notificationService: INotificationService,
39+
@ITelemetryService telemetryService: ITelemetryService,
40+
@IKeybindingService keybindingService: IKeybindingService,
41+
@IConfigurationService configurationService: IConfigurationService,
42+
@IEnvironmentService environmentService: IEnvironmentService,
43+
@IContextViewService contextViewService: IContextViewService,
44+
@IThemeService themeService: IThemeService
45+
) {
46+
super();
47+
48+
// Custom context menu: Linux/Windows if custom title is enabled
49+
if (!isMacintosh && getTitleBarStyle(configurationService, environmentService) === 'custom') {
50+
this.impl = new HTMLContextMenuService(null, telemetryService, notificationService, contextViewService, keybindingService, themeService);
51+
}
52+
53+
// Native context menu: otherwise
54+
else {
55+
this.impl = new NativeContextMenuService(notificationService, telemetryService, keybindingService);
56+
}
57+
}
58+
59+
showContextMenu(delegate: IContextMenuDelegate): void {
60+
this.impl.showContextMenu(delegate);
61+
}
62+
}
63+
64+
class NativeContextMenuService extends Disposable implements IContextMenuService {
65+
66+
_serviceBrand: any;
67+
2668
private _onDidContextMenu = this._register(new Emitter<void>());
2769
get onDidContextMenu(): Event<void> { return this._onDidContextMenu.event; }
2870

@@ -145,3 +187,5 @@ export class ContextMenuService extends Disposable implements IContextMenuServic
145187
res.then(undefined, e => this.notificationService.error(e));
146188
}
147189
}
190+
191+
registerSingleton(IContextMenuService, ContextMenuService, true);

src/vs/workbench/workbench.main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import 'vs/workbench/services/mode/common/workbenchModeService';
9797
import 'vs/workbench/services/commands/common/commandService';
9898
import 'vs/workbench/services/themes/browser/workbenchThemeService';
9999
import 'vs/workbench/services/extensions/electron-browser/extensionService';
100+
import 'vs/workbench/services/contextmenu/electron-browser/contextmenuService';
100101

101102
registerSingleton(IMenuService, MenuService, true);
102103
registerSingleton(IListService, ListService, true);

0 commit comments

Comments
 (0)