提交 a0850eeb 编写于 作者: J Joao Moreno

create global viewlet toolbar

上级 dd6e5ee5
......@@ -35,6 +35,7 @@ import events = require('vs/base/common/events');
export class ActivitybarPart extends Part implements IActivityService {
public serviceId = IActivityService;
private viewletSwitcherBar: ActionBar;
private globalViewletSwitcherBar: ActionBar;
private globalToolBar: ToolBar;
private activityActionItems: { [actionId: string]: IActionItem; };
private viewletIdToActions: { [viewletId: string]: ActivityAction; };
......@@ -126,34 +127,53 @@ export class ActivitybarPart extends Part implements IActivityService {
});
this.viewletSwitcherBar.getContainer().addClass('position-top');
// Global viewlet switcher is right below
this.globalViewletSwitcherBar = new ActionBar(div, {
actionItemProvider: (action: Action) => this.activityActionItems[action.id],
orientation: ActionsOrientation.VERTICAL,
ariaLabel: nls.localize('globalActivityBarAriaLabel', "Active Global View Switcher")
});
this.globalViewletSwitcherBar.getContainer().addClass('position-bottom');
// Build Viewlet Actions in correct order
let activeViewlet = this.viewletService.getActiveViewlet();
let registry = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets));
let viewletActions: Action[] = registry.getViewlets()
.sort((v1: ViewletDescriptor, v2: ViewletDescriptor) => v1.order - v2.order)
.map((viewlet: ViewletDescriptor) => {
let action = this.instantiationService.createInstance(ViewletActivityAction, viewlet.id + '.activity-bar-action', viewlet);
const activeViewlet = this.viewletService.getActiveViewlet();
const registry = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets));
const allViewletActions = registry.getViewlets();
const actionOptions = { label: true, icon: true };
const toAction = (viewlet: ViewletDescriptor) => {
let action = this.instantiationService.createInstance(ViewletActivityAction, viewlet.id + '.activity-bar-action', viewlet);
let keybinding: string = null;
let keys = this.keybindingService.lookupKeybindings(viewlet.id).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) {
keybinding = keys[0];
}
let keybinding: string = null;
let keys = this.keybindingService.lookupKeybindings(viewlet.id).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) {
keybinding = keys[0];
}
this.activityActionItems[action.id] = new ActivityActionItem(action, viewlet.name, keybinding);
this.viewletIdToActions[viewlet.id] = action;
this.activityActionItems[action.id] = new ActivityActionItem(action, viewlet.name, keybinding);
this.viewletIdToActions[viewlet.id] = action;
// Mark active viewlet action as active
if (activeViewlet && activeViewlet.getId() === viewlet.id) {
action.activate();
}
// Mark active viewlet action as active
if (activeViewlet && activeViewlet.getId() === viewlet.id) {
action.activate();
}
return action;
};
return action;
}
);
// Add to viewlet switcher
this.viewletSwitcherBar.push(allViewletActions
.filter(v => !v.isGlobal)
.sort((v1, v2) => v1.order - v2.order)
.map(toAction)
, actionOptions);
// Add to viewlet switcher
this.viewletSwitcherBar.push(viewletActions, { label: true, icon: true });
this.globalViewletSwitcherBar.push(allViewletActions
.filter(v => v.isGlobal)
.sort((v1, v2) => v1.order - v2.order)
.map(toAction),
actionOptions);
}
private createGlobalToolBarArea(div: Builder): void {
......
......@@ -158,7 +158,14 @@ export abstract class ViewerViewlet extends Viewlet {
/**
* A viewlet descriptor is a leightweight descriptor of a viewlet in the monaco workbench.
*/
export class ViewletDescriptor extends CompositeDescriptor<Viewlet> { }
export class ViewletDescriptor extends CompositeDescriptor<Viewlet> {
public isGlobal: boolean;
constructor(moduleId: string, ctorName: string, id: string, name: string, cssClass?: string, order?: number, isGlobal?: boolean) {
super(moduleId, ctorName, id, name, cssClass, order);
this.isGlobal = isGlobal || false;
}
}
export const Extensions = {
Viewlets: 'workbench.contributions.viewlets'
......@@ -178,14 +185,14 @@ export class ViewletRegistry extends CompositeRegistry<Viewlet> {
* Returns the viewlet descriptor for the given id or null if none.
*/
public getViewlet(id: string): ViewletDescriptor {
return this.getComposite(id);
return this.getComposite(id) as ViewletDescriptor;
}
/**
* Returns an array of registered viewlets known to the platform.
*/
public getViewlets(): ViewletDescriptor[] {
return this.getComposits();
return this.getComposits() as ViewletDescriptor[];
}
/**
......
......@@ -64,7 +64,8 @@ const viewletDescriptor = new ViewletDescriptor(
'workbench.viewlet.extensions',
localize('extensions', "Extensions"),
'extensions',
100
100,
true
);
Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册