From 40dac139d6c43574c54888438d5f44e90e473d56 Mon Sep 17 00:00:00 2001 From: isidor Date: Wed, 16 Nov 2016 17:16:43 +0100 Subject: [PATCH] zen mode: esc to exit zen mode with lowest weight --- .../electron-browser/main.contribution.ts | 15 ++++++++++++++- src/vs/workbench/electron-browser/workbench.ts | 12 ++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/electron-browser/main.contribution.ts b/src/vs/workbench/electron-browser/main.contribution.ts index 4d795bcb566..bf38e82e714 100644 --- a/src/vs/workbench/electron-browser/main.contribution.ts +++ b/src/vs/workbench/electron-browser/main.contribution.ts @@ -13,11 +13,13 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'v import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry'; import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes'; import platform = require('vs/base/common/platform'); +import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IKeybindings } from 'vs/platform/keybinding/common/keybinding'; import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { IPartService } from 'vs/workbench/services/part/common/partService'; import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService'; import { CloseEditorAction, ReportIssueAction, ZoomResetAction, ZoomOutAction, ZoomInAction, ToggleFullScreenAction, ToggleMenuBarAction, CloseFolderAction, CloseWindowAction, SwitchWindow, NewWindowAction, CloseMessagesAction } from 'vs/workbench/electron-browser/actions'; -import { MessagesVisibleContext, NoEditorsVisibleContext } from 'vs/workbench/electron-browser/workbench'; +import { MessagesVisibleContext, NoEditorsVisibleContext, InZenModeContext } from 'vs/workbench/electron-browser/workbench'; import { IJSONSchema } from 'vs/base/common/jsonSchema'; const closeEditorOrWindowKeybindings: IKeybindings = { primary: KeyMod.CtrlCmd | KeyCode.KEY_W, win: { primary: KeyMod.CtrlCmd | KeyCode.F4, secondary: [KeyMod.CtrlCmd | KeyCode.KEY_W] } }; @@ -70,6 +72,17 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ } }); +KeybindingsRegistry.registerCommandAndKeybindingRule({ + id: '_workbench.exitZenMode', + weight: 0, + handler(accessor: ServicesAccessor, configurationOrName: any) { + const partService = accessor.get(IPartService); + partService.toggleZenMode(); + }, + when: InZenModeContext, + primary: KeyCode.Escape +}); + // Configuration: Workbench const configurationRegistry = Registry.as(ConfigurationExtensions.Configuration); configurationRegistry.registerConfiguration({ diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index c810565f472..66cce557ae2 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -92,6 +92,7 @@ import { IWindowConfiguration } from 'vs/workbench/electron-browser/common'; export const MessagesVisibleContext = new RawContextKey('globalMessageVisible', false); export const EditorsVisibleContext = new RawContextKey('editorIsOpen', false); +export const InZenModeContext = new RawContextKey('inZenMode', false); export const NoEditorsVisibleContext: ContextKeyExpr = EditorsVisibleContext.toNegated(); interface WorkbenchParams { @@ -166,6 +167,7 @@ export class Workbench implements IPartService { private editorBackgroundDelayer: Delayer; private messagesVisibleContext: IContextKey; private editorsVisibleContext: IContextKey; + private inZenMode: IContextKey; private hasFilesToCreateOpenOrDiff: boolean; private zenMode: { active: boolean; @@ -243,6 +245,7 @@ export class Workbench implements IPartService { // Contexts this.messagesVisibleContext = MessagesVisibleContext.bindTo(this.contextKeyService); this.editorsVisibleContext = EditorsVisibleContext.bindTo(this.contextKeyService); + this.inZenMode = InZenModeContext.bindTo(this.contextKeyService); // Register Listeners this.registerListeners(); @@ -842,14 +845,12 @@ export class Workbench implements IPartService { // Apply as CSS class const isFullscreen = browser.isFullscreen(); - let exitedZenMode = false; if (isFullscreen) { this.addClass('fullscreen'); } else { this.removeClass('fullscreen'); - if (this.zenMode.transitionedToFullScreen) { - this.zenMode.active = false; - exitedZenMode = true; + if (this.zenMode.transitionedToFullScreen && this.zenMode.active) { + this.toggleZenMode(); } } @@ -857,8 +858,6 @@ export class Workbench implements IPartService { const hasCustomTitle = this.getCustomTitleBarStyle() === 'custom'; if (hasCustomTitle) { this._onTitleBarVisibilityChange.fire(); - } - if (hasCustomTitle || exitedZenMode) { this.layout(); // handle title bar when fullscreen changes } } @@ -1070,6 +1069,7 @@ export class Workbench implements IPartService { public toggleZenMode(): void { this.zenMode.active = !this.zenMode.active; + this.inZenMode.set(this.zenMode.active); Object.keys(this.zenMode.isPartVisible).forEach(key => this.zenMode.isPartVisible[key] = false); if (!this.zenMode.active && this.zenMode.transitionedToFullScreen && browser.isFullscreen()) { // Zen mode transitioned to full screen, now that we are out of zen mode we need to go out of full screen -- GitLab