diff --git a/src/vs/workbench/browser/parts/compositeBar.ts b/src/vs/workbench/browser/parts/compositeBar.ts index 5e83a9458bdf7..11577775c8e39 100644 --- a/src/vs/workbench/browser/parts/compositeBar.ts +++ b/src/vs/workbench/browser/parts/compositeBar.ts @@ -267,6 +267,10 @@ export class CompositeBar extends Widget implements ICompositeBar { return this.model.pinnedItems; } + getPinnedCompositeIds(): string[] { + return this.getPinnedComposites().map(c => c.id); + } + getVisibleComposites(): ICompositeBarItem[] { return this.model.visibleItems; } @@ -651,19 +655,22 @@ export class CompositeBar extends Widget implements ICompositeBar { getContextMenuActions(e?: MouseEvent | GestureEvent): IAction[] { const actions: IAction[] = this.model.visibleItems - .map(({ id, name, activityAction }) => (toAction({ - id, - label: this.getAction(id).label || name || id, - checked: this.isPinned(id), - enabled: activityAction.enabled, - run: () => { - if (this.isPinned(id)) { - this.unpin(id); - } else { - this.pin(id, true); + .map(({ id, name, activityAction }) => { + const isPinned = this.isPinned(id); + return toAction({ + id, + label: this.getAction(id).label || name || id, + checked: isPinned, + enabled: activityAction.enabled && (!isPinned || this.getPinnedCompositeIds().length > 1), + run: () => { + if (this.isPinned(id)) { + this.unpin(id); + } else { + this.pin(id, true); + } } - } - }))); + }); + }); this.options.fillExtraContextMenuActions(actions, e); diff --git a/src/vs/workbench/browser/parts/compositeBarActions.ts b/src/vs/workbench/browser/parts/compositeBarActions.ts index 15f6b06331c8e..89876b6dffc61 100644 --- a/src/vs/workbench/browser/parts/compositeBarActions.ts +++ b/src/vs/workbench/browser/parts/compositeBarActions.ts @@ -45,6 +45,11 @@ export interface ICompositeBar { */ isPinned(compositeId: string): boolean; + /** + * Get pinned composite ids in the composite bar. + */ + getPinnedCompositeIds(): string[]; + /** * Returns if badges are enabled for that specified composite. * @param compositeId The id of the composite to check @@ -689,8 +694,10 @@ export class CompositeActionViewItem extends CompositeBarActionViewItem { if (isPinned) { this.toggleCompositePinnedAction.label = localize('hide', "Hide '{0}'", this.compositeBarActionItem.name); this.toggleCompositePinnedAction.checked = false; + this.toggleCompositePinnedAction.enabled = this.compositeBar.getPinnedCompositeIds().length > 1; } else { this.toggleCompositePinnedAction.label = localize('keep', "Keep '{0}'", this.compositeBarActionItem.name); + this.toggleCompositePinnedAction.enabled = true; } const isBadgeEnabled = this.compositeBar.areBadgesEnabled(this.compositeBarActionItem.id);