Skip to content

Commit

Permalink
Make debug toolbar customisable
Browse files Browse the repository at this point in the history
fixes #45116
  • Loading branch information
isidorn committed Feb 21, 2019
1 parent beabc81 commit b4d581b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const enum MenuId {
DebugConsoleContext,
DebugVariablesContext,
DebugWatchContext,
DebugToolbar,
EditorContext,
EditorTitle,
EditorTitleContext,
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/menusExtensionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 27 additions & 10 deletions src/vs/workbench/contrib/debug/browser/debugToolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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);

Expand All @@ -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, {
Expand All @@ -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;
}
Expand All @@ -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 });
Expand Down Expand Up @@ -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));
Expand All @@ -264,15 +276,14 @@ 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));
}

const state = debugService.state;
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;
}
Expand All @@ -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 {
Expand Down
17 changes: 16 additions & 1 deletion src/vs/workbench/contrib/debug/browser/debugViewlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

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

constructor(
@IPartService partService: IPartService,
Expand All @@ -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);

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down

0 comments on commit b4d581b

Please sign in to comment.