提交 894c3cf4 编写于 作者: P Pine Wu

Refactor and consistent naming

上级 d153d96c
......@@ -34,9 +34,16 @@ export class ActivitybarPart extends Part implements IActivityService {
private compositeIdToActions: { [compositeId: string]: ActivityAction; };
private enabledExternalViewlets: string[];
private registeredViewlets: { [viewletId: string]: ViewletDescriptor; };
private externalViewlets: { [viewletId: string]: ViewletDescriptor; };
private externalViewletIdToOpen: string;
// Serves two purposes:
// 1. Expose the viewletId that will be assigned to an external Viewlet,
// which wouldn't know its viewletId until construction time.
// 2. When workbench restores sidebar, if the last-opened Viewlet is external,
// it'll set this value and defer restoration until all extensions are loaded.
private _externalViewletIdToOpen: string;
public get externalViewletIdToOpen() { return this._externalViewletIdToOpen; };
public set externalViewletIdToOpen(viewletId: string) { this._externalViewletIdToOpen = viewletId; };
private static ENABLED_EXTERNAL_VIEWLETS = 'workbench.activityBar.enabledExternalViewlets';
......@@ -56,7 +63,7 @@ export class ActivitybarPart extends Part implements IActivityService {
const enabledExternalViewletsJson = this.storageService.get(ActivitybarPart.ENABLED_EXTERNAL_VIEWLETS);
this.enabledExternalViewlets = enabledExternalViewletsJson ? JSON.parse(enabledExternalViewletsJson) : [];
this.registeredViewlets = {};
this.externalViewlets = {};
this.registerListeners();
}
......@@ -72,18 +79,20 @@ export class ActivitybarPart extends Part implements IActivityService {
// Update activity bar on registering external viewlets
this.extensionService.onReady().then(() => {
const viewlets = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets)).getViewlets();
this.onDidRegisterExternalViewlets(viewlets);
this.onExtensionServiceReady(viewlets);
});
}
private onDidRegisterExternalViewlets(viewlets: ViewletDescriptor[]): void {
private onExtensionServiceReady(viewlets: ViewletDescriptor[]): void {
viewlets.forEach(v => {
this.registeredViewlets[v.id] = v;
if (v.isExternal) {
this.externalViewlets[v.id] = v;
}
});
this.viewletSwitcherBar.push(this.getAllEnabledExternalViewlets().map(d => this.toAction(d)), { label: true, icon: true });
if (this.externalViewletIdToOpen) {
this.compositeIdToActions[this.externalViewletIdToOpen].run().done();
if (this._externalViewletIdToOpen) {
this.compositeIdToActions[this._externalViewletIdToOpen].run().done();
}
}
......@@ -99,23 +108,23 @@ export class ActivitybarPart extends Part implements IActivityService {
}
}
public getInfoForRegisteredViewlets(): {
public getInfoForExternalViewlets(): {
[viewletId: string]: {
isEnabled: boolean;
treeLabel: string;
}
} {
const result = {};
for (let viewletId in this.registeredViewlets) {
for (let viewletId in this.externalViewlets) {
result[viewletId] = {
isEnabled: (this.enabledExternalViewlets.indexOf(viewletId) !== -1),
treeLabel: this.registeredViewlets[viewletId].name
treeLabel: this.externalViewlets[viewletId].name
};
}
return result;
}
public toggleViewlet(viewletId: string): void {
public toggleExternalViewlet(viewletId: string): void {
const index = this.enabledExternalViewlets.indexOf(viewletId);
if (index === -1) {
this.enabledExternalViewlets.push(viewletId);
......@@ -189,13 +198,9 @@ export class ActivitybarPart extends Part implements IActivityService {
// Get a list of all enabled external viewlets, ordered by the enabling sequence
private getAllEnabledExternalViewlets(): ViewletDescriptor[] {
const externalViewletsToShow: ViewletDescriptor[] = [];
this.enabledExternalViewlets.forEach(viewletId => {
if (this.registeredViewlets[viewletId]) {
externalViewletsToShow.push(this.registeredViewlets[viewletId]);
}
});
return externalViewletsToShow;
return this.enabledExternalViewlets
.filter(viewletId => this.externalViewlets[viewletId])
.map(viewletId => this.externalViewlets[viewletId]);
}
private toAction(composite: ViewletDescriptor): ActivityAction {
......@@ -204,7 +209,7 @@ export class ActivitybarPart extends Part implements IActivityService {
// Later retrieved by TreeExplorerViewlet, which wouldn't know its id until
// its construction at runtime.
action.onOpenExternalViewlet((viewletId) => {
this.externalViewletIdToOpen = viewletId;
this._externalViewletIdToOpen = viewletId;
});
this.activityActionItems[action.id] = new ActivityActionItem(action, composite.name, this.getKeybindingLabel(composite.id));
......@@ -213,14 +218,6 @@ export class ActivitybarPart extends Part implements IActivityService {
return action;
};
setExternalViewletIdToOpen(viewletId: string): void {
this.externalViewletIdToOpen = viewletId;
}
getExternalViewletIdToOpen(): string {
return this.externalViewletIdToOpen;
}
private getKeybindingLabel(id: string): string {
const keys = this.keybindingService.lookupKeybindings(id).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) {
......
......@@ -228,9 +228,9 @@ export class Workbench implements IPartService {
viewletId = this.storageService.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE, viewletId); // help developers and restore last view
}
// If external viewlet is the last active viewlet, defer its construction until extensions get registered
// If external viewlet is the last active viewlet, defer its construction until all extensions are loaded
if (!viewletRegistry.getViewlet(viewletId)) {
this.activitybarPart.setExternalViewletIdToOpen(viewletId);
this.activitybarPart.externalViewletIdToOpen = viewletId;
} else {
if (!this.sideBarHidden && !!viewletId) {
const viewletTimerEvent = timer.start(timer.Topic.STARTUP, strings.format('Opening Viewlet: {0}', viewletId));
......
......@@ -29,11 +29,11 @@ export class ToggleExternalViewletAction extends Action {
}
run(): TPromise<any> {
const infoForRegisteredViewlets = this.activityService.getInfoForRegisteredViewlets();
const infoForExternalViewlets = this.activityService.getInfoForExternalViewlets();
const picks: IPickOpenEntry[] = [];
for (let viewletId in infoForRegisteredViewlets) {
const { isEnabled, treeLabel } = infoForRegisteredViewlets[viewletId];
for (let viewletId in infoForExternalViewlets) {
const { isEnabled, treeLabel } = infoForExternalViewlets[viewletId];
picks.push({
id: viewletId,
label: (isEnabled ? 'Disable ' : 'Enable ') + treeLabel
......@@ -43,7 +43,7 @@ export class ToggleExternalViewletAction extends Action {
return TPromise.timeout(50 /* quick open is sensitive to being opened so soon after another */).then(() => {
this.quickOpenService.pick(picks, { placeHolder: 'Select Viewlet to toggle', autoFocus: 2 }).then(pick => {
if (pick) {
this.activityService.toggleViewlet(pick.id);
this.activityService.toggleExternalViewlet(pick.id);
}
});
});
......
......@@ -36,7 +36,7 @@ export class TreeExplorerViewlet extends Viewlet {
this.viewletState = new TreeExplorerViewletState();
this.externalViewletId = this.activityService.getExternalViewletIdToOpen();
this.externalViewletId = this.activityService.externalViewletIdToOpen;
this.treeNodeProviderId = this.getTreeProviderName(this.externalViewletId);
TreeExplorerViewlet._idCounter++;
......
......@@ -60,6 +60,7 @@ export const IActivityService = createDecorator<IActivityService>('activityServi
export interface IActivityService {
_serviceBrand: any;
externalViewletIdToOpen: string;
/**
* Show activity in the activitybar for the given viewlet or panel.
......@@ -74,7 +75,7 @@ export interface IActivityService {
/**
* Get registered external viewlets' info for populating 'Toggle Custom Explorer' command picks.
*/
getInfoForRegisteredViewlets(): {
getInfoForExternalViewlets(): {
[viewletId: string]: {
isEnabled: boolean;
treeLabel: string;
......@@ -84,10 +85,5 @@ export interface IActivityService {
/**
* Enable/disable an external viewlet.
*/
toggleViewlet(viewletId: string): void;
/**
* Get the external viewlet id that is about to open.
*/
getExternalViewletIdToOpen(): string;
toggleExternalViewlet(viewletId: string): void;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册