提交 13cf79ac 编写于 作者: I isidor

debug debt: debug service is no longer an event emitter

上级 238cc8ae
......@@ -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);
......
......@@ -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();
}
......
......@@ -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
});
}
......
......@@ -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);
}
}));
......
......@@ -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;
......
......@@ -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) => {
......
......@@ -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<IDebugService>(DEBUG_SERVICE_ID);
export interface IDebugService extends ee.IEventEmitter {
export interface IDebugService {
serviceId: ServiceIdentifier<any>;
/**
......@@ -281,6 +277,11 @@ export interface IDebugService extends ee.IEventEmitter {
*/
getState(): State;
/**
* Allows to register on debug state changes.
*/
onDidChangeState: Event<State>;
/**
* Gets the current configuration manager.
*/
......
......@@ -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);
......
......@@ -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<debug.State>;
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<debug.State>();
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<debug.State> {
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 {
......
......@@ -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<debug.State> {
return null;
}
public getConfigurationManager(): debug.IConfigurationManager {
return null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册