Skip to content

Commit

Permalink
There should be an option to hide the menu bar. (fixes #945)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Dec 18, 2015
1 parent ca683b5 commit c34d2e7
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
16 changes: 16 additions & 0 deletions src/vs/workbench/electron-browser/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ export class ToggleFullScreenAction extends Action {
}
}

export class ToggleMenuBarAction extends Action {

public static ID = 'workbench.action.toggleMenuBar';
public static LABEL = nls.localize('toggleMenuBar', "Toggle Menu Bar");

constructor(id: string, label: string, @IWindowService private windowService: IWindowService) {
super(id, label);
}

public run(): Promise {
ipc.send('vscode:toggleMenuBar', this.windowService.getWindowId());

return Promise.as(true);
}
}

export class ToggleDevToolsAction extends Action {

public static ID = 'workbench.action.toggleDevTools';
Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/electron-browser/main.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {SyncActionDescriptor} from 'vs/platform/actions/common/actions';
import {IConfigurationRegistry, Extensions as ConfigurationExtensions} from 'vs/platform/configuration/common/configurationRegistry';
import {IWorkbenchActionRegistry, Extensions} from 'vs/workbench/browser/actionRegistry';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import platform = require('vs/base/common/platform');
import {WorkbenchMessageService} from 'vs/workbench/services/message/browser/messageService';
import {CloseEditorAction, ReloadWindowAction, ShowStartupPerformance, ZoomResetAction, ZoomOutAction, ZoomInAction, ToggleDevToolsAction, ToggleFullScreenAction, OpenRecentAction, CloseFolderAction, CloseWindowAction, NewWindowAction, CloseMessagesAction} from 'vs/workbench/electron-browser/actions';
import {CloseEditorAction, ReloadWindowAction, ShowStartupPerformance, ZoomResetAction, ZoomOutAction, ZoomInAction, ToggleDevToolsAction, ToggleFullScreenAction, ToggleMenuBarAction, OpenRecentAction, CloseFolderAction, CloseWindowAction, NewWindowAction, CloseMessagesAction} from 'vs/workbench/electron-browser/actions';

// Contribute Global Actions
const viewCategory = nls.localize('view', "View");
Expand All @@ -32,6 +33,9 @@ workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(Reload
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseMessagesAction, CloseMessagesAction.ID, CloseMessagesAction.LABEL, { primary: KeyCode.Escape }, [{ key: WorkbenchMessageService.GLOBAL_MESSAGES_SHOWING_CONTEXT }]));
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseEditorAction, CloseEditorAction.ID, CloseEditorAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_W, win: { primary: KeyMod.CtrlCmd | KeyCode.F4, secondary: [KeyMod.CtrlCmd | KeyCode.KEY_W] } }), viewCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleFullScreenAction, ToggleFullScreenAction.ID, ToggleFullScreenAction.LABEL, { primary: KeyCode.F11, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.KEY_F } }), viewCategory);
if (platform.isWindows) {
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMenuBarAction, ToggleMenuBarAction.ID, ToggleMenuBarAction.LABEL), viewCategory);
}

