diff --git a/src/vs/code/electron-main/menus.ts b/src/vs/code/electron-main/menus.ts index c636a3730c176..fbfbe7c5adea8 100644 --- a/src/vs/code/electron-main/menus.ts +++ b/src/vs/code/electron-main/menus.ts @@ -33,6 +33,9 @@ interface IConfiguration extends IFilesConfiguration { }, statusBar: { visible: boolean; + }, + activityBar: { + visible: boolean; } }; } @@ -46,6 +49,7 @@ export class VSCodeMenu { private currentAutoSaveSetting: string; private currentSidebarLocation: 'left' | 'right'; private currentStatusbarVisible: boolean; + private currentActivityBarVisible: boolean; private isQuitting: boolean; private appMenuInstalled: boolean; @@ -158,6 +162,15 @@ export class VSCodeMenu { updateMenu = true; } + let newActivityBarVisible = config && config.workbench && config.workbench.activityBar && config.workbench.activityBar.visible; + if (typeof newActivityBarVisible !== 'boolean') { + newActivityBarVisible = true; + } + if (newActivityBarVisible !== this.currentActivityBarVisible) { + this.currentActivityBarVisible = newActivityBarVisible; + updateMenu = true; + } + if (handleMenu && updateMenu) { this.updateMenu(); } @@ -547,6 +560,14 @@ export class VSCodeMenu { } const toggleStatusbar = this.createMenuItem(statusBarLabel, 'workbench.action.toggleStatusbarVisibility'); + let activityBarLabel: string; + if (this.currentActivityBarVisible) { + activityBarLabel = nls.localize({ key: 'miHideActivityBar', comment: ['&& denotes a mnemonic'] }, "Hide &&Activity Bar"); + } else { + activityBarLabel = nls.localize({ key: 'miShowActivityBar', comment: ['&& denotes a mnemonic'] }, "Show &&Activity Bar"); + } + const toggleActivtyBar = this.createMenuItem(activityBarLabel, 'workbench.action.toggleActivityBarVisibility'); + const toggleWordWrap = this.createMenuItem(nls.localize({ key: 'miToggleWordWrap', comment: ['&& denotes a mnemonic'] }, "Toggle &&Word Wrap"), 'editor.action.toggleWordWrap'); const toggleRenderWhitespace = this.createMenuItem(nls.localize({ key: 'miToggleRenderWhitespace', comment: ['&& denotes a mnemonic'] }, "Toggle &&Render Whitespace"), 'editor.action.toggleRenderWhitespace'); const toggleRenderControlCharacters = this.createMenuItem(nls.localize({ key: 'miToggleRenderControlCharacters', comment: ['&& denotes a mnemonic'] }, "Toggle &&Control Characters"), 'editor.action.toggleRenderControlCharacter'); @@ -578,6 +599,7 @@ export class VSCodeMenu { toggleSidebar, togglePanel, toggleStatusbar, + toggleActivtyBar, __separator__(), toggleWordWrap, toggleRenderWhitespace, diff --git a/src/vs/test/utils/servicesTestUtils.ts b/src/vs/test/utils/servicesTestUtils.ts index 4965a8996a21d..688ff9a4f96b7 100644 --- a/src/vs/test/utils/servicesTestUtils.ts +++ b/src/vs/test/utils/servicesTestUtils.ts @@ -257,6 +257,12 @@ export class TestPartService implements IPartService { return false; } + public isActivityBarHidden(): boolean { + return false; + } + + public setActivityBarHidden(hidden: boolean): void { } + public isSideBarHidden(): boolean { return false; } diff --git a/src/vs/workbench/browser/actions/toggleActivityBarVisibility.ts b/src/vs/workbench/browser/actions/toggleActivityBarVisibility.ts new file mode 100644 index 0000000000000..6968f8efce8ac --- /dev/null +++ b/src/vs/workbench/browser/actions/toggleActivityBarVisibility.ts @@ -0,0 +1,49 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import { TPromise } from 'vs/base/common/winjs.base'; +import nls = require('vs/nls'); +import { Registry } from 'vs/platform/platform'; +import { Action } from 'vs/base/common/actions'; +import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; +import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry'; +import { IMessageService, Severity } from 'vs/platform/message/common/message'; +import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing'; +import { IPartService } from 'vs/workbench/services/part/common/partService'; + +export class ToggleActivityBarVisibilityAction extends Action { + + public static ID = 'workbench.action.toggleActivityBarVisibility'; + public static LABEL = nls.localize('toggleActivityBar', "Toggle Activity Bar Visibility"); + + private static activityBarVisibleKey = 'workbench.activityBar.visible'; + + constructor( + id: string, + label: string, + @IPartService private partService: IPartService, + @IMessageService private messageService: IMessageService, + @IConfigurationEditingService private configurationEditingService: IConfigurationEditingService + ) { + super(id, label); + + this.enabled = !!this.partService; + } + + public run(): TPromise { + const visibility = !this.partService.isActivityBarHidden(); + const newVisibilityValue = !visibility; + + this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleActivityBarVisibilityAction.activityBarVisibleKey, value: newVisibilityValue }).then(null, error => { + this.messageService.show(Severity.Error, error); + }); + + return TPromise.as(null); + } +} + +let registry = Registry.as(Extensions.WorkbenchActions); +registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleActivityBarVisibilityAction, ToggleActivityBarVisibilityAction.ID, ToggleActivityBarVisibilityAction.LABEL), 'View: Toggle Activity Bar Visibility', nls.localize('view', "View")); \ No newline at end of file diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index 688c38f9ccc18..b92f3b0c49589 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -335,6 +335,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal this.workbenchSize = this.getWorkbenchArea(); + const isActivityBarHidden = this.partService.isActivityBarHidden(); const isTitlebarHidden = !this.partService.isVisible(Parts.TITLEBAR_PART); const isPanelHidden = !this.partService.isVisible(Parts.PANEL_PART); const isStatusbarHidden = !this.partService.isVisible(Parts.STATUSBAR_PART); @@ -359,7 +360,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal let sidebarSize = new Dimension(sidebarWidth, this.sidebarHeight); // Activity Bar - this.activitybarWidth = this.computedStyles.activitybar.width; + this.activitybarWidth = isActivityBarHidden ? 0 : this.computedStyles.activitybar.width; let activityBarSize = new Dimension(this.activitybarWidth, sidebarSize.height); // Panel part @@ -487,6 +488,11 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal this.activitybar.getContainer().getHTMLElement().style.left = ''; this.activitybar.getContainer().position(this.titlebarHeight, 0, 0, null); } + if (isActivityBarHidden) { + this.activitybar.getContainer().hide(); + } else { + this.activitybar.getContainer().show(); + } // Sidebar Part this.sidebar.getContainer().size(sidebarSize.width, sidebarSize.height); diff --git a/src/vs/workbench/electron-browser/main.contribution.ts b/src/vs/workbench/electron-browser/main.contribution.ts index 347b37a365f42..99d765f89a1dc 100644 --- a/src/vs/workbench/electron-browser/main.contribution.ts +++ b/src/vs/workbench/electron-browser/main.contribution.ts @@ -129,6 +129,11 @@ configurationRegistry.registerConfiguration({ 'type': 'boolean', 'default': true, 'description': nls.localize('statusBarVisibility', "Controls the visibility of the status bar at the bottom of the workbench.") + }, + 'workbench.activityBar.visible': { + 'type': 'boolean', + 'default': true, + 'description': nls.localize('activityBarVisibility', "Controls the visibility of the activity bar in the workbench.") } } }); diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index 08551469f1fd0..97325470a31e0 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -121,6 +121,7 @@ export class Workbench implements IPartService { private static sidebarPositionConfigurationKey = 'workbench.sideBar.location'; private static statusbarVisibleConfigurationKey = 'workbench.statusBar.visible'; + private static activityBarVisibleConfigurationKey = 'workbench.activityBar.visible'; private _onTitleBarVisibilityChange: Emitter; @@ -154,6 +155,7 @@ export class Workbench implements IPartService { private creationPromiseComplete: ValueCallback; private sideBarHidden: boolean; private statusBarHidden: boolean; + private activityBarHidden: boolean; private sideBarPosition: Position; private panelHidden: boolean; private editorBackgroundDelayer: Delayer; @@ -488,6 +490,10 @@ export class Workbench implements IPartService { // Statusbar visibility const statusBarVisible = this.configurationService.lookup(Workbench.statusbarVisibleConfigurationKey).value; this.statusBarHidden = !statusBarVisible; + + // Activity bar visibility + const activityBarVisible = this.configurationService.lookup(Workbench.activityBarVisibleConfigurationKey).value; + this.activityBarHidden = !activityBarVisible; } /** @@ -553,6 +559,8 @@ export class Workbench implements IPartService { return !this.panelHidden; case Parts.STATUSBAR_PART: return !this.statusBarHidden; + case Parts.ACTIVITYBAR_PART: + return !this.activityBarHidden; } return true; // any other part cannot be hidden @@ -605,6 +613,19 @@ export class Workbench implements IPartService { } } + public isActivityBarHidden(): boolean { + return this.activityBarHidden; + } + + public setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void { + this.activityBarHidden = hidden; + + // Layout + if (!skipLayout) { + this.workbenchLayout.layout({ forceStyleRecompute: true }); + } + } + public isSideBarHidden(): boolean { return this.sideBarHidden; } @@ -814,6 +835,11 @@ export class Workbench implements IPartService { if (newStatusbarHiddenValue !== this.isStatusBarHidden()) { this.setStatusBarHidden(newStatusbarHiddenValue); } + + const newActivityBarHiddenValue = !this.configurationService.lookup(Workbench.activityBarVisibleConfigurationKey).value; + if (newActivityBarHiddenValue !== this.isActivityBarHidden()) { + this.setActivityBarHidden(newActivityBarHiddenValue); + } } private createWorkbenchLayout(): void { diff --git a/src/vs/workbench/services/part/common/partService.ts b/src/vs/workbench/services/part/common/partService.ts index 50ebcacb9aeb4..c111a2e8c0c63 100644 --- a/src/vs/workbench/services/part/common/partService.ts +++ b/src/vs/workbench/services/part/common/partService.ts @@ -67,6 +67,16 @@ export interface IPartService { */ isVisible(part: Parts): boolean; + /** + * Checks if the activity bar is currently hidden or not + */ + isActivityBarHidden(): boolean; + + /** + * Set activity bar hidden or not + */ + setActivityBarHidden(hidden: boolean): void; + /** * Returns iff the custom titlebar part is visible. */ diff --git a/src/vs/workbench/workbench.main.ts b/src/vs/workbench/workbench.main.ts index 13181a9da0687..342fee04e6b8d 100644 --- a/src/vs/workbench/workbench.main.ts +++ b/src/vs/workbench/workbench.main.ts @@ -20,6 +20,7 @@ import 'vs/editor/browser/editor.all'; import 'vs/platform/actions/browser/menusExtensionPoint'; // Workbench +import 'vs/workbench/browser/actions/toggleActivityBarVisibility'; import 'vs/workbench/browser/actions/toggleStatusbarVisibility'; import 'vs/workbench/browser/actions/toggleSidebarVisibility'; import 'vs/workbench/browser/actions/toggleSidebarPosition';