Skip to content

Commit 007b298

Browse files
author
Benjamin Pasero
committed
avoid direct access of registries
1 parent 011ad12 commit 007b298

10 files changed

Lines changed: 53 additions & 29 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ import { Action } from 'vs/base/common/actions';
1111
import { Registry } from 'vs/platform/platform';
1212
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
1313
import { IWorkbenchActionRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/actionRegistry';
14-
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
14+
import { IPanelService, IPanelIdentifier } from 'vs/workbench/services/panel/common/panelService';
1515
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
16-
import { PanelDescriptor } from 'vs/workbench/browser/panel';
1716

1817
export class PanelAction extends Action {
1918

2019
constructor(
21-
private panel: PanelDescriptor,
20+
private panel: IPanelIdentifier,
2221
@IPanelService private panelService: IPanelService
2322
) {
24-
super(panel.id, panel.name, panel.cssClass);
23+
super(panel.id, panel.name);
2524
}
2625

2726
public run(event): TPromise<any> {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { Registry } from 'vs/platform/platform';
1313
import { Scope } from 'vs/workbench/browser/actionBarRegistry';
1414
import { IPanel } from 'vs/workbench/common/panel';
1515
import { CompositePart, ICompositeTitleLabel } from 'vs/workbench/browser/parts/compositePart';
16-
import { Panel, PanelRegistry, Extensions as PanelExtensions, PanelDescriptor } from 'vs/workbench/browser/panel';
17-
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
16+
import { Panel, PanelRegistry, Extensions as PanelExtensions } from 'vs/workbench/browser/panel';
17+
import { IPanelService, IPanelIdentifier } from 'vs/workbench/services/panel/common/panelService';
1818
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
1919
import { IStorageService } from 'vs/platform/storage/common/storage';
2020
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
@@ -110,6 +110,12 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
110110
return promise.then(() => this.openComposite(id, focus));
111111
}
112112

113+
public getPanels(): IPanelIdentifier[] {
114+
return Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels()
115+
.sort((v1, v2) => v1.order - v2.order)
116+
.map(p => { return { id: p.id, name: p.name }; });
117+
}
118+
113119
protected getActions(): IAction[] {
114120
return [this.instantiationService.createInstance(ClosePanelAction, ClosePanelAction.ID, ClosePanelAction.LABEL)];
115121
}
@@ -161,9 +167,4 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
161167
return action;
162168
}), { label: true });
163169
}
164-
165-
private getPanels(): PanelDescriptor[] {
166-
return Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels()
167-
.sort((v1, v2) => v1.order - v2.order);
168-
}
169170
}

src/vs/workbench/parts/markers/browser/markersWorkbenchContributions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export function registerContributions(): void {
3737
Constants.MARKERS_PANEL_ID,
3838
Messages.MARKERS_PANEL_TITLE_PROBLEMS,
3939
'markersPanel',
40-
10
41-
40+
20
4241
));
4342

4443
// actions

src/vs/workbench/parts/output/browser/output.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Registry.as<PanelRegistry>(Extensions.Panels).registerPanel(new PanelDescriptor(
3939
OUTPUT_PANEL_ID,
4040
nls.localize('output', "Output"),
4141
'output',
42-
20
42+
10
4343
));
4444

4545
// register toggle output action globally

