expose a withScmViewletProgress-API

This commit is contained in:
Johannes Rieken
2017-01-16 18:11:12 +01:00
parent 1f102d1c37
commit 0c46df976e
4 changed files with 27 additions and 9 deletions

View File

@@ -185,7 +185,7 @@ export abstract class MainThreadOutputServiceShape {
}
export abstract class MainThreadProgressShape {
$progressStart(handle: number): void { throw ni(); }
$progressStart(handle: number, location: string): void { throw ni(); }
$progressReport(handle: number, message: string): void { throw ni(); }
$progressEnd(handle: number, err?: any): void { throw ni(); }
}

View File

@@ -17,9 +17,17 @@ export class ExtHostProgress {
}
withWindowProgress<R>(task: (progress: Progress<string>, token: CancellationToken) => Thenable<R>): Thenable<R> {
return this._withProgress('window', task);
}
withScmViewletProgress<R>(task: (progress: Progress<number>) => Thenable<R>): Thenable<R> {
return this._withProgress('scm', task);
}
private _withProgress<R>(type: string, task: (progress: Progress<any>, token: CancellationToken) => Thenable<R>): Thenable<R> {
const handle = this._handles++;
this._proxy.$progressStart(handle);
this._proxy.$progressStart(handle, type);
const progress = {
report: (message: string) => {
this._proxy.$progressReport(handle, message);

View File

@@ -4,14 +4,14 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IProgressService2 } from 'vs/platform/progress/common/progress';
import { IProgressService2, IProgress } from 'vs/platform/progress/common/progress';
import { TPromise } from 'vs/base/common/winjs.base';
import { MainThreadProgressShape } from './extHost.protocol';
export class MainThreadProgress extends MainThreadProgressShape {
private _progressService: IProgressService2;
private progress = new Map<number, { resolve: Function, reject: Function, progress: { report(m: string) } }>();
private progress = new Map<number, { resolve: Function, reject: Function, progress: IProgress<any> }>();
constructor(
@IProgressService2 progressService: IProgressService2
@@ -21,15 +21,25 @@ export class MainThreadProgress extends MainThreadProgressShape {
}
$progressStart(handle: number): void {
this._progressService.withWindowProgress(progress => {
$progressStart(handle: number, where: string): void {
const task = (progress: IProgress<any>) => {
return new TPromise<any>((resolve, reject) => {
this.progress.set(handle, { resolve, reject, progress });
});
});
};
switch (where) {
case 'window':
this._progressService.withWindowProgress(task);
break;
case 'scm':
this._progressService.withViewletProgress('workbench.view.git', task);
}
}
$progressReport(handle: number, message: string): void {
$progressReport(handle: number, message: any): void {
this.progress.get(handle).progress.report(message);
}