diff --git a/src/vs/workbench/parts/debug/browser/debugActionItems.ts b/src/vs/workbench/parts/debug/browser/debugActionItems.ts index a31a70085660a63d5b6efa1add0554c654e26b17..aaa9532e7e36b76e9591b88ddfd51bf9cb35667b 100644 --- a/src/vs/workbench/parts/debug/browser/debugActionItems.ts +++ b/src/vs/workbench/parts/debug/browser/debugActionItems.ts @@ -10,7 +10,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import dom = require('vs/base/browser/dom'); import { IAction } from 'vs/base/common/actions'; import { BaseActionItem } from 'vs/base/browser/ui/actionbar/actionbar'; -import { IDebugService, ServiceEvents, State } from 'vs/workbench/parts/debug/common/debug'; +import { IDebugService, State } from 'vs/workbench/parts/debug/common/debug'; import { IConfigurationService, ConfigurationServiceEventTypes } from 'vs/platform/configuration/common/configuration'; export class SelectConfigActionItem extends BaseActionItem { @@ -36,8 +36,8 @@ export class SelectConfigActionItem extends BaseActionItem { this.toDispose.push(dom.addStandardDisposableListener(this.select, 'change', (e) => { this.actionRunner.run(this._action, e.target.value).done(null, errors.onUnexpectedError); })); - this.toDispose.push(this.debugService.addListener2(ServiceEvents.STATE_CHANGED, () => { - this.select.disabled = this.debugService.getState() !== State.Inactive; + this.toDispose.push(this.debugService.onDidChangeState(state => { + this.select.disabled = state !== State.Inactive; })); this.toDispose.push(configurationService.addListener2(ConfigurationServiceEventTypes.UPDATED, e => { this.setOptions().done(null, errors.onUnexpectedError); diff --git a/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts b/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts index e1b603139b9f5632ac7af34a3da79f0443d1d33e..9db574c0348cc43a80e4d0d8f6ea2f51e4c3bd52 100644 --- a/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts +++ b/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts @@ -55,8 +55,8 @@ export class DebugActionsWidget implements wbext.IWorkbenchContribution { } private registerListeners(): void { - this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => { - this.onDebugStateChange(); + this.toDispose.push(this.debugService.onDidChangeState(state => { + this.onDebugStateChange(state); })); this.toDispose.push(this.actionBar.actionRunner.addListener2(events.EventType.RUN, (e: any) => { // check for error @@ -75,8 +75,7 @@ export class DebugActionsWidget implements wbext.IWorkbenchContribution { return DebugActionsWidget.ID; } - private onDebugStateChange(): void { - const state = this.debugService.getState(); + private onDebugStateChange(state: debug.State): void { if (state === debug.State.Disabled || state === debug.State.Inactive || state === debug.State.Initializing) { return this.hide(); } diff --git a/src/vs/workbench/parts/debug/browser/debugEditorContribution.ts b/src/vs/workbench/parts/debug/browser/debugEditorContribution.ts index 4b3a9eda1f3cd1b02f6c0e68f2012dfe8856bddb..4a4400d14ee8fc509020550f24460076eff70e44 100644 --- a/src/vs/workbench/parts/debug/browser/debugEditorContribution.ts +++ b/src/vs/workbench/parts/debug/browser/debugEditorContribution.ts @@ -111,7 +111,7 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution { this.toDispose.push(this.editor.addListener2(editorcommon.EventType.MouseLeave, (e: editorbrowser.IEditorMouseEvent) => { this.ensureBreakpointHintDecoration(-1); })); - this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => this.onDebugStateUpdate())); + this.toDispose.push(this.debugService.onDidChangeState(state => this.onDebugStateUpdate(state))); // hover listeners & hover widget this.toDispose.push(this.editor.addListener2(editorcommon.EventType.MouseDown, (e: editorbrowser.IEditorMouseEvent) => this.onEditorMouseDown(e))); @@ -147,12 +147,12 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution { this.breakpointHintDecoration = this.editor.deltaDecorations(this.breakpointHintDecoration, newDecoration); } - private onDebugStateUpdate(): void { - if (this.debugService.getState() !== debug.State.Stopped) { + private onDebugStateUpdate(state: debug.State): void { + if (state !== debug.State.Stopped) { this.hideHoverWidget(); } this.contextService.updateOptions('editor', { - hover: this.debugService.getState() !== debug.State.Stopped + hover: state !== debug.State.Stopped }); } diff --git a/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts b/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts index 5eca74f6b6128675a6725e870291b56961d4eb89..0fb0077ad7eea0b2026b8bba495f7d5ec6998923 100644 --- a/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts +++ b/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts @@ -8,7 +8,7 @@ import objects = require('vs/base/common/objects'); import lifecycle = require('vs/base/common/lifecycle'); import editorcommon = require('vs/editor/common/editorCommon'); import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; -import { IDebugService, IBreakpoint, IRawBreakpoint, State, ServiceEvents } from 'vs/workbench/parts/debug/common/debug'; +import { IDebugService, IBreakpoint, IRawBreakpoint, State } from 'vs/workbench/parts/debug/common/debug'; import { IModelService } from 'vs/editor/common/services/modelService'; function toMap(arr: string[]): { [key: string]: boolean; } { @@ -82,8 +82,8 @@ export class DebugEditorModelManager implements IWorkbenchContribution { this.toDispose.push(this.debugService.getModel().onDidChangeBreakpoints(() => this.onBreakpointsChange())); this.toDispose.push(this.debugService.getViewModel().onDidFocusStackFrame(() => this.onFocusStackFrame())); - this.toDispose.push(this.debugService.addListener2(ServiceEvents.STATE_CHANGED, () => { - if (this.debugService.getState() === State.Inactive) { + this.toDispose.push(this.debugService.onDidChangeState(state => { + if (state === State.Inactive) { Object.keys(this.modelData).forEach(key => this.modelData[key].dirty = false); } })); diff --git a/src/vs/workbench/parts/debug/browser/debugViewlet.ts b/src/vs/workbench/parts/debug/browser/debugViewlet.ts index b3d5b3d0254dbe4d429a10cc931783f607b6dad8..9bc69cd2d5b4b036a06f74e99c102d7cf4830a1c 100644 --- a/src/vs/workbench/parts/debug/browser/debugViewlet.ts +++ b/src/vs/workbench/parts/debug/browser/debugViewlet.ts @@ -51,8 +51,8 @@ export class DebugViewlet extends Viewlet { this.progressRunner = null; this.viewletSettings = this.getMemento(storageService, memento.Scope.WORKSPACE); this.toDispose = []; - this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => { - this.onDebugServiceStateChange(); + this.toDispose.push(this.debugService.onDidChangeState((state) => { + this.onDebugServiceStateChange(state); })); } @@ -144,12 +144,12 @@ export class DebugViewlet extends Viewlet { return null; } - private onDebugServiceStateChange(): void { + private onDebugServiceStateChange(newState: debug.State): void { if (this.progressRunner) { this.progressRunner.done(); } - if (this.debugService.getState() === debug.State.Initializing) { + if (newState === debug.State.Initializing) { this.progressRunner = this.progressService.show(true); } else { this.progressRunner = null; diff --git a/src/vs/workbench/parts/debug/browser/debugViews.ts b/src/vs/workbench/parts/debug/browser/debugViews.ts index b87544a7017f0148bf65d1215f26780d6c37bdca..e943f9398cabf7df554b05c7eaaccfe05c06d849 100644 --- a/src/vs/workbench/parts/debug/browser/debugViews.ts +++ b/src/vs/workbench/parts/debug/browser/debugViews.ts @@ -83,8 +83,8 @@ export class VariablesView extends viewlet.CollapsibleViewletView { this.toolBar.setActions(actionbarregistry.prepareActions([collapseAction]))(); this.toDispose.push(viewModel.onDidFocusStackFrame(sf => this.onFocusStackFrame(sf))); - this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => { - collapseAction.enabled = this.debugService.getState() === debug.State.Running || this.debugService.getState() === debug.State.Stopped; + this.toDispose.push(this.debugService.onDidChangeState(state => { + collapseAction.enabled = state === debug.State.Running || state === debug.State.Stopped; })); this.toDispose.push(this.tree.addListener2(events.EventType.FOCUS, (e: tree.IFocusEvent) => { diff --git a/src/vs/workbench/parts/debug/common/debug.ts b/src/vs/workbench/parts/debug/common/debug.ts index 2714adde5e3363d5a50a443cc14c6500f79a2e71..ac6174d25c07f283fcfecd894c879c87bf0ffe60 100644 --- a/src/vs/workbench/parts/debug/common/debug.ts +++ b/src/vs/workbench/parts/debug/common/debug.ts @@ -134,10 +134,6 @@ export interface IExceptionBreakpoint extends IEnablement { label: string; } -export var ServiceEvents = { - STATE_CHANGED: 'StateChanged' -}; - export var SessionEvents = { INITIALIZED: 'initialized', STOPPED: 'stopped', @@ -273,7 +269,7 @@ export interface IConfigurationManager { export var IDebugService = createDecorator(DEBUG_SERVICE_ID); -export interface IDebugService extends ee.IEventEmitter { +export interface IDebugService { serviceId: ServiceIdentifier; /** @@ -281,6 +277,11 @@ export interface IDebugService extends ee.IEventEmitter { */ getState(): State; + /** + * Allows to register on debug state changes. + */ + onDidChangeState: Event; + /** * Gets the current configuration manager. */ diff --git a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts index 04810b2d729dd137fdf391aeea132961fb508b00..ea3378b2eef7066dfebdccd54f7c6b4b9c6c6f3b 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts @@ -35,7 +35,7 @@ export class AbstractDebugAction extends actions.Action { this.debugService = debugService; this.keybindingService = keybindingService; this.toDispose = []; - this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => this.updateEnablement())); + this.toDispose.push(this.debugService.onDidChangeState(() => this.updateEnablement())); const keys = this.keybindingService.lookupKeybindings(id).map(k => this.keybindingService.getLabelFor(k)); if (keys && keys.length) { @@ -134,7 +134,7 @@ export class RestartDebugAction extends AbstractDebugAction { constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { super(id, label, 'debug-action restart', debugService, keybindingService); this.updateEnablement(); - this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => { + this.toDispose.push(this.debugService.onDidChangeState(() => { const session = this.debugService.getActiveSession(); if (session) { this.updateLabel(session.isAttach ? RestartDebugAction.RECONNECT_LABEL : RestartDebugAction.LABEL); @@ -209,7 +209,7 @@ export class StopDebugAction extends AbstractDebugAction { constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { super(id, label, 'debug-action stop', debugService, keybindingService); - this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => { + this.toDispose.push(this.debugService.onDidChangeState(() => { const session = this.debugService.getActiveSession(); if (session) { this.updateLabel(session.isAttach ? StopDebugAction.DISCONNECT_LABEL : StopDebugAction.LABEL); diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index 2413499b664cd4043ce6e196a2f29f2cd667b762..deeb1ee11b33d52f5db6190b812ef431c9a0a7f1 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -6,7 +6,7 @@ import nls = require('vs/nls'); import lifecycle = require('vs/base/common/lifecycle'); import mime = require('vs/base/common/mime'); -import ee = require('vs/base/common/eventEmitter'); +import Event, { Emitter } from 'vs/base/common/event'; import uri from 'vs/base/common/uri'; import { Action } from 'vs/base/common/actions'; import arrays = require('vs/base/common/arrays'); @@ -56,10 +56,11 @@ const DEBUG_EXCEPTION_BREAKPOINTS_KEY = 'debug.exceptionbreakpoint'; const DEBUG_WATCH_EXPRESSIONS_KEY = 'debug.watchexpressions'; const DEBUG_SELECTED_CONFIG_NAME_KEY = 'debug.selectedconfigname'; -export class DebugService extends ee.EventEmitter implements debug.IDebugService { +export class DebugService implements debug.IDebugService { public serviceId = debug.IDebugService; private state: debug.State; + private _onDidChangeState: Emitter; private session: session.RawDebugSession; private model: model.Model; private viewModel: viewmodel.ViewModel; @@ -91,13 +92,12 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService @IMarkerService private markerService: IMarkerService, @ITaskService private taskService: ITaskService ) { - super(); - this.toDispose = []; this.toDisposeOnSessionEnd = []; this.debugStringEditorInputs = []; this.session = null; this.state = debug.State.Inactive; + this._onDidChangeState = new Emitter(); if (!this.contextService.getWorkspace()) { this.state = debug.State.Disabled; @@ -404,9 +404,13 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService return this.state; } + public get onDidChangeState(): Event { + return this._onDidChangeState.event; + } + private setStateAndEmit(newState: debug.State): void { this.state = newState; - this.emit(debug.ServiceEvents.STATE_CHANGED); + this._onDidChangeState.fire(newState); } public get enabled(): boolean { diff --git a/src/vs/workbench/parts/debug/test/common/mockDebugService.ts b/src/vs/workbench/parts/debug/test/common/mockDebugService.ts index c1bd5d07eed9766603665bab3c1e78c517ee4349..9975b52d85af5e6e59de1eaf5c04157df45da3a9 100644 --- a/src/vs/workbench/parts/debug/test/common/mockDebugService.ts +++ b/src/vs/workbench/parts/debug/test/common/mockDebugService.ts @@ -3,21 +3,21 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import debug = require('vs/workbench/parts/debug/common/debug'); -import editor = require('vs/editor/common/editorCommon'); +import Event from 'vs/base/common/event'; import ee = require('vs/base/common/eventEmitter'); import uri from 'vs/base/common/uri'; -import editorbrowser = require('vs/editor/browser/editorBrowser'); import severity from 'vs/base/common/severity'; import { TPromise } from 'vs/base/common/winjs.base'; +import editor = require('vs/editor/common/editorCommon'); +import editorbrowser = require('vs/editor/browser/editorBrowser'); +import debug = require('vs/workbench/parts/debug/common/debug'); import { Source } from 'vs/workbench/parts/debug/common/debugSource'; -export class MockDebugService extends ee.EventEmitter implements debug.IDebugService { +export class MockDebugService implements debug.IDebugService { private session: MockRawSession; public serviceId = debug.IDebugService; constructor() { - super(); this.session = new MockRawSession(); } @@ -25,6 +25,10 @@ export class MockDebugService extends ee.EventEmitter implements debug.IDebugSer return null; } + public get onDidChangeState(): Event { + return null; + } + public getConfigurationManager(): debug.IConfigurationManager { return null; }