提交 88e869a9 编写于 作者: P Pine Wu

Refactor activitybar and clean up

上级 13641598
...@@ -43,7 +43,7 @@ namespace schema { ...@@ -43,7 +43,7 @@ namespace schema {
} }
ExtensionsRegistry.registerExtensionPoint<schema.IExplorer>('explorer', schema.explorerContribtion).setHandler(extensions => { ExtensionsRegistry.registerExtensionPoint<schema.IExplorer>('explorer', schema.explorerContribtion).setHandler(extensions => {
let baseOrder = 200; let baseOrder = 200; // Stock viewlet order goes up to 100
let descriptors = []; let descriptors = [];
for (let extension of extensions) { for (let extension of extensions) {
...@@ -69,7 +69,8 @@ ExtensionsRegistry.registerExtensionPoint<schema.IExplorer>('explorer', schema.e ...@@ -69,7 +69,8 @@ ExtensionsRegistry.registerExtensionPoint<schema.IExplorer>('explorer', schema.e
'workbench.view.customTreeExplorerViewlet.' + treeExplorerNodeProviderId, 'workbench.view.customTreeExplorerViewlet.' + treeExplorerNodeProviderId,
treeLabel, treeLabel,
treeExplorerNodeProviderId, treeExplorerNodeProviderId,
baseOrder++ baseOrder++,
true
)); ));
} }
Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets).registerExternalViewlets(descriptors); Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets).registerExternalViewlets(descriptors);
......
...@@ -33,7 +33,7 @@ export class ActivitybarPart extends Part implements IActivityService { ...@@ -33,7 +33,7 @@ export class ActivitybarPart extends Part implements IActivityService {
private viewletsToggleStatus: { [viewletId: string]: boolean; }; private viewletsToggleStatus: { [viewletId: string]: boolean; };
private registeredViewlets: string[]; private registeredViewlets: string[];
private VIEWLETS_TOGGLE_STATUS = "workbench.activityBar.enabledExternalViewlets"; private VIEWLETS_TOGGLE_STATUS = "workbench.activityBar.viewletsToggleStatus";
constructor( constructor(
id: string, id: string,
...@@ -103,6 +103,7 @@ export class ActivitybarPart extends Part implements IActivityService { ...@@ -103,6 +103,7 @@ export class ActivitybarPart extends Part implements IActivityService {
public toggleViewlet(viewletId: string): void { public toggleViewlet(viewletId: string): void {
this.viewletsToggleStatus[viewletId] = !this.viewletsToggleStatus[viewletId]; this.viewletsToggleStatus[viewletId] = !this.viewletsToggleStatus[viewletId];
this.setViewletsToggleStatus(); this.setViewletsToggleStatus();
this.refreshViewletSwitcher();
} }
private setViewletsToggleStatus(): void { private setViewletsToggleStatus(): void {
...@@ -128,25 +129,40 @@ export class ActivitybarPart extends Part implements IActivityService { ...@@ -128,25 +129,40 @@ export class ActivitybarPart extends Part implements IActivityService {
const $result = $('.content').appendTo($el); const $result = $('.content').appendTo($el);
// Top Actionbar with action items for each viewlet action // Top Actionbar with action items for each viewlet action
this.createViewletSwitcher($result.clone()); this.createViewletSwitcher($result.clone().addClass('position-top'));
return $result; return $result;
} }
private createViewletSwitcher(div: Builder): void { private createViewletSwitcher(div: Builder): void {
// Composite switcher is on top
this.viewletSwitcherBar = new ActionBar(div, { this.viewletSwitcherBar = new ActionBar(div, {
actionItemProvider: (action: Action) => this.activityActionItems[action.id], actionItemProvider: (action: Action) => this.activityActionItems[action.id],
orientation: ActionsOrientation.VERTICAL, orientation: ActionsOrientation.VERTICAL,
ariaLabel: nls.localize('activityBarAriaLabel', "Active View Switcher") ariaLabel: nls.localize('activityBarAriaLabel', "Active View Switcher")
}); });
this.viewletSwitcherBar.getContainer().addClass('position-top');
// Build Viewlet Actions in correct order // Load stock viewlets
const allViewlets = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets)).getViewlets(); const allViewlets = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets)).getViewlets().filter(v => !v.isExternal);
const viewletActions = allViewlets.sort((v1, v2) => v1.order - v2.order).map(viewlet => this.toAction(viewlet)); this.fillViewletSwitcher(allViewlets);
}
private refreshViewletSwitcher(): void {
this.viewletSwitcherBar.clear();
// Load stock viewlets + enabled external viewlets
const allEnabledViewlets = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets)).getViewlets().filter(descriptor => {
if (!descriptor.isExternal) {
return true;
} else {
return this.viewletsToggleStatus[descriptor.id];
}
});
this.fillViewletSwitcher(allEnabledViewlets);
}
private fillViewletSwitcher(viewlets: ViewletDescriptor[]) {
// Build Viewlet Actions in correct order
const viewletActions = viewlets.sort((v1, v2) => v1.order - v2.order).map(v => this.toAction(v));
this.viewletSwitcherBar.push(viewletActions, { label: true, icon: true }); this.viewletSwitcherBar.push(viewletActions, { label: true, icon: true });
} }
...@@ -157,11 +173,6 @@ export class ActivitybarPart extends Part implements IActivityService { ...@@ -157,11 +173,6 @@ export class ActivitybarPart extends Part implements IActivityService {
this.activityActionItems[action.id] = new ActivityActionItem(action, composite.name, this.getKeybindingLabel(composite.id)); this.activityActionItems[action.id] = new ActivityActionItem(action, composite.name, this.getKeybindingLabel(composite.id));
this.compositeIdToActions[composite.id] = action; this.compositeIdToActions[composite.id] = action;
// Mark active viewlet as active
if (activeViewlet && activeViewlet.getId() === composite.id) {
action.activate();
}
return action; return action;
}; };
......
...@@ -154,7 +154,7 @@ export abstract class ViewerViewlet extends Viewlet { ...@@ -154,7 +154,7 @@ export abstract class ViewerViewlet extends Viewlet {
*/ */
export class ViewletDescriptor extends CompositeDescriptor<Viewlet> { export class ViewletDescriptor extends CompositeDescriptor<Viewlet> {
constructor(moduleId: string, ctorName: string, id: string, name: string, cssClass?: string, order?: number) { constructor(moduleId: string, ctorName: string, id: string, name: string, cssClass?: string, order?: number, public isExternal: boolean = false) {
super(moduleId, ctorName, id, name, cssClass, order); super(moduleId, ctorName, id, name, cssClass, order);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册