提交 6dbb27e6 编写于 作者: J Johannes Rieken

debt - make actions return a Thenable

上级 01c138cd
......@@ -9,7 +9,6 @@ import 'vs/css!./actionbar';
import * as platform from 'vs/base/common/platform';
import * as nls from 'vs/nls';
import { Disposable, dispose } from 'vs/base/common/lifecycle';
import { TPromise } from 'vs/base/common/winjs.base';
import { SelectBox, ISelectBoxOptions } from 'vs/base/browser/ui/selectBox/selectBox';
import { IAction, IActionRunner, Action, IActionChangeEvent, ActionRunner, IRunEvent } from 'vs/base/common/actions';
import * as DOM from 'vs/base/browser/dom';
......@@ -737,7 +736,7 @@ export class ActionBar extends Disposable implements IActionRunner {
this._onDidCancel.fire();
}
run(action: IAction, context?: any): TPromise<void> {
run(action: IAction, context?: any): Thenable<void> {
return this._actionRunner.run(action, context);
}
......@@ -798,4 +797,4 @@ export class SelectActionItem extends BaseActionItem {
render(container: HTMLElement): void {
this.selectBox.render(container);
}
}
\ No newline at end of file
}
......@@ -4,10 +4,9 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { IDisposable, combinedDisposable, Disposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
import { isThenable } from 'vs/base/common/async';
export interface ITelemetryData {
from?: string;
......@@ -23,11 +22,11 @@ export interface IAction extends IDisposable {
enabled: boolean;
checked: boolean;
radio: boolean;
run(event?: any): TPromise<any>;
run(event?: any): Thenable<any>;
}
export interface IActionRunner extends IDisposable {
run(action: IAction, context?: any): TPromise<any>;
run(action: IAction, context?: any): Thenable<any>;
onDidRun: Event<IRunEvent>;
onDidBeforeRun: Event<IRunEvent>;
}
......@@ -63,9 +62,9 @@ export class Action implements IAction {
protected _enabled: boolean;
protected _checked: boolean;
protected _radio: boolean;
protected _actionCallback: (event?: any) => TPromise<any>;
protected _actionCallback: (event?: any) => Thenable<any>;
constructor(id: string, label: string = '', cssClass: string = '', enabled: boolean = true, actionCallback?: (event?: any) => TPromise<any>) {
constructor(id: string, label: string = '', cssClass: string = '', enabled: boolean = true, actionCallback?: (event?: any) => Thenable<any>) {
this._id = id;
this._label = label;
this._cssClass = cssClass;
......@@ -167,12 +166,12 @@ export class Action implements IAction {
}
}
run(event?: any, data?: ITelemetryData): TPromise<any> {
run(event?: any, data?: ITelemetryData): Thenable<any> {
if (this._actionCallback !== void 0) {
return this._actionCallback(event);
}
return TPromise.as(true);
return Promise.resolve(true);
}
dispose() {
......@@ -194,9 +193,9 @@ export class ActionRunner extends Disposable implements IActionRunner {
private _onDidRun = this._register(new Emitter<IRunEvent>());
get onDidRun(): Event<IRunEvent> { return this._onDidRun.event; }
run(action: IAction, context?: any): TPromise<any> {
run(action: IAction, context?: any): Thenable<any> {
if (!action.enabled) {
return TPromise.as(null);
return Promise.resolve(null);
}
this._onDidBeforeRun.fire({ action: action });
......@@ -208,14 +207,9 @@ export class ActionRunner extends Disposable implements IActionRunner {
});
}
protected runAction(action: IAction, context?: any): TPromise<any> {
protected runAction(action: IAction, context?: any): Thenable<any> {
const res = context ? action.run(context) : action.run();
if (isThenable(res)) {
return res;
}
return TPromise.wrap(res);
return Promise.resolve(res);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册