windows.ts 8.3 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';
B
Benjamin Pasero 已提交
14 15
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { IRecentlyOpened } from 'vs/platform/history/common/history';
16
import { ICommandAction } from 'vs/platform/actions/common/actions';
J
Joao Moreno 已提交
17 18 19

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

B
Benjamin Pasero 已提交
20 21 22 23 24 25 26 27 28 29
export interface INativeOpenDialogOptions {
	windowId?: number;
	forceNewWindow?: boolean;

	dialogOptions?: Electron.OpenDialogOptions;

	telemetryEventName?: string;
	telemetryExtraData?: ITelemetryData;
}

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

J
Joao Moreno 已提交
35 36 37 38
export interface IWindowsService {

	_serviceBrand: any;

J
Joao Moreno 已提交
39
	onWindowOpen: Event<number>;
J
Joao Moreno 已提交
40
	onWindowFocus: Event<number>;
41
	onWindowBlur: Event<number>;
J
Joao Moreno 已提交
42

B
Benjamin Pasero 已提交
43 44 45
	pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
	pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
	pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
46
	reloadWindow(windowId: number): TPromise<void>;
J
Joao Moreno 已提交
47
	openDevTools(windowId: number): TPromise<void>;
J
Joao Moreno 已提交
48
	toggleDevTools(windowId: number): TPromise<void>;
49
	closeWorkspace(windowId: number): TPromise<void>;
50
	openWorkspace(windowId: number): TPromise<void>;
B
Benjamin Pasero 已提交
51
	createAndEnterWorkspace(windowId: number, folderPaths?: string[], path?: string): TPromise<IEnterWorkspaceResult>;
52
	saveAndEnterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult>;
J
Joao Moreno 已提交
53
	toggleFullScreen(windowId: number): TPromise<void>;
54
	setRepresentedFilename(windowId: number, fileName: string): TPromise<void>;
55
	addRecentlyOpened(files: string[]): TPromise<void>;
56
	removeFromRecentlyOpened(paths: string[]): TPromise<void>;
B
Benjamin Pasero 已提交
57
	clearRecentlyOpened(): TPromise<void>;
58
	getRecentlyOpened(windowId: number): TPromise<IRecentlyOpened>;
J
Joao Moreno 已提交
59
	focusWindow(windowId: number): TPromise<void>;
60
	closeWindow(windowId: number): TPromise<void>;
61
	isFocused(windowId: number): TPromise<boolean>;
62 63 64
	isMaximized(windowId: number): TPromise<boolean>;
	maximizeWindow(windowId: number): TPromise<void>;
	unmaximizeWindow(windowId: number): TPromise<void>;
65
	onWindowTitleDoubleClick(windowId: number): TPromise<void>;
J
Joao Moreno 已提交
66
	setDocumentEdited(windowId: number, flag: boolean): TPromise<void>;
67
	quit(): TPromise<void>;
J
Johannes Rieken 已提交
68
	relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise<void>;
69

70 71 72 73 74 75 76
	// macOS Native Tabs
	showPreviousWindowTab(): TPromise<void>;
	showNextWindowTab(): TPromise<void>;
	moveWindowTabToNewWindow(): TPromise<void>;
	mergeAllWindowTabs(): TPromise<void>;
	toggleWindowTabsBar(): TPromise<void>;

77 78 79
	// macOS TouchBar
	updateTouchBar(windowId: number, items: ICommandAction[][]): TPromise<void>;

80
	// Shared process
81
	whenSharedProcessReady(): TPromise<void>;
82 83
	toggleSharedProcess(): TPromise<void>;

J
Joao Moreno 已提交
84
	// Global methods
85
	openWindow(paths: string[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean; }): TPromise<void>;
J
Joao Moreno 已提交
86
	openNewWindow(): TPromise<void>;
J
Joao Moreno 已提交
87
	showWindow(windowId: number): TPromise<void>;
88
	getWindows(): TPromise<{ id: number; workspace?: IWorkspaceIdentifier; folderPath?: string; title: string; filename?: string; }[]>;
89
	getWindowCount(): TPromise<number>;
J
Joao Moreno 已提交
90
	log(severity: string, ...messages: string[]): TPromise<void>;
J
Joao Moreno 已提交
91
	showItemInFolder(path: string): TPromise<void>;
J
Joao Moreno 已提交
92

93
	// This needs to be handled from browser process to prevent
J
Joao Moreno 已提交
94
	// foreground ordering issues on Windows
95
	openExternal(url: string): TPromise<boolean>;
96 97 98

	// TODO: this is a bit backwards
	startCrashReporter(config: Electron.CrashReporterStartOptions): TPromise<void>;
J
Joao Moreno 已提交
99 100 101 102
}

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

103 104 105 106 107
export interface IMessageBoxResult {
	button: number;
	checkboxChecked?: boolean;
}

J
Joao Moreno 已提交
108 109 110 111
export interface IWindowService {

