提交 113d877e 编写于 作者: I isidor

debug: view model is no longer an EventEmitter

上级 dd7801f8
......@@ -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, ModelEvents, ViewModelEvents, IBreakpoint, IRawBreakpoint, State, ServiceEvents } from 'vs/workbench/parts/debug/common/debug';
import { IDebugService, ModelEvents, IBreakpoint, IRawBreakpoint, State, ServiceEvents } from 'vs/workbench/parts/debug/common/debug';
import { IModelService } from 'vs/editor/common/services/modelService';
function toMap(arr: string[]): { [key: string]: boolean; } {
......@@ -81,7 +81,7 @@ export class DebugEditorModelManager implements IWorkbenchContribution {
this.toDispose.push(this.modelService.onModelRemoved(this.onModelRemoved, this));
this.toDispose.push(this.debugService.getModel().addListener2(ModelEvents.BREAKPOINTS_UPDATED, () => this.onBreakpointsChanged()));
this.toDispose.push(this.debugService.getViewModel().addListener2(ViewModelEvents.FOCUSED_STACK_FRAME_UPDATED, () => this.onFocusedStackFrameUpdated()));
this.toDispose.push(this.debugService.getViewModel().onDidFocusStackFrame(() => this.onFocusStackFrame()));
this.toDispose.push(this.debugService.addListener2(ServiceEvents.STATE_CHANGED, () => {
if (this.debugService.getState() === State.Inactive) {
Object.keys(this.modelData).forEach(key => this.modelData[key].dirty = false);
......@@ -123,7 +123,7 @@ export class DebugEditorModelManager implements IWorkbenchContribution {
// call stack management. Represent data coming from the debug service.
private onFocusedStackFrameUpdated(): void {
private onFocusStackFrame(): void {
Object.keys(this.modelData).forEach(modelUrlStr => {
const modelData = this.modelData[modelUrlStr];
modelData.currentStackDecorations = modelData.model.deltaDecorations(modelData.currentStackDecorations, this.createCallStackDecorations(modelUrlStr));
......
......@@ -82,7 +82,7 @@ export class VariablesView extends viewlet.CollapsibleViewletView {
const collapseAction = this.instantiationService.createInstance(viewlet.CollapseAction, this.tree, false, 'explorer-action collapse-explorer');
this.toolBar.setActions(actionbarregistry.prepareActions([collapseAction]))();
this.toDispose.push(viewModel.addListener2(debug.ViewModelEvents.FOCUSED_STACK_FRAME_UPDATED, () => this.onFocusedStackFrameUpdated()));
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;
}));
......@@ -97,9 +97,8 @@ export class VariablesView extends viewlet.CollapsibleViewletView {
}));
}
private onFocusedStackFrameUpdated(): void {
private onFocusStackFrame(stackFrame: debug.IStackFrame): void {
this.tree.refresh().then(() => {
const stackFrame = this.debugService.getViewModel().getFocusedStackFrame();
if (stackFrame) {
return stackFrame.getScopes(this.debugService).then(scopes => {
if (scopes.length > 0) {
......@@ -162,7 +161,7 @@ export class WatchExpressionsView extends viewlet.CollapsibleViewletView {
this.toolBar.setActions(actionbarregistry.prepareActions([addWatchExpressionAction, collapseAction, removeAllWatchExpressionsAction]))();
this.toDispose.push(this.debugService.getModel().addListener2(debug.ModelEvents.WATCH_EXPRESSIONS_UPDATED, (we: model.Expression) => this.onWatchExpressionsUpdated(we)));
this.toDispose.push(this.debugService.getViewModel().addListener2(debug.ViewModelEvents.SELECTED_EXPRESSION_UPDATED, (expression: debug.IExpression) => {
this.toDispose.push(this.debugService.getViewModel().onDidSelectExpression(expression => {
if (!expression || !(expression instanceof model.Expression)) {
return;
}
......@@ -280,8 +279,8 @@ export class CallStackView extends viewlet.CollapsibleViewletView {
this.tree.refresh().done(null, errors.onUnexpectedError);
}));
this.toDispose.push(this.debugService.getViewModel().addListener2(debug.ViewModelEvents.FOCUSED_STACK_FRAME_UPDATED, () => {
const focussedThread = this.debugService.getModel().getThreads()[this.debugService.getViewModel().getFocusedThreadId()];
this.toDispose.push(this.debugService.getViewModel().onDidFocusStackFrame(sf => {
const focussedThread = sf ? this.debugService.getModel().getThreads()[sf.threadId] : null;
if (!focussedThread) {
this.pauseMessage.hide();
return;
......@@ -398,7 +397,7 @@ export class BreakpointsView extends viewlet.AdaptiveCollapsibleViewletView {
}
}));
this.toDispose.push(this.debugService.getViewModel().addListener2(debug.ViewModelEvents.SELECTED_FUNCTION_BREAKPOINT_UPDATED, (fbp: debug.IFunctionBreakpoint) => {
this.toDispose.push(this.debugService.getViewModel().onDidSelectFunctionBreakpoint(fbp => {
if (!fbp || !(fbp instanceof model.FunctionBreakpoint)) {
return;
}
......
......@@ -166,13 +166,17 @@ export var SessionEvents = {
// model interfaces
export interface IViewModel extends ee.EventEmitter {
export interface IViewModel {
getFocusedStackFrame(): IStackFrame;
getSelectedExpression(): IExpression;
getFocusedThreadId(): number;
setSelectedExpression(expression: IExpression);
getSelectedFunctionBreakpoint(): IFunctionBreakpoint;
setSelectedFunctionBreakpoint(functionBreakpoint: IFunctionBreakpoint): void;
onDidFocusStackFrame: Event<IStackFrame>;
onDidSelectExpression: Event<IExpression>;
onDidSelectFunctionBreakpoint: Event<IFunctionBreakpoint>;
}
export interface IModel extends ee.IEventEmitter, ITreeElement {
......@@ -281,6 +285,10 @@ export var IDebugService = createDecorator<IDebugService>(DEBUG_SERVICE_ID);
export interface IDebugService extends ee.IEventEmitter {
serviceId: ServiceIdentifier<any>;
/**
* Gets the current debug state.
*/
getState(): State;
/**
......
......@@ -2,14 +2,24 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import ee = require('vs/base/common/eventEmitter');
import Event, { Emitter } from 'vs/base/common/event';
import debug = require('vs/workbench/parts/debug/common/debug');
export class ViewModel extends ee.EventEmitter implements debug.IViewModel, debug.ITreeElement {
export class ViewModel implements debug.IViewModel, debug.ITreeElement {
private focusedStackFrame: debug.IStackFrame;
private selectedExpression: debug.IExpression;
private selectedFunctionBreakpoint: debug.IFunctionBreakpoint;
private _onDidFocusStackFrame: Emitter<debug.IStackFrame>;
private _onDidSelectExpression: Emitter<debug.IExpression>;
private _onDidSelectFunctionBreakpoint: Emitter<debug.IFunctionBreakpoint>;
constructor() {
this._onDidFocusStackFrame = new Emitter<debug.IStackFrame>();
this._onDidSelectExpression = new Emitter<debug.IExpression>();
this._onDidSelectFunctionBreakpoint = new Emitter<debug.IFunctionBreakpoint>();
}
public getId(): string {
return 'root';
......@@ -21,7 +31,11 @@ export class ViewModel extends ee.EventEmitter implements debug.IViewModel, debu
public setFocusedStackFrame(focusedStackFrame: debug.IStackFrame): void {
this.focusedStackFrame = focusedStackFrame;
this.emit(debug.ViewModelEvents.FOCUSED_STACK_FRAME_UPDATED);
this._onDidFocusStackFrame.fire(focusedStackFrame);
}
public get onDidFocusStackFrame(): Event<debug.IStackFrame> {
return this._onDidFocusStackFrame.event;
}
public getFocusedThreadId(): number {
......@@ -34,7 +48,11 @@ export class ViewModel extends ee.EventEmitter implements debug.IViewModel, debu
public setSelectedExpression(expression: debug.IExpression) {
this.selectedExpression = expression;
this.emit(debug.ViewModelEvents.SELECTED_EXPRESSION_UPDATED, expression);
this._onDidSelectExpression.fire(expression);
}
public get onDidSelectExpression(): Event<debug.IExpression> {
return this._onDidSelectExpression.event;
}
public getSelectedFunctionBreakpoint(): debug.IFunctionBreakpoint {
......@@ -43,6 +61,10 @@ export class ViewModel extends ee.EventEmitter implements debug.IViewModel, debu
public setSelectedFunctionBreakpoint(functionBreakpoint: debug.IFunctionBreakpoint): void {
this.selectedFunctionBreakpoint = functionBreakpoint;
this.emit(debug.ViewModelEvents.SELECTED_FUNCTION_BREAKPOINT_UPDATED, functionBreakpoint);
this._onDidSelectFunctionBreakpoint.fire(functionBreakpoint);
}
public get onDidSelectFunctionBreakpoint(): Event<debug.IFunctionBreakpoint> {
return this._onDidSelectFunctionBreakpoint.event;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册