提交 d5519c3a 编写于 作者: B Benjamin Pasero 提交者: GitHub

Merge pull request #14940 from golf1052/hide-activity-bar

Provide an option to hide the activity bar (fixes #1105)
......@@ -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,
......
......@@ -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;
}
......
/*---------------------------------------------------------------------------------------------
* 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"));
\ No newline at end of file
......@@ -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);
......
......@@ -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.")
}
}
});
......
......@@ -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>;
......@@ -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>;
......@@ -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;
}
/**
......@@ -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<boolean>(Workbench.activityBarVisibleConfigurationKey).value;
if (newActivityBarHiddenValue !== this.isActivityBarHidden()) {
this.setActivityBarHidden(newActivityBarHiddenValue);
}
}
private createWorkbenchLayout(): void {
......
......@@ -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.
*/
......
......@@ -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';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册