windows.ts 9.8 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5 6 7 8 9
/*---------------------------------------------------------------------------------------------
 *  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 { TPromise } from 'vs/base/common/winjs.base';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
J
Joao Moreno 已提交
10
import Event from 'vs/base/common/event';
11
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
B
Benjamin Pasero 已提交
12 13
import { IProcessEnvironment } from 'vs/base/common/platform';
import { ParsedArgs } from 'vs/platform/environment/common/environment';
14
import { IWorkspaceIdentifier, IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces';
B
Benjamin Pasero 已提交
15
import { IRecentlyOpened } from 'vs/platform/history/common/history';
16
import { ICommandAction } from 'vs/platform/actions/common/actions';
17
import { PerformanceEntry } from 'vs/base/common/performance';
J
Joao Moreno 已提交
18 19 20

export const IWindowsService = createDecorator<IWindowsService>('windowsService');

B
Benjamin Pasero 已提交
21 22 23 24
export interface INativeOpenDialogOptions {
	windowId?: number;
	forceNewWindow?: boolean;

25
	dialogOptions?: OpenDialogOptions;
B
Benjamin Pasero 已提交
26 27 28 29 30

	telemetryEventName?: string;
	telemetryExtraData?: ITelemetryData;
}

31 32 33 34 35
export interface IEnterWorkspaceResult {
	workspace: IWorkspaceIdentifier;
	backupPath: string;
}

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
export interface CrashReporterStartOptions {
	companyName?: string;
	submitURL: string;
	productName?: string;
	uploadToServer?: boolean;
	ignoreSystemCrashHandler?: boolean;
	extra?: any;
	crashesDirectory?: string;
}

export interface OpenDialogOptions {
	title?: string;
	defaultPath?: string;
	buttonLabel?: string;
	filters?: FileFilter[];
	properties?: Array<'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | 'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory'>;
	message?: string;
}

export interface FileFilter {
	extensions: string[];
	name: string;
}

export interface MessageBoxOptions {
	type?: string;
	buttons?: string[];
	defaultId?: number;
	title?: string;
	message: string;
	detail?: string;
	checkboxLabel?: string;
	checkboxChecked?: boolean;
	cancelId?: number;
	noLink?: boolean;
	normalizeAccessKeys?: boolean;
}

export interface SaveDialogOptions {
	title?: string;
	defaultPath?: string;
	buttonLabel?: string;
	filters?: FileFilter[];
	message?: string;
	nameFieldLabel?: string;
	showsTagField?: boolean;
}

export interface OpenDialogOptions {
	title?: string;
	defaultPath?: string;
	buttonLabel?: string;
	filters?: FileFilter[];
	properties?: Array<'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | 'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory'>;
	message?: string;
}

J
Joao Moreno 已提交
93 94 95 96
export interface IWindowsService {

	_serviceBrand: any;

J
Joao Moreno 已提交
97
	onWindowOpen: Event<number>;
J
Joao Moreno 已提交
98
	onWindowFocus: Event<number>;
99
	onWindowBlur: Event<number>;
J
Joao Moreno 已提交
100

B
Benjamin Pasero 已提交
101 102 103
	pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
	pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
	pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
104
	pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
105
	reloadWindow(windowId: number): TPromise<void>;
J
Joao Moreno 已提交
106
	openDevTools(windowId: number): TPromise<void>;
J
Joao Moreno 已提交
107
	toggleDevTools(windowId: number): TPromise<void>;
108
	closeWorkspace(windowId: number): TPromise<void>;
109
	createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult>;
110
	saveAndEnterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult>;
J
Joao Moreno 已提交
111
	toggleFullScreen(windowId: number): TPromise<void>;
112
	setRepresentedFilename(windowId: number, fileName: string): TPromise<void>;
113
	addRecentlyOpened(files: string[]): TPromise<void>;
114
	removeFromRecentlyOpened(paths: string[]): TPromise<void>;
B
Benjamin Pasero 已提交
115
	clearRecentlyOpened(): TPromise<void>;
116
	getRecentlyOpened(windowId: number): TPromise<IRecentlyOpened>;
J
Joao Moreno 已提交
117
	focusWindow(windowId: number): TPromise<void>;
118
	closeWindow(windowId: number): TPromise<void>;
119
	isFocused(windowId: number): TPromise<boolean>;
120 121 122
	isMaximized(windowId: number): TPromise<boolean>;
	maximizeWindow(windowId: number): TPromise<void>;
	unmaximizeWindow(windowId: number): TPromise<void>;
123
	onWindowTitleDoubleClick(windowId: number): TPromise<void>;
J
Joao Moreno 已提交
124
	setDocumentEdited(windowId: number, flag: boolean): TPromise<void>;
125
	quit(): TPromise<void>;
J
Johannes Rieken 已提交
126
	relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise<void>;
127

128 129 130 131 132 133 134
	// macOS Native Tabs
	showPreviousWindowTab(): TPromise<void>;
	showNextWindowTab(): TPromise<void>;
	moveWindowTabToNewWindow(): TPromise<void>;
	mergeAllWindowTabs(): TPromise<void>;
	toggleWindowTabsBar(): TPromise<void>;

135 136 137
	// macOS TouchBar
	updateTouchBar(windowId: number, items: ICommandAction[][]): TPromise<void>;

138
	// Shared process
139
	whenSharedProcessReady(): TPromise<void>;
140 141
	toggleSharedProcess(): TPromise<void>;

J
Joao Moreno 已提交
142
	// Global methods
143
	openWindow(paths: string[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean; }): TPromise<void>;
J
Joao Moreno 已提交
144
	openNewWindow(): TPromise<void>;
J
Joao Moreno 已提交
145
	showWindow(windowId: number): TPromise<void>;
146
	getWindows(): TPromise<{ id: number; workspace?: IWorkspaceIdentifier; folderPath?: string; title: string; filename?: string; }[]>;
147
	getWindowCount(): TPromise<number>;
J
Joao Moreno 已提交
148
	log(severity: string, ...messages: string[]): TPromise<void>;
J
Joao Moreno 已提交
149
	showItemInFolder(path: string): TPromise<void>;
J
Joao Moreno 已提交
150

151
	// This needs to be handled from browser process to prevent
J
Joao Moreno 已提交
152
	// foreground ordering issues on Windows
153
	openExternal(url: string): TPromise<boolean>;
154 155

	// TODO: this is a bit backwards
156
	startCrashReporter(config: CrashReporterStartOptions): TPromise<void>;
J
Joao Moreno 已提交
157 158 159 160
}

export const IWindowService = createDecorator<IWindowService>('windowService');

161 162 163 164 165
export interface IMessageBoxResult {
	button: number;
	checkboxChecked?: boolean;
}

J
Joao Moreno 已提交
166 167 168 169
export interface IWindowService {

	_serviceBrand: any;

J
Joao Moreno 已提交
170
	onDidChangeFocus: Event<boolean>;
171

172
	getConfiguration(): IWindowConfiguration;
J
Joao Moreno 已提交
173
	getCurrentWindowId(): number;
B
Benjamin Pasero 已提交
174 175 176
	pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
	pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
	pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
177
	pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
178
	reloadWindow(): TPromise<void>;
J
Joao Moreno 已提交
179
	openDevTools(): TPromise<void>;
J
Joao Moreno 已提交
180
	toggleDevTools(): TPromise<void>;
181
	closeWorkspace(): TPromise<void>;
182
	updateTouchBar(items: ICommandAction[][]): TPromise<void>;
183
	createAndEnterWorkspace(folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult>;
184
	saveAndEnterWorkspace(path: string): TPromise<IEnterWorkspaceResult>;
J
Joao Moreno 已提交
185
	toggleFullScreen(): TPromise<void>;
186
	setRepresentedFilename(fileName: string): TPromise<void>;
187
	getRecentlyOpened(): TPromise<IRecentlyOpened>;
J
Joao Moreno 已提交
188
	focusWindow(): TPromise<void>;
189
	closeWindow(): TPromise<void>;
190
	isFocused(): TPromise<boolean>;
J
Joao Moreno 已提交
191
	setDocumentEdited(flag: boolean): TPromise<void>;
192
	onWindowTitleDoubleClick(): TPromise<void>;
J
Joao 已提交
193
	show(): TPromise<void>;
B
Benjamin Pasero 已提交
194
	showMessageBox(options: MessageBoxOptions): number;
195 196
	showSaveDialog(options: SaveDialogOptions): string;
	showOpenDialog(options: OpenDialogOptions): string[];
B
Benjamin Pasero 已提交
197
	showMessageBoxWithCheckbox(options: MessageBoxOptions): TPromise<IMessageBoxResult>;
198 199
}

200 201
export type MenuBarVisibility = 'default' | 'visible' | 'toggle' | 'hidden';

202
export interface IWindowsConfiguration {
203 204 205
	window: IWindowSettings;
}

206
export interface IWindowSettings {
207 208
	openFilesInNewWindow: 'on' | 'off' | 'default';
	openFoldersInNewWindow: 'on' | 'off' | 'default';
209 210
	restoreWindows: 'all' | 'folders' | 'one' | 'none';
	reopenFolders: 'all' | 'one' | 'none'; // TODO@Ben deprecated
211 212 213
	restoreFullscreen: boolean;
	zoomLevel: number;
	titleBarStyle: 'native' | 'custom';
214
	autoDetectHighContrast: boolean;
215
	menuBarVisibility: MenuBarVisibility;
216
	newWindowDimensions: 'default' | 'inherit' | 'maximized' | 'fullscreen';
217
	nativeTabs: boolean;
218
	enableMenuBarMnemonics: boolean;
219
	closeWhenEmpty: boolean;
J
Johannes Rieken 已提交
220
}
221

B
Benjamin Pasero 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
export enum OpenContext {

	// opening when running from the command line
	CLI,

	// macOS only: opening from the dock (also when opening files to a running instance from desktop)
	DOCK,

	// opening from the main application window
	MENU,

	// opening from a file or folder dialog
	DIALOG,

	// opening from the OS's UI
	DESKTOP,

	// opening through the API
	API
}

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
export enum ReadyState {

	/**
	 * This window has not loaded any HTML yet
	 */
	NONE,

	/**
	 * This window is loading HTML
	 */
	LOADING,

	/**
	 * This window is navigating to another HTML
	 */
	NAVIGATING,

	/**
	 * This window is done loading HTML
	 */
	READY
}

