Skip to content

Commit

Permalink
Disable action to remove last view container (#229969)
Browse files Browse the repository at this point in the history
Don't allow removing last view container
  • Loading branch information
benibenj authored Sep 27, 2024
1 parent cee1e10 commit 449e524
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/vs/workbench/browser/parts/compositeBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/browser/parts/compositeBarActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 449e524

Please sign in to comment.