Skip to content

Commit

Permalink
Merge pull request #14940 from golf1052/hide-activity-bar
Browse files Browse the repository at this point in the history
Provide an option to hide the activity bar (fixes #1105)
  • Loading branch information
bpasero authored Nov 10, 2016
2 parents 2d75d95 + 86a4be1 commit d5519c3
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/vs/code/electron-main/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ interface IConfiguration extends IFilesConfiguration {
},
statusBar: {
visible: boolean;
},
activityBar: {
visible: boolean;
}
};
}
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -578,6 +599,7 @@ export class VSCodeMenu {
toggleSidebar,
togglePanel,
toggleStatusbar,
toggleActivtyBar,
__separator__(),
toggleWordWrap,
toggleRenderWhitespace,
Expand Down
6 changes: 6 additions & 0 deletions src/vs/test/utils/servicesTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
49 changes: 49 additions & 0 deletions src/vs/workbench/browser/actions/toggleActivityBarVisibility.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
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 = <IWorkbenchActionRegistry>Registry.as(Extensions.WorkbenchActions);
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleActivityBarVisibilityAction, ToggleActivityBarVisibilityAction.ID, ToggleActivityBarVisibilityAction.LABEL), 'View: Toggle Activity Bar Visibility', nls.localize('view', "View"));
8 changes: 7 additions & 1 deletion src/vs/workbench/browser/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/electron-browser/main.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}
});
Expand Down
26 changes: 26 additions & 0 deletions src/vs/workbench/electron-browser/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;

Expand Down Expand Up @@ -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<void>;
Expand Down Expand Up @@ -488,6 +490,10 @@ export class Workbench implements IPartService {
// Statusbar visibility
const statusBarVisible = this.configurationService.lookup<string>(Workbench.statusbarVisibleConfigurationKey).value;
this.statusBarHidden = !statusBarVisible;

// Activity bar visibility
const activityBarVisible = this.configurationService.lookup<string>(Workbench.activityBarVisibleConfigurationKey).value;
this.activityBarHidden = !activityBarVisible;
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -814,6 +835,11 @@ export class Workbench implements IPartService {
if (newStatusbarHiddenValue !== this.isStatusBarHidden()) {
this.setStatusBarHidden(newStatusbarHiddenValue);
}

const newActivityBarHiddenValue = !this.configurationService.lookup<boolean>(Workbench.activityBarVisibleConfigurationKey).value;
if (newActivityBarHiddenValue !== this.isActivityBarHidden()) {
this.setActivityBarHidden(newActivityBarHiddenValue);
}
}

private createWorkbenchLayout(): void {
Expand Down
10 changes: 10 additions & 0 deletions src/vs/workbench/services/part/common/partService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/workbench.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit d5519c3

Please sign in to comment.