提交 c4db36ea 编写于 作者: J Johannes Rieken

viewlet progress shows progress bar and activity badge

上级 aa522145
......@@ -35,6 +35,8 @@ export interface IProgress<T> {
report(item: T): void;
}
export const emptyProgress: IProgress<any> = Object.freeze({ report() { } });
export class Progress<T> implements IProgress<T> {
private _callback: () => void;
......
......@@ -464,6 +464,10 @@ export abstract class CompositePart<T extends Composite> extends Part {
this.messageService.show(Severity.Error, types.isString(error) ? new Error(error) : error);
}
public getProgressIndicator(id: string): IProgressService {
return this.mapProgressServiceToComposite[id];
}
protected getActions(): IAction[] {
return [];
}
......
......@@ -25,16 +25,7 @@ import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import Event from 'vs/base/common/event';
export interface ISidebar {
onDidViewletOpen: Event<IViewlet>;
onDidViewletClose: Event<IViewlet>;
openViewlet(id: string, focus?: boolean): TPromise<IViewlet>;
getActiveViewlet(): IViewlet;
getLastActiveViewletId(): string;
hideActiveViewlet(): TPromise<void>;
}
export class SidebarPart extends CompositePart<Viewlet> implements ISidebar {
export class SidebarPart extends CompositePart<Viewlet> {
public static activeViewletSettingsKey = 'workbench.sidebar.activeviewletid';
......
......@@ -5,39 +5,16 @@
'use strict';
import 'vs/css!vs/workbench/services/progress/browser/media/progressService2';
import { always } from 'vs/base/common/async';
import * as dom from 'vs/base/browser/dom';
import { IActivityBarService, ProgressBadge } from 'vs/workbench/services/activity/common/activityBarService';
import { IDisposable } from 'vs/base/common/lifecycle';
import { Registry } from 'vs/platform/platform';
import { IProgressService2, IProgress, Progress } from 'vs/platform/progress/common/progress';
import { IProgressService2, IProgress, Progress, emptyProgress } 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/platform';
import { StatusbarAlignment, IStatusbarRegistry, StatusbarItemDescriptor, Extensions, IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { TPromise } from 'vs/base/common/winjs.base';
import { IActivityBarService, ProgressBadge } from 'vs/workbench/services/activity/common/activityBarService';
import * as dom from 'vs/base/browser/dom';
class ActivityBarProgress implements IProgress<number> {
private _handle: IDisposable;
constructor(
private _activityBar: IActivityBarService,
private _viewletId: string) {
}
dispose(): void {
if (this._handle) {
this._handle.dispose();
this._handle = undefined;
}
}
report(n: number): void {
if (!this._handle) {
this._handle = this._activityBar.showActivity(this._viewletId, new ProgressBadge(() => '...'), 'progress-badge');
}
}
}
import { always } from 'vs/base/common/async';
class WindowProgressItem implements IStatusbarItem {
......@@ -79,7 +56,8 @@ export class ProgressService2 implements IProgressService2 {
private _stack: Progress<string>[] = [];
constructor(
@IActivityBarService private _activityBar: IActivityBarService
@IActivityBarService private _activityBar: IActivityBarService,
@IViewletService private _viewletService: IViewletService
) {
//
}
......@@ -98,11 +76,6 @@ export class ProgressService2 implements IProgressService2 {
});
}
withViewletProgress(viewletId: string, task: (progress: IProgress<number>) => TPromise<any>): void {
const progress = new ActivityBarProgress(this._activityBar, viewletId);
always(task(progress), () => progress.dispose());
}
private _updateProgress() {
if (this._stack.length === 0) {
WindowProgressItem.Instance.hide();
......@@ -111,6 +84,26 @@ export class ProgressService2 implements IProgressService2 {
WindowProgressItem.Instance.text = this._stack[0].value;
}
}
withViewletProgress(viewletId: string, task: (progress: IProgress<number>) => TPromise<any>): void {
const promise = task(emptyProgress);
// show in viewlet
const viewletProgress = this._viewletService.getProgressIndicator(viewletId);
viewletProgress.showWhile(promise);
// show activity bar
const activityProgress = this._activityBar.showActivity(
viewletId,
new ProgressBadge(() => '...'),
'progress-badge'
);
always(promise, () => {
activityProgress.dispose();
});
}
}
......
......@@ -9,6 +9,7 @@ import { IViewlet } from 'vs/workbench/common/viewlet';
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import Event from 'vs/base/common/event';
import { ViewletDescriptor } from 'vs/workbench/browser/viewlet';
import { IProgressService } from 'vs/platform/progress/common/progress';
export const IViewletService = createDecorator<IViewletService>('viewletService');
......@@ -42,4 +43,9 @@ export interface IViewletService {
* Returns all registered viewlets
*/
getViewlets(): ViewletDescriptor[];
}
\ No newline at end of file
/**
*
*/
getProgressIndicator(id: string): IProgressService;
}
......@@ -8,16 +8,17 @@ import { TPromise, ValueCallback } from 'vs/base/common/winjs.base';
import { IViewlet } from 'vs/workbench/common/viewlet';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import Event from 'vs/base/common/event';
import { ISidebar } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
import { Registry } from 'vs/platform/platform';
import { ViewletDescriptor, ViewletRegistry, Extensions as ViewletExtensions } from 'vs/workbench/browser/viewlet';
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
import { IProgressService } from 'vs/platform/progress/common/progress';
export class ViewletService implements IViewletService {
public _serviceBrand: any;
private sidebarPart: ISidebar;
private sidebarPart: SidebarPart;
private viewletRegistry: ViewletRegistry;
private extensionViewlets: ViewletDescriptor[];
......@@ -28,7 +29,7 @@ export class ViewletService implements IViewletService {
public get onDidViewletClose(): Event<IViewlet> { return this.sidebarPart.onDidViewletClose; };
constructor(
sidebarPart: ISidebar,
sidebarPart: SidebarPart,
@IExtensionService private extensionService: IExtensionService
) {
this.sidebarPart = sidebarPart;
......@@ -99,4 +100,8 @@ export class ViewletService implements IViewletService {
public getViewlet(id: string): ViewletDescriptor {
return this.getViewlets().filter(viewlet => viewlet.id === id)[0];
}
}
\ No newline at end of file
public getProgressIndicator(id: string): IProgressService {
return this.sidebarPart.getProgressIndicator(id);
}
}
......@@ -126,6 +126,10 @@ class TestViewletService implements IViewletService {
public getViewlet(id: string): ViewletDescriptor {
return null;
}
public getProgressIndicator(id: string) {
return null;
}
}
class TestPanelService implements IPanelService {
......@@ -444,4 +448,4 @@ suite('Workbench UI Services', () => {
});
});
});
});
\ No newline at end of file
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册