From b4d581b75ae94f7cd6433afa8f665c701a93a06c Mon Sep 17 00:00:00 2001 From: isidor Date: Thu, 21 Feb 2019 17:46:36 +0100 Subject: [PATCH] Make debug toolbar customisable fixes #45116 --- src/vs/platform/actions/common/actions.ts | 1 + .../api/common/menusExtensionPoint.ts | 1 + .../contrib/debug/browser/debugToolbar.ts | 37 ++++++++++++++----- .../contrib/debug/browser/debugViewlet.ts | 17 ++++++++- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index c0b5b2f8879..ead87925df7 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -65,6 +65,7 @@ export const enum MenuId { DebugConsoleContext, DebugVariablesContext, DebugWatchContext, + DebugToolbar, EditorContext, EditorTitle, EditorTitleContext, diff --git a/src/vs/workbench/api/common/menusExtensionPoint.ts b/src/vs/workbench/api/common/menusExtensionPoint.ts index 74406c0ef9c..ac48ab103d9 100644 --- a/src/vs/workbench/api/common/menusExtensionPoint.ts +++ b/src/vs/workbench/api/common/menusExtensionPoint.ts @@ -34,6 +34,7 @@ namespace schema { case 'explorer/context': return MenuId.ExplorerContext; case 'editor/title/context': return MenuId.EditorTitleContext; case 'debug/callstack/context': return MenuId.DebugCallStackContext; + case 'debug/toolbar': return MenuId.DebugToolbar; case 'scm/title': return MenuId.SCMTitle; case 'scm/sourceControl': return MenuId.SCMSourceControl; case 'scm/resourceGroup/context': return MenuId.SCMResourceGroupContext; diff --git a/src/vs/workbench/contrib/debug/browser/debugToolbar.ts b/src/vs/workbench/contrib/debug/browser/debugToolbar.ts index 3ec36f960ca..11b92b33bd8 100644 --- a/src/vs/workbench/contrib/debug/browser/debugToolbar.ts +++ b/src/vs/workbench/contrib/debug/browser/debugToolbar.ts @@ -24,12 +24,15 @@ import { IThemeService } from 'vs/platform/theme/common/themeService'; import { registerColor, contrastBorder, widgetShadow } from 'vs/platform/theme/common/colorRegistry'; import { localize } from 'vs/nls'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; -import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; +import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { RunOnceScheduler } from 'vs/base/common/async'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IDisposable } from 'vs/base/common/lifecycle'; import { isExtensionHostDebugging } from 'vs/workbench/contrib/debug/common/debugUtils'; +import { fillInActionBarActions, MenuItemActionItem } from 'vs/platform/actions/browser/menuItemActionItem'; +import { IMenu, IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions'; +import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; const DEBUG_TOOLBAR_POSITION_KEY = 'debug.actionswidgetposition'; const DEBUG_TOOLBAR_Y_KEY = 'debug.actionswidgety'; @@ -51,8 +54,9 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution { private dragArea: HTMLElement; private actionBar: ActionBar; private allActions: AbstractDebugAction[] = []; - private activeActions: AbstractDebugAction[]; + private activeActions: IAction[]; private updateScheduler: RunOnceScheduler; + private debugToolbarMenu: IMenu; private isVisible: boolean; private isBuilt: boolean; @@ -67,7 +71,10 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution { @IThemeService themeService: IThemeService, @IKeybindingService private readonly keybindingService: IKeybindingService, @IContextViewService contextViewService: IContextViewService, - @IInstantiationService private readonly instantiationService: IInstantiationService + @IInstantiationService private readonly instantiationService: IInstantiationService, + @IMenuService menuService: IMenuService, + @IContextMenuService contextMenuService: IContextMenuService, + @IContextKeyService contextKeyService: IContextKeyService ) { super(themeService); @@ -77,6 +84,8 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution { this.dragArea = dom.append(this.$el, dom.$('div.drag-area')); const actionBarContainer = dom.append(this.$el, dom.$('div.action-bar-container')); + this.debugToolbarMenu = menuService.createMenu(MenuId.DebugToolbar, contextKeyService); + this.toDispose.push(this.debugToolbarMenu); this.activeActions = []; this.actionBar = this._register(new ActionBar(actionBarContainer, { @@ -85,6 +94,9 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution { if (action.id === FocusSessionAction.ID) { return new FocusSessionActionItem(action, this.debugService, this.themeService, contextViewService); } + if (action instanceof MenuItemAction) { + return new MenuItemActionItem(action, this.keybindingService, this.notificationService, contextMenuService); + } return null; } @@ -97,7 +109,7 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution { return this.hide(); } - const actions = DebugToolbar.getActions(this.allActions, this.toDispose, this.debugService, this.keybindingService, this.instantiationService); + const actions = DebugToolbar.getActions(this.debugToolbarMenu, this.allActions, this.toDispose, this.debugService, this.keybindingService, this.instantiationService); if (!arrays.equals(actions, this.activeActions, (first, second) => first.id === second.id)) { this.actionBar.clear(); this.actionBar.push(actions, { icon: true, label: false }); @@ -252,7 +264,7 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution { dom.hide(this.$el); } - public static getActions(allActions: AbstractDebugAction[], toDispose: IDisposable[], debugService: IDebugService, keybindingService: IKeybindingService, instantiationService: IInstantiationService): AbstractDebugAction[] { + public static getActions(menu: IMenu, allActions: AbstractDebugAction[], toDispose: IDisposable[], debugService: IDebugService, keybindingService: IKeybindingService, instantiationService: IInstantiationService): IAction[] { if (allActions.length === 0) { allActions.push(new ContinueAction(ContinueAction.ID, ContinueAction.LABEL, debugService, keybindingService)); allActions.push(new PauseAction(PauseAction.ID, PauseAction.LABEL, debugService, keybindingService)); @@ -264,7 +276,6 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution { allActions.push(instantiationService.createInstance(RestartAction, RestartAction.ID, RestartAction.LABEL)); allActions.push(new StepBackAction(StepBackAction.ID, StepBackAction.LABEL, debugService, keybindingService)); allActions.push(new ReverseContinueAction(ReverseContinueAction.ID, ReverseContinueAction.LABEL, debugService, keybindingService)); - allActions.push(instantiationService.createInstance(FocusSessionAction, FocusSessionAction.ID, FocusSessionAction.LABEL)); allActions.forEach(a => toDispose.push(a)); } @@ -272,7 +283,7 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution { const session = debugService.getViewModel().focusedSession; const attached = session && session.configuration.request === 'attach' && !isExtensionHostDebugging(session.configuration); - return allActions.filter(a => { + const actions: IAction[] = allActions.filter(a => { if (a.id === ContinueAction.ID) { return state !== State.Running; } @@ -291,12 +302,18 @@ export class DebugToolbar extends Themable implements IWorkbenchContribution { if (a.id === StopAction.ID) { return !attached; } - if (a.id === FocusSessionAction.ID) { - return debugService.getViewModel().isMultiSessionView(); - } return true; }).sort((first, second) => first.weight - second.weight); + + const primary: IAction[] = []; + fillInActionBarActions(menu, undefined, { primary, secondary: [] }); + actions.push(...primary); + if (debugService.getViewModel().isMultiSessionView()) { + actions.push(instantiationService.createInstance(FocusSessionAction, FocusSessionAction.ID, FocusSessionAction.LABEL)); + } + + return actions; } public dispose(): void { diff --git a/src/vs/workbench/contrib/debug/browser/debugViewlet.ts b/src/vs/workbench/contrib/debug/browser/debugViewlet.ts index 8660286c4fb..37f54c86874 100644 --- a/src/vs/workbench/contrib/debug/browser/debugViewlet.ts +++ b/src/vs/workbench/contrib/debug/browser/debugViewlet.ts @@ -27,6 +27,10 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { DebugToolbar } from 'vs/workbench/contrib/debug/browser/debugToolbar'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { ViewletPanel } from 'vs/workbench/browser/parts/views/panelViewlet'; +import { IMenu, MenuId, IMenuService, MenuItemAction } from 'vs/platform/actions/common/actions'; +import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { MenuItemActionItem } from 'vs/platform/actions/browser/menuItemActionItem'; +import { INotificationService } from 'vs/platform/notification/common/notification'; export class DebugViewlet extends ViewContainerViewlet { @@ -35,6 +39,7 @@ export class DebugViewlet extends ViewContainerViewlet { private breakpointView: ViewletPanel; private panelListeners = new Map(); private allActions: AbstractDebugAction[] = []; + private debugToolbarMenu: IMenu; constructor( @IPartService partService: IPartService, @@ -50,6 +55,9 @@ export class DebugViewlet extends ViewContainerViewlet { @IConfigurationService configurationService: IConfigurationService, @IKeybindingService private readonly keybindingService: IKeybindingService, @IContextViewService private readonly contextViewService: IContextViewService, + @IMenuService private readonly menuService: IMenuService, + @IContextKeyService private readonly contextKeyService: IContextKeyService, + @INotificationService private readonly notificationService: INotificationService ) { super(VIEWLET_ID, `${VIEWLET_ID}.state`, false, configurationService, partService, telemetryService, storageService, instantiationService, themeService, contextMenuService, extensionService, contextService); @@ -102,7 +110,11 @@ export class DebugViewlet extends ViewContainerViewlet { return [this.startAction, this.configureAction, this.toggleReplAction]; } - return DebugToolbar.getActions(this.allActions, this.toDispose, this.debugService, this.keybindingService, this.instantiationService); + if (!this.debugToolbarMenu) { + this.debugToolbarMenu = this.menuService.createMenu(MenuId.DebugToolbar, this.contextKeyService); + this.toDispose.push(this.debugToolbarMenu); + } + return DebugToolbar.getActions(this.debugToolbarMenu, this.allActions, this.toDispose, this.debugService, this.keybindingService, this.instantiationService); } get showInitialDebugActions(): boolean { @@ -126,6 +138,9 @@ export class DebugViewlet extends ViewContainerViewlet { if (action.id === FocusSessionAction.ID) { return new FocusSessionActionItem(action, this.debugService, this.themeService, this.contextViewService); } + if (action instanceof MenuItemAction) { + return new MenuItemActionItem(action, this.keybindingService, this.notificationService, this.contextMenuService); + } return null; } -- GitLab