	_serviceBrand: any;

J
Joao Moreno 已提交
112
	onDidChangeFocus: Event<boolean>;
113

J
Joao Moreno 已提交
114
	getCurrentWindowId(): number;
B
Benjamin Pasero 已提交
115 116 117
	pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
	pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
	pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
118
	reloadWindow(): TPromise<void>;
J
Joao Moreno 已提交
119
	openDevTools(): TPromise<void>;
J
Joao Moreno 已提交
120
	toggleDevTools(): TPromise<void>;
121
	closeWorkspace(): TPromise<void>;
122
	openWorkspace(): TPromise<void>;
123
	updateTouchBar(items: ICommandAction[][]): TPromise<void>;
B
Benjamin Pasero 已提交
124
	createAndEnterWorkspace(folderPaths?: string[], path?: string): TPromise<IEnterWorkspaceResult>;
125
	saveAndEnterWorkspace(path: string): TPromise<IEnterWorkspaceResult>;
J
Joao Moreno 已提交
126
	toggleFullScreen(): TPromise<void>;
127
	setRepresentedFilename(fileName: string): TPromise<void>;
128
	getRecentlyOpened(): TPromise<IRecentlyOpened>;
J
Joao Moreno 已提交
129
	focusWindow(): TPromise<void>;
130
	closeWindow(): TPromise<void>;
131
	isFocused(): TPromise<boolean>;
J
Joao Moreno 已提交
132
	setDocumentEdited(flag: boolean): TPromise<void>;
133 134 135
	isMaximized(): TPromise<boolean>;
	maximizeWindow(): TPromise<void>;
	unmaximizeWindow(): TPromise<void>;
136
	onWindowTitleDoubleClick(): TPromise<void>;
J
Joao 已提交
137
	show(): TPromise<void>;
138 139
	showMessageBoxSync(options: Electron.MessageBoxOptions): number;
	showMessageBox(options: Electron.MessageBoxOptions): TPromise<IMessageBoxResult>;
140
	showSaveDialog(options: Electron.SaveDialogOptions, callback?: (fileName: string) => void): string;
141
	showOpenDialog(options: Electron.OpenDialogOptions, callback?: (fileNames: string[]) => void): string[];
142 143
}

144 145
export type MenuBarVisibility = 'default' | 'visible' | 'toggle' | 'hidden';

146
export interface IWindowsConfiguration {
147 148 149
	window: IWindowSettings;
}

150
export interface IWindowSettings {
151 152
	openFilesInNewWindow: 'on' | 'off' | 'default';
	openFoldersInNewWindow: 'on' | 'off' | 'default';
153 154
	restoreWindows: 'all' | 'folders' | 'one' | 'none';
	reopenFolders: 'all' | 'one' | 'none'; // TODO@Ben deprecated
155 156 157
	restoreFullscreen: boolean;
	zoomLevel: number;
	titleBarStyle: 'native' | 'custom';
158
	autoDetectHighContrast: boolean;
159
	menuBarVisibility: MenuBarVisibility;
160
	newWindowDimensions: 'default' | 'inherit' | 'maximized' | 'fullscreen';
161
	nativeTabs: boolean;
162
	enableMenuBarMnemonics: boolean;
163
	closeWhenEmpty: boolean;
J
Johannes Rieken 已提交
164
}
165

B
Benjamin Pasero 已提交
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
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
}

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
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 已提交
210
export interface IPath {
211

B
Benjamin Pasero 已提交
212 213
	// the file path to open within a Code instance
	filePath?: string;
214

B
Benjamin Pasero 已提交
215 216
	// the line number in the file path to open
	lineNumber?: number;
217

B
Benjamin Pasero 已提交
218 219 220
	// the column number in the file path to open
	columnNumber?: number;
}
221

222 223 224 225 226
export interface IPathsToWaitFor {
	paths: IPath[];
	waitMarkerFilePath: string;
}

227 228 229 230
export interface IOpenFileRequest {
	filesToOpen?: IPath[];
	filesToCreate?: IPath[];
	filesToDiff?: IPath[];
231
	filesToWait?: IPathsToWaitFor;
232 233
}

234 235 236 237
export interface IAddFoldersRequest {
	foldersToAdd: IPath[];
}

238
export interface IWindowConfiguration extends ParsedArgs, IOpenFileRequest {
B
Benjamin Pasero 已提交
239 240
	appRoot: string;
	execPath: string;
B
Benjamin Pasero 已提交
241
	isInitialStartup?: boolean;
B
Benjamin Pasero 已提交
242 243

	userEnv: IProcessEnvironment;
B
Benjamin Pasero 已提交
244
	nodeCachedDataDir: string;
B
Benjamin Pasero 已提交
245

B
Benjamin Pasero 已提交
246
	backupPath?: string;
B
Benjamin Pasero 已提交
247

B
Benjamin Pasero 已提交
248 249 250
	workspace?: IWorkspaceIdentifier;
	folderPath?: string;

B
Benjamin Pasero 已提交
251 252 253 254 255 256 257 258 259 260
	zoomLevel?: number;
	fullscreen?: boolean;
	highContrast?: boolean;
	baseTheme?: string;
	backgroundColor?: string;
	accessibilitySupport?: boolean;

	perfStartTime?: number;
	perfAppReady?: number;
	perfWindowLoadTime?: number;
261 262 263 264 265
}

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