Skip to content

Commit 17f7970

Browse files
author
Benjamin Pasero
committed
1 parent 9f3f18b commit 17f7970

6 files changed

Lines changed: 57 additions & 13 deletions

File tree

src/vs/workbench/browser/panel.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ export class PanelRegistry extends CompositeRegistry<Panel> {
4141
super.deregisterComposite(id);
4242
}
4343

44+
/**
45+
* Returns a panel by id.
46+
*/
47+
getPanel(id: string): PanelDescriptor | null {
48+
return this.getComposite(id);
49+
}
50+
4451
/**
4552
* Returns an array of registered panels known to the platform.
4653
*/

src/vs/workbench/browser/parts/panel/panelPart.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { Dimension, trackFocus } from 'vs/base/browser/dom';
3030
import { localize } from 'vs/nls';
3131
import { IDisposable } from 'vs/base/common/lifecycle';
3232
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
33-
import { isUndefinedOrNull, withUndefinedAsNull } from 'vs/base/common/types';
33+
import { isUndefinedOrNull, withUndefinedAsNull, withNullAsUndefined } from 'vs/base/common/types';
3434
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
3535
import { LayoutPriority } from 'vs/base/browser/ui/grid/gridview';
3636
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
@@ -229,8 +229,8 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
229229
return this.compositeBar.showActivity(panelId, badge, clazz);
230230
}
231231