B
Benjamin Pasero 已提交
266
export interface IPath {
267

B
Benjamin Pasero 已提交
268 269
	// the file path to open within a Code instance
	filePath?: string;
270

B
Benjamin Pasero 已提交
271 272
	// the line number in the file path to open
	lineNumber?: number;
273

B
Benjamin Pasero 已提交
274 275 276
	// the column number in the file path to open
	columnNumber?: number;
}
277

278 279 280 281 282
export interface IPathsToWaitFor {
	paths: IPath[];
	waitMarkerFilePath: string;
}

283 284 285 286
export interface IOpenFileRequest {
	filesToOpen?: IPath[];
	filesToCreate?: IPath[];
	filesToDiff?: IPath[];
287
	filesToWait?: IPathsToWaitFor;
288 289
}

290 291 292 293
export interface IAddFoldersRequest {
	foldersToAdd: IPath[];
}

294
export interface IWindowConfiguration extends ParsedArgs, IOpenFileRequest {
295 296
	machineId: string;

B
Benjamin Pasero 已提交
297 298
	appRoot: string;
	execPath: string;
B
Benjamin Pasero 已提交
299
	isInitialStartup?: boolean;
B
Benjamin Pasero 已提交
300 301

	userEnv: IProcessEnvironment;
B
Benjamin Pasero 已提交
302
	nodeCachedDataDir: string;
B
Benjamin Pasero 已提交
303

B
Benjamin Pasero 已提交
304
	backupPath?: string;
B
Benjamin Pasero 已提交
305

B
Benjamin Pasero 已提交
306 307 308
	workspace?: IWorkspaceIdentifier;
	folderPath?: string;

B
Benjamin Pasero 已提交
309 310 311 312 313 314 315
	zoomLevel?: number;
	fullscreen?: boolean;
	highContrast?: boolean;
	baseTheme?: string;
	backgroundColor?: string;
	accessibilitySupport?: boolean;

316
	perfEntries: PerformanceEntry[];
B
Benjamin Pasero 已提交
317 318 319
	perfStartTime?: number;
	perfAppReady?: number;
	perfWindowLoadTime?: number;
320 321 322 323 324
}

export interface IRunActionInWindowRequest {
	id: string;
	from: 'menu' | 'touchbar' | 'mouse';
325
}