Skip to content

Commit b4d581b

Browse files
committed
Make debug toolbar customisable
fixes microsoft#45116
1 parent beabc81 commit b4d581b

4 files changed

Lines changed: 45 additions & 11 deletions

File tree

src/vs/platform/actions/common/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const enum MenuId {
6565
DebugConsoleContext,
6666
DebugVariablesContext,
6767
DebugWatchContext,
68+
DebugToolbar,
6869
EditorContext,
6970
EditorTitle,
7071
EditorTitleContext,

src/vs/workbench/api/common/menusExtensionPoint.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace schema {
3434
case 'explorer/context': return MenuId.ExplorerContext;
3535
case 'editor/title/context': return MenuId.EditorTitleContext;
3636
case 'debug/callstack/context': return MenuId.DebugCallStackContext;
37+
case 'debug/toolbar': return MenuId.DebugToolbar;
3738
case 'scm/title': return MenuId.SCMTitle;
3839
case 'scm/sourceControl': return MenuId.SCMSourceControl;
3940
case 'scm/resourceGroup/context': return MenuId.SCMResourceGroupContext;

src/vs/workbench/contrib/debug/browser/debugToolbar.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
2424
import { registerColor, contrastBorder, widgetShadow } from 'vs/platform/theme/common/colorRegistry';
2525
import { localize } from 'vs/nls';
2626
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
27-
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
27+
import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView';
2828
import { INotificationService } from 'vs/platform/notification/common/notification';
2929
import { RunOnceScheduler } from 'vs/base/common/async';
3030
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
3131
import { IDisposable } from 'vs/base/common/lifecycle';
3232
import { isExtensionHostDebugging } from 'vs/workbench/contrib/debug/common/debugUtils';
33+
import { fillInActionBarActions, MenuItemActionItem } from 'vs/platform/actions/browser/menuItemActionItem';
34+
import { IMenu, IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';
35+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
3336

3437
const DEBUG_TOOLBAR_POSITION_KEY = 'debug.actionswidgetposition';
3538
const DEBUG_TOOLBAR_Y_KEY = 'debug.actionswidgety';
@@ -51,8 +54,9 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution {
5154
private dragArea: HTMLElement;
5255
private actionBar: ActionBar;
5356
private allActions: AbstractDebugAction[] = [];
54-
private activeActions: AbstractDebugAction[];
57+
private activeActions: IAction[];
5558
private updateScheduler: RunOnceScheduler;
59+
private debugToolbarMenu: IMenu;
5660

5761
private isVisible: boolean;
5862
private isBuilt: boolean;
@@ -67,7 +71,10 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution {
6771
@IThemeService themeService: IThemeService,
6872
@IKeybindingService private readonly keybindingService: IKeybindingService,
6973
@IContextViewService contextViewService: IContextViewService,
70-
@IInstantiationService private readonly instantiationService: IInstantiationService
74+
@IInstantiationService private readonly instantiationService: IInstantiationService,
75+
@IMenuService menuService: IMenuService,
76+
@IContextMenuService contextMenuService: IContextMenuService,
77+
@IContextKeyService contextKeyService: IContextKeyService
7178
) {
7279
super(themeService);
7380

@@ -77,6 +84,8 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution {
7784
this.dragArea = dom.append(this.$el, dom.$('div.drag-area'));
7885

7986
const actionBarContainer = dom.append(this.$el, dom.$('div.action-bar-container'));
87+
this.debugToolbarMenu = menuService.createMenu(MenuId.DebugToolbar, contextKeyService);
88+
this.toDispose.push(this.debugToolbarMenu);
8089

8190
this.activeActions = [];
8291
this.actionBar = this._register(new ActionBar(actionBarContainer, {
@@ -85,6 +94,9 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution {
8594
if (action.id === FocusSessionAction.ID) {
8695
return new FocusSessionActionItem(action, this.debugService, this.themeService, contextViewService);
8796
}
97+
if (action instanceof MenuItemAction) {
98+
return new MenuItemActionItem(action, this.keybindingService, this.notificationService, contextMenuService);
99+
}
88100

89101
return null;
90102
}
@@ -97,7 +109,7 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution {
97109
return this.hide();
98110
}
99111

100-
const actions = DebugToolbar.getActions(this.allActions, this.toDispose, this.debugService, this.keybindingService, this.instantiationService);
112+
const actions = DebugToolbar.getActions(this.debugToolbarMenu, this.allActions, this.toDispose, this.debugService, this.keybindingService, this.instantiationService);
101113
if (!arrays.equals(actions, this.activeActions, (first, second) => first.id === second.id)) {
102114
this.actionBar.clear();
103115
this.actionBar.push(actions, { icon: true, label: false });
@@ -252,7 +264,7 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution {
252264
dom.hide(this.$el);
253265
}
254266

255-
public static getActions(allActions: AbstractDebugAction[], toDispose: IDisposable[], debugService: IDebugService, keybindingService: IKeybindingService, instantiationService: IInstantiationService): AbstractDebugAction[] {
267+
public static getActions(menu: IMenu, allActions: AbstractDebugAction[], toDispose: IDisposable[], debugService: IDebugService, keybindingService: IKeybindingService, instantiationService: IInstantiationService): IAction[] {
256268
if (allActions.length === 0) {
257269
allActions.push(new ContinueAction(ContinueAction.ID, ContinueAction.LABEL, debugService, keybindingService));
258270
allActions.push(new PauseAction(PauseAction.ID, PauseAction.LABEL, debugService, keybindingService));
@@ -264,15 +276,14 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution {
264276
allActions.push(instantiationService.createInstance(RestartAction, RestartAction.ID, RestartAction.LABEL));
265277
allActions.push(new StepBackAction(StepBackAction.ID, StepBackAction.LABEL, debugService, keybindingService));
266278
allActions.push(new ReverseContinueAction(ReverseContinueAction.ID, ReverseContinueAction.LABEL, debugService, keybindingService));
267-
allActions.push(instantiationService.createInstance(FocusSessionAction, FocusSessionAction.ID, FocusSessionAction.LABEL));
268279
allActions.forEach(a => toDispose.push(a));
269280
}
270281

271282
const state = debugService.state;
272283
const session = debugService.getViewModel().focusedSession;
273284
const attached = session && session.configuration.request === 'attach' && !isExtensionHostDebugging(session.configuration);
274285

275-
return allActions.filter(a => {
286+
const actions: IAction[] = allActions.filter(a => {
276287
if (a.id === ContinueAction.ID) {
277288
return state !== State.Running;
278289
}
@@ -291,12 +302,18 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution {
291302
if (a.id === StopAction.ID) {
292303
return !attached;
293304
}
294-
if (a.id === FocusSessionAction.ID) {
295-
return debugService.getViewModel().isMultiSessionView();
296-
}
297305

298306
return true;
299307
}).sort((first, second) => first.weight - second.weight);
308+
309+
const primary: IAction[] = [];
310+
fillInActionBarActions(menu, undefined, { primary, secondary: [] });
311+
actions.push(...primary);
312+
if (debugService.getViewModel().isMultiSessionView()) {
313+
actions.push(instantiationService.createInstance(FocusSessionAction, FocusSessionAction.ID, FocusSessionAction.LABEL));
314+
}
315+
316+
return actions;
300317
}
301318

302319
public dispose(): void {

src/vs/workbench/contrib/debug/browser/debugViewlet.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
2727
import { DebugToolbar } from 'vs/workbench/contrib/debug/browser/debugToolbar';
2828
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2929
import { ViewletPanel } from 'vs/workbench/browser/parts/views/panelViewlet';
30+
import { IMenu, MenuId, IMenuService, MenuItemAction } from 'vs/platform/actions/common/actions';
31+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
32+
import { MenuItemActionItem } from 'vs/platform/actions/browser/menuItemActionItem';
33+
import { INotificationService } from 'vs/platform/notification/common/notification';
3034

3135
export class DebugViewlet extends ViewContainerViewlet {
3236

@@ -35,6 +39,7 @@ export class DebugViewlet extends ViewContainerViewlet {
3539
private breakpointView: ViewletPanel;
3640
private panelListeners = new Map<string, IDisposable>();
3741
private allActions: AbstractDebugAction[] = [];
42+
private debugToolbarMenu: IMenu;
3843

3944
constructor(
4045
@IPartService partService: IPartService,
@@ -50,6 +55,9 @@ export class DebugViewlet extends ViewContainerViewlet {
5055
@IConfigurationService configurationService: IConfigurationService,
5156
@IKeybindingService private readonly keybindingService: IKeybindingService,
5257
@IContextViewService private readonly contextViewService: IContextViewService,
58+
@IMenuService private readonly menuService: IMenuService,
59+
@IContextKeyService private readonly contextKeyService: IContextKeyService,
60+
@INotificationService private readonly notificationService: INotificationService
5361
) {
5462
super(VIEWLET_ID, `${VIEWLET_ID}.state`, false, configurationService, partService, telemetryService, storageService, instantiationService, themeService, contextMenuService, extensionService, contextService);
5563

@@ -102,7 +110,11 @@ export class DebugViewlet extends ViewContainerViewlet {
102110
return [this.startAction, this.configureAction, this.toggleReplAction];
103111
}
104112

105-
return DebugToolbar.getActions(this.allActions, this.toDispose, this.debugService, this.keybindingService, this.instantiationService);
113+
if (!this.debugToolbarMenu) {
114+
this.debugToolbarMenu = this.menuService.createMenu(MenuId.DebugToolbar, this.contextKeyService);
115+
this.toDispose.push(this.debugToolbarMenu);
116+
}
117+
return DebugToolbar.getActions(this.debugToolbarMenu, this.allActions, this.toDispose, this.debugService, this.keybindingService, this.instantiationService);
106118
}
107119

108120
get showInitialDebugActions(): boolean {
@@ -126,6 +138,9 @@ export class DebugViewlet extends ViewContainerViewlet {
126138
if (action.id === FocusSessionAction.ID) {
127139
return new FocusSessionActionItem(action, this.debugService, this.themeService, this.contextViewService);
128140
}
141+
if (action instanceof MenuItemAction) {
142+
return new MenuItemActionItem(action, this.keybindingService, this.notificationService, this.contextMenuService);
143+
}
129144

130145
return null;
131146
}

0 commit comments

Comments
 (0)