mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-25 06:10:30 -04:00
Merge from master
This commit is contained in:
@@ -2,10 +2,8 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IDisposable, combinedDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, combinedDisposable, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
|
||||
export interface ITelemetryData {
|
||||
@@ -18,15 +16,15 @@ export interface IAction extends IDisposable {
|
||||
id: string;
|
||||
label: string;
|
||||
tooltip: string;
|
||||
class: string;
|
||||
class: string | undefined;
|
||||
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>;
|
||||
}
|
||||
@@ -53,17 +51,18 @@ export interface IActionChangeEvent {
|
||||
export class Action implements IAction {
|
||||
|
||||
protected _onDidChange = new Emitter<IActionChangeEvent>();
|
||||
readonly onDidChange: Event<IActionChangeEvent> = this._onDidChange.event;
|
||||
|
||||
protected _id: string;
|
||||
protected _label: string;
|
||||
protected _tooltip: string;
|
||||
protected _cssClass: string;
|
||||
protected _cssClass: string | undefined;
|
||||
protected _enabled: boolean;
|
||||
protected _checked: boolean;
|
||||
protected _radio: boolean;
|
||||
protected _order: number;
|
||||
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;
|
||||
@@ -71,23 +70,15 @@ export class Action implements IAction {
|
||||
this._actionCallback = actionCallback;
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
this._onDidChange.dispose();
|
||||
}
|
||||
|
||||
public get onDidChange(): Event<IActionChangeEvent> {
|
||||
return this._onDidChange.event;
|
||||
}
|
||||
|
||||
public get id(): string {
|
||||
get id(): string {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get label(): string {
|
||||
get label(): string {
|
||||
return this._label;
|
||||
}
|
||||
|
||||
public set label(value: string) {
|
||||
set label(value: string) {
|
||||
this._setLabel(value);
|
||||
}
|
||||
|
||||
@@ -98,11 +89,11 @@ export class Action implements IAction {
|
||||
}
|
||||
}
|
||||
|
||||
public get tooltip(): string {
|
||||
get tooltip(): string {
|
||||
return this._tooltip;
|
||||
}
|
||||
|
||||
public set tooltip(value: string) {
|
||||
set tooltip(value: string) {
|
||||
this._setTooltip(value);
|
||||
}
|
||||
|
||||
@@ -113,26 +104,26 @@ export class Action implements IAction {
|
||||
}
|
||||
}
|
||||
|
||||
public get class(): string {
|
||||
get class(): string | undefined {
|
||||
return this._cssClass;
|
||||
}
|
||||
|
||||
public set class(value: string) {
|
||||
set class(value: string | undefined) {
|
||||
this._setClass(value);
|
||||
}
|
||||
|
||||
protected _setClass(value: string): void {
|
||||
protected _setClass(value: string | undefined): void {
|
||||
if (this._cssClass !== value) {
|
||||
this._cssClass = value;
|
||||
this._onDidChange.fire({ class: value });
|
||||
}
|
||||
}
|
||||
|
||||
public get enabled(): boolean {
|
||||
get enabled(): boolean {
|
||||
return this._enabled;
|
||||
}
|
||||
|
||||
public set enabled(value: boolean) {
|
||||
set enabled(value: boolean) {
|
||||
this._setEnabled(value);
|
||||
}
|
||||
|
||||
@@ -143,19 +134,19 @@ export class Action implements IAction {
|
||||
}
|
||||
}
|
||||
|
||||
public get checked(): boolean {
|
||||
get checked(): boolean {
|
||||
return this._checked;
|
||||
}
|
||||
|
||||
public set checked(value: boolean) {
|
||||
set checked(value: boolean) {
|
||||
this._setChecked(value);
|
||||
}
|
||||
|
||||
public get radio(): boolean {
|
||||
get radio(): boolean {
|
||||
return this._radio;
|
||||
}
|
||||
|
||||
public set radio(value: boolean) {
|
||||
set radio(value: boolean) {
|
||||
this._setRadio(value);
|
||||
}
|
||||
|
||||
@@ -173,19 +164,16 @@ export class Action implements IAction {
|
||||
}
|
||||
}
|
||||
|
||||
public get order(): number {
|
||||
return this._order;
|
||||
}
|
||||
|
||||
public set order(value: number) {
|
||||
this._order = value;
|
||||
}
|
||||
|
||||
public run(event?: any, data?: ITelemetryData): TPromise<any> {
|
||||
if (this._actionCallback !== void 0) {
|
||||
run(event?: any, _data?: ITelemetryData): Thenable<any> {
|
||||
if (this._actionCallback) {
|
||||
return this._actionCallback(event);
|
||||
}
|
||||
return TPromise.as(true);
|
||||
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this._onDidChange.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,22 +183,17 @@ export interface IRunEvent {
|
||||
error?: any;
|
||||
}
|
||||
|
||||
export class ActionRunner implements IActionRunner {
|
||||
export class ActionRunner extends Disposable implements IActionRunner {
|
||||
|
||||
private _onDidBeforeRun = new Emitter<IRunEvent>();
|
||||
private _onDidRun = new Emitter<IRunEvent>();
|
||||
private _onDidBeforeRun = this._register(new Emitter<IRunEvent>());
|
||||
readonly onDidBeforeRun: Event<IRunEvent> = this._onDidBeforeRun.event;
|
||||
|
||||
public get onDidRun(): Event<IRunEvent> {
|
||||
return this._onDidRun.event;
|
||||
}
|
||||
private _onDidRun = this._register(new Emitter<IRunEvent>());
|
||||
readonly onDidRun: Event<IRunEvent> = this._onDidRun.event;
|
||||
|
||||
public get onDidBeforeRun(): Event<IRunEvent> {
|
||||
return this._onDidBeforeRun.event;
|
||||
}
|
||||
|
||||
public 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 });
|
||||
@@ -222,28 +205,18 @@ export class ActionRunner 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 (TPromise.is(res)) {
|
||||
return res;
|
||||
}
|
||||
|
||||
return TPromise.wrap(res);
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this._onDidBeforeRun.dispose();
|
||||
this._onDidRun.dispose();
|
||||
return Promise.resolve(res);
|
||||
}
|
||||
}
|
||||
|
||||
export class RadioGroup {
|
||||
|
||||
private _disposable: IDisposable;
|
||||
export class RadioGroup extends Disposable {
|
||||
|
||||
constructor(readonly actions: Action[]) {
|
||||
this._disposable = combinedDisposable(actions.map(action => {
|
||||
super();
|
||||
|
||||
this._register(combinedDisposable(actions.map(action => {
|
||||
return action.onDidChange(e => {
|
||||
if (e.checked && action.checked) {
|
||||
for (const candidate of actions) {
|
||||
@@ -253,10 +226,6 @@ export class RadioGroup {
|
||||
}
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._disposable.dispose();
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user