232-
private getPanel(panelId: string): IPanelIdentifier | undefined {
233-
return this.getPanels().filter(p => p.id === panelId).pop();
232+
getPanel(panelId: string): IPanelIdentifier | undefined {
233+
return withNullAsUndefined(Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanel(panelId));
234234
}
235235

236236
getPanels(): PanelDescriptor[] {

src/vs/workbench/services/panel/common/panelService.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { IPanel } from 'vs/workbench/common/panel';
88
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
99
import { IBadge } from 'vs/workbench/services/activity/common/activity';
1010
import { IDisposable } from 'vs/base/common/lifecycle';
11+
import { ILocalProgressService } from 'vs/platform/progress/common/progress';
1112

1213
export const IPanelService = createDecorator<IPanelService>('panelService');
1314

@@ -18,11 +19,11 @@ export interface IPanelIdentifier {
1819
}
1920

2021
export interface IPanelService {
21-
_serviceBrand: ServiceIdentifier<any>;
2222

23-
onDidPanelOpen: Event<{ panel: IPanel, focus: boolean }>;
23+
_serviceBrand: ServiceIdentifier<any>;
2424

25-
onDidPanelClose: Event<IPanel>;
25+
readonly onDidPanelOpen: Event<{ panel: IPanel, focus: boolean }>;
26+
readonly onDidPanelClose: Event<IPanel>;
2627

2728
/**
2829
* Opens a panel with the given identifier and pass keyboard focus to it if specified.
@@ -35,7 +36,12 @@ export interface IPanelService {
3536
getActivePanel(): IPanel | null;
3637

3738
/**
38-
* Returns all built-in panels following the default order (Problems - Output - Debug Console - Terminal)
39+
* Returns the panel by id.
40+
*/
41+
getPanel(id: string): IPanelIdentifier | undefined;
42+
43+
/**
44+
* Returns all built-in panels following the default order
3945
*/
4046
getPanels(): IPanelIdentifier[];
4147

@@ -44,6 +50,11 @@ export interface IPanelService {
4450
*/
4551
getPinnedPanels(): IPanelIdentifier[];
4652

53+
/**
54+
* Returns the progress indicator for the panel bar.
55+
*/
56+
getProgressIndicator(id: string): ILocalProgressService | null;
57+
4758
/**
4859
* Show an activity in a panel.
4960
*/

src/vs/workbench/services/progress/browser/progressService.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2424
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
2525
import { EventHelper } from 'vs/base/browser/dom';
2626
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
27+
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
2728

2829
export class ProgressService implements IProgressService, IDisposable {
2930

@@ -35,6 +36,7 @@ export class ProgressService implements IProgressService, IDisposable {
3536
constructor(
3637
@IActivityService private readonly _activityBar: IActivityService,
3738
@IViewletService private readonly _viewletService: IViewletService,
39+
@IPanelService private readonly _panelService: IPanelService,
3840
@INotificationService private readonly _notificationService: INotificationService,
3941
@IStatusbarService private readonly _statusbarService: IStatusbarService,
4042
@ILayoutService private readonly _layoutService: ILayoutService,
@@ -49,11 +51,14 @@ export class ProgressService implements IProgressService, IDisposable {
4951
withProgress<R = unknown>(options: IProgressOptions, task: (progress: IProgress<IProgressStep>) => Promise<R>, onDidCancel?: () => void): Promise<R> {
5052
const { location } = options;
5153
if (typeof location === 'string') {
52-
const viewlet = this._viewletService.getViewlet(location);
53-
if (viewlet) {
54+
if (this._viewletService.getProgressIndicator(location)) {
5455
return this._withViewletProgress(location, task, { ...options, location });
5556
}
5657

58+
if (this._panelService.getProgressIndicator(location)) {
59+
return this._withPanelProgress(location, task, { ...options, location });
60+
}
61+
5762
return Promise.reject(new Error(`Bad progress location: ${location}`));
5863
}
5964

@@ -281,6 +286,18 @@ export class ProgressService implements IProgressService, IDisposable {
281286
return promise;
282287
}
283288

289+
private _withPanelProgress<P extends Promise<R>, R = unknown>(panelid: string, task: (progress: IProgress<{ message?: string }>) => P, options: IProgressCompositeOptions): P {
290+
const promise = task(emptyProgress);
291+
292+
// show in panel
293+
const panelProgress = this._panelService.getProgressIndicator(panelid);
294+
if (panelProgress) {
295+
panelProgress.showWhile(promise, options.delay);
296+
}
297+
298+
return promise;
299+
}
300+
284301
private _withDialogProgress<P extends Promise<R>, R = unknown>(options: IProgressOptions, task: (progress: IProgress<{ message?: string, increment?: number }>) => P, onDidCancel?: () => void): P {
285302
const disposables = new DisposableStore();
286303
const allowableCommands = [

src/vs/workbench/services/viewlet/browser/viewlet.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import { ILocalProgressService } from 'vs/platform/progress/common/progress';
1212
export const IViewletService = createDecorator<IViewletService>('viewletService');
1313

1414
export interface IViewletService {
15+
1516
_serviceBrand: ServiceIdentifier<any>;
1617

17-
onDidViewletRegister: Event<ViewletDescriptor>;
18-
onDidViewletDeregister: Event<ViewletDescriptor>;
19-
onDidViewletOpen: Event<IViewlet>;
20-
onDidViewletClose: Event<IViewlet>;
18+
readonly onDidViewletRegister: Event<ViewletDescriptor>;
19+
readonly onDidViewletDeregister: Event<ViewletDescriptor>;
20+
readonly onDidViewletOpen: Event<IViewlet>;
21+
readonly onDidViewletClose: Event<IViewlet>;
2122

2223
/**
2324
* Opens a viewlet with the given identifier and pass keyboard focus to it if specified.

src/vs/workbench/test/workbenchTestServices.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,10 @@ export class TestPanelService implements IPanelService {
620620
return null!;
621621
}
622622

623+
public getPanel(id: string): any {
624+
return activeViewlet;
625+
}
626+
623627
public getPanels(): any[] {
624628
return [];
625629
}
@@ -641,6 +645,10 @@ export class TestPanelService implements IPanelService {
641645
throw new Error('Method not implemented.');
642646
}
643647

648+
public getProgressIndicator(id: string) {
649+
return null!;
650+
}
651+
644652
public hideActivePanel(): void { }
645653

646654
public getLastActivePanelId(): string {

0 commit comments

Comments
 (0)