提交 b4d581b7 编写于 作者: I isidor

Make debug toolbar customisable

fixes #45116
上级 beabc815
......@@ -65,6 +65,7 @@ export const enum MenuId {
DebugConsoleContext,
DebugVariablesContext,
DebugWatchContext,
DebugToolbar,
EditorContext,
EditorTitle,
EditorTitleContext,
......
......@@ -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;
......
......@@ -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 {
......
......@@ -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<string, IDisposable>();
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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册