mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-27 15:20:30 -04:00
Merge from master
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import * as types from 'vs/base/common/types';
|
||||
import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar';
|
||||
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
|
||||
@@ -16,7 +15,7 @@ interface ProgressState {
|
||||
total?: number;
|
||||
worked?: number;
|
||||
done?: boolean;
|
||||
whilePromise?: TPromise<any>;
|
||||
whilePromise?: Thenable<any>;
|
||||
whileStart?: number;
|
||||
whileDelay?: number;
|
||||
}
|
||||
@@ -31,7 +30,7 @@ export abstract class ScopedService extends Disposable {
|
||||
|
||||
registerListeners(): void {
|
||||
this._register(this.viewletService.onDidViewletOpen(viewlet => this.onScopeOpened(viewlet.getId())));
|
||||
this._register(this.panelService.onDidPanelOpen(panel => this.onScopeOpened(panel.getId())));
|
||||
this._register(this.panelService.onDidPanelOpen(({ panel }) => this.onScopeOpened(panel.getId())));
|
||||
|
||||
this._register(this.viewletService.onDidViewletClose(viewlet => this.onScopeClosed(viewlet.getId())));
|
||||
this._register(this.panelService.onDidPanelClose(panel => this.onScopeClosed(panel.getId())));
|
||||
@@ -206,7 +205,7 @@ export class ScopedProgressService extends ScopedService implements IProgressSer
|
||||
};
|
||||
}
|
||||
|
||||
showWhile(promise: TPromise<any>, delay?: number): TPromise<void> {
|
||||
showWhile(promise: Thenable<any>, delay?: number): Thenable<void> {
|
||||
let stack: boolean = !!this.progressState.whilePromise;
|
||||
|
||||
// Reset State
|
||||
@@ -216,7 +215,7 @@ export class ScopedProgressService extends ScopedService implements IProgressSer
|
||||
|
||||
// Otherwise join with existing running promise to ensure progress is accurate
|
||||
else {
|
||||
promise = TPromise.join([promise, this.progressState.whilePromise]);
|
||||
promise = Promise.all([promise, this.progressState.whilePromise]);
|
||||
}
|
||||
|
||||
// Keep Promise in State
|
||||
@@ -287,7 +286,7 @@ export class ProgressService implements IProgressService {
|
||||
};
|
||||
}
|
||||
|
||||
showWhile(promise: TPromise<any>, delay?: number): TPromise<void> {
|
||||
showWhile(promise: Thenable<any>, delay?: number): Thenable<void> {
|
||||
const stop = () => {
|
||||
this.progressbar.stop().hide();
|
||||
};
|
||||
@@ -296,4 +295,4 @@ export class ProgressService implements IProgressService {
|
||||
|
||||
return promise.then(stop, stop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,102 +2,43 @@
|
||||
* 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 'vs/css!./media/progressService2';
|
||||
import * as dom from 'vs/base/browser/dom';
|
||||
|
||||
import { localize } from 'vs/nls';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IProgressService2, IProgressOptions, IProgressStep, ProgressLocation } from 'vs/workbench/services/progress/common/progress';
|
||||
import { IProgress, emptyProgress, Progress } from 'vs/platform/progress/common/progress';
|
||||
import { IProgressService2, IProgressOptions, IProgressStep, ProgressLocation, IProgress, emptyProgress, Progress } from 'vs/platform/progress/common/progress';
|
||||
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
|
||||
import { OcticonLabel } from 'vs/base/browser/ui/octiconLabel/octiconLabel';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { StatusbarAlignment, IStatusbarRegistry, StatusbarItemDescriptor, Extensions, IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { StatusbarAlignment, IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
|
||||
import { always, timeout } from 'vs/base/common/async';
|
||||
import { ProgressBadge, IActivityService } from 'vs/workbench/services/activity/common/activity';
|
||||
import { INotificationService, Severity, INotificationHandle, INotificationActions } from 'vs/platform/notification/common/notification';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import { once } from 'vs/base/common/event';
|
||||
import { ViewContainer } from 'vs/workbench/common/views';
|
||||
|
||||
class WindowProgressItem implements IStatusbarItem {
|
||||
|
||||
static Instance: WindowProgressItem;
|
||||
|
||||
private _element: HTMLElement;
|
||||
private _label: OcticonLabel;
|
||||
|
||||
constructor() {
|
||||
WindowProgressItem.Instance = this;
|
||||
}
|
||||
|
||||
render(element: HTMLElement): IDisposable {
|
||||
this._element = element;
|
||||
this._element.classList.add('progress');
|
||||
|
||||
const container = document.createElement('span');
|
||||
this._element.appendChild(container);
|
||||
|
||||
const spinnerContainer = document.createElement('span');
|
||||
spinnerContainer.classList.add('spinner-container');
|
||||
container.appendChild(spinnerContainer);
|
||||
|
||||
const spinner = new OcticonLabel(spinnerContainer);
|
||||
spinner.text = '$(sync~spin)';
|
||||
|
||||
const labelContainer = document.createElement('span');
|
||||
container.appendChild(labelContainer);
|
||||
|
||||
this._label = new OcticonLabel(labelContainer);
|
||||
|
||||
this.hide();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
set text(value: string) {
|
||||
this._label.text = value;
|
||||
}
|
||||
|
||||
set title(value: string) {
|
||||
this._label.title = value;
|
||||
}
|
||||
|
||||
hide() {
|
||||
dom.hide(this._element);
|
||||
}
|
||||
|
||||
show() {
|
||||
dom.show(this._element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class ProgressService2 implements IProgressService2 {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
private _stack: [IProgressOptions, Progress<IProgressStep>][] = [];
|
||||
private readonly _stack: [IProgressOptions, Progress<IProgressStep>][] = [];
|
||||
private _globalStatusEntry: IDisposable;
|
||||
|
||||
constructor(
|
||||
@IActivityService private readonly _activityBar: IActivityService,
|
||||
@IViewletService private readonly _viewletService: IViewletService,
|
||||
@INotificationService private readonly _notificationService: INotificationService
|
||||
) {
|
||||
//
|
||||
}
|
||||
@INotificationService private readonly _notificationService: INotificationService,
|
||||
@IStatusbarService private readonly _statusbarService: IStatusbarService,
|
||||
) { }
|
||||
|
||||
withProgress<P extends Thenable<R>, R=any>(options: IProgressOptions, task: (progress: IProgress<IProgressStep>) => P, onDidCancel?: () => void): P {
|
||||
|
||||
const { location } = options;
|
||||
if (location instanceof ViewContainer) {
|
||||
const viewlet = this._viewletService.getViewlet(location.id);
|
||||
if (typeof location === 'string') {
|
||||
const viewlet = this._viewletService.getViewlet(location);
|
||||
if (viewlet) {
|
||||
return this._withViewletProgress(location.id, task);
|
||||
return this._withViewletProgress(location, task);
|
||||
}
|
||||
console.warn(`Bad progress location: ${location.id}`);
|
||||
console.warn(`Bad progress location: ${location}`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -147,9 +88,11 @@ export class ProgressService2 implements IProgressService2 {
|
||||
}
|
||||
|
||||
private _updateWindowProgress(idx: number = 0) {
|
||||
if (idx >= this._stack.length) {
|
||||
WindowProgressItem.Instance.hide();
|
||||
} else {
|
||||
|
||||
dispose(this._globalStatusEntry);
|
||||
|
||||
if (idx < this._stack.length) {
|
||||
|
||||
const [options, progress] = this._stack[idx];
|
||||
|
||||
let progressTitle = options.title;
|
||||
@@ -178,9 +121,10 @@ export class ProgressService2 implements IProgressService2 {
|
||||
return;
|
||||
}
|
||||
|
||||
WindowProgressItem.Instance.text = text;
|
||||
WindowProgressItem.Instance.title = title;
|
||||
WindowProgressItem.Instance.show();
|
||||
this._globalStatusEntry = this._statusbarService.addEntry({
|
||||
text: `$(sync~spin) ${text}`,
|
||||
tooltip: title
|
||||
}, StatusbarAlignment.LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,12 +143,12 @@ export class ProgressService2 implements IProgressService2 {
|
||||
super('progress.cancel', localize('cancel', "Cancel"), null, true);
|
||||
}
|
||||
|
||||
run(): TPromise<any> {
|
||||
run(): Thenable<any> {
|
||||
if (typeof onDidCancel === 'function') {
|
||||
onDidCancel();
|
||||
}
|
||||
|
||||
return TPromise.as(undefined);
|
||||
return Promise.resolve(void 0);
|
||||
}
|
||||
};
|
||||
toDispose.push(cancelAction);
|
||||
@@ -286,7 +230,7 @@ export class ProgressService2 implements IProgressService2 {
|
||||
// show in viewlet
|
||||
const viewletProgress = this._viewletService.getProgressIndicator(viewletId);
|
||||
if (viewletProgress) {
|
||||
viewletProgress.showWhile(TPromise.wrap(promise));
|
||||
viewletProgress.showWhile(promise);
|
||||
}
|
||||
|
||||
// show activity bar
|
||||
@@ -324,8 +268,3 @@ export class ProgressService2 implements IProgressService2 {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Registry.as<IStatusbarRegistry>(Extensions.Statusbar).registerStatusbarItem(
|
||||
new StatusbarItemDescriptor(WindowProgressItem, StatusbarAlignment.LEFT)
|
||||
);
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IProgress } from 'vs/platform/progress/common/progress';
|
||||
import { ViewContainer } from 'vs/workbench/common/views';
|
||||
|
||||
export enum ProgressLocation {
|
||||
Explorer = 1,
|
||||
Scm = 3,
|
||||
Extensions = 5,
|
||||
Window = 10,
|
||||
Notification = 15
|
||||
}
|
||||
|
||||
export interface IProgressOptions {
|
||||
location: ProgressLocation | ViewContainer;
|
||||
title?: string;
|
||||
source?: string;
|
||||
total?: number;
|
||||
cancellable?: boolean;
|
||||
}
|
||||
|
||||
export interface IProgressStep {
|
||||
message?: string;
|
||||
increment?: number;
|
||||
}
|
||||
|
||||
export const IProgressService2 = createDecorator<IProgressService2>('progressService2');
|
||||
|
||||
export interface IProgressService2 {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
withProgress<P extends Thenable<R>, R=any>(options: IProgressOptions, task: (progress: IProgress<IProgressStep>) => P, onDidCancel?: () => void): P;
|
||||
}
|
||||
@@ -3,11 +3,8 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { IAction, IActionItem } from 'vs/base/common/actions';
|
||||
import { Promise, TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IEditorControl } from 'vs/workbench/common/editor';
|
||||
import { Viewlet, ViewletDescriptor } from 'vs/workbench/browser/viewlet';
|
||||
import { IPanel } from 'vs/workbench/common/panel';
|
||||
@@ -32,14 +29,18 @@ class TestViewletService implements IViewletService {
|
||||
onDidViewletClose = this.onDidViewletCloseEmitter.event;
|
||||
onDidViewletEnablementChange = this.onDidViewletEnableEmitter.event;
|
||||
|
||||
public openViewlet(id: string, focus?: boolean): TPromise<IViewlet> {
|
||||
return TPromise.as(null);
|
||||
public openViewlet(id: string, focus?: boolean): Promise<IViewlet> {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
public getViewlets(): ViewletDescriptor[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
public getAllViewlets(): ViewletDescriptor[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
public getActiveViewlet(): IViewlet {
|
||||
return activeViewlet;
|
||||
}
|
||||
@@ -64,17 +65,21 @@ class TestViewletService implements IViewletService {
|
||||
class TestPanelService implements IPanelService {
|
||||
public _serviceBrand: any;
|
||||
|
||||
onDidPanelOpen = new Emitter<IPanel>().event;
|
||||
onDidPanelOpen = new Emitter<{ panel: IPanel, focus: boolean }>().event;
|
||||
onDidPanelClose = new Emitter<IPanel>().event;
|
||||
|
||||
public openPanel(id: string, focus?: boolean): Promise {
|
||||
return TPromise.as(null);
|
||||
public openPanel(id: string, focus?: boolean): IPanel {
|
||||
return null;
|
||||
}
|
||||
|
||||
public getPanels(): any[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
public getPinnedPanels(): any[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
public getActivePanel(): IViewlet {
|
||||
return activeViewlet;
|
||||
}
|
||||
@@ -240,7 +245,7 @@ suite('Progress Service', () => {
|
||||
|
||||
});
|
||||
|
||||
test('WorkbenchProgressService', function () {
|
||||
test('WorkbenchProgressService', async () => {
|
||||
let testProgressBar = new TestProgressBar();
|
||||
let viewletService = new TestViewletService();
|
||||
let panelService = new TestPanelService();
|
||||
@@ -282,18 +287,14 @@ suite('Progress Service', () => {
|
||||
assert.strictEqual(80, testProgressBar.fTotal);
|
||||
|
||||
// Acive: Show While
|
||||
let p = TPromise.as(null);
|
||||
return service.showWhile(p).then(() => {
|
||||
assert.strictEqual(true, testProgressBar.fDone);
|
||||
|
||||
viewletService.onDidViewletCloseEmitter.fire(testViewlet);
|
||||
p = TPromise.as(null);
|
||||
return service.showWhile(p).then(() => {
|
||||
assert.strictEqual(true, testProgressBar.fDone);
|
||||
|
||||
viewletService.onDidViewletOpenEmitter.fire(testViewlet);
|
||||
assert.strictEqual(true, testProgressBar.fDone);
|
||||
});
|
||||
});
|
||||
let p = Promise.resolve(null);
|
||||
await service.showWhile(p);
|
||||
assert.strictEqual(true, testProgressBar.fDone);
|
||||
viewletService.onDidViewletCloseEmitter.fire(testViewlet);
|
||||
p = Promise.resolve(null);
|
||||
await service.showWhile(p);
|
||||
assert.strictEqual(true, testProgressBar.fDone);
|
||||
viewletService.onDidViewletOpenEmitter.fire(testViewlet);
|
||||
assert.strictEqual(true, testProgressBar.fDone);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user