提交 e789ea1d 编写于 作者: B Benjamin Pasero

💄

上级 6312e73f
......@@ -53,7 +53,7 @@ export class ActivitybarPart extends Part implements IActivityService {
this.toUnbind.push(this.viewletService.onDidViewletClose(viewlet => this.onCompositeClosed(viewlet)));
// Update viewlet switcher when external viewlets become ready
this.toUnbind.push(this.viewletService.onDidExtViewletsLoad(() => this.refreshViewletSwitcher()));
this.toUnbind.push(this.viewletService.onDidExtensionViewletsLoad(() => this.refreshViewletSwitcher()));
// Update viewlet switcher on toggling of a viewlet
this.toUnbind.push(this.viewletService.onDidViewletToggle(() => this.refreshViewletSwitcher()));
......
......@@ -153,13 +153,25 @@ export abstract class ViewerViewlet extends Viewlet {
*/
export class ViewletDescriptor extends CompositeDescriptor<Viewlet> {
constructor(moduleId: string, ctorName: string, id: string, name: string, cssClass?: string, order?: number, public isExternal: boolean = false) {
constructor(
moduleId: string,
ctorName: string,
id: string,
name: string,
cssClass?: string,
order?: number,
private _fromExtension = false
) {
super(moduleId, ctorName, id, name, cssClass, order);
if (isExternal) {
// Pass viewletId to external viewlet, which doesn't know its id until runtime.
this.appendStaticArguments([id]);
if (_fromExtension) {
this.appendStaticArguments([id]); // Pass viewletId to external viewlet, which doesn't know its id until runtime.
}
}
public get fromExtension(): boolean {
return this._fromExtension;
}
}
export const Extensions = {
......
......@@ -19,7 +19,6 @@ import { ViewletRegistry, Extensions as ViewletExtensions, ViewletDescriptor } f
import { ITreeExplorer } from 'vs/platform/extensionManagement/common/extensionManagement';
import { toCustomExplorerViewletId, toCustomExplorerViewletCSSClass, isValidViewletId } from 'vs/workbench/parts/explorers/common/treeExplorer';
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
registerSingleton(ICustomTreeExplorerService, CustomTreeExplorerService);
......@@ -42,16 +41,14 @@ const explorerSchema: IJSONSchema = {
}
};
export class ExplorerContribtion implements IWorkbenchContribution {
export class ExtensionExplorersContribtion implements IWorkbenchContribution {
constructor(
@IMessageService private messageService: IMessageService
) {
constructor() {
this.init();
}
public getId(): string {
return 'vs.explorer';
return 'vs.explorers.extensionExplorers';
}
private init() {
......@@ -60,13 +57,15 @@ export class ExplorerContribtion implements IWorkbenchContribution {
const { treeExplorerNodeProviderId, treeLabel, icon } = extension.value;
if (!isValidViewletId(treeExplorerNodeProviderId)) {
return this.messageService.show(Severity.Error, localize('treeExplorer.invalidId', 'Tree Explorer extension {0} has invalid id and failed to activate.', treeLabel));
console.warn(`Tree Explorer extension '${treeLabel}' has invalid id and failed to activate.`);
continue;
}
const getIconRule = (iconPath) => { return `background-image: url('${iconPath}')`; };
if (icon) {
const iconClass = `.monaco-workbench > .activitybar .monaco-action-bar .action-label.${toCustomExplorerViewletCSSClass(treeExplorerNodeProviderId)}`;
const iconPath = join(extension.description.extensionFolderPath, icon);
createCSSRule(iconClass, getIconRule(iconPath));
}
......@@ -76,12 +75,12 @@ export class ExplorerContribtion implements IWorkbenchContribution {
toCustomExplorerViewletId(treeExplorerNodeProviderId),
treeLabel,
toCustomExplorerViewletCSSClass(treeExplorerNodeProviderId),
-1, // External viewlets are ordered by enabling sequence, so order here doesn't matter.
true
-1, // External viewlets are ordered by enabling sequence, so order here doesn't matter.
true // from extension
));
}
});
}
}
(<IWorkbenchContributionsRegistry>Registry.as(WorkbenchExtensions.Workbench)).registerWorkbenchContribution(ExplorerContribtion);
\ No newline at end of file
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(ExtensionExplorersContribtion);
\ No newline at end of file
......@@ -31,13 +31,13 @@ export class ToggleExternalViewletAction extends Action {
}
run(): TPromise<any> {
const extViewlets = this.viewletService.getAllViewlets().filter(viewlet => viewlet.isExternal);
const extViewlets = this.viewletService.getAllViewlets().filter(viewlet => viewlet.fromExtension);
const picks: IPickOpenEntry[] = [];
extViewlets.forEach(viewlet => {
const isEnabled = this.viewletService.isViewletEnabled(viewlet.id);
const actionLabel = isEnabled ? localize('disable', 'Disable') : localize('enable', 'Enable');
const actionLabel = isEnabled ? localize('disable', "Disable") : localize('enable', "Enable");
picks.push({
id: viewlet.id,
label: `${actionLabel} ${viewlet.name}`,
......
......@@ -13,7 +13,7 @@ import { toCustomExplorerViewletActionId } from 'vs/workbench/parts/explorers/co
export class RefreshViewExplorerAction extends Action {
constructor(view: TreeExplorerView) {
super(toCustomExplorerViewletActionId('refresh'), nls.localize('refresh', 'Refresh'), 'customExplorer-action toggle', true, () => {
super(toCustomExplorerViewletActionId('refresh'), nls.localize('refresh', "Refresh"), 'customExplorer-action toggle', true, () => {
view.updateInput();
return TPromise.as(null);
});
......
......@@ -5,15 +5,15 @@
'use strict';
export function toCustomExplorerViewletId(viewletId: string): string {
return 'workbench.view.customExplorer.' + viewletId;
return `workbench.view.customExplorer.${viewletId}`;
}
export function toCustomExplorerViewletActionId(viewletId: string): string {
return 'workbench.action.customExplorer.' + viewletId;
return `workbench.action.customExplorer.${viewletId}`;
}
export function toCustomExplorerViewletCSSClass(viewletId: string): string {
return 'customExplorer-' + viewletId;
return `customExplorer-${viewletId}`;
}
export function isValidViewletId(viewletId: string): boolean {
......
......@@ -17,7 +17,7 @@ export interface IViewletService {
onDidViewletOpen: Event<IViewlet>;
onDidViewletClose: Event<IViewlet>;
onDidExtViewletsLoad: Event<void>;
onDidExtensionViewletsLoad: Event<void>;
onDidViewletToggle: Event<void>;
/**
......
......@@ -16,20 +16,20 @@ import { IExtensionService } from 'vs/platform/extensions/common/extensions';
export class ViewletService implements IViewletService {
public static readonly ENABLED_EXT_VIEWLETS = 'workbench.viewlet.enabledExtViewlets';
private static readonly ENABLED_EXTENSION_VIEWLETS = 'workbench.viewlet.enabledExtViewlets';
public _serviceBrand: any;
private sidebarPart: ISidebar;
private viewletRegistry: ViewletRegistry;
private enabledExtViewletIds: string[];
private extViewlets: ViewletDescriptor[];
private _onDidExtViewletsLoad = new Emitter<void>();
private enabledExtensionViewletIds: string[];
private extensionViewlets: ViewletDescriptor[];
private _onDidExtensionViewletsLoad = new Emitter<void>();
private _onDidViewletToggle = new Emitter<void>();
public get onDidViewletOpen(): Event<IViewlet> { return this.sidebarPart.onDidViewletOpen; };
public get onDidViewletClose(): Event<IViewlet> { return this.sidebarPart.onDidViewletClose; };
public get onDidExtViewletsLoad(): Event<void> { return this._onDidExtViewletsLoad.event; };
public get onDidExtensionViewletsLoad(): Event<void> { return this._onDidExtensionViewletsLoad.event; };
public get onDidViewletToggle(): Event<void> { return this._onDidViewletToggle.event; };
constructor(
......@@ -40,9 +40,9 @@ export class ViewletService implements IViewletService {
this.sidebarPart = sidebarPart;
this.viewletRegistry = <ViewletRegistry>Registry.as(ViewletExtensions.Viewlets);
const enabledExtViewletsJson = this.storageService.get(ViewletService.ENABLED_EXT_VIEWLETS);
this.enabledExtViewletIds = enabledExtViewletsJson ? JSON.parse(enabledExtViewletsJson) : [];
this.extViewlets = [];
const enabledExtensionViewletsJson = this.storageService.get(ViewletService.ENABLED_EXTENSION_VIEWLETS);
this.enabledExtensionViewletIds = enabledExtensionViewletsJson ? JSON.parse(enabledExtensionViewletsJson) : [];
this.extensionViewlets = [];
this.extensionService.onReady().then(() => {
this.onExtensionServiceReady();
......@@ -52,12 +52,12 @@ export class ViewletService implements IViewletService {
private onExtensionServiceReady(): void {
const viewlets = this.viewletRegistry.getViewlets();
viewlets.forEach(v => {
if (v.isExternal) {
this.extViewlets.push(v);
if (v.fromExtension) {
this.extensionViewlets.push(v);
}
});
this._onDidExtViewletsLoad.fire();
this._onDidExtensionViewletsLoad.fire();
}
public openViewlet(id: string, focus?: boolean): TPromise<IViewlet> {
......@@ -73,7 +73,7 @@ export class ViewletService implements IViewletService {
return this.sidebarPart.openViewlet(id, shouldFocus);
} else {
return new TPromise<IViewlet>(c => {
this.onDidExtViewletsLoad(() => {
this.onDidExtensionViewletsLoad(() => {
// It's possible the external viewlet is uninstalled and not available.
// Restore file explorer in that case.
if (!this.viewletRegistry.getViewlet(id)) {
......@@ -88,14 +88,14 @@ export class ViewletService implements IViewletService {
}
public toggleViewlet(id: string): TPromise<void> {
const index = this.enabledExtViewletIds.indexOf(id);
const index = this.enabledExtensionViewletIds.indexOf(id);
if (index === -1) {
this.enabledExtViewletIds.push(id);
this.enabledExtensionViewletIds.push(id);
} else {
this.enabledExtViewletIds.splice(index, 1);
this.enabledExtensionViewletIds.splice(index, 1);
}
this.setEnabledExtViewlets();
this.setEnabledExtensionViewlets();
this._onDidViewletToggle.fire();
return TPromise.as(null);
}
......@@ -106,31 +106,31 @@ export class ViewletService implements IViewletService {
public getAllViewlets(): ViewletDescriptor[] {
const stockViewlets = this.getStockViewlets();
return stockViewlets.concat(this.extViewlets);
return stockViewlets.concat(this.extensionViewlets);
}
public getAllViewletsToDisplay(): ViewletDescriptor[] {
const stockViewlets = this.getStockViewlets();
const enabledExtViewlets = this.extViewlets
.filter(v => this.enabledExtViewletIds.indexOf(v.id) !== -1)
const enabledExtensionViewlets = this.extensionViewlets
.filter(v => this.enabledExtensionViewletIds.indexOf(v.id) !== -1)
.sort((v1, v2) => {
return this.enabledExtViewletIds.indexOf(v1.id) - this.enabledExtViewletIds.indexOf(v2.id);
return this.enabledExtensionViewletIds.indexOf(v1.id) - this.enabledExtensionViewletIds.indexOf(v2.id);
});
return stockViewlets.concat(enabledExtViewlets);
return stockViewlets.concat(enabledExtensionViewlets);
}
public isViewletEnabled(id: string): boolean {
return this.enabledExtViewletIds.indexOf(id) !== -1;
return this.enabledExtensionViewletIds.indexOf(id) !== -1;
}
// Get an ordered list of all stock viewlets
private getStockViewlets(): ViewletDescriptor[] {
return this.viewletRegistry.getViewlets()
.filter(viewlet => !viewlet.isExternal)
.filter(viewlet => !viewlet.fromExtension)
.sort((v1, v2) => v1.order - v2.order);
}
private setEnabledExtViewlets(): void {
this.storageService.store(ViewletService.ENABLED_EXT_VIEWLETS, JSON.stringify(this.enabledExtViewletIds));
private setEnabledExtensionViewlets(): void {
this.storageService.store(ViewletService.ENABLED_EXTENSION_VIEWLETS, JSON.stringify(this.enabledExtensionViewletIds));
}
}
\ No newline at end of file
......@@ -105,7 +105,7 @@ class TestViewletService implements IViewletService {
onDidViewletOpen = this.onDidViewletOpenEmitter.event;
onDidViewletClose = this.onDidViewletCloseEmitter.event;
onDidExtViewletsLoad = this.onDidExtletsLoadEmitter.event;
onDidExtensionViewletsLoad = this.onDidExtletsLoadEmitter.event;
onDidViewletToggle = this.onDidViewletToggleEmitter.event;
public openViewlet(id: string, focus?: boolean): TPromise<IViewlet> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册