提交 347df0bf 编写于 作者: I isidor

activitybar: generalize code to talk about composites not viewlets

上级 c9c65c9c
...@@ -32,14 +32,15 @@ import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; ...@@ -32,14 +32,15 @@ import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
export class ActivitybarPart extends Part implements IActivityService { export class ActivitybarPart extends Part implements IActivityService {
public _serviceBrand: any; public _serviceBrand: any;
private viewletSwitcherBar: ActionBar; private compositeSwitcherBar: ActionBar;
private globalToolBar: ToolBar; private globalToolBar: ToolBar;
private activityActionItems: { [actionId: string]: IActionItem; }; private activityActionItems: { [actionId: string]: IActionItem; };
private viewletIdToActions: { [viewletId: string]: ActivityAction; }; private compositeIdToActions: { [compositeId: string]: ActivityAction; };
constructor( constructor(
id: string, id: string,
@IViewletService private viewletService: IViewletService, @IViewletService private viewletService: IViewletService,
@IPanelService private panelService: IPanelService,
@IMessageService private messageService: IMessageService, @IMessageService private messageService: IMessageService,
@ITelemetryService private telemetryService: ITelemetryService, @ITelemetryService private telemetryService: ITelemetryService,
@IContextMenuService private contextMenuService: IContextMenuService, @IContextMenuService private contextMenuService: IContextMenuService,
...@@ -49,7 +50,7 @@ export class ActivitybarPart extends Part implements IActivityService { ...@@ -49,7 +50,7 @@ export class ActivitybarPart extends Part implements IActivityService {
super(id); super(id);
this.activityActionItems = {}; this.activityActionItems = {};
this.viewletIdToActions = {}; this.compositeIdToActions = {};
this.registerListeners(); this.registerListeners();
} }
...@@ -64,26 +65,26 @@ export class ActivitybarPart extends Part implements IActivityService { ...@@ -64,26 +65,26 @@ export class ActivitybarPart extends Part implements IActivityService {
} }
private onActiveViewletChanged(viewlet: IViewlet): void { private onActiveViewletChanged(viewlet: IViewlet): void {
if (this.viewletIdToActions[viewlet.getId()]) { if (this.compositeIdToActions[viewlet.getId()]) {
this.viewletIdToActions[viewlet.getId()].activate(); this.compositeIdToActions[viewlet.getId()].activate();
// There can only be one active viewlet action // There can only be one active viewlet action
for (let key in this.viewletIdToActions) { for (let key in this.compositeIdToActions) {
if (this.viewletIdToActions.hasOwnProperty(key) && key !== viewlet.getId()) { if (this.compositeIdToActions.hasOwnProperty(key) && key !== viewlet.getId() && this.compositeIdToActions[key] instanceof ViewletActivityAction) {
this.viewletIdToActions[key].deactivate(); this.compositeIdToActions[key].deactivate();
} }
} }
} }
} }
private onViewletClosed(viewlet: IViewlet): void { private onViewletClosed(viewlet: IViewlet): void {
if (this.viewletIdToActions[viewlet.getId()]) { if (this.compositeIdToActions[viewlet.getId()]) {
this.viewletIdToActions[viewlet.getId()].deactivate(); this.compositeIdToActions[viewlet.getId()].deactivate();
} }
} }
public showActivity(viewletId: string, badge: IBadge, clazz?: string): void { public showActivity(compositeId: string, badge: IBadge, clazz?: string): void {
let action = this.viewletIdToActions[viewletId]; const action = this.compositeIdToActions[compositeId];
if (action) { if (action) {
action.setBadge(badge); action.setBadge(badge);
if (clazz) { if (clazz) {
...@@ -92,50 +93,52 @@ export class ActivitybarPart extends Part implements IActivityService { ...@@ -92,50 +93,52 @@ export class ActivitybarPart extends Part implements IActivityService {
} }
} }
public clearActivity(viewletId: string): void { public clearActivity(compositeId: string): void {
this.showActivity(viewletId, null); this.showActivity(compositeId, null);
} }
public createContentArea(parent: Builder): Builder { public createContentArea(parent: Builder): Builder {
let $el = $(parent); const $el = $(parent);
let $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.createCompositeSwitcher($result.clone());
return $result; return $result;
} }
private createViewletSwitcher(div: Builder): void { private createCompositeSwitcher(div: Builder): void {
// Viewlet switcher is on top // Composite switcher is on top
this.viewletSwitcherBar = new ActionBar(div, { this.compositeSwitcherBar = 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'); this.compositeSwitcherBar.getContainer().addClass('position-top');
// Build Viewlet Actions in correct order // Build Viewlet Actions in correct order
const activeViewlet = this.viewletService.getActiveViewlet(); const activeViewlet = this.viewletService.getActiveViewlet();
const activePanel = this.panelService.getActivePanel();
const registry = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets)); const registry = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets));
const allViewletActions = registry.getViewlets(); const allViewletActions = registry.getViewlets();
const actionOptions = { label: true, icon: true }; const actionOptions = { label: true, icon: true };
const toAction = (viewlet: ViewletDescriptor) => { const toAction = (composite: CompositeDescriptor<Viewlet | Panel>) => {
let action = this.instantiationService.createInstance(ViewletActivityAction, viewlet.id + '.activity-bar-action', viewlet); const action = composite instanceof ViewletDescriptor ? this.instantiationService.createInstance(ViewletActivityAction, composite.id + '.activity-bar-action', composite)
: this.instantiationService.createInstance(PanelActivityAction, composite.id + '.activity-bar-action', composite);
let keybinding: string = null; let keybinding: string = null;
let keys = this.keybindingService.lookupKeybindings(viewlet.id).map(k => this.keybindingService.getLabelFor(k)); const keys = this.keybindingService.lookupKeybindings(composite.id).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) { if (keys && keys.length) {
keybinding = keys[0]; keybinding = keys[0];
} }
this.activityActionItems[action.id] = new ActivityActionItem(action, viewlet.name, keybinding); this.activityActionItems[action.id] = new ActivityActionItem(action, composite.name, keybinding);
this.viewletIdToActions[viewlet.id] = action; this.compositeIdToActions[composite.id] = action;
// Mark active viewlet action as active // Mark active viewlet and panel action as active
if (activeViewlet && activeViewlet.getId() === viewlet.id) { if (activeViewlet && activeViewlet.getId() === composite.id || activePanel && activePanel.getId() === composite.id) {
action.activate(); action.activate();
} }
...@@ -143,7 +146,7 @@ export class ActivitybarPart extends Part implements IActivityService { ...@@ -143,7 +146,7 @@ export class ActivitybarPart extends Part implements IActivityService {
}; };
// Add to viewlet switcher // Add to viewlet switcher
this.viewletSwitcherBar.push(allViewletActions this.compositeSwitcherBar.push(allViewletActions
.filter(v => !v.isGlobal) .filter(v => !v.isGlobal)
.sort((v1, v2) => v1.order - v2.order) .sort((v1, v2) => v1.order - v2.order)
.map(toAction) .map(toAction)
...@@ -151,9 +154,9 @@ export class ActivitybarPart extends Part implements IActivityService { ...@@ -151,9 +154,9 @@ export class ActivitybarPart extends Part implements IActivityService {
} }
public dispose(): void { public dispose(): void {
if (this.viewletSwitcherBar) { if (this.compositeSwitcherBar) {
this.viewletSwitcherBar.dispose(); this.compositeSwitcherBar.dispose();
this.viewletSwitcherBar = null; this.compositeSwitcherBar = null;
} }
if (this.globalToolBar) { if (this.globalToolBar) {
...@@ -185,7 +188,7 @@ abstract class CompositeActivityAction<T extends Composite> extends ActivityActi ...@@ -185,7 +188,7 @@ abstract class CompositeActivityAction<T extends Composite> extends ActivityActi
public run(): TPromise<any> { public run(): TPromise<any> {
// prevent accident trigger on a doubleclick (to help nervous people) // prevent accident trigger on a doubleclick (to help nervous people)
let now = Date.now(); const now = Date.now();
if (now - this.lastRun < CompositeActivityAction.preventDoubleClickDelay) { if (now - this.lastRun < CompositeActivityAction.preventDoubleClickDelay) {
return TPromise.as(true); return TPromise.as(true);
} }
......
...@@ -62,12 +62,12 @@ export interface IActivityService { ...@@ -62,12 +62,12 @@ export interface IActivityService {
_serviceBrand: any; _serviceBrand: any;
/** /**
* Show activity in the activitybar for the given viewlet. * Show activity in the activitybar for the given viewlet or panel.
*/ */
showActivity(viewletId: string, badge: IBadge, clazz?: string): void; showActivity(compositeId: string, badge: IBadge, clazz?: string): void;
/** /**
* Clears activity shown in the activitybar for the given viewlet. * Clears activity shown in the activitybar for the given viewlet or panel.
*/ */
clearActivity(viewletId: string): void; clearActivity(compositeId: string): void;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册