src/vs/workbench/parts/output/browser/outputActions.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
import { TPromise } from 'vs/base/common/winjs.base';
88
import nls = require('vs/nls');
9-
import { Registry } from 'vs/platform/platform';
109
import { IAction, Action } from 'vs/base/common/actions';
11-
import { IOutputChannelRegistry, Extensions, IOutputService, OUTPUT_PANEL_ID } from 'vs/workbench/parts/output/common/output';
10+
import { IOutputService, OUTPUT_PANEL_ID } from 'vs/workbench/parts/output/common/output';
1211
import { SelectActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
1312
import { IPartService } from 'vs/workbench/services/part/common/partService';
1413
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
@@ -76,7 +75,7 @@ export class SwitchOutputActionItem extends SelectActionItem {
7675
}
7776

7877
protected getActionContext(option: string): string {
79-
const channel = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannels().filter(channelData => channelData.label === option).pop();
78+
const channel = this.outputService.getChannels().filter(channelData => channelData.label === option).pop();
8079

8180
return channel ? channel.id : option;
8281
}
@@ -89,7 +88,7 @@ export class SwitchOutputActionItem extends SelectActionItem {
8988
}
9089

9190
private static getChannelLabels(outputService: IOutputService): string[] {
92-
const contributedChannels = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannels().map(channelData => channelData.label);
91+
const contributedChannels = outputService.getChannels().map(channelData => channelData.label);
9392

9493
return contributedChannels.sort(); // sort by name
9594
}

src/vs/workbench/parts/output/browser/outputServices.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
1313
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
1414
import { Registry } from 'vs/platform/platform';
1515
import { EditorOptions } from 'vs/workbench/common/editor';
16-
import { OutputEditors, IOutputEvent, IOutputChannel, IOutputService, Extensions, OUTPUT_PANEL_ID, IOutputChannelRegistry, MAX_OUTPUT_LENGTH, OUTPUT_SCHEME, OUTPUT_MIME } from 'vs/workbench/parts/output/common/output';
16+
import { IOutputChannelIdentifier, OutputEditors, IOutputEvent, IOutputChannel, IOutputService, Extensions, OUTPUT_PANEL_ID, IOutputChannelRegistry, MAX_OUTPUT_LENGTH, OUTPUT_SCHEME, OUTPUT_MIME } from 'vs/workbench/parts/output/common/output';
1717
import { OutputPanel } from 'vs/workbench/parts/output/browser/outputPanel';
1818
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
1919
import { IModelService } from 'vs/editor/common/services/modelService';
@@ -56,7 +56,7 @@ export class OutputService implements IOutputService {
5656

5757
this.receivedOutput = Object.create(null);
5858

59-
const channels = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannels();
59+
const channels = this.getChannels();
6060
this.activeChannelId = this.storageService.get(OUTPUT_ACTIVE_CHANNEL_KEY, StorageScope.WORKSPACE, channels && channels.length > 0 ? channels[0].id : null);
6161

6262
this._outputLinkDetector = new OutputLinkProvider(contextService, modelService);
@@ -78,7 +78,7 @@ export class OutputService implements IOutputService {
7878
}
7979

8080
public getChannel(id: string): IOutputChannel {
81-
const channelData = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannels().filter(channelData => channelData.id === id).pop();
81+
const channelData = this.getChannels().filter(channelData => channelData.id === id).pop();
8282

8383
const self = this;
8484
return {
@@ -93,6 +93,10 @@ export class OutputService implements IOutputService {
9393
};
9494
}
9595

96+
public getChannels(): IOutputChannelIdentifier[] {
97+
return Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannels();
98+
}
99+
96100
private append(channelId: string, output: string): void {
97101

98102
// Initialize

src/vs/workbench/parts/output/common/output.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export interface IOutputService {
6666
*/
6767
getChannel(id: string): IOutputChannel;
6868

69+
/**
70+
* Returns an array of all known output channels as identifiers.
71+
*/
72+
getChannels(): IOutputChannelIdentifier[];
73+
6974
/**
7075
* Returns the currently active channel.
7176
* Only one channel can be active at a given moment.
@@ -121,6 +126,11 @@ export interface IOutputChannel {
121126
clear(): void;
122127
}
123128

129+
export interface IOutputChannelIdentifier {
130+
id: string;
131+
label: string;
132+
}
133+
124134
export interface IOutputChannelRegistry {
125135

126136
/**
@@ -131,11 +141,11 @@ export interface IOutputChannelRegistry {
131141
/**
132142
* Returns the list of channels known to the output world.
133143
*/
134-
getChannels(): { id: string, label: string }[];
144+
getChannels(): IOutputChannelIdentifier[];
135145
}
136146

137147
class OutputChannelRegistry implements IOutputChannelRegistry {
138-
private channels: { id: string, label: string }[];
148+
private channels: IOutputChannelIdentifier[];
139149

140150
constructor() {
141151
this.channels = [];
@@ -147,7 +157,7 @@ class OutputChannelRegistry implements IOutputChannelRegistry {
147157
}
148158
}
149159

150-
public getChannels(): { id: string, label: string }[] {
160+
public getChannels(): IOutputChannelIdentifier[] {
151161
return this.channels;
152162
}
153163
}

src/vs/workbench/parts/quickopen/browser/viewPickerHandler.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66

77
import { TPromise } from 'vs/base/common/winjs.base';
88
import nls = require('vs/nls');
9-
import { Registry } from 'vs/platform/platform';
10-
import { PanelRegistry, Extensions as PanelExtensions } from 'vs/workbench/browser/panel';
119
import errors = require('vs/base/common/errors');
1210
import strings = require('vs/base/common/strings');
1311
import scorer = require('vs/base/common/scorer');
1412
import { Mode, IEntryRunContext, IAutoFocus, IQuickNavigateConfiguration } from 'vs/base/parts/quickopen/common/quickOpen';
1513
import { QuickOpenModel, QuickOpenEntryGroup, QuickOpenEntry } from 'vs/base/parts/quickopen/browser/quickOpenModel';
1614
import { QuickOpenHandler, QuickOpenAction } from 'vs/workbench/browser/quickopen';
1715
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
18-
import { IOutputService, Extensions as OutputExtensions, IOutputChannelRegistry, OUTPUT_PANEL_ID } from 'vs/workbench/parts/output/common/output';
16+
import { IOutputService, OUTPUT_PANEL_ID } from 'vs/workbench/parts/output/common/output';
1917
import { ITerminalService, TERMINAL_PANEL_ID } from 'vs/workbench/parts/terminal/common/terminal';
2018
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
2119
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
@@ -125,7 +123,7 @@ export class ViewPickerHandler extends QuickOpenHandler {
125123
const terminals = this.terminalService.terminalInstances;
126124

127125
// Panels
128-
const panels = Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels().filter(p => {
126+
const panels = this.panelService.getPanels().filter(p => {
129127
if (p.id === OUTPUT_PANEL_ID) {
130128
return false; // since we already show output channels below
131129
}
@@ -156,7 +154,7 @@ export class ViewPickerHandler extends QuickOpenHandler {
156154
});
157155

158156
// Output Channels
159-
const channels = Registry.as<IOutputChannelRegistry>(OutputExtensions.OutputChannels).getChannels();
157+
const channels = this.outputService.getChannels();
160158
channels.forEach((channel, index) => {
161159
const outputCategory = nls.localize('channels', "Output");
162160
const entry = new ViewEntry(channel.label, outputCategory, () => this.outputService.getChannel(channel.id).show().done(null, errors.onUnexpectedError));

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/co
1010

1111
export const IPanelService = createDecorator<IPanelService>('panelService');
1212

13+
export interface IPanelIdentifier {
14+
id: string;
15+
name: string;
16+
}
17+
1318
export interface IPanelService {
1419
_serviceBrand: ServiceIdentifier<any>;
1520

@@ -26,4 +31,9 @@ export interface IPanelService {
2631
* Returns the current active panel or null if none
2732
*/
2833
getActivePanel(): IPanel;
34+
35+
/**
36+
* Returns all registered panels
37+
*/
38+
getPanels(): IPanelIdentifier[];
2939
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ class TestPanelService implements IPanelService {
138138
return TPromise.as(null);
139139
}
140140

141+
public getPanels(): any[] {
142+
return [];
143+
}
144+
141145
public getActivePanel(): IViewlet {
142146
return activeViewlet;
143147
}

0 commit comments

Comments
 (0)