From c805ab792ef340f05e7a77cabd139dbc26805ee4 Mon Sep 17 00:00:00 2001 From: SteVen Batten Date: Fri, 18 Oct 2019 15:21:30 -0700 Subject: [PATCH] centralize part visibility eventing add context key for editor area visible fixes #67707 --- .../browser/actions/layoutActions.ts | 12 ++++++++- src/vs/workbench/browser/contextkeys.ts | 8 +++++- src/vs/workbench/browser/layout.ts | 26 +++++++++++-------- src/vs/workbench/browser/part.ts | 7 +++++ .../parts/activitybar/activitybarPart.ts | 6 ----- .../browser/parts/editor/editorPart.ts | 7 ----- .../browser/parts/panel/panelPart.ts | 9 +------ .../browser/parts/sidebar/sidebarPart.ts | 7 ----- src/vs/workbench/common/editor.ts | 1 + .../services/layout/browser/layoutService.ts | 5 ++++ .../workbench/test/workbenchTestServices.ts | 1 + 11 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/vs/workbench/browser/actions/layoutActions.ts b/src/vs/workbench/browser/actions/layoutActions.ts index a59a10af03f..3f237de2aef 100644 --- a/src/vs/workbench/browser/actions/layoutActions.ts +++ b/src/vs/workbench/browser/actions/layoutActions.ts @@ -20,7 +20,7 @@ import { MenuBarVisibility } from 'vs/platform/windows/common/windows'; import { isWindows, isLinux, isWeb } from 'vs/base/common/platform'; import { IsMacNativeContext } from 'vs/workbench/browser/contextkeys'; import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; -import { InEditorZenModeContext, IsCenteredLayoutContext } from 'vs/workbench/common/editor'; +import { InEditorZenModeContext, IsCenteredLayoutContext, EditorAreaVisibleContext } from 'vs/workbench/common/editor'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { SideBarVisibleContext } from 'vs/workbench/common/viewlet'; @@ -232,6 +232,16 @@ export class ToggleEditorVisibilityAction extends Action { registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleEditorVisibilityAction, ToggleEditorVisibilityAction.ID, ToggleEditorVisibilityAction.LABEL), 'View: Toggle Editor Area Visibility', viewCategory); +MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, { + group: '2_workbench_layout', + command: { + id: ToggleEditorVisibilityAction.ID, + title: nls.localize({ key: 'miShowEditorArea', comment: ['&& denotes a mnemonic'] }, "Show &&Editor Area"), + toggled: EditorAreaVisibleContext + }, + order: 5 +}); + export class ToggleSidebarVisibilityAction extends Action { static readonly ID = 'workbench.action.toggleSidebarVisibility'; diff --git a/src/vs/workbench/browser/contextkeys.ts b/src/vs/workbench/browser/contextkeys.ts index 2a88e72a81c..06f1118d18a 100644 --- a/src/vs/workbench/browser/contextkeys.ts +++ b/src/vs/workbench/browser/contextkeys.ts @@ -8,7 +8,7 @@ import { Disposable } from 'vs/base/common/lifecycle'; import { IContextKeyService, IContextKey, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { InputFocusedContext } from 'vs/platform/contextkey/common/contextkeys'; import { IWindowsConfiguration } from 'vs/platform/windows/common/windows'; -import { ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, TEXT_DIFF_EDITOR_ID, SplitEditorsVertically, InEditorZenModeContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorIsSaveableContext, toResource, SideBySideEditor } from 'vs/workbench/common/editor'; +import { ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, TEXT_DIFF_EDITOR_ID, SplitEditorsVertically, InEditorZenModeContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorIsSaveableContext, toResource, SideBySideEditor, EditorAreaVisibleContext } 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'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; @@ -73,6 +73,7 @@ export class WorkbenchContextKeysHandler extends Disposable { private isFullscreenContext: IContextKey; private isCenteredLayoutContext: IContextKey; private sideBarVisibleContext: IContextKey; + private editorAreaVisibleContext: IContextKey; private panelPositionContext: IContextKey; constructor( @@ -146,6 +147,9 @@ export class WorkbenchContextKeysHandler extends Disposable { // Centered Layout this.isCenteredLayoutContext = IsCenteredLayoutContext.bindTo(this.contextKeyService); + // Editor Area + this.editorAreaVisibleContext = EditorAreaVisibleContext.bindTo(this.contextKeyService); + // Sidebar this.sideBarVisibleContext = SideBarVisibleContext.bindTo(this.contextKeyService); @@ -184,6 +188,8 @@ export class WorkbenchContextKeysHandler extends Disposable { this._register(this.viewletService.onDidViewletClose(() => this.updateSideBarContextKeys())); this._register(this.viewletService.onDidViewletOpen(() => this.updateSideBarContextKeys())); + + this._register(this.layoutService.onPartVisibilityChange(() => this.editorAreaVisibleContext.set(this.layoutService.isVisible(Parts.EDITOR_PART)))); } private updateEditorContextKeys(): void { diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index cd21e91bf81..adf6f6668a7 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -99,6 +99,9 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi private readonly _onPanelPositionChange: Emitter = this._register(new Emitter()); readonly onPanelPositionChange: Event = this._onPanelPositionChange.event; + private readonly _onPartVisibilityChange: Emitter = this._register(new Emitter()); + readonly onPartVisibilityChange: Event = this._onPartVisibilityChange.event; + private readonly _onLayout = this._register(new Emitter()); readonly onLayout: Event = this._onLayout.event; @@ -797,17 +800,18 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi this.container.prepend(workbenchGrid.element); this.workbenchGrid = workbenchGrid; - this._register((this.sideBarPartView as SidebarPart).onDidVisibilityChange((visible) => { - this.setSideBarHidden(!visible, true); - })); - - this._register((this.panelPartView as PanelPart).onDidVisibilityChange((visible) => { - this.setPanelHidden(!visible, true); - })); - - this._register((this.editorPartView as PanelPart).onDidVisibilityChange((visible) => { - this.setEditorHidden(!visible, true); - })); + [titleBar, editorPart, activityBar, panelPart, sideBar, statusBar].forEach((part: Part) => { + this._register(part.onDidVisibilityChange((visible) => { + this._onPartVisibilityChange.fire(); + if (part === sideBar) { + this.setSideBarHidden(!visible, true); + } else if (part === panelPart) { + this.setPanelHidden(!visible, true); + } else if (part === editorPart) { + this.setEditorHidden(!visible, true); + } + })); + }); this._register(this.storageService.onWillSaveState(() => { const grid = this.workbenchGrid as SerializableGrid; diff --git a/src/vs/workbench/browser/part.ts b/src/vs/workbench/browser/part.ts index aa36e60b373..d5ee8de2887 100644 --- a/src/vs/workbench/browser/part.ts +++ b/src/vs/workbench/browser/part.ts @@ -33,6 +33,9 @@ export abstract class Part extends Component implements ISerializableView { private _dimension: Dimension | undefined; get dimension(): Dimension | undefined { return this._dimension; } + protected _onDidVisibilityChange = this._register(new Emitter()); + readonly onDidVisibilityChange: Event = this._onDidVisibilityChange.event; + private parent: HTMLElement | undefined; private titleArea: HTMLElement | undefined; private contentArea: HTMLElement | undefined; @@ -138,6 +141,10 @@ export abstract class Part extends Component implements ISerializableView { this._dimension = new Dimension(width, height); } + setVisible(visible: boolean) { + this._onDidVisibilityChange.fire(visible); + } + abstract toJSON(): object; //#endregion diff --git a/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts b/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts index 5b258eab12c..561076cbbd8 100644 --- a/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts +++ b/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts @@ -437,12 +437,6 @@ export class ActivitybarPart extends Part implements IActivityBarService { .map(v => v.id); } - setVisible(visible: boolean): void { - if (this.element) { - this.element.style.display = visible ? '' : 'none'; - } - } - layout(width: number, height: number): void { if (!this.layoutService.isVisible(Parts.ACTIVITYBAR_PART)) { return; diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index 20392c4f0bd..75c49c31c86 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -114,9 +114,6 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro private _onDidSizeConstraintsChange = this._register(new Relay<{ width: number; height: number; } | undefined>()); get onDidSizeConstraintsChange(): Event<{ width: number; height: number; } | undefined> { return Event.any(this.onDidSetGridWidget.event, this._onDidSizeConstraintsChange.event); } - private _onDidVisibilityChange = this._register(new Emitter()); - readonly onDidVisibilityChange: Event = this._onDidVisibilityChange.event; - //#endregion private readonly workspaceMemento: MementoObject; @@ -1037,10 +1034,6 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro //#endregion - setVisible(visible: boolean): void { - this._onDidVisibilityChange.fire(visible); - } - toJSON(): object { return { type: Parts.EDITOR_PART diff --git a/src/vs/workbench/browser/parts/panel/panelPart.ts b/src/vs/workbench/browser/parts/panel/panelPart.ts index f9a66d07a6b..be69e4c61e5 100644 --- a/src/vs/workbench/browser/parts/panel/panelPart.ts +++ b/src/vs/workbench/browser/parts/panel/panelPart.ts @@ -5,7 +5,7 @@ import 'vs/css!./media/panelpart'; import { IAction } from 'vs/base/common/actions'; -import { Event, Emitter } from 'vs/base/common/event'; +import { Event } from 'vs/base/common/event'; import { Registry } from 'vs/platform/registry/common/platform'; import { ActionsOrientation } from 'vs/base/browser/ui/actionbar/actionbar'; import { IPanel, ActivePanelContext, PanelFocusContext } from 'vs/workbench/common/panel'; @@ -74,9 +74,6 @@ export class PanelPart extends CompositePart implements IPanelService { get onDidPanelOpen(): Event<{ panel: IPanel, focus: boolean; }> { return Event.map(this.onDidCompositeOpen.event, compositeOpen => ({ panel: compositeOpen.composite, focus: compositeOpen.focus })); } readonly onDidPanelClose: Event = this.onDidCompositeClose.event; - private _onDidVisibilityChange = this._register(new Emitter()); - readonly onDidVisibilityChange: Event = this._onDidVisibilityChange.event; - private activePanelContextKey: IContextKey; private panelFocusContextKey: IContextKey; @@ -446,10 +443,6 @@ export class PanelPart extends CompositePart implements IPanelService { this.storageService.store(PanelPart.PINNED_PANELS, value, StorageScope.GLOBAL); } - setVisible(visible: boolean): void { - this._onDidVisibilityChange.fire(visible); - } - toJSON(): object { return { type: Parts.PANEL_PART diff --git a/src/vs/workbench/browser/parts/sidebar/sidebarPart.ts b/src/vs/workbench/browser/parts/sidebar/sidebarPart.ts index 9600cb74a4f..809316c6777 100644 --- a/src/vs/workbench/browser/parts/sidebar/sidebarPart.ts +++ b/src/vs/workbench/browser/parts/sidebar/sidebarPart.ts @@ -70,9 +70,6 @@ export class SidebarPart extends CompositePart implements IViewletServi get onDidViewletRegister(): Event { return >this.viewletRegistry.onDidRegister; } - private _onDidVisibilityChange = this._register(new Emitter()); - readonly onDidVisibilityChange: Event = this._onDidVisibilityChange.event; - private _onDidViewletDeregister = this._register(new Emitter()); readonly onDidViewletDeregister: Event = this._onDidViewletDeregister.event; @@ -284,10 +281,6 @@ export class SidebarPart extends CompositePart implements IViewletServi } } - setVisible(visible: boolean): void { - this._onDidVisibilityChange.fire(visible); - } - toJSON(): object { return { type: Parts.SIDEBAR_PART diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 255d6671f30..fba48795013 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -38,6 +38,7 @@ export const SingleEditorGroupsContext = MultipleEditorGroupsContext.toNegated() export const InEditorZenModeContext = new RawContextKey('inZenMode', false); export const IsCenteredLayoutContext = new RawContextKey('isCenteredLayout', false); export const SplitEditorsVertically = new RawContextKey('splitEditorsVertically', false); +export const EditorAreaVisibleContext = new RawContextKey('editorAreaVisible', true); /** * Text diff editor id. diff --git a/src/vs/workbench/services/layout/browser/layoutService.ts b/src/vs/workbench/services/layout/browser/layoutService.ts index 0176b9ff57e..f17b466b5fb 100644 --- a/src/vs/workbench/services/layout/browser/layoutService.ts +++ b/src/vs/workbench/services/layout/browser/layoutService.ts @@ -56,6 +56,11 @@ export interface IWorkbenchLayoutService extends ILayoutService { */ readonly onPanelPositionChange: Event; + /** + * Emit when part visibility changes + */ + readonly onPartVisibilityChange: Event; + /** * Asks the part service if all parts have been fully restored. For editor part * this means that the contents of editors have loaded. diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index e7a3f20e3a2..b82d44d11a3 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -462,6 +462,7 @@ export class TestLayoutService implements IWorkbenchLayoutService { onCenteredLayoutChange: Event = Event.None; onFullscreenChange: Event = Event.None; onPanelPositionChange: Event = Event.None; + onPartVisibilityChange: Event = Event.None; onLayout = Event.None; private readonly _onTitleBarVisibilityChange = new Emitter();