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

How to configure a window (also for reload case)? (fixes #27192)

上级 145310ae
......@@ -9,7 +9,7 @@ import * as nls from 'vs/nls';
import { isMacintosh, isLinux, isWindows, language } from 'vs/base/common/platform';
import * as arrays from 'vs/base/common/arrays';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ipcMain as ipc, app, shell, dialog, Menu, MenuItem } from 'electron';
import { ipcMain as ipc, app, shell, dialog, Menu, MenuItem, BrowserWindow } from 'electron';
import { OpenContext } from 'vs/code/common/windows';
import { IWindowsMainService } from 'vs/code/electron-main/windows';
import { VSCodeWindow } from 'vs/code/electron-main/window';
......@@ -908,7 +908,7 @@ export class VSCodeMenu {
label: this.mnemonicLabel(nls.localize({ key: 'miAccessibilityOptions', comment: ['&& denotes a mnemonic'] }, "Accessibility &&Options")),
accelerator: null,
click: () => {
this.windowsService.openAccessibilityOptions();
this.openAccessibilityOptions();
}
}, false));
......@@ -974,6 +974,22 @@ export class VSCodeMenu {
}
}
private openAccessibilityOptions(): void {
let win = new BrowserWindow({
alwaysOnTop: true,
skipTaskbar: true,
resizable: false,
width: 450,
height: 300,
show: true,
title: nls.localize('accessibilityOptionsWindowTitle', "Accessibility Options")
});
win.setMenuBarVisibility(false);
win.loadURL('chrome://accessibility');
}
private getUpdateMenuItems(): Electron.MenuItem[] {
switch (this.updateService.state) {
case UpdateState.Uninitialized:
......
......@@ -22,7 +22,7 @@ import product from 'vs/platform/node/product';
import { getCommonHTTPHeaders } from 'vs/platform/environment/node/http';
import { IWindowSettings, MenuBarVisibility } from 'vs/platform/windows/common/windows';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { KeyboardLayoutMonitor } from "vs/code/node/keyboard";
export interface IWindowState {
width?: number;
......@@ -82,10 +82,7 @@ export interface IWindowConfiguration extends ParsedArgs {
* The physical keyboard is of ISO type (on OSX).
*/
isISOKeyboard?: boolean;
/**
* Accessibility support is enabled.
*/
accessibilitySupportEnabled?: boolean;
zoomLevel?: number;
fullscreen?: boolean;
highContrast?: boolean;
......@@ -558,6 +555,9 @@ export class VSCodeWindow {
windowConfiguration.highContrast = platform.isWindows && systemPreferences.isInvertedColorScheme() && (!windowConfig || windowConfig.autoDetectHighContrast);
windowConfiguration.accessibilitySupport = app.isAccessibilitySupportEnabled();
// Set Keyboard Config
windowConfiguration.isISOKeyboard = KeyboardLayoutMonitor.INSTANCE.isISOKeyboard();
// Theme
windowConfiguration.baseTheme = this.getBaseTheme();
windowConfiguration.backgroundColor = this.getBackgroundColor();
......
......@@ -31,8 +31,7 @@ import product from 'vs/platform/node/product';
import { OpenContext } from 'vs/code/common/windows';
import { ITelemetryService, ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
import { isParent, isEqual, isEqualOrParent } from 'vs/platform/files/common/files';
import * as nativeKeymap from 'native-keymap';
import { IDisposable } from 'vs/base/common/lifecycle';
import { KeyboardLayoutMonitor } from "vs/code/node/keyboard";
enum WindowError {
UNRESPONSIVE,
......@@ -107,7 +106,6 @@ export interface IWindowsMainService {
openFileFolderPicker(forceNewWindow?: boolean, data?: ITelemetryData): void;
openFilePicker(forceNewWindow?: boolean, path?: string, window?: VSCodeWindow, data?: ITelemetryData): void;
openFolderPicker(forceNewWindow?: boolean, window?: VSCodeWindow, data?: ITelemetryData): void;
openAccessibilityOptions(): void;
focusLastActive(cli: ParsedArgs, context: OpenContext): VSCodeWindow;
getLastActiveWindow(): VSCodeWindow;
findWindow(workspacePath: string, filePath?: string, extensionDevelopmentPath?: string): VSCodeWindow;
......@@ -343,6 +341,7 @@ export class WindowsManager implements IWindowsMainService {
}
private onBroadcast(event: string, payload: any): void {
// Theme changes
if (event === 'vscode:changeColorTheme' && typeof payload === 'string') {
......@@ -737,8 +736,6 @@ export class WindowsManager implements IWindowsMainService {
configuration.filesToCreate = filesToCreate;
configuration.filesToDiff = filesToDiff;
configuration.nodeCachedDataDir = this.environmentService.nodeCachedDataDir;
configuration.isISOKeyboard = KeyboardLayoutMonitor.INSTANCE.isISOKeyboard();
configuration.accessibilitySupportEnabled = app.isAccessibilitySupportEnabled();
return configuration;
}
......@@ -1028,22 +1025,6 @@ export class WindowsManager implements IWindowsMainService {
this.doPickAndOpen({ pickFolders: true, forceNewWindow, window }, 'openFolder', data);
}
public openAccessibilityOptions(): void {
let win = new BrowserWindow({
alwaysOnTop: true,
skipTaskbar: true,
resizable: false,
width: 450,
height: 300,
show: true,
title: nls.localize('accessibilityOptionsWindowTitle', "Accessibility Options")
});
win.setMenuBarVisibility(false);
win.loadURL('chrome://accessibility');
}
private doPickAndOpen(options: INativeOpenDialogOptions, eventName: string, data?: ITelemetryData): void {
this.getFileOrFolderPaths(options, (paths: string[]) => {
const nOfPaths = paths ? paths.length : 0;
......@@ -1338,63 +1319,4 @@ export class WindowsManager implements IWindowsMainService {
}, 10 /* delay to unwind callback stack (IPC) */);
}
}
}
class KeyboardLayoutMonitor {
public static INSTANCE = new KeyboardLayoutMonitor();
private _emitter: Emitter<boolean>;
private _registered: boolean;
private _isISOKeyboard: boolean;
private constructor() {
this._emitter = new Emitter<boolean>();
this._registered = false;
this._isISOKeyboard = this._readIsISOKeyboard();
}
public onDidChangeKeyboardLayout(callback: (isISOKeyboard: boolean) => void): IDisposable {
if (!this._registered) {
this._registered = true;
nativeKeymap.onDidChangeKeyboardLayout(() => {
this._emitter.fire(this._isISOKeyboard);
});
if (platform.isMacintosh) {
// See https://github.com/Microsoft/vscode/issues/24153
// On OSX, on ISO keyboards, Chromium swaps the scan codes
// of IntlBackslash and Backquote.
//
// The C++ methods can give the current keyboard type (ISO or not)
// only after a NSEvent was handled.
//
// We therefore poll.
setInterval(() => {
let newValue = this._readIsISOKeyboard();
if (this._isISOKeyboard === newValue) {
// no change
return;
}
this._isISOKeyboard = newValue;
this._emitter.fire(this._isISOKeyboard);
}, 3000);
}
}
return this._emitter.event(callback);
}
private _readIsISOKeyboard(): boolean {
if (platform.isMacintosh) {
return nativeKeymap.isISOKeyboard();
}
return false;
}
public isISOKeyboard(): boolean {
return this._isISOKeyboard;
}
}
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* 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 * as nativeKeymap from 'native-keymap';
import { IDisposable } from 'vs/base/common/lifecycle';
import { isMacintosh } from "vs/base/common/platform";
import { Emitter } from "vs/base/common/event";
export class KeyboardLayoutMonitor {
public static readonly INSTANCE = new KeyboardLayoutMonitor();
private _emitter: Emitter<boolean>;
private _registered: boolean;
private _isISOKeyboard: boolean;
private constructor() {
this._emitter = new Emitter<boolean>();
this._registered = false;
this._isISOKeyboard = this._readIsISOKeyboard();
}
public onDidChangeKeyboardLayout(callback: (isISOKeyboard: boolean) => void): IDisposable {
if (!this._registered) {
this._registered = true;
nativeKeymap.onDidChangeKeyboardLayout(() => {
this._emitter.fire(this._isISOKeyboard);
});
if (isMacintosh) {
// See https://github.com/Microsoft/vscode/issues/24153
// On OSX, on ISO keyboards, Chromium swaps the scan codes
// of IntlBackslash and Backquote.
//
// The C++ methods can give the current keyboard type (ISO or not)
// only after a NSEvent was handled.
//
// We therefore poll.
setInterval(() => {
let newValue = this._readIsISOKeyboard();
if (this._isISOKeyboard === newValue) {
// no change
return;
}
this._isISOKeyboard = newValue;
this._emitter.fire(this._isISOKeyboard);
}, 3000);
}
}
return this._emitter.event(callback);
}
private _readIsISOKeyboard(): boolean {
if (isMacintosh) {
return nativeKeymap.isISOKeyboard();
}
return false;
}
public isISOKeyboard(): boolean {
return this._isISOKeyboard;
}
}
......@@ -42,10 +42,7 @@ export interface IWindowConfiguration extends ParsedArgs, IOpenFileRequest {
*/
isISOKeyboard?: boolean;
/**
* Accessibility support is enabled.
*/
accessibilitySupportEnabled?: boolean;
accessibilitySupport?: boolean;
appRoot: string;
execPath: string;
......@@ -62,15 +59,16 @@ export function startup(configuration: IWindowConfiguration): TPromise<void> {
// Ensure others can listen to zoom level changes
browser.setZoomFactor(webFrame.getZoomFactor());
// See https://github.com/Microsoft/vscode/issues/26151
// Can be trusted because we are not setting it ourselves.
browser.setZoomLevel(webFrame.getZoomLevel(), /*isTrusted*/true);
browser.setZoomLevel(webFrame.getZoomLevel(), true /* isTrusted */);
browser.setFullscreen(!!configuration.fullscreen);
KeyboardMapperFactory.INSTANCE._onKeyboardLayoutChanged(configuration.isISOKeyboard);
browser.setAccessibilitySupport(configuration.accessibilitySupportEnabled ? platform.AccessibilitySupport.Enabled : platform.AccessibilitySupport.Disabled);
browser.setAccessibilitySupport(configuration.accessibilitySupport ? platform.AccessibilitySupport.Enabled : platform.AccessibilitySupport.Disabled);
// Setup Intl
comparer.setFileNameComparer(new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册