-
Notifications
You must be signed in to change notification settings - Fork 30.3k
/
Copy pathwindows.ts
273 lines (212 loc) · 7.61 KB
/
windows.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { isMacintosh, isLinux, isWeb, IProcessEnvironment } from 'vs/base/common/platform';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { URI, UriComponents } from 'vs/base/common/uri';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { LogLevel } from 'vs/platform/log/common/log';
import { ExportData } from 'vs/base/common/performance';
export const WindowMinimumSize = {
WIDTH: 400,
WIDTH_WITH_VERTICAL_PANEL: 600,
HEIGHT: 270
};
export interface IBaseOpenWindowsOptions {
forceReuseWindow?: boolean;
}
export interface IOpenWindowOptions extends IBaseOpenWindowsOptions {
forceNewWindow?: boolean;
preferNewWindow?: boolean;
noRecentEntry?: boolean;
addMode?: boolean;
diffMode?: boolean;
gotoLineMode?: boolean;
waitMarkerFileURI?: URI;
}
export interface IAddFoldersRequest {
foldersToAdd: UriComponents[];
}
export interface IOpenedWindow {
id: number;
workspace?: IWorkspaceIdentifier;
folderUri?: ISingleFolderWorkspaceIdentifier;
title: string;
filename?: string;
dirty: boolean;
}
export interface IOpenEmptyWindowOptions extends IBaseOpenWindowsOptions {
remoteAuthority?: string;
}
export type IWindowOpenable = IWorkspaceToOpen | IFolderToOpen | IFileToOpen;
export interface IBaseWindowOpenable {
label?: string;
}
export interface IWorkspaceToOpen extends IBaseWindowOpenable {
workspaceUri: URI;
}
export interface IFolderToOpen extends IBaseWindowOpenable {
folderUri: URI;
}
export interface IFileToOpen extends IBaseWindowOpenable {
fileUri: URI;
}
export function isWorkspaceToOpen(uriToOpen: IWindowOpenable): uriToOpen is IWorkspaceToOpen {
return !!(uriToOpen as IWorkspaceToOpen).workspaceUri;
}
export function isFolderToOpen(uriToOpen: IWindowOpenable): uriToOpen is IFolderToOpen {
return !!(uriToOpen as IFolderToOpen).folderUri;
}
export function isFileToOpen(uriToOpen: IWindowOpenable): uriToOpen is IFileToOpen {
return !!(uriToOpen as IFileToOpen).fileUri;
}
export type MenuBarVisibility = 'default' | 'visible' | 'toggle' | 'hidden' | 'compact';
export function getMenuBarVisibility(configurationService: IConfigurationService, environment: IEnvironmentService, isExtensionDevelopment = environment.isExtensionDevelopment): MenuBarVisibility {
const titleBarStyle = getTitleBarStyle(configurationService, environment, isExtensionDevelopment);
const menuBarVisibility = configurationService.getValue<MenuBarVisibility>('window.menuBarVisibility');
if (titleBarStyle === 'native' && menuBarVisibility === 'compact') {
return 'default';
} else {
return menuBarVisibility;
}
}
export interface IWindowsConfiguration {
window: IWindowSettings;
}
export interface IWindowSettings {
openFilesInNewWindow: 'on' | 'off' | 'default';
openFoldersInNewWindow: 'on' | 'off' | 'default';
openWithoutArgumentsInNewWindow: 'on' | 'off';
restoreWindows: 'preserve' | 'all' | 'folders' | 'one' | 'none';
restoreFullscreen: boolean;
zoomLevel: number;
titleBarStyle: 'native' | 'custom';
autoDetectHighContrast: boolean;
menuBarVisibility: MenuBarVisibility;
newWindowDimensions: 'default' | 'inherit' | 'offset' | 'maximized' | 'fullscreen';
nativeTabs: boolean;
nativeFullScreen: boolean;
enableMenuBarMnemonics: boolean;
closeWhenEmpty: boolean;
clickThroughInactive: boolean;
enableExperimentalProxyLoginDialog: boolean;
}
export function getTitleBarStyle(configurationService: IConfigurationService, environment: IEnvironmentService, isExtensionDevelopment = environment.isExtensionDevelopment): 'native' | 'custom' {
if (isWeb) {
return 'custom';
}
const configuration = configurationService.getValue<IWindowSettings | undefined>('window');
const isDev = !environment.isBuilt || isExtensionDevelopment;
if (isMacintosh && isDev) {
return 'native'; // not enabled when developing due to https://github.com/electron/electron/issues/3647
}
if (configuration) {
const useNativeTabs = isMacintosh && configuration.nativeTabs === true;
if (useNativeTabs) {
return 'native'; // native tabs on sierra do not work with custom title style
}
const useSimpleFullScreen = isMacintosh && configuration.nativeFullScreen === false;
if (useSimpleFullScreen) {
return 'native'; // simple fullscreen does not work well with custom title style (https://github.com/microsoft/vscode/issues/63291)
}
const style = configuration.titleBarStyle;
if (style === 'native' || style === 'custom') {
return style;
}
}
return isLinux ? 'native' : 'custom'; // default to custom on all macOS and Windows
}
export interface IPath extends IPathData {
// the file path to open within the instance
fileUri?: URI;
}
export interface IPathData {
// the file path to open within the instance
fileUri?: UriComponents;
// the line number in the file path to open
lineNumber?: number;
// the column number in the file path to open
columnNumber?: number;
// a hint that the file exists. if true, the
// file exists, if false it does not. with
// undefined the state is unknown.
exists?: boolean;
// Specifies if the file should be only be opened if it exists
openOnlyIfExists?: boolean;
// Specifies an optional id to override the editor used to edit the resource, e.g. custom editor.
overrideId?: string;
}
export interface IPathsToWaitFor extends IPathsToWaitForData {
paths: IPath[];
waitMarkerFileUri: URI;
}
interface IPathsToWaitForData {
paths: IPathData[];
waitMarkerFileUri: UriComponents;
}
export interface IOpenFileRequest {
filesToOpenOrCreate?: IPathData[];
filesToDiff?: IPathData[];
}
/**
* Additional context for the request on native only.
*/
export interface INativeOpenFileRequest extends IOpenFileRequest {
termProgram?: string;
filesToWait?: IPathsToWaitForData;
}
export interface INativeRunActionInWindowRequest {
id: string;
from: 'menu' | 'touchbar' | 'mouse';
args?: any[];
}
export interface INativeRunKeybindingInWindowRequest {
userSettingsLabel: string;
}
export interface IColorScheme {
dark: boolean;
highContrast: boolean;
}
export interface IWindowConfiguration {
sessionId: string;
remoteAuthority?: string;
colorScheme: IColorScheme;
autoDetectHighContrast?: boolean;
filesToOpenOrCreate?: IPath[];
filesToDiff?: IPath[];
}
export interface IOSConfiguration {
release: string;
}
export interface INativeWindowConfiguration extends IWindowConfiguration, NativeParsedArgs {
mainPid: number;
windowId: number;
machineId: string;
appRoot: string;
execPath: string;
backupPath?: string;
nodeCachedDataDir?: string;
partsSplashPath: string;
workspace?: IWorkspaceIdentifier;
folderUri?: ISingleFolderWorkspaceIdentifier;
isInitialStartup?: boolean;
logLevel: LogLevel;
zoomLevel?: number;
fullscreen?: boolean;
maximized?: boolean;
accessibilitySupport?: boolean;
perfEntries: ExportData;
userEnv: IProcessEnvironment;
filesToWait?: IPathsToWaitFor;
os: IOSConfiguration;
}
/**
* According to Electron docs: `scale := 1.2 ^ level`.
* https://github.com/electron/electron/blob/master/docs/api/web-contents.md#contentssetzoomlevellevel
*/
export function zoomLevelToZoomFactor(zoomLevel = 0): number {
return Math.pow(1.2, zoomLevel);
}