提交 23c4c8d1 编写于 作者: J Johannes Rieken

progress - make window progress get a title

上级 f5de1525
......@@ -62,7 +62,7 @@ export interface IProgressService2 {
_serviceBrand: any;
withWindowProgress(task: (progress: IProgress<string>) => TPromise<any>): void;
withWindowProgress(title: string, task: (progress: IProgress<string>) => TPromise<any>): void;
withViewletProgress(viewletId: string, task: (progress: IProgress<number>) => TPromise<any>): void;
}
......@@ -27,7 +27,7 @@ declare module 'vscode' {
*
* @param task A function callback that represents a long running operation.
*/
export function withWindowProgress<R>(task: (progress: Progress<string>, token: CancellationToken) => Thenable<R>): Thenable<R>;
export function withWindowProgress<R>(title: string, task: (progress: Progress<string>, token: CancellationToken) => Thenable<R>): Thenable<R>;
export function withScmProgress<R>(task: (progress: Progress<number>) => Thenable<R>): Thenable<R>;
......
......@@ -308,10 +308,10 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ
setStatusBarMessage(text: string, timeoutOrThenable?: number | Thenable<any>): vscode.Disposable {
return extHostStatusBar.setStatusBarMessage(text, timeoutOrThenable);
},
withWindowProgress: proposedApiFunction(extension, <R>(task: (progress: vscode.Progress<string>, token: vscode.CancellationToken) => Thenable<R>): Thenable<R> => {
return extHostProgress.withWindowProgress(extension, task);
withWindowProgress: proposedApiFunction(extension, <R>(title: string, task: (progress: vscode.Progress<string>, token: vscode.CancellationToken) => Thenable<R>): Thenable<R> => {
return extHostProgress.withWindowProgress(extension, title, task);
}),
withScmProgress: proposedApiFunction(extension, (task: (progress: vscode.Progress<number>) => Thenable<any>) => {
withScmProgress: proposedApiFunction(extension, <R>(task: (progress: vscode.Progress<number>) => Thenable<R>) => {
return extHostProgress.withScmProgress(extension, task);
}),
createOutputChannel(name: string): vscode.OutputChannel {
......
......@@ -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(); }
}
......
......@@ -17,18 +17,20 @@ export class ExtHostProgress {
this._proxy = proxy;
}
withWindowProgress<R>(extension: IExtensionDescription, task: (progress: Progress<string>, token: CancellationToken) => Thenable<R>): Thenable<R> {
return this._withProgress(extension, 'window', task);
withWindowProgress<R>(extension: IExtensionDescription, title: string, task: (progress: Progress<string>, token: CancellationToken) => Thenable<R>): Thenable<R> {
const handle = this._handles++;
this._proxy.$startWindow(handle, title);
return this._withProgress(handle, task);
}
withScmProgress<R>(extension: IExtensionDescription, task: (progress: Progress<number>) => Thenable<R>): Thenable<R> {
return this._withProgress(extension, 'scm', task);
const handle = this._handles++;
this._proxy.$startScm(handle);
return this._withProgress(handle, task);
}
private _withProgress<R>(extension: IExtensionDescription, type: string, task: (progress: Progress<any>, token: CancellationToken) => Thenable<R>): Thenable<R> {
const handle = this._handles++;
private _withProgress<R>(handle: number, task: (progress: Progress<any>, token: CancellationToken) => Thenable<R>): Thenable<R> {
this._proxy.$progressStart(handle, extension.id, type);
const progress = {
report: (message: string) => {
this._proxy.$progressReport(handle, message);
......
......@@ -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<any>) => {
private _createTask(handle: number) {
return (progress: IProgress<any>) => {
return new TPromise<any>(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 {
......
......@@ -48,12 +48,17 @@ class WindowProgressItem implements IStatusbarItem {
}
}
interface IWindowProgressTask {
title: string;
progress: Progress<string>;
}
export class ProgressService2 implements IProgressService2 {
_serviceBrand: any;
private _stack: Progress<string>[] = [];
private _stack: IWindowProgressTask[] = [];
constructor(
@IActivityBarService private _activityBar: IActivityBarService,
......@@ -62,15 +67,19 @@ export class ProgressService2 implements IProgressService2 {
//
}
withWindowProgress(task: (progress: IProgress<string>) => TPromise<any>): void {
withWindowProgress(title: string, callback: (progress: IProgress<string>) => TPromise<any>): void {
const task = {
progress: new Progress<string>(() => this._updateProgress()),
title
};
const progress = new Progress<string>(() => 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;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册