update menu entry logic

This commit is contained in:
SteVen Batten
2020-01-22 18:59:49 -08:00
parent 7f42ea140d
commit 8bb42eaa29
4 changed files with 46 additions and 25 deletions
@@ -40,6 +40,7 @@ export interface ICompositeBarOptions {
getCompositePinnedAction: (compositeId: string) => Action;
getOnCompositeClickAction: (compositeId: string) => Action;
getContextMenuActions: () => Action[];
getContextMenuActionsForCompositeId?: (compositeId: string) => Action[];
openComposite: (compositeId: string) => Promise<any>;
getDefaultCompositeId: () => string;
hidePart: () => void;
@@ -100,7 +101,14 @@ export class CompositeBar extends Widget implements ICompositeBar {
return this.compositeOverflowActionViewItem;
}
const item = this.model.findItem(action.id);
return item && this.instantiationService.createInstance(CompositeActionViewItem, action as ActivityAction, item.pinnedAction, () => this.getContextMenuActions() as Action[], this.options.colors, this.options.icon, this);
return item && this.instantiationService.createInstance(
CompositeActionViewItem, action as ActivityAction, item.pinnedAction,
(compositeId: string) => { return this.options.getContextMenuActionsForCompositeId === undefined ? [] : this.options.getContextMenuActionsForCompositeId(compositeId); },
() => this.getContextMenuActions() as Action[],
this.options.colors,
this.options.icon,
this
);
},
orientation: this.options.orientation,
ariaLabel: nls.localize('activityBarAriaLabel', "Active View Switcher"),
@@ -463,6 +463,7 @@ export class CompositeActionViewItem extends ActivityActionViewItem {
constructor(
private compositeActivityAction: ActivityAction,
private toggleCompositePinnedAction: Action,
private compositeMenuActionsProvider: (compositeId: string) => ReadonlyArray<Action>,
private contextMenuActionsProvider: () => ReadonlyArray<Action>,
colors: (theme: ITheme) => ICompositeBarColors,
icon: boolean,
@@ -596,6 +597,12 @@ export class CompositeActionViewItem extends ActivityActionViewItem {
private showContextMenu(container: HTMLElement): void {
const actions: Action[] = [this.toggleCompositePinnedAction];
const compositeSpecificActions = this.compositeMenuActionsProvider(this.activity.id);
if (compositeSpecificActions.length) {
actions.push(...compositeSpecificActions);
}
if ((<any>this.compositeActivityAction.activity).extensionId) {
actions.push(new Separator());
actions.push(CompositeActionViewItem.manageExtensionAction);
@@ -131,13 +131,13 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
getCompositePinnedAction: (compositeId: string) => this.getCompositeActions(compositeId).pinnedAction,
getOnCompositeClickAction: (compositeId: string) => this.instantiationService.createInstance(PanelActivityAction, assertIsDefined(this.getPanel(compositeId))),
getContextMenuActions: () => [
...this.getContextMenuActions(),
...PositionPanelActionConfigs
// show the contextual menu item if it is not in that position
.filter(({ when }) => contextKeyService.contextMatchesRules(when))
.map(({ id, label }) => this.instantiationService.createInstance(SetPanelPositionAction, id, label)),
this.instantiationService.createInstance(TogglePanelAction, TogglePanelAction.ID, localize('hidePanel', "Hide Panel"))
] as Action[],
getContextMenuActionsForCompositeId: (compositeId: string) => this.getContextMenuActionsForCompositeId(compositeId) as Action[],
getDefaultCompositeId: () => this.panelRegistry.getDefaultPanelId(),
hidePart: () => this.layoutService.setPanelHidden(true),
compositeSize: 0,
@@ -161,14 +161,14 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
this.onDidRegisterPanels([...this.getPanels()]);
}
private getContextMenuActions(): readonly IAction[] {
const activePanel = this.getActivePanel();
private getContextMenuActionsForCompositeId(compositeId: string): readonly IAction[] {
const panel = this.getActivePanel();
if (!activePanel) {
if (!panel || panel.getId() !== compositeId) {
return [];
}
return activePanel.getContextMenuActions();
return panel.getContextMenuActions();
}
private onDidRegisterPanels(panels: PanelDescriptor[]): void {
@@ -397,10 +397,13 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer {
viewDescriptor = Registry.as<IViewsRegistry>(ViewsExtensions.ViewsRegistry).getView(viewId)!;
}
const viewContainerRegistry = Registry.as<IViewContainersRegistry>(ViewsExtensions.ViewContainersRegistry);
const currentLocation = viewContainerRegistry.getViewContainerLocation(this.viewContainer);
const result: IAction[] = [];
if (viewDescriptor) {
if (!this.isViewMergedWithContainer()) {
// For now, restrict any additional actions to the sidebar only
if (!this.isViewMergedWithContainer() && currentLocation === ViewContainerLocation.Sidebar) {
result.push(<IAction>{
id: `${viewDescriptor.id}.removeView`,
label: nls.localize('hideView', "Hide"),
@@ -410,28 +413,33 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer {
}
if (viewDescriptor.canMoveView) {
const newLocation = currentLocation === ViewContainerLocation.Panel ? ViewContainerLocation.Sidebar : ViewContainerLocation.Panel;
result.push(<IAction>{
id: `${viewDescriptor.id}.removeView`,
label: this.isViewMergedWithContainer() ? nls.localize('toggleSpecificViewLocation', "Toggle {0} View Location", viewDescriptor.name) : nls.localize('toggleViewLocation', "Toggle View Location"),
id: `${viewDescriptor.id}.moveView`,
label: newLocation === ViewContainerLocation.Sidebar ? nls.localize('moveViewToSidebar', "Move to Sidebar") : nls.localize('moveViewToPanel', "Move to Panel"),
enabled: true,
run: () => this.moveView(viewDescriptor!)
run: () => this.moveView(viewDescriptor!, newLocation)
});
}
}
const viewToggleActions = this.viewsModel.viewDescriptors.map(viewDescriptor => (<IAction>{
id: `${viewDescriptor.id}.toggleVisibility`,
label: viewDescriptor.name,
checked: this.viewsModel.isVisible(viewDescriptor.id),
enabled: viewDescriptor.canToggleVisibility,
run: () => this.toggleViewVisibility(viewDescriptor.id)
}));
// For now, restrict any additional actions to the sidebar only
if (currentLocation === ViewContainerLocation.Sidebar) {
const viewToggleActions = this.viewsModel.viewDescriptors.map(viewDescriptor => (<IAction>{
id: `${viewDescriptor.id}.toggleVisibility`,
label: viewDescriptor.name,
checked: this.viewsModel.isVisible(viewDescriptor.id),
enabled: viewDescriptor.canToggleVisibility,
run: () => this.toggleViewVisibility(viewDescriptor.id)
}));
if (result.length && viewToggleActions.length) {
result.push(new Separator());
if (result.length && viewToggleActions.length) {
result.push(new Separator());
}
result.push(...viewToggleActions);
}
result.push(...viewToggleActions);
return result;
}
@@ -673,10 +681,8 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer {
this.viewsModel.setVisible(viewId, visible);
}
protected moveView(viewDescriptor: IViewDescriptor): void {
const viewContainerRegistry = Registry.as<IViewContainersRegistry>(ViewsExtensions.ViewContainersRegistry);
const currentLocation = viewContainerRegistry.getViewContainerLocation(this.viewContainer);
this.viewDescriptorService.moveViewToLocation(viewDescriptor, currentLocation === ViewContainerLocation.Sidebar ? ViewContainerLocation.Panel : ViewContainerLocation.Sidebar);
protected moveView(viewDescriptor: IViewDescriptor, location: ViewContainerLocation): void {
this.viewDescriptorService.moveViewToLocation(viewDescriptor, location);
this.viewsService.openView(viewDescriptor.id, true);
}