From 02cff42b185e394fbfba743d7dbed492fe43522e Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Sat, 7 Oct 2023 23:28:28 +0200 Subject: [PATCH] top position requires titlebar --- src/vs/workbench/browser/contextkeys.ts | 12 +++++++++++- src/vs/workbench/browser/layout.ts | 14 +++++++++++++- .../browser/parts/activitybar/activitybarPart.ts | 7 +++---- .../workbench/browser/parts/sidebar/sidebarPart.ts | 2 +- src/vs/workbench/browser/workbench.contribution.ts | 4 ++-- src/vs/workbench/common/contextkeys.ts | 6 ++++++ 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/browser/contextkeys.ts b/src/vs/workbench/browser/contextkeys.ts index feca5c8da58..c77d98a5758 100644 --- a/src/vs/workbench/browser/contextkeys.ts +++ b/src/vs/workbench/browser/contextkeys.ts @@ -7,7 +7,7 @@ import { Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import { IContextKeyService, IContextKey, setConstant as setConstantContextKey } from 'vs/platform/contextkey/common/contextkey'; import { InputFocusedContext, IsMacContext, IsLinuxContext, IsWindowsContext, IsWebContext, IsMacNativeContext, IsDevelopmentContext, IsIOSContext, ProductQualityContext, IsMobileContext } from 'vs/platform/contextkey/common/contextkeys'; -import { SplitEditorsVertically, InEditorZenModeContext, ActiveEditorCanRevertContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext, AuxiliaryBarVisibleContext, SideBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelVisibleContext, ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, EmbedderIdentifierContext, EditorTabsVisibleContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorReadonlyContext, EditorAreaVisibleContext, ActiveEditorAvailableEditorIdsContext, DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, IsFullscreenContext, OpenFolderWorkspaceSupportContext, RemoteNameContext, VirtualWorkspaceContext, WorkbenchStateContext, WorkspaceFolderCountContext, PanelPositionContext, TemporaryWorkspaceContext, ActiveEditorCanToggleReadonlyContext, applyAvailableEditorIds } from 'vs/workbench/common/contextkeys'; +import { SplitEditorsVertically, InEditorZenModeContext, ActiveEditorCanRevertContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext, AuxiliaryBarVisibleContext, SideBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelVisibleContext, ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, EmbedderIdentifierContext, EditorTabsVisibleContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorReadonlyContext, EditorAreaVisibleContext, ActiveEditorAvailableEditorIdsContext, DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, IsFullscreenContext, OpenFolderWorkspaceSupportContext, RemoteNameContext, VirtualWorkspaceContext, WorkbenchStateContext, WorkspaceFolderCountContext, PanelPositionContext, TemporaryWorkspaceContext, ActiveEditorCanToggleReadonlyContext, applyAvailableEditorIds, TitleBarVisibleContext } from 'vs/workbench/common/contextkeys'; import { TEXT_DIFF_EDITOR_ID, EditorInputCapabilities, SIDE_BY_SIDE_EDITOR_ID, EditorResourceAccessor, SideBySideEditor } from 'vs/workbench/common/editor'; import { trackFocus, addDisposableListener, EventType } from 'vs/base/browser/dom'; import { preferredSideBySideGroupDirection, GroupDirection, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; @@ -74,6 +74,7 @@ export class WorkbenchContextKeysHandler extends Disposable { private panelMaximizedContext: IContextKey; private auxiliaryBarVisibleContext: IContextKey; private editorTabsVisibleContext: IContextKey; + private titleAreaVisibleContext: IContextKey; constructor( @IContextKeyService private readonly contextKeyService: IContextKeyService, @@ -195,6 +196,10 @@ export class WorkbenchContextKeysHandler extends Disposable { // Sidebar this.sideBarVisibleContext = SideBarVisibleContext.bindTo(this.contextKeyService); + // Title Bar + this.titleAreaVisibleContext = TitleBarVisibleContext.bindTo(this.contextKeyService); + this.updateTitleBarContextKeys(); + // Panel this.panelPositionContext = PanelPositionContext.bindTo(this.contextKeyService); this.panelPositionContext.set(positionToString(this.layoutService.getPanelPosition())); @@ -259,6 +264,7 @@ export class WorkbenchContextKeysHandler extends Disposable { this.panelVisibleContext.set(this.layoutService.isVisible(Parts.PANEL_PART)); this.panelMaximizedContext.set(this.layoutService.isPanelMaximized()); this.auxiliaryBarVisibleContext.set(this.layoutService.isVisible(Parts.AUXILIARYBAR_PART)); + this.updateTitleBarContextKeys(); })); this._register(this.workingCopyService.onDidChangeDirty(workingCopy => this.dirtyWorkingCopiesContext.set(workingCopy.isDirty() || this.workingCopyService.hasDirty))); @@ -367,6 +373,10 @@ export class WorkbenchContextKeysHandler extends Disposable { this.sideBarVisibleContext.set(this.layoutService.isVisible(Parts.SIDEBAR_PART)); } + private updateTitleBarContextKeys(): void { + this.titleAreaVisibleContext.set(this.layoutService.isVisible(Parts.TITLEBAR_PART)); + } + private updateWorkspaceContextKeys(): void { this.virtualWorkspaceContext.set(getVirtualWorkspaceScheme(this.contextService.getWorkspace()) || ''); this.temporaryWorkspaceContext.set(isTemporaryWorkspace(this.contextService.getWorkspace())); diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index f22e8a3da1f..151f2052c2d 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -490,6 +490,11 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi this.stateModel.setRuntimeValue(LayoutStateKeys.EDITOR_HIDDEN, false); } + // Activity bar cannot be hidden + if (this.stateModel.getRuntimeValue(LayoutStateKeys.ACTIVITYBAR_HIDDEN) && !this.canActivityBarBeHidden()) { + this.stateModel.setRuntimeValue(LayoutStateKeys.ACTIVITYBAR_HIDDEN, false); + } + this.stateModel.onDidChangeState(change => { if (change.key === LayoutStateKeys.ACTIVITYBAR_HIDDEN) { this.setActivityBarHidden(change.value as boolean); @@ -1521,11 +1526,18 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi } private setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void { - // Propagate to grid + if (hidden && !this.canActivityBarBeHidden()) { + return; + } this.stateModel.setRuntimeValue(LayoutStateKeys.ACTIVITYBAR_HIDDEN, hidden); + // Propagate to grid this.workbenchGrid.setViewVisible(this.activityBarPartView, !hidden); } + private canActivityBarBeHidden(): boolean { + return !(this.configurationService.getValue(LayoutSettings.ACTIVITY_BAR_LOCATION) === ActivityBarPosition.TOP && !this.isVisible(Parts.TITLEBAR_PART)); + } + private setBannerHidden(hidden: boolean): void { this.workbenchGrid.setViewVisible(this.bannerPartView, !hidden); } diff --git a/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts b/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts index f4f99322364..7a1c9536253 100644 --- a/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts +++ b/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts @@ -37,6 +37,7 @@ import { Categories } from 'vs/platform/action/common/actionCommonCategories'; import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { ViewContainerLocation, ViewContainerLocationToString } from 'vs/workbench/common/views'; import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite'; +import { TitleBarVisibleContext } from 'vs/workbench/common/contextkeys'; export class ActivitybarPart extends Part { @@ -318,7 +319,6 @@ registerAction2(class extends Action2 { }, shortTitle: localize('side', "Side"), category: Categories.View, - f1: true, toggled: ContextKeyExpr.equals(`config.${LayoutSettings.ACTIVITY_BAR_LOCATION}`, ActivityBarPosition.SIDE), menu: [{ id: MenuId.ActivityBarPositionMenu, @@ -346,14 +346,14 @@ registerAction2(class extends Action2 { }, shortTitle: localize('top', "Top"), category: Categories.View, - f1: true, toggled: ContextKeyExpr.equals(`config.${LayoutSettings.ACTIVITY_BAR_LOCATION}`, ActivityBarPosition.TOP), menu: [{ id: MenuId.ActivityBarPositionMenu, + when: TitleBarVisibleContext.isEqualTo(true), order: 2 }, { id: MenuId.CommandPalette, - when: ContextKeyExpr.notEquals(`config.${LayoutSettings.ACTIVITY_BAR_LOCATION}`, ActivityBarPosition.TOP), + when: ContextKeyExpr.and(ContextKeyExpr.notEquals(`config.${LayoutSettings.ACTIVITY_BAR_LOCATION}`, ActivityBarPosition.TOP), TitleBarVisibleContext.isEqualTo(true)), }] }); } @@ -374,7 +374,6 @@ registerAction2(class extends Action2 { }, shortTitle: localize('hide', "Hidden"), category: Categories.View, - f1: true, toggled: ContextKeyExpr.equals(`config.${LayoutSettings.ACTIVITY_BAR_LOCATION}`, ActivityBarPosition.HIDDEN), menu: [{ id: MenuId.ActivityBarPositionMenu, diff --git a/src/vs/workbench/browser/parts/sidebar/sidebarPart.ts b/src/vs/workbench/browser/parts/sidebar/sidebarPart.ts index c58fb04d5cd..1a77eab24c6 100644 --- a/src/vs/workbench/browser/parts/sidebar/sidebarPart.ts +++ b/src/vs/workbench/browser/parts/sidebar/sidebarPart.ts @@ -179,7 +179,7 @@ export class SidebarPart extends AbstractPaneCompositePart { } protected shouldShowCompositeBar(): boolean { - return this.configurationService.getValue('workbench.activityBar.location') === ActivityBarPosition.TOP; + return this.layoutService.isVisible(Parts.TITLEBAR_PART) && this.configurationService.getValue('workbench.activityBar.location') === ActivityBarPosition.TOP; } override getPinnedPaneCompositeIds(): string[] { diff --git a/src/vs/workbench/browser/workbench.contribution.ts b/src/vs/workbench/browser/workbench.contribution.ts index 58a75aa0576..5e867ccc662 100644 --- a/src/vs/workbench/browser/workbench.contribution.ts +++ b/src/vs/workbench/browser/workbench.contribution.ts @@ -467,10 +467,10 @@ const registry = Registry.as(ConfigurationExtensions.Con 'type': 'string', 'enum': ['side', 'top', 'hidden'], 'default': 'side', - 'markdownDescription': localize({ comment: ['This is the description for a setting'], key: 'activityBarLocation' }, "Controls the location of the activity bar. It can either show to the `side` or `top` of the primary side bar or `hidden`. When shown in the top, settings and user menu actions are shown in the title bar to the right (requires `{0}`).", '#window.commandCenter#'), + 'markdownDescription': localize({ comment: ['This is the description for a setting'], key: 'activityBarLocation' }, "Controls the location of the activity bar. It can either show to the `side` or `top` (requires `{0}`) of the primary side bar or `hidden`.", '#window.commandCenter#'), 'enumDescriptions': [ localize('workbench.activityBar.location.side', "Show the activity bar to the side of the primary side bar."), - localize('workbench.activityBar.location.top', "Show the activity bar on top of the primary side bar. When in this mode, application settings and user menu are shown in the title bar to the right."), + localize('workbench.activityBar.location.top', "Show the activity bar on top of the primary side bar."), localize('workbench.activityBar.location.hide', "Hide the activity bar.") ] }, diff --git a/src/vs/workbench/common/contextkeys.ts b/src/vs/workbench/common/contextkeys.ts index 585b45ec13c..8403b656459 100644 --- a/src/vs/workbench/common/contextkeys.ts +++ b/src/vs/workbench/common/contextkeys.ts @@ -97,6 +97,12 @@ export const StatusBarFocused = new RawContextKey('statusBarFocused', f //#endregion +//#region < --- Title Bar --- > + +export const TitleBarVisibleContext = new RawContextKey('titleBarVisible', false, localize('titleBarVisible', "Whether the title bar is visible")); + +//#endregion + //#region < --- Banner --- >