From 712147afdbdd2a59e78397003f6c95bd8d888a0c Mon Sep 17 00:00:00 2001 From: isidor Date: Fri, 4 Nov 2016 11:49:35 +0100 Subject: [PATCH] debugActionsWidget: use action weights --- .../parts/debug/browser/debugActions.ts | 21 +++--- .../parts/debug/browser/debugActionsWidget.ts | 68 +++++++++---------- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/src/vs/workbench/parts/debug/browser/debugActions.ts b/src/vs/workbench/parts/debug/browser/debugActions.ts index 101eeeb5270..63cc182d0d3 100644 --- a/src/vs/workbench/parts/debug/browser/debugActions.ts +++ b/src/vs/workbench/parts/debug/browser/debugActions.ts @@ -34,7 +34,8 @@ export class AbstractDebugAction extends Action { constructor( id: string, label: string, cssClass: string, @IDebugService protected debugService: IDebugService, - @IKeybindingService protected keybindingService: IKeybindingService + @IKeybindingService protected keybindingService: IKeybindingService, + public weight?: number ) { super(id, label, cssClass, false); this.debugService = debugService; @@ -134,7 +135,7 @@ export class RestartAction extends AbstractDebugAction { static RECONNECT_LABEL = nls.localize('reconnectDebug', "Reconnect"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, 'debug-action restart', debugService, keybindingService); + super(id, label, 'debug-action restart', debugService, keybindingService, 70); this.setLabel(this.debugService.getViewModel().focusedProcess); this.toDispose.push(this.debugService.getViewModel().onDidFocusStackFrame(() => this.setLabel(this.debugService.getViewModel().focusedProcess))); } @@ -158,7 +159,7 @@ export class StepOverAction extends AbstractDebugAction { static LABEL = nls.localize('stepOverDebug', "Step Over"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, 'debug-action step-over', debugService, keybindingService); + super(id, label, 'debug-action step-over', debugService, keybindingService, 20); } public run(thread: debug.IThread): TPromise { @@ -179,7 +180,7 @@ export class StepIntoAction extends AbstractDebugAction { static LABEL = nls.localize('stepIntoDebug', "Step Into"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, 'debug-action step-into', debugService, keybindingService); + super(id, label, 'debug-action step-into', debugService, keybindingService, 30); } public run(thread: debug.IThread): TPromise { @@ -200,7 +201,7 @@ export class StepOutAction extends AbstractDebugAction { static LABEL = nls.localize('stepOutDebug', "Step Out"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, 'debug-action step-out', debugService, keybindingService); + super(id, label, 'debug-action step-out', debugService, keybindingService, 40); } public run(thread: debug.IThread): TPromise { @@ -221,7 +222,7 @@ export class StepBackAction extends AbstractDebugAction { static LABEL = nls.localize('stepBackDebug', "Step Back"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, 'debug-action step-back', debugService, keybindingService); + super(id, label, 'debug-action step-back', debugService, keybindingService, 50); } public run(thread: debug.IThread): TPromise { @@ -244,7 +245,7 @@ export class StopAction extends AbstractDebugAction { static LABEL = nls.localize('stopDebug', "Stop"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, 'debug-action stop', debugService, keybindingService); + super(id, label, 'debug-action stop', debugService, keybindingService, 80); } public run(): TPromise { @@ -262,7 +263,7 @@ export class DisconnectAction extends AbstractDebugAction { static LABEL = nls.localize('disconnectDebug', "Disconnect"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, 'debug-action disconnect', debugService, keybindingService); + super(id, label, 'debug-action disconnect', debugService, keybindingService, 80); } public run(): TPromise { @@ -280,7 +281,7 @@ export class ContinueAction extends AbstractDebugAction { static LABEL = nls.localize('continueDebug', "Continue"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, 'debug-action continue', debugService, keybindingService); + super(id, label, 'debug-action continue', debugService, keybindingService, 10); } public run(thread: debug.IThread): TPromise { @@ -301,7 +302,7 @@ export class PauseAction extends AbstractDebugAction { static LABEL = nls.localize('pauseDebug', "Pause"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, 'debug-action pause', debugService, keybindingService); + super(id, label, 'debug-action pause', debugService, keybindingService, 10); } public run(thread: debug.IThread): TPromise { diff --git a/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts b/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts index cefa39b267b..c81e219bdde 100644 --- a/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts +++ b/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts @@ -16,7 +16,7 @@ import { ActionBar, ActionsOrientation } from 'vs/base/browser/ui/actionbar/acti import { IPartService } from 'vs/workbench/services/part/common/partService'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import * as debug from 'vs/workbench/parts/debug/common/debug'; -import { PauseAction, ContinueAction, StepBackAction, StopAction, DisconnectAction, StepOverAction, StepIntoAction, StepOutAction, RestartAction } from 'vs/workbench/parts/debug/browser/debugActions'; +import { AbstractDebugAction, PauseAction, ContinueAction, StepBackAction, StopAction, DisconnectAction, StepOverAction, StepIntoAction, StepOutAction, RestartAction } from 'vs/workbench/parts/debug/browser/debugActions'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; import { IMessageService } from 'vs/platform/message/common/message'; @@ -34,12 +34,7 @@ export class DebugActionsWidget implements IWorkbenchContribution { private dragArea: builder.Builder; private toDispose: lifecycle.IDisposable[]; private actionBar: ActionBar; - private actions: IAction[]; - private pauseAction: PauseAction; - private continueAction: ContinueAction; - private stepBackAction: StepBackAction; - private stopAction: StopAction; - private disconnectAction: DisconnectAction; + private actions: AbstractDebugAction[]; private isVisible: boolean; private isBuilt: boolean; @@ -139,7 +134,7 @@ export class DebugActionsWidget implements IWorkbenchContribution { } this.actionBar.clear(); - this.actionBar.push(this.getActions(this.instantiationService, this.debugService.state), { icon: true, label: false }); + this.actionBar.push(this.getActions(), { icon: true, label: false }); this.show(); } @@ -162,43 +157,46 @@ export class DebugActionsWidget implements IWorkbenchContribution { this.$el.hide(); } - private getActions(instantiationService: IInstantiationService, state: debug.State): IAction[] { + private getActions(): IAction[] { if (!this.actions) { - this.continueAction = instantiationService.createInstance(ContinueAction, ContinueAction.ID, ContinueAction.LABEL); - this.pauseAction = instantiationService.createInstance(PauseAction, PauseAction.ID, PauseAction.LABEL); - this.stopAction = instantiationService.createInstance(StopAction, StopAction.ID, StopAction.LABEL); - this.disconnectAction = instantiationService.createInstance(DisconnectAction, DisconnectAction.ID, DisconnectAction.LABEL); - this.actions = [ - this.continueAction, - instantiationService.createInstance(StepOverAction, StepOverAction.ID, StepOverAction.LABEL), - instantiationService.createInstance(StepIntoAction, StepIntoAction.ID, StepIntoAction.LABEL), - instantiationService.createInstance(StepOutAction, StepOutAction.ID, StepOutAction.LABEL), - instantiationService.createInstance(RestartAction, RestartAction.ID, RestartAction.LABEL), - this.stopAction - ]; - + this.actions = []; + this.actions.push(this.instantiationService.createInstance(ContinueAction, ContinueAction.ID, ContinueAction.LABEL)); + this.actions.push(this.instantiationService.createInstance(PauseAction, PauseAction.ID, PauseAction.LABEL)); + this.actions.push(this.instantiationService.createInstance(StopAction, StopAction.ID, StopAction.LABEL)); + this.actions.push(this.instantiationService.createInstance(DisconnectAction, DisconnectAction.ID, DisconnectAction.LABEL)); + this.actions.push(this.instantiationService.createInstance(StepOverAction, StepOverAction.ID, StepOverAction.LABEL)); + this.actions.push(this.instantiationService.createInstance(StepIntoAction, StepIntoAction.ID, StepIntoAction.LABEL)); + this.actions.push(this.instantiationService.createInstance(StepOutAction, StepOutAction.ID, StepOutAction.LABEL)); + this.actions.push(this.instantiationService.createInstance(RestartAction, RestartAction.ID, RestartAction.LABEL)); + this.actions.push(this.instantiationService.createInstance(StepBackAction, StepBackAction.ID, StepBackAction.LABEL)); this.actions.forEach(a => { this.toDispose.push(a); }); - this.toDispose.push(this.pauseAction); - this.toDispose.push(this.disconnectAction); } - this.actions[0] = state === debug.State.Running ? this.pauseAction : this.continueAction; + const state = this.debugService.state; const process = this.debugService.getViewModel().focusedProcess; - this.actions[5] = (process && !strings.equalsIgnoreCase(process.session.configuration.type, 'extensionHost') && process.session.requestType === debug.SessionRequestType.ATTACH) ? this.disconnectAction : this.stopAction; + const attached = process && !strings.equalsIgnoreCase(process.session.configuration.type, 'extensionHost') && process.session.requestType === debug.SessionRequestType.ATTACH; - if (process && process.session.configuration.capabilities.supportsStepBack) { - if (!this.stepBackAction) { - this.stepBackAction = instantiationService.createInstance(StepBackAction, StepBackAction.ID, StepBackAction.LABEL); - this.toDispose.push(this.stepBackAction); + return this.actions.filter(a => { + if (a.id === ContinueAction.ID) { + return state !== debug.State.Running; + } + if (a.id === PauseAction.ID) { + return state === debug.State.Running; + } + if (a.id === StepBackAction.ID) { + return process && process.session.configuration.capabilities.supportsStepBack; + } + if (a.id === DisconnectAction.ID) { + return attached; + } + if (a.id === StopAction.ID) { + return !attached; } - // Return a copy of this.actions containing stepBackAction - return [...this.actions.slice(0, 4), this.stepBackAction, ...this.actions.slice(4)]; - } else { - return this.actions; - } + return true; + }).sort((first, second) => first.weight - second.weight); } public dispose(): void { -- GitLab