提交 c34d2e77 编写于 作者: B Benjamin Pasero

There should be an option to hide the menu bar. (fixes #945)

上级 ca683b56
......@@ -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';
......
......@@ -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");
......@@ -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);
......
......@@ -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');
......@@ -544,6 +544,7 @@ export class VSCodeMenu {
output,
__separator__(),
fullscreen,
platform.isWindows ? toggleMenuBar : void 0,
__separator__(),
splitEditor,
toggleSidebar,
......
......@@ -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];
}
......
......@@ -25,6 +25,11 @@ export interface IWindowState {
mode?: WindowMode;
}
export interface IWindowCreationOptions {
state: IWindowState;
isPluginDevelopmentHost: boolean;
}
export enum WindowMode {
Maximized,
Normal,
......@@ -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;
......@@ -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();
......@@ -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();
}
......@@ -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);
......
......@@ -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');
......@@ -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[] = [];
......@@ -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; }) => {
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册