Skip to content

Commit d5519c3

Browse files
authored
Merge pull request #14940 from golf1052/hide-activity-bar
Provide an option to hide the activity bar (fixes #1105)
2 parents 2d75d95 + 86a4be1 commit d5519c3

File tree

8 files changed

+126
-1
lines changed

8 files changed

+126
-1
lines changed

src/vs/code/electron-main/menus.ts

+22
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ interface IConfiguration extends IFilesConfiguration {
3333
},
3434
statusBar: {
3535
visible: boolean;
36+
},
37+
activityBar: {
38+
visible: boolean;
3639
}
3740
};
3841
}
@@ -46,6 +49,7 @@ export class VSCodeMenu {
4649
private currentAutoSaveSetting: string;
4750
private currentSidebarLocation: 'left' | 'right';
4851
private currentStatusbarVisible: boolean;
52+
private currentActivityBarVisible: boolean;
4953

5054
private isQuitting: boolean;
5155
private appMenuInstalled: boolean;
@@ -158,6 +162,15 @@ export class VSCodeMenu {
158162
updateMenu = true;
159163
}
160164

165+
let newActivityBarVisible = config && config.workbench && config.workbench.activityBar && config.workbench.activityBar.visible;
166+
if (typeof newActivityBarVisible !== 'boolean') {
167+
newActivityBarVisible = true;
168+
}
169+
if (newActivityBarVisible !== this.currentActivityBarVisible) {
170+
this.currentActivityBarVisible = newActivityBarVisible;
171+
updateMenu = true;
172+
}
173+
161174
if (handleMenu && updateMenu) {
162175
this.updateMenu();
163176
}
@@ -547,6 +560,14 @@ export class VSCodeMenu {
547560
}
548561
const toggleStatusbar = this.createMenuItem(statusBarLabel, 'workbench.action.toggleStatusbarVisibility');
549562

563+
let activityBarLabel: string;
564+
if (this.currentActivityBarVisible) {
565+
activityBarLabel = nls.localize({ key: 'miHideActivityBar', comment: ['&& denotes a mnemonic'] }, "Hide &&Activity Bar");
566+
} else {
567+
activityBarLabel = nls.localize({ key: 'miShowActivityBar', comment: ['&& denotes a mnemonic'] }, "Show &&Activity Bar");
568+
}
569+
const toggleActivtyBar = this.createMenuItem(activityBarLabel, 'workbench.action.toggleActivityBarVisibility');
570+
550571
const toggleWordWrap = this.createMenuItem(nls.localize({ key: 'miToggleWordWrap', comment: ['&& denotes a mnemonic'] }, "Toggle &&Word Wrap"), 'editor.action.toggleWordWrap');
551572
const toggleRenderWhitespace = this.createMenuItem(nls.localize({ key: 'miToggleRenderWhitespace', comment: ['&& denotes a mnemonic'] }, "Toggle &&Render Whitespace"), 'editor.action.toggleRenderWhitespace');
552573
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 {
578599
toggleSidebar,
579600
togglePanel,
580601
toggleStatusbar,
602+
toggleActivtyBar,
581603
__separator__(),
582604
toggleWordWrap,
583605
toggleRenderWhitespace,

src/vs/test/utils/servicesTestUtils.ts

+6
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ export class TestPartService implements IPartService {
257257
return false;
258258
}
259259

260+
public isActivityBarHidden(): boolean {
261+
return false;
262+
}
263+
264+
public setActivityBarHidden(hidden: boolean): void { }
265+
260266
public isSideBarHidden(): boolean {
261267
return false;
262268
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
7+
import { TPromise } from 'vs/base/common/winjs.base';
8+
import nls = require('vs/nls');
9+
import { Registry } from 'vs/platform/platform';
10+
import { Action } from 'vs/base/common/actions';
11+
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
12+
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
13+
import { IMessageService, Severity } from 'vs/platform/message/common/message';
14+
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
15+
import { IPartService } from 'vs/workbench/services/part/common/partService';
16+
17+
export class ToggleActivityBarVisibilityAction extends Action {
18+
19+
public static ID = 'workbench.action.toggleActivityBarVisibility';
20+
public static LABEL = nls.localize('toggleActivityBar', "Toggle Activity Bar Visibility");
21+
22+
private static activityBarVisibleKey = 'workbench.activityBar.visible';
23+
24+
constructor(
25+
id: string,
26+
label: string,
27+
@IPartService private partService: IPartService,
28+
@IMessageService private messageService: IMessageService,
29+
@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService
30+
) {
31+
super(id, label);
32+
33+
this.enabled = !!this.partService;
34+
}
35+
36+
public run(): TPromise<any> {
37+
const visibility = !this.partService.isActivityBarHidden();
38+
const newVisibilityValue = !visibility;
39+
40+
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleActivityBarVisibilityAction.activityBarVisibleKey, value: newVisibilityValue }).then(null, error => {
41+
this.messageService.show(Severity.Error, error);
42+
});
43+
44+
return TPromise.as(null);
45+
}
46+
}
47+
48+
let registry = <IWorkbenchActionRegistry>Registry.as(Extensions.WorkbenchActions);
49+
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleActivityBarVisibilityAction, ToggleActivityBarVisibilityAction.ID, ToggleActivityBarVisibilityAction.LABEL), 'View: Toggle Activity Bar Visibility', nls.localize('view', "View"));

src/vs/workbench/browser/layout.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
335335

336336
this.workbenchSize = this.getWorkbenchArea();
337337

338+
const isActivityBarHidden = this.partService.isActivityBarHidden();
338339
const isTitlebarHidden = !this.partService.isVisible(Parts.TITLEBAR_PART);
339340
const isPanelHidden = !this.partService.isVisible(Parts.PANEL_PART);
340341
const isStatusbarHidden = !this.partService.isVisible(Parts.STATUSBAR_PART);
@@ -359,7 +360,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
359360
let sidebarSize = new Dimension(sidebarWidth, this.sidebarHeight);
360361

361362
// Activity Bar
362-
this.activitybarWidth = this.computedStyles.activitybar.width;
363+
this.activitybarWidth = isActivityBarHidden ? 0 : this.computedStyles.activitybar.width;
363364
let activityBarSize = new Dimension(this.activitybarWidth, sidebarSize.height);
364365

365366
// Panel part
@@ -487,6 +488,11 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
487488
this.activitybar.getContainer().getHTMLElement().style.left = '';
488489
this.activitybar.getContainer().position(this.titlebarHeight, 0, 0, null);
489490
}
491+
if (isActivityBarHidden) {
492+
this.activitybar.getContainer().hide();
493+
} else {
494+
this.activitybar.getContainer().show();
495+
}
490496

491497
// Sidebar Part
492498
this.sidebar.getContainer().size(sidebarSize.width, sidebarSize.height);

src/vs/workbench/electron-browser/main.contribution.ts

+5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ configurationRegistry.registerConfiguration({
129129
'type': 'boolean',
130130
'default': true,
131131
'description': nls.localize('statusBarVisibility', "Controls the visibility of the status bar at the bottom of the workbench.")
132+
},
133+
'workbench.activityBar.visible': {
134+
'type': 'boolean',
135+
'default': true,
136+
'description': nls.localize('activityBarVisibility', "Controls the visibility of the activity bar in the workbench.")
132137
}
133138
}
134139
});

src/vs/workbench/electron-browser/workbench.ts

+26
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export class Workbench implements IPartService {
121121

122122
private static sidebarPositionConfigurationKey = 'workbench.sideBar.location';
123123
private static statusbarVisibleConfigurationKey = 'workbench.statusBar.visible';
124+
private static activityBarVisibleConfigurationKey = 'workbench.activityBar.visible';
124125

125126
private _onTitleBarVisibilityChange: Emitter<void>;
126127

@@ -154,6 +155,7 @@ export class Workbench implements IPartService {
154155
private creationPromiseComplete: ValueCallback;
155156
private sideBarHidden: boolean;
156157
private statusBarHidden: boolean;
158+
private activityBarHidden: boolean;
157159
private sideBarPosition: Position;
158160
private panelHidden: boolean;
159161
private editorBackgroundDelayer: Delayer<void>;
@@ -488,6 +490,10 @@ export class Workbench implements IPartService {
488490
// Statusbar visibility
489491
const statusBarVisible = this.configurationService.lookup<string>(Workbench.statusbarVisibleConfigurationKey).value;
490492
this.statusBarHidden = !statusBarVisible;
493+
494+
// Activity bar visibility
495+
const activityBarVisible = this.configurationService.lookup<string>(Workbench.activityBarVisibleConfigurationKey).value;
496+
this.activityBarHidden = !activityBarVisible;
491497
}
492498

493499
/**
@@ -553,6 +559,8 @@ export class Workbench implements IPartService {
553559
return !this.panelHidden;
554560
case Parts.STATUSBAR_PART:
555561
return !this.statusBarHidden;
562+
case Parts.ACTIVITYBAR_PART:
563+
return !this.activityBarHidden;
556564
}
557565

558566
return true; // any other part cannot be hidden
@@ -605,6 +613,19 @@ export class Workbench implements IPartService {
605613
}
606614
}
607615

616+
public isActivityBarHidden(): boolean {
617+
return this.activityBarHidden;
618+
}
619+
620+
public setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
621+
this.activityBarHidden = hidden;
622+
623+
// Layout
624+
if (!skipLayout) {
625+
this.workbenchLayout.layout({ forceStyleRecompute: true });
626+
}
627+
}
628+
608629
public isSideBarHidden(): boolean {
609630
return this.sideBarHidden;
610631
}
@@ -814,6 +835,11 @@ export class Workbench implements IPartService {
814835
if (newStatusbarHiddenValue !== this.isStatusBarHidden()) {
815836
this.setStatusBarHidden(newStatusbarHiddenValue);
816837
}
838+
839+
const newActivityBarHiddenValue = !this.configurationService.lookup<boolean>(Workbench.activityBarVisibleConfigurationKey).value;
840+
if (newActivityBarHiddenValue !== this.isActivityBarHidden()) {
841+
this.setActivityBarHidden(newActivityBarHiddenValue);
842+
}
817843
}
818844

819845
private createWorkbenchLayout(): void {

src/vs/workbench/services/part/common/partService.ts

+10
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ export interface IPartService {
6767
*/
6868
isVisible(part: Parts): boolean;
6969

70+
/**
71+
* Checks if the activity bar is currently hidden or not
72+
*/
73+
isActivityBarHidden(): boolean;
74+
75+
/**
76+
* Set activity bar hidden or not
77+
*/
78+
setActivityBarHidden(hidden: boolean): void;
79+
7080
/**
7181
* Returns iff the custom titlebar part is visible.
7282
*/

src/vs/workbench/workbench.main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'vs/editor/browser/editor.all';
2020
import 'vs/platform/actions/browser/menusExtensionPoint';
2121

2222
// Workbench
23+
import 'vs/workbench/browser/actions/toggleActivityBarVisibility';
2324
import 'vs/workbench/browser/actions/toggleStatusbarVisibility';
2425
import 'vs/workbench/browser/actions/toggleSidebarVisibility';
2526
import 'vs/workbench/browser/actions/toggleSidebarPosition';

0 commit comments

Comments
 (0)