diff --git a/src/vs/platform/progress/common/progress.ts b/src/vs/platform/progress/common/progress.ts index 7d223123221d8badbcfa458e98b3ec24a758a96d..9fbe62637a15092eae19bb609a6bb26b37fa7f42 100644 --- a/src/vs/platform/progress/common/progress.ts +++ b/src/vs/platform/progress/common/progress.ts @@ -62,7 +62,7 @@ export interface IProgressService2 { _serviceBrand: any; - withWindowProgress(task: (progress: IProgress) => TPromise): void; + withWindowProgress(title: string, task: (progress: IProgress) => TPromise): void; withViewletProgress(viewletId: string, task: (progress: IProgress) => TPromise): void; } diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 58357e25af928ef694af9e416f01ae2faee20e8c..b079e68d109345d3bacb299b6d855863582dc7d0 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -27,7 +27,7 @@ declare module 'vscode' { * * @param task A function callback that represents a long running operation. */ - export function withWindowProgress(task: (progress: Progress, token: CancellationToken) => Thenable): Thenable; + export function withWindowProgress(title: string, task: (progress: Progress, token: CancellationToken) => Thenable): Thenable; export function withScmProgress(task: (progress: Progress) => Thenable): Thenable; diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 2f9a3b3cc426d265b67469884b911c683940c376..fe24d01158c2f4f82f264d4a83c514a3896a9c1c 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -308,10 +308,10 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ setStatusBarMessage(text: string, timeoutOrThenable?: number | Thenable): vscode.Disposable { return extHostStatusBar.setStatusBarMessage(text, timeoutOrThenable); }, - withWindowProgress: proposedApiFunction(extension, (task: (progress: vscode.Progress, token: vscode.CancellationToken) => Thenable): Thenable => { - return extHostProgress.withWindowProgress(extension, task); + withWindowProgress: proposedApiFunction(extension, (title: string, task: (progress: vscode.Progress, token: vscode.CancellationToken) => Thenable): Thenable => { + return extHostProgress.withWindowProgress(extension, title, task); }), - withScmProgress: proposedApiFunction(extension, (task: (progress: vscode.Progress) => Thenable) => { + withScmProgress: proposedApiFunction(extension, (task: (progress: vscode.Progress) => Thenable) => { return extHostProgress.withScmProgress(extension, task); }), createOutputChannel(name: string): vscode.OutputChannel { diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index be1ff89665312229527ed428f7d50f5b91140524..6b9ea8b2260de256acdff5e262258fbf28eeacac 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -186,7 +186,9 @@ export abstract class MainThreadOutputServiceShape { } export abstract class MainThreadProgressShape { - $progressStart(handle: number, extensionId: string, location: string): void { throw ni(); } + + $startWindow(handle: number, title: string): void { throw ni(); }; + $startScm(handle: number): void { throw ni(); }; $progressReport(handle: number, message: string): void { throw ni(); } $progressEnd(handle: number): void { throw ni(); } } diff --git a/src/vs/workbench/api/node/extHostProgress.ts b/src/vs/workbench/api/node/extHostProgress.ts index 63f5f6f791bf9297193eb78d32fafc91aacb6583..3d0b2b42e1a5703c2f0e2d788d305709475167cb 100644 --- a/src/vs/workbench/api/node/extHostProgress.ts +++ b/src/vs/workbench/api/node/extHostProgress.ts @@ -17,18 +17,20 @@ export class ExtHostProgress { this._proxy = proxy; } - withWindowProgress(extension: IExtensionDescription, task: (progress: Progress, token: CancellationToken) => Thenable): Thenable { - return this._withProgress(extension, 'window', task); + withWindowProgress(extension: IExtensionDescription, title: string, task: (progress: Progress, token: CancellationToken) => Thenable): Thenable { + const handle = this._handles++; + this._proxy.$startWindow(handle, title); + return this._withProgress(handle, task); } withScmProgress(extension: IExtensionDescription, task: (progress: Progress) => Thenable): Thenable { - return this._withProgress(extension, 'scm', task); + const handle = this._handles++; + this._proxy.$startScm(handle); + return this._withProgress(handle, task); } - private _withProgress(extension: IExtensionDescription, type: string, task: (progress: Progress, token: CancellationToken) => Thenable): Thenable { - const handle = this._handles++; + private _withProgress(handle: number, task: (progress: Progress, token: CancellationToken) => Thenable): Thenable { - this._proxy.$progressStart(handle, extension.id, type); const progress = { report: (message: string) => { this._proxy.$progressReport(handle, message); diff --git a/src/vs/workbench/api/node/mainThreadProgress.ts b/src/vs/workbench/api/node/mainThreadProgress.ts index 5d35ba4ef854f59dfdf484d57a6f8bf829832d34..10f91b4720f76a802e8d433caea212eb98472c0f 100644 --- a/src/vs/workbench/api/node/mainThreadProgress.ts +++ b/src/vs/workbench/api/node/mainThreadProgress.ts @@ -21,23 +21,22 @@ export class MainThreadProgress extends MainThreadProgressShape { } - $progressStart(handle: number, extensionId: string, where: string): void { + $startWindow(handle: number, title: string): void { + const task = this._createTask(handle); + this._progressService.withWindowProgress(title, task); + } + + $startScm(handle: number): void { + const task = this._createTask(handle); + this._progressService.withViewletProgress('workbench.view.scm', task); + } - const task = (progress: IProgress) => { + private _createTask(handle: number) { + return (progress: IProgress) => { return new TPromise(resolve => { this.progress.set(handle, { resolve, progress }); }); }; - - switch (where) { - case 'window': - this._progressService.withWindowProgress(task); - break; - case 'scm': - this._progressService.withViewletProgress('workbench.view.scm', task); - break; - } - } $progressReport(handle: number, message: any): void { diff --git a/src/vs/workbench/services/progress/browser/progressService2.ts b/src/vs/workbench/services/progress/browser/progressService2.ts index 415002927d7e2dd1f42d82800085421e67095e38..e8268fa469ef00f1530a23f3ea352c60632ae58c 100644 --- a/src/vs/workbench/services/progress/browser/progressService2.ts +++ b/src/vs/workbench/services/progress/browser/progressService2.ts @@ -48,12 +48,17 @@ class WindowProgressItem implements IStatusbarItem { } } +interface IWindowProgressTask { + title: string; + progress: Progress; +} + export class ProgressService2 implements IProgressService2 { _serviceBrand: any; - private _stack: Progress[] = []; + private _stack: IWindowProgressTask[] = []; constructor( @IActivityBarService private _activityBar: IActivityBarService, @@ -62,15 +67,19 @@ export class ProgressService2 implements IProgressService2 { // } - withWindowProgress(task: (progress: IProgress) => TPromise): void { + withWindowProgress(title: string, callback: (progress: IProgress) => TPromise): void { + + const task = { + progress: new Progress(() => this._updateProgress()), + title + }; - const progress = new Progress(() => this._updateProgress()); - this._stack.unshift(progress); + this._stack.unshift(task); - const promise = task(progress); + const promise = callback(task.progress); always(promise, () => { - const idx = this._stack.indexOf(progress); + const idx = this._stack.indexOf(task); this._stack.splice(idx, 1); this._updateProgress(); }); @@ -80,8 +89,9 @@ export class ProgressService2 implements IProgressService2 { if (this._stack.length === 0) { WindowProgressItem.Instance.hide(); } else { + const {title, progress} = this._stack[0]; + WindowProgressItem.Instance.text = progress.value || title; WindowProgressItem.Instance.show(); - WindowProgressItem.Instance.text = this._stack[0].value; } }