提交 d48541bb 编写于 作者: S Sandeep Somavarapu

Cache and dispose composite actions by the creators

上级 bfb9eb67
...@@ -48,6 +48,7 @@ export class ActivitybarPart extends Part { ...@@ -48,6 +48,7 @@ export class ActivitybarPart extends Part {
private globalActivityIdToActions: { [globalActivityId: string]: GlobalActivityAction; }; private globalActivityIdToActions: { [globalActivityId: string]: GlobalActivityAction; };
private compositeBar: CompositeBar; private compositeBar: CompositeBar;
private compositeActions: { [compositeId: string]: { activityAction: ViewletActivityAction, pinnedAction: ToggleCompositePinnedAction } };
constructor( constructor(
id: string, id: string,
...@@ -60,14 +61,15 @@ export class ActivitybarPart extends Part { ...@@ -60,14 +61,15 @@ export class ActivitybarPart extends Part {
this.globalActivityIdToActions = Object.create(null); this.globalActivityIdToActions = Object.create(null);
this.compositeActions = Object.create(null);
this.compositeBar = this.instantiationService.createInstance(CompositeBar, { this.compositeBar = this.instantiationService.createInstance(CompositeBar, {
icon: true, icon: true,
storageId: ActivitybarPart.PINNED_VIEWLETS, storageId: ActivitybarPart.PINNED_VIEWLETS,
orientation: ActionsOrientation.VERTICAL, orientation: ActionsOrientation.VERTICAL,
composites: this.viewletService.getViewlets().filter(v => this.canShow(v)), composites: this.viewletService.getViewlets().filter(v => this.canShow(v)),
openComposite: (compositeId: string) => this.viewletService.openViewlet(compositeId, true), openComposite: (compositeId: string) => this.viewletService.openViewlet(compositeId, true),
getActivityAction: (compositeId: string) => this.instantiationService.createInstance(ViewletActivityAction, this.viewletService.getViewlet(compositeId)), getActivityAction: (compositeId: string) => this.getCompositeActions(compositeId).activityAction,
getCompositePinnedAction: (compositeId: string) => new ToggleCompositePinnedAction(this.viewletService.getViewlet(compositeId), this.compositeBar), getCompositePinnedAction: (compositeId: string) => this.getCompositeActions(compositeId).pinnedAction,
getOnCompositeClickAction: (compositeId: string) => this.instantiationService.createInstance(ToggleViewletAction, this.viewletService.getViewlet(compositeId)), getOnCompositeClickAction: (compositeId: string) => this.instantiationService.createInstance(ToggleViewletAction, this.viewletService.getViewlet(compositeId)),
getContextMenuActions: () => [this.instantiationService.createInstance(ToggleActivityBarVisibilityAction, ToggleActivityBarVisibilityAction.ID, nls.localize('hideActivitBar', "Hide Activity Bar"))], getContextMenuActions: () => [this.instantiationService.createInstance(ToggleActivityBarVisibilityAction, ToggleActivityBarVisibilityAction.ID, nls.localize('hideActivitBar', "Hide Activity Bar"))],
getDefaultCompositeId: () => this.viewletService.getDefaultViewletId(), getDefaultCompositeId: () => this.viewletService.getDefaultViewletId(),
...@@ -96,7 +98,7 @@ export class ActivitybarPart extends Part { ...@@ -96,7 +98,7 @@ export class ActivitybarPart extends Part {
if (enabled) { if (enabled) {
this.compositeBar.addComposite(this.viewletService.getViewlet(id), true); this.compositeBar.addComposite(this.viewletService.getViewlet(id), true);
} else { } else {
this.compositeBar.removeComposite(id); this.removeComposite(id);
} }
})); }));
} }
...@@ -177,6 +179,18 @@ export class ActivitybarPart extends Part { ...@@ -177,6 +179,18 @@ export class ActivitybarPart extends Part {
}); });
} }
private getCompositeActions(compositeId: string): { activityAction: ViewletActivityAction, pinnedAction: ToggleCompositePinnedAction } {
let compositeActions = this.compositeActions[compositeId];
if (!compositeActions) {
compositeActions = {
activityAction: this.instantiationService.createInstance(ViewletActivityAction, this.viewletService.getViewlet(compositeId)),
pinnedAction: new ToggleCompositePinnedAction(this.viewletService.getViewlet(compositeId), this.compositeBar)
};
this.compositeActions[compositeId] = compositeActions;
}
return compositeActions;
}
private updateCompositebar(): void { private updateCompositebar(): void {
const viewlets = this.viewletService.getViewlets(); const viewlets = this.viewletService.getViewlets();
for (const viewlet of viewlets) { for (const viewlet of viewlets) {
...@@ -189,11 +203,21 @@ export class ActivitybarPart extends Part { ...@@ -189,11 +203,21 @@ export class ActivitybarPart extends Part {
this.compositeBar.activateComposite(viewlet.id); this.compositeBar.activateComposite(viewlet.id);
} }
} else { } else {
this.compositeBar.removeComposite(viewlet.id); this.removeComposite(viewlet.id);
} }
} }
} }
private removeComposite(compositeId: string): void {
this.compositeBar.removeComposite(compositeId);
const compositeActions = this.compositeActions[compositeId];
if (compositeActions) {
compositeActions.activityAction.dispose();
compositeActions.pinnedAction.dispose();
delete this.compositeActions[compositeId];
}
}
private canShow(viewlet: ViewletDescriptor): boolean { private canShow(viewlet: ViewletDescriptor): boolean {
const viewLocation = ViewLocation.get(viewlet.id); const viewLocation = ViewLocation.get(viewlet.id);
if (viewLocation) { if (viewLocation) {
......
...@@ -478,7 +478,7 @@ interface ISerializedCompositeBarItem { ...@@ -478,7 +478,7 @@ interface ISerializedCompositeBarItem {
order: number; order: number;
} }
interface ICompositeBarItem extends ISerializedCompositeBarItem, IDisposable { interface ICompositeBarItem extends ISerializedCompositeBarItem {
name: string; name: string;
activityAction: ActivityAction; activityAction: ActivityAction;
pinnedAction: Action; pinnedAction: Action;
...@@ -494,28 +494,13 @@ class CompositeBarModel { ...@@ -494,28 +494,13 @@ class CompositeBarModel {
private createCompositeBarItem(id: string, name: string, order: number, pinned: boolean): ICompositeBarItem { private createCompositeBarItem(id: string, name: string, order: number, pinned: boolean): ICompositeBarItem {
const options = this.options; const options = this.options;
let activityAction, pinnedAction;
return { return {
id, name, pinned, order, activity: [], id, name, pinned, order, activity: [],
get activityAction() { get activityAction() {
if (!activityAction) { return options.getActivityAction(id);
activityAction = options.getActivityAction(id);
}
return activityAction;
}, },
get pinnedAction() { get pinnedAction() {
if (!pinnedAction) { return options.getCompositePinnedAction(id);
pinnedAction = options.getCompositePinnedAction(id);
}
return pinnedAction;
},
dispose: () => {
if (activityAction) {
activityAction.dispose();
}
if (pinnedAction) {
pinnedAction.dispose();
}
} }
}; };
} }
...@@ -541,8 +526,7 @@ class CompositeBarModel { ...@@ -541,8 +526,7 @@ class CompositeBarModel {
remove(id: string): boolean { remove(id: string): boolean {
for (let index = 0; index < this.items.length; index++) { for (let index = 0; index < this.items.length; index++) {
if (this.items[index].id === id) { if (this.items[index].id === id) {
const item = this.items.splice(index, 1)[0]; this.items.splice(index, 1);
item.dispose();
return true; return true;
} }
} }
......
...@@ -42,6 +42,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService { ...@@ -42,6 +42,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
private blockOpeningPanel: boolean; private blockOpeningPanel: boolean;
private compositeBar: CompositeBar; private compositeBar: CompositeBar;
private compositeActions: { [compositeId: string]: { activityAction: PanelActivityAction, pinnedAction: ToggleCompositePinnedAction } };
private dimension: Dimension; private dimension: Dimension;
constructor( constructor(
...@@ -74,14 +75,15 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService { ...@@ -74,14 +75,15 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
{ hasTitle: true } { hasTitle: true }
); );
this.compositeActions = Object.create(null);
this.compositeBar = this.instantiationService.createInstance(CompositeBar, { this.compositeBar = this.instantiationService.createInstance(CompositeBar, {
icon: false, icon: false,
storageId: PanelPart.PINNED_PANELS, storageId: PanelPart.PINNED_PANELS,
orientation: ActionsOrientation.HORIZONTAL, orientation: ActionsOrientation.HORIZONTAL,
composites: this.getPanels(), composites: this.getPanels(),
openComposite: (compositeId: string) => this.openPanel(compositeId, true), openComposite: (compositeId: string) => this.openPanel(compositeId, true),
getActivityAction: (compositeId: string) => this.instantiationService.createInstance(PanelActivityAction, this.getPanel(compositeId)), getActivityAction: (compositeId: string) => this.getCompositeActions(compositeId).activityAction,
getCompositePinnedAction: (compositeId: string) => new ToggleCompositePinnedAction(this.getPanel(compositeId), this.compositeBar), getCompositePinnedAction: (compositeId: string) => this.getCompositeActions(compositeId).pinnedAction,
getOnCompositeClickAction: (compositeId: string) => this.instantiationService.createInstance(PanelActivityAction, this.getPanel(compositeId)), getOnCompositeClickAction: (compositeId: string) => this.instantiationService.createInstance(PanelActivityAction, this.getPanel(compositeId)),
getContextMenuActions: () => [this.instantiationService.createInstance(TogglePanelAction, TogglePanelAction.ID, localize('hidePanel', "Hide Panel"))], getContextMenuActions: () => [this.instantiationService.createInstance(TogglePanelAction, TogglePanelAction.ID, localize('hidePanel', "Hide Panel"))],
getDefaultCompositeId: () => Registry.as<PanelRegistry>(PanelExtensions.Panels).getDefaultPanelId(), getDefaultCompositeId: () => Registry.as<PanelRegistry>(PanelExtensions.Panels).getDefaultPanelId(),
...@@ -178,7 +180,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService { ...@@ -178,7 +180,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
this.compositeBar.activateComposite(descriptor.id); this.compositeBar.activateComposite(descriptor.id);
}); });
} else { } else {
this.compositeBar.removeComposite(id); this.removeComposite(id);
} }
} }
} }
...@@ -253,6 +255,28 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService { ...@@ -253,6 +255,28 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
} }
} }
private getCompositeActions(compositeId: string): { activityAction: PanelActivityAction, pinnedAction: ToggleCompositePinnedAction } {
let compositeActions = this.compositeActions[compositeId];
if (!compositeActions) {
compositeActions = {
activityAction: this.instantiationService.createInstance(PanelActivityAction, this.getPanel(compositeId)),
pinnedAction: new ToggleCompositePinnedAction(this.getPanel(compositeId), this.compositeBar)
};
this.compositeActions[compositeId] = compositeActions;
}
return compositeActions;
}
private removeComposite(compositeId: string): void {
this.compositeBar.removeComposite(compositeId);
const compositeActions = this.compositeActions[compositeId];
if (compositeActions) {
compositeActions.activityAction.dispose();
compositeActions.pinnedAction.dispose();
delete this.compositeActions[compositeId];
}
}
private getToolbarWidth(): number { private getToolbarWidth(): number {
const activePanel = this.getActivePanel(); const activePanel = this.getActivePanel();
if (!activePanel) { if (!activePanel) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册