// Configuration: Window
const configurationRegistry = <IConfigurationRegistry>Registry.as(ConfigurationExtensions.Configuration);
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/electron-main/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ export class VSCodeMenu {
let output = this.createMenuItem(nls.localize('miToggleOutput', "Toggle &&Output"), 'workbench.action.output.toggleOutput');

let fullscreen = new MenuItem({ label: mnemonicLabel(nls.localize('miToggleFullScreen', "Toggle &&Full Screen")), accelerator: this.getAccelerator('workbench.action.toggleFullScreen'), click: () => windows.manager.getLastActiveWindow().toggleFullScreen(), enabled: windows.manager.getWindowCount() > 0 });

let toggleMenuBar = this.createMenuItem(nls.localize('miToggleMenuBar', "Toggle Menu &&Bar"), 'workbench.action.toggleMenuBar');
let splitEditor = this.createMenuItem(nls.localize('miSplitEditor', "Split &&Editor"), 'workbench.action.splitEditor');
let toggleSidebar = this.createMenuItem(nls.localize('miToggleSidebar', "&&Toggle Side Bar"), 'workbench.action.toggleSidebarVisibility');
let moveSidebar = this.createMenuItem(nls.localize('miMoveSidebar', "&&Move Side Bar"), 'workbench.action.toggleSidebarPosition');
Expand All @@ -544,6 +544,7 @@ export class VSCodeMenu {
output,
__separator__(),
fullscreen,
platform.isWindows ? toggleMenuBar : void 0,
__separator__(),
splitEditor,
toggleSidebar,
Expand Down
7 changes: 6 additions & 1 deletion src/vs/workbench/electron-main/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ export function onStore<T>(clb: (key: string, oldValue: T, newValue: T) => void)
return () => eventEmitter.removeListener(EventTypes.STORE, clb);
}

export function getItem<T>(key: string): T {
export function getItem<T>(key: string, defaultValue?: T): T {
if (!database) {
database = load();
}

const res = database[key];
if (typeof res === 'undefined') {
return defaultValue;
}

return database[key];
}

Expand Down
31 changes: 26 additions & 5 deletions src/vs/workbench/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export interface IWindowState {
mode?: WindowMode;
}

export interface IWindowCreationOptions {
state: IWindowState;
isPluginDevelopmentHost: boolean;
}

export enum WindowMode {
Maximized,
Normal,
Expand Down Expand Up @@ -128,6 +133,9 @@ const enableDebugLogging = false;

export class VSCodeWindow {

public static menuBarHiddenKey = 'menuBarHidden';
public static themeStorageKey = 'theme'; // TODO@Ben this key is only used to find out if a window can be shown instantly because of light theme, remove once we have support for bg color

private static MIN_WIDTH = 200;
private static MIN_HEIGHT = 120;

Expand All @@ -144,16 +152,17 @@ export class VSCodeWindow {
private currentConfig: IWindowConfiguration;
private pendingLoadConfig: IWindowConfiguration;

constructor(state?: IWindowState, isPluginDevelopmentHost?: boolean, usesLightTheme?: boolean) {
constructor(config: IWindowCreationOptions) {
this._lastFocusTime = -1;
this._readyState = ReadyState.NONE;
this._isPluginDevelopmentHost = isPluginDevelopmentHost;
this._isPluginDevelopmentHost = config.isPluginDevelopmentHost;
this.whenReadyCallbacks = [];

// Load window state
this.restoreWindowState(state);
this.restoreWindowState(config.state);

// For VS theme we can show directly because background is white
const usesLightTheme = /vs($| )/.test(storage.getItem<string>(VSCodeWindow.themeStorageKey));
let showDirectly = usesLightTheme;
if (showDirectly && !global.windowShow) {
global.windowShow = new Date().getTime();
Expand Down Expand Up @@ -190,6 +199,10 @@ export class VSCodeWindow {
this._lastFocusTime = new Date().getTime(); // since we show directly, we need to set the last focus time too
}

if (storage.getItem<boolean>(VSCodeWindow.menuBarHiddenKey, false)) {
this.setMenuBarVisibility(false); // respect configured menu bar visibility
}

this.registerListeners();
}

Expand Down Expand Up @@ -532,11 +545,19 @@ export class VSCodeWindow {

// Windows: Hide the menu bar but still allow to bring it up by pressing the Alt key
if (platform.isWindows) {
this.win.setMenuBarVisibility(!willBeFullScreen);
this.win.setAutoHideMenuBar(willBeFullScreen);
if (willBeFullScreen) {
this.setMenuBarVisibility(false);
} else {
this.setMenuBarVisibility(!storage.getItem<boolean>(VSCodeWindow.menuBarHiddenKey, false)); // restore as configured
}
}
}

public setMenuBarVisibility(visible: boolean): void {
this.win.setMenuBarVisibility(visible);
this.win.setAutoHideMenuBar(!visible);
}

public sendWhenReady(channel: string, ...args: any[]): void {
this.ready().then(() => {
this.send(channel, ...args);
Expand Down
22 changes: 19 additions & 3 deletions src/vs/workbench/electron-main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import lifecycle = require('vs/workbench/electron-main/lifecycle');
import nls = require('vs/nls');
import paths = require('vs/base/common/paths');
import arrays = require('vs/base/common/arrays');
import types = require('vs/base/common/types');
import objects = require('vs/base/common/objects');
import storage = require('vs/workbench/electron-main/storage');
import settings = require('vs/workbench/electron-main/settings');
Expand Down Expand Up @@ -97,7 +98,6 @@ export class WindowsManager {

private static workingDirPickerStorageKey = 'pickerWorkingDir';
private static windowsStateStorageKey = 'windowsState';
private static themeStorageKey = 'theme'; // TODO@Ben this key is only used to find out if a window can be shown instantly because of light theme, remove once we have support for bg color

private static WINDOWS: window.VSCodeWindow[] = [];

Expand Down Expand Up @@ -229,9 +229,21 @@ export class WindowsManager {
}
});

ipc.on('vscode:toggleMenuBar', (event: Event, windowId: number) => {
env.log('IPC#vscode:toggleMenuBar');

// Update in settings
let menuBarHidden = storage.getItem(window.VSCodeWindow.menuBarHiddenKey, false);
let newMenuBarHidden = !menuBarHidden;
storage.setItem(window.VSCodeWindow.menuBarHiddenKey, newMenuBarHidden);

// Update across windows
WindowsManager.WINDOWS.forEach(w => w.setMenuBarVisibility(!newMenuBarHidden));
});

ipc.on('vscode:changeTheme', (event, theme: string) => {
this.sendToAll('vscode:changeTheme', theme);
storage.setItem(WindowsManager.themeStorageKey, theme);
storage.setItem(window.VSCodeWindow.themeStorageKey, theme);
});

ipc.on('vscode:broadcast', (event: Event, windowId: number, target: string, broadcast: { channel: string; payload: any; }) => {
Expand Down Expand Up @@ -679,7 +691,11 @@ export class WindowsManager {

// New window
if (!vscodeWindow) {
vscodeWindow = new window.VSCodeWindow(this.getNewWindowState(configuration), !!configuration.pluginDevelopmentPath, /vs($| )/.test(storage.getItem<string>(WindowsManager.themeStorageKey)));
vscodeWindow = new window.VSCodeWindow({
state: this.getNewWindowState(configuration),
isPluginDevelopmentHost: !!configuration.pluginDevelopmentPath
});

WindowsManager.WINDOWS.push(vscodeWindow);

// Window Events
Expand Down

0 comments on commit c34d2e7

Please sign in to comment.