actions.ts 55.4 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

8 9
import 'vs/css!./media/actions';

10
import URI from 'vs/base/common/uri';
J
Johannes Rieken 已提交
11 12
import { TPromise } from 'vs/base/common/winjs.base';
import { Action } from 'vs/base/common/actions';
13
import { IWindowService, IWindowsService, MenuBarVisibility } from 'vs/platform/windows/common/windows';
14
import * as nls from 'vs/nls';
15 16
import product from 'vs/platform/node/product';
import pkg from 'vs/platform/node/package';
17
import * as errors from 'vs/base/common/errors';
18
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
J
Johannes Rieken 已提交
19
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
20
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
J
Johannes Rieken 已提交
21
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
22
import * as paths from 'vs/base/common/paths';
S
SteVen Batten 已提交
23
import { isMacintosh, isLinux, language } from 'vs/base/common/platform';
S
Sandeep Somavarapu 已提交
24
import { IQuickOpenService, IFilePickOpenEntry, ISeparator, IPickOpenAction, IPickOpenItem } from 'vs/platform/quickOpen/common/quickOpen';
25
import * as browser from 'vs/base/browser/browser';
J
Johannes Rieken 已提交
26
import { IIntegrityService } from 'vs/platform/integrity/common/integrity';
B
Benjamin Pasero 已提交
27
import { IEntryRunContext } from 'vs/base/parts/quickopen/common/quickOpen';
B
Benjamin Pasero 已提交
28
import { ITimerService, IStartupMetrics } from 'vs/workbench/services/timer/common/timerService';
29
import { IEditorGroupsService, GroupDirection } from 'vs/workbench/services/group/common/editorGroupsService';
S
sj.hwang 已提交
30
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
31
import { IPartService, Parts, Position as PartPosition } from 'vs/workbench/services/part/common/partService';
S
sj.hwang 已提交
32
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
B
Benjamin Pasero 已提交
33
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
B
Benjamin Pasero 已提交
34
import * as os from 'os';
S
SteVen Batten 已提交
35
import { webFrame, shell } from 'electron';
B
Benjamin Pasero 已提交
36
import { getPathLabel, getBaseLabel } from 'vs/base/common/labels';
B
Benjamin Pasero 已提交
37 38
import { IViewlet } from 'vs/workbench/common/viewlet';
import { IPanel } from 'vs/workbench/common/panel';
B
Benjamin Pasero 已提交
39
import { IWorkspaceIdentifier, getWorkspaceLabel, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
S
Sandeep Somavarapu 已提交
40
import { FileKind } from 'vs/platform/files/common/files';
B
Benjamin Pasero 已提交
41
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
42
import { IExtensionService, ActivationTimes } from 'vs/workbench/services/extensions/common/extensions';
43
import { getEntries } from 'vs/base/common/performance';
44
import { IssueType } from 'vs/platform/issue/common/issue';
J
Joao Moreno 已提交
45 46 47 48 49 50
import { domEvent } from 'vs/base/browser/event';
import { once } from 'vs/base/common/event';
import { IDisposable, toDisposable, dispose } from 'vs/base/common/lifecycle';
import { getDomNodePagePosition, createStyleSheet, createCSSRule } from 'vs/base/browser/dom';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { Context } from 'vs/platform/contextkey/browser/contextKeyService';
51
import { IWorkbenchIssueService } from 'vs/workbench/services/issue/common/issue';
52
import { INotificationService } from 'vs/platform/notification/common/notification';
E
Erich Gamma 已提交
53

54 55
// --- actions

56
export class CloseCurrentWindowAction extends Action {
E
Erich Gamma 已提交
57

M
Matt Bierner 已提交
58 59
	public static readonly ID = 'workbench.action.closeWindow';
	public static readonly LABEL = nls.localize('closeWindow', "Close Window");
E
Erich Gamma 已提交
60

61
	constructor(id: string, label: string, @IWindowService private windowService: IWindowService) {
E
Erich Gamma 已提交
62 63 64
		super(id, label);
	}

65
	public run(): TPromise<boolean> {
66
		this.windowService.closeWindow();
E
Erich Gamma 已提交
67

A
Alex Dima 已提交
68
		return TPromise.as(true);
E
Erich Gamma 已提交
69 70 71
	}
}

72
export class CloseWorkspaceAction extends Action {
E
Erich Gamma 已提交
73

74
	static readonly ID = 'workbench.action.closeFolder';
75
	static LABEL = nls.localize('closeWorkspace', "Close Workspace");
E
Erich Gamma 已提交
76 77 78 79 80

	constructor(
		id: string,
		label: string,
		@IWorkspaceContextService private contextService: IWorkspaceContextService,
81
		@INotificationService private notificationService: INotificationService,
J
Joao Moreno 已提交
82
		@IWindowService private windowService: IWindowService
E
Erich Gamma 已提交
83 84 85 86
	) {
		super(id, label);
	}

J
Joao Moreno 已提交
87
	run(): TPromise<void> {
88
		if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY) {
89
			this.notificationService.info(nls.localize('noWorkspaceOpened', "There is currently no workspace opened in this instance to close."));
90

J
Joao Moreno 已提交
91
			return TPromise.as(null);
E
Erich Gamma 已提交
92 93
		}

94
		return this.windowService.closeWorkspace();
E
Erich Gamma 已提交
95 96 97 98 99
	}
}

export class NewWindowAction extends Action {

100
	static readonly ID = 'workbench.action.newWindow';
J
Joao Moreno 已提交
101
	static LABEL = nls.localize('newWindow', "New Window");
E
Erich Gamma 已提交
102

B
Benjamin Pasero 已提交
103 104 105
	constructor(
		id: string,
		label: string,
J
Joao Moreno 已提交
106
		@IWindowsService private windowsService: IWindowsService
B
Benjamin Pasero 已提交
107
	) {
E
Erich Gamma 已提交
108 109 110
		super(id, label);
	}

J
Joao Moreno 已提交
111 112
	run(): TPromise<void> {
		return this.windowsService.openNewWindow();
E
Erich Gamma 已提交
113 114 115 116 117
	}
}

export class ToggleFullScreenAction extends Action {

118
	static readonly ID = 'workbench.action.toggleFullScreen';
J
Joao Moreno 已提交
119
	static LABEL = nls.localize('toggleFullScreen', "Toggle Full Screen");
E
Erich Gamma 已提交
120

J
Joao Moreno 已提交
121
	constructor(id: string, label: string, @IWindowService private windowService: IWindowService) {
E
Erich Gamma 已提交
122 123 124
		super(id, label);
	}

J
Joao Moreno 已提交
125 126
	run(): TPromise<void> {
		return this.windowService.toggleFullScreen();
E
Erich Gamma 已提交
127 128 129
	}
}

130 131
export class ToggleMenuBarAction extends Action {

132
	static readonly ID = 'workbench.action.toggleMenuBar';
J
Joao Moreno 已提交
133
	static LABEL = nls.localize('toggleMenuBar', "Toggle Menu Bar");
134

135
	private static readonly menuBarVisibilityKey = 'window.menuBarVisibility';
136 137 138 139

	constructor(
		id: string,
		label: string,
140
		@IConfigurationService private configurationService: IConfigurationService
141
	) {
142 143 144
		super(id, label);
	}

B
Benjamin Pasero 已提交
145
	public run(): TPromise<void> {
146
		let currentVisibilityValue = this.configurationService.getValue<MenuBarVisibility>(ToggleMenuBarAction.menuBarVisibilityKey);
147 148
		if (typeof currentVisibilityValue !== 'string') {
			currentVisibilityValue = 'default';
149 150 151
		}

		let newVisibilityValue: string;
152
		if (currentVisibilityValue === 'visible' || currentVisibilityValue === 'default') {
153 154
			newVisibilityValue = 'toggle';
		} else {
155
			newVisibilityValue = 'default';
156 157
		}

158
		this.configurationService.updateValue(ToggleMenuBarAction.menuBarVisibilityKey, newVisibilityValue, ConfigurationTarget.USER);
159 160

		return TPromise.as(null);
161 162 163
	}
}

E
Erich Gamma 已提交
164 165
export class ToggleDevToolsAction extends Action {

166
	static readonly ID = 'workbench.action.toggleDevTools';
J
Joao Moreno 已提交
167
	static LABEL = nls.localize('toggleDevTools', "Toggle Developer Tools");
E
Erich Gamma 已提交
168

J
Joao Moreno 已提交
169
	constructor(id: string, label: string, @IWindowService private windowsService: IWindowService) {
E
Erich Gamma 已提交
170 171 172
		super(id, label);
	}

B
Benjamin Pasero 已提交
173
	public run(): TPromise<void> {
J
Joao Moreno 已提交
174
		return this.windowsService.toggleDevTools();
E
Erich Gamma 已提交
175 176 177
	}
}

178
export abstract class BaseZoomAction extends Action {
179
	private static readonly SETTING_KEY = 'window.zoomLevel';
180 181 182 183

	constructor(
		id: string,
		label: string,
184
		@IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService
185 186 187 188 189
	) {
		super(id, label);
	}

	protected setConfiguredZoomLevel(level: number): void {
190 191
		level = Math.round(level); // when reaching smallest zoom, prevent fractional zoom levels

B
Benjamin Pasero 已提交
192
		const applyZoom = () => {
193
			webFrame.setZoomLevel(level);
B
Benjamin Pasero 已提交
194
			browser.setZoomFactor(webFrame.getZoomFactor());
195 196 197 198
			// See https://github.com/Microsoft/vscode/issues/26151
			// Cannot be trusted because the webFrame might take some time
			// until it really applies the new zoom level
			browser.setZoomLevel(webFrame.getZoomLevel(), /*isTrusted*/false);
199 200
		};

201
		this.configurationService.updateValue(BaseZoomAction.SETTING_KEY, level).done(() => applyZoom());
202 203 204 205
	}
}

export class ZoomInAction extends BaseZoomAction {
E
Erich Gamma 已提交
206

M
Matt Bierner 已提交
207 208
	public static readonly ID = 'workbench.action.zoomIn';
	public static readonly LABEL = nls.localize('zoomIn', "Zoom In");
E
Erich Gamma 已提交
209

210 211 212
	constructor(
		id: string,
		label: string,
213
		@IWorkspaceConfigurationService configurationService: IWorkspaceConfigurationService
214
	) {
215
		super(id, label, configurationService);
E
Erich Gamma 已提交
216 217
	}

218
	public run(): TPromise<boolean> {
219
		this.setConfiguredZoomLevel(webFrame.getZoomLevel() + 1);
E
Erich Gamma 已提交
220

A
Alex Dima 已提交
221
		return TPromise.as(true);
E
Erich Gamma 已提交
222 223 224
	}
}

225
export class ZoomOutAction extends BaseZoomAction {
E
Erich Gamma 已提交
226

M
Matt Bierner 已提交
227 228
	public static readonly ID = 'workbench.action.zoomOut';
	public static readonly LABEL = nls.localize('zoomOut', "Zoom Out");
E
Erich Gamma 已提交
229

230 231
	constructor(
		id: string,
232
		label: string,
233
		@IWorkspaceConfigurationService configurationService: IWorkspaceConfigurationService
234
	) {
235
		super(id, label, configurationService);
E
Erich Gamma 已提交
236 237
	}

238
	public run(): TPromise<boolean> {
239
		this.setConfiguredZoomLevel(webFrame.getZoomLevel() - 1);
240

241
		return TPromise.as(true);
E
Erich Gamma 已提交
242 243 244
	}
}

245
export class ZoomResetAction extends BaseZoomAction {
E
Erich Gamma 已提交
246

M
Matt Bierner 已提交
247 248
	public static readonly ID = 'workbench.action.zoomReset';
	public static readonly LABEL = nls.localize('zoomReset', "Reset Zoom");
E
Erich Gamma 已提交
249

250 251 252
	constructor(
		id: string,
		label: string,
253
		@IWorkspaceConfigurationService configurationService: IWorkspaceConfigurationService
254
	) {
255
		super(id, label, configurationService);
E
Erich Gamma 已提交
256 257
	}

258
	public run(): TPromise<boolean> {
259
		this.setConfiguredZoomLevel(0);
260

261
		return TPromise.as(true);
E
Erich Gamma 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
	}
}

/* Copied from loader.ts */
enum LoaderEventType {
	LoaderAvailable = 1,

	BeginLoadingScript = 10,
	EndLoadingScriptOK = 11,
	EndLoadingScriptError = 12,

	BeginInvokeFactory = 21,
	EndInvokeFactory = 22,

	NodeBeginEvaluatingScript = 31,
	NodeEndEvaluatingScript = 32,

	NodeBeginNativeRequire = 33,
	NodeEndNativeRequire = 34
}
282

E
Erich Gamma 已提交
283 284 285 286 287
interface ILoaderEvent {
	type: LoaderEventType;
	timestamp: number;
	detail: string;
}
288

E
Erich Gamma 已提交
289 290
export class ShowStartupPerformance extends Action {

M
Matt Bierner 已提交
291 292
	public static readonly ID = 'workbench.action.appPerf';
	public static readonly LABEL = nls.localize('appPerf', "Startup Performance");
E
Erich Gamma 已提交
293

294 295 296
	constructor(
		id: string,
		label: string,
J
Joao Moreno 已提交
297
		@IWindowService private windowService: IWindowService,
B
Benjamin Pasero 已提交
298
		@ITimerService private timerService: ITimerService,
299 300
		@IEnvironmentService private environmentService: IEnvironmentService,
		@IExtensionService private extensionService: IExtensionService
301
	) {
E
Erich Gamma 已提交
302
		super(id, label);
303 304 305 306 307 308 309 310 311
	}

	public run(): TPromise<boolean> {

		// Show dev tools
		this.windowService.openDevTools();

		// Print to console
		setTimeout(() => {
312
			(<any>console).group('Startup Performance Measurement');
B
Benjamin Pasero 已提交
313 314 315 316 317
			const metrics: IStartupMetrics = this.timerService.startupMetrics;
			console.log(`OS: ${metrics.platform} (${metrics.release})`);
			console.log(`CPUs: ${metrics.cpus.model} (${metrics.cpus.count} x ${metrics.cpus.speed})`);
			console.log(`Memory (System): ${(metrics.totalmem / (1024 * 1024 * 1024)).toFixed(2)}GB (${(metrics.freemem / (1024 * 1024 * 1024)).toFixed(2)}GB free)`);
			console.log(`Memory (Process): ${(metrics.meminfo.workingSetSize / 1024).toFixed(2)}MB working set (${(metrics.meminfo.peakWorkingSetSize / 1024).toFixed(2)}MB peak, ${(metrics.meminfo.privateBytes / 1024).toFixed(2)}MB private, ${(metrics.meminfo.sharedBytes / 1024).toFixed(2)}MB shared)`);
318
			console.log(`VM (likelyhood): ${metrics.isVMLikelyhood}%`);
B
Benjamin Pasero 已提交
319 320 321
			console.log(`Initial Startup: ${metrics.initialStartup}`);
			console.log(`Screen Reader Active: ${metrics.hasAccessibilitySupport}`);
			console.log(`Empty Workspace: ${metrics.emptyWorkbench}`);
322 323 324 325 326 327 328

			let nodeModuleLoadTime: number;
			if (this.environmentService.performance) {
				const nodeModuleTimes = this.analyzeNodeModulesLoadTimes();
				nodeModuleLoadTime = nodeModuleTimes.duration;
			}

B
Benjamin Pasero 已提交
329
			(<any>console).table(this.getStartupMetricsTable(nodeModuleLoadTime));
330

331 332 333 334 335 336 337 338
			if (this.environmentService.performance) {
				const data = this.analyzeLoaderStats();
				for (let type in data) {
					(<any>console).groupCollapsed(`Loader: ${type}`);
					(<any>console).table(data[type]);
					(<any>console).groupEnd();
				}
			}
339

340
			(<any>console).groupEnd();
341 342

			(<any>console).group('Extension Activation Stats');
A
Alex Dima 已提交
343 344 345 346 347 348 349 350 351
			let extensionsActivationTimes: { [id: string]: ActivationTimes; } = {};
			let extensionsStatus = this.extensionService.getExtensionsStatus();
			for (let id in extensionsStatus) {
				const status = extensionsStatus[id];
				if (status.activationTimes) {
					extensionsActivationTimes[id] = status.activationTimes;
				}
			}
			(<any>console).table(extensionsActivationTimes);
352
			(<any>console).groupEnd();
353 354

			(<any>console).group('Raw Startup Timers (CSV)');
355 356
			let value = `Name\tStart\n`;
			let entries = getEntries('mark').slice(0).sort((a, b) => a.startTime - b.startTime);
357
			for (const entry of entries) {
358
				value += `${entry.name}\t${entry.startTime}\n`;
359 360 361
			}
			console.log(value);
			(<any>console).groupEnd();
362
		}, 1000);
363

364
		return TPromise.as(true);
E
Erich Gamma 已提交
365 366
	}

B
Benjamin Pasero 已提交
367
	private getStartupMetricsTable(nodeModuleLoadTime?: number): any[] {
368
		const table: any[] = [];
B
Benjamin Pasero 已提交
369
		const metrics: IStartupMetrics = this.timerService.startupMetrics;
370

B
Benjamin Pasero 已提交
371
		if (metrics.initialStartup) {
372
			table.push({ Topic: '[main] start => app.isReady', 'Took (ms)': metrics.timers.ellapsedAppReady });
D
Dirk Baeumer 已提交
373
			table.push({ Topic: '[main] nls:start => nls:end', 'Took (ms)': metrics.timers.ellapsedNlsGeneration });
374
			table.push({ Topic: '[main] app.isReady => window.loadUrl()', 'Took (ms)': metrics.timers.ellapsedWindowLoad });
E
Erich Gamma 已提交
375
		}
376

B
Benjamin Pasero 已提交
377 378
		table.push({ Topic: '[renderer] window.loadUrl() => begin to require(workbench.main.js)', 'Took (ms)': metrics.timers.ellapsedWindowLoadToRequire });
		table.push({ Topic: '[renderer] require(workbench.main.js)', 'Took (ms)': metrics.timers.ellapsedRequire });
379 380 381 382 383

		if (nodeModuleLoadTime) {
			table.push({ Topic: '[renderer] -> of which require() node_modules', 'Took (ms)': nodeModuleLoadTime });
		}

B
Benjamin Pasero 已提交
384 385 386 387
		table.push({ Topic: '[renderer] create extension host => extensions onReady()', 'Took (ms)': metrics.timers.ellapsedExtensions });
		table.push({ Topic: '[renderer] restore viewlet', 'Took (ms)': metrics.timers.ellapsedViewletRestore });
		table.push({ Topic: '[renderer] restore editor view state', 'Took (ms)': metrics.timers.ellapsedEditorRestore });
		table.push({ Topic: '[renderer] overall workbench load', 'Took (ms)': metrics.timers.ellapsedWorkbench });
388
		table.push({ Topic: '------------------------------------------------------' });
B
Benjamin Pasero 已提交
389 390
		table.push({ Topic: '[main, renderer] start => extensions ready', 'Took (ms)': metrics.timers.ellapsedExtensionsReady });
		table.push({ Topic: '[main, renderer] start => workbench ready', 'Took (ms)': metrics.ellapsed });
E
Erich Gamma 已提交
391

392
		return table;
E
Erich Gamma 已提交
393 394
	}

395
	private analyzeNodeModulesLoadTimes(): { table: any[], duration: number } {
396 397 398 399 400 401 402 403 404
		const stats = <ILoaderEvent[]>(<any>require).getStats();
		const result = [];

		let total = 0;

		for (let i = 0, len = stats.length; i < len; i++) {
			if (stats[i].type === LoaderEventType.NodeEndNativeRequire) {
				if (stats[i - 1].type === LoaderEventType.NodeBeginNativeRequire && stats[i - 1].detail === stats[i].detail) {
					const entry: any = {};
405
					const dur = (stats[i].timestamp - stats[i - 1].timestamp);
406
					entry['Event'] = 'nodeRequire ' + stats[i].detail;
407 408 409 410
					entry['Took (ms)'] = dur.toFixed(2);
					total += dur;
					entry['Start (ms)'] = '**' + stats[i - 1].timestamp.toFixed(2);
					entry['End (ms)'] = '**' + stats[i - 1].timestamp.toFixed(2);
411 412 413 414 415 416
					result.push(entry);
				}
			}
		}

		if (total > 0) {
417 418
			result.push({ Event: '------------------------------------------------------' });

419
			const entry: any = {};
420 421
			entry['Event'] = '[renderer] total require() node_modules';
			entry['Took (ms)'] = total.toFixed(2);
422 423 424 425 426
			entry['Start (ms)'] = '**';
			entry['End (ms)'] = '**';
			result.push(entry);
		}

427
		return { table: result, duration: Math.round(total) };
E
Erich Gamma 已提交
428
	}
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536

	private analyzeLoaderStats(): { [type: string]: any[] } {
		const stats = <ILoaderEvent[]>(<any>require).getStats().slice(0).sort((a: ILoaderEvent, b: ILoaderEvent) => {
			if (a.detail < b.detail) {
				return -1;
			} else if (a.detail > b.detail) {
				return 1;
			} else if (a.type < b.type) {
				return -1;
			} else if (a.type > b.type) {
				return 1;
			} else {
				return 0;
			}
		});

		class Tick {

			public readonly duration: number;
			public readonly detail: string;

			constructor(public readonly start: ILoaderEvent, public readonly end: ILoaderEvent) {
				console.assert(start.detail === end.detail);

				this.duration = this.end.timestamp - this.start.timestamp;
				this.detail = start.detail;
			}

			toTableObject() {
				return {
					['Path']: this.start.detail,
					['Took (ms)']: this.duration.toFixed(2),
					// ['Start (ms)']: this.start.timestamp,
					// ['End (ms)']: this.end.timestamp
				};
			}

			static compareUsingStartTimestamp(a: Tick, b: Tick): number {
				if (a.start.timestamp < b.start.timestamp) {
					return -1;
				} else if (a.start.timestamp > b.start.timestamp) {
					return 1;
				} else {
					return 0;
				}
			}
		}

		const ticks: { [type: number]: Tick[] } = {
			[LoaderEventType.BeginLoadingScript]: [],
			[LoaderEventType.BeginInvokeFactory]: [],
			[LoaderEventType.NodeBeginEvaluatingScript]: [],
			[LoaderEventType.NodeBeginNativeRequire]: [],
		};

		for (let i = 1; i < stats.length - 1; i++) {
			const stat = stats[i];
			const nextStat = stats[i + 1];

			if (nextStat.type - stat.type > 2) {
				//bad?!
				break;
			}

			i += 1;
			ticks[stat.type].push(new Tick(stat, nextStat));
		}

		ticks[LoaderEventType.BeginInvokeFactory].sort(Tick.compareUsingStartTimestamp);
		ticks[LoaderEventType.BeginInvokeFactory].sort(Tick.compareUsingStartTimestamp);
		ticks[LoaderEventType.NodeBeginEvaluatingScript].sort(Tick.compareUsingStartTimestamp);
		ticks[LoaderEventType.NodeBeginNativeRequire].sort(Tick.compareUsingStartTimestamp);

		const ret = {
			'Load Script': ticks[LoaderEventType.BeginLoadingScript].map(t => t.toTableObject()),
			'(Node) Load Script': ticks[LoaderEventType.NodeBeginNativeRequire].map(t => t.toTableObject()),
			'Eval Script': ticks[LoaderEventType.BeginInvokeFactory].map(t => t.toTableObject()),
			'(Node) Eval Script': ticks[LoaderEventType.NodeBeginEvaluatingScript].map(t => t.toTableObject()),
		};

		function total(ticks: Tick[]): number {
			let sum = 0;
			for (const tick of ticks) {
				sum += tick.duration;
			}
			return sum;
		}

		// totals
		ret['Load Script'].push({
			['Path']: 'TOTAL TIME',
			['Took (ms)']: total(ticks[LoaderEventType.BeginLoadingScript]).toFixed(2)
		});
		ret['Eval Script'].push({
			['Path']: 'TOTAL TIME',
			['Took (ms)']: total(ticks[LoaderEventType.BeginInvokeFactory]).toFixed(2)
		});
		ret['(Node) Load Script'].push({
			['Path']: 'TOTAL TIME',
			['Took (ms)']: total(ticks[LoaderEventType.NodeBeginNativeRequire]).toFixed(2)
		});
		ret['(Node) Eval Script'].push({
			['Path']: 'TOTAL TIME',
			['Took (ms)']: total(ticks[LoaderEventType.NodeBeginEvaluatingScript]).toFixed(2)
		});

		return ret;
	}
E
Erich Gamma 已提交
537 538 539 540
}

export class ReloadWindowAction extends Action {

541
	static readonly ID = 'workbench.action.reloadWindow';
542
	static LABEL = nls.localize('reloadWindow', "Reload Window");
E
Erich Gamma 已提交
543

544 545 546
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
547
		@IWindowService private windowService: IWindowService
548
	) {
E
Erich Gamma 已提交
549 550 551
		super(id, label);
	}

552 553
	run(): TPromise<boolean> {
		return this.windowService.reloadWindow().then(() => true);
E
Erich Gamma 已提交
554 555 556
	}
}

557 558 559 560 561 562 563 564 565 566 567 568 569 570
export class ReloadWindowWithExtensionsDisabledAction extends Action {

	static readonly ID = 'workbench.action.reloadWindowWithExtensionsDisabled';
	static LABEL = nls.localize('reloadWindowWithExntesionsDisabled', "Reload Window With Extensions Disabled");

	constructor(
		id: string,
		label: string,
		@IWindowService private windowService: IWindowService
	) {
		super(id, label);
	}

	run(): TPromise<boolean> {
571
		return this.windowService.reloadWindow({ _: [], 'disable-extensions': true }).then(() => true);
572 573 574
	}
}

B
Benjamin Pasero 已提交
575
export abstract class BaseSwitchWindow extends Action {
576
	private closeWindowAction: CloseWindowAction;
E
Erich Gamma 已提交
577

B
Benjamin Pasero 已提交
578 579 580 581 582 583
	constructor(
		id: string,
		label: string,
		private windowsService: IWindowsService,
		private windowService: IWindowService,
		private quickOpenService: IQuickOpenService,
584 585
		private keybindingService: IKeybindingService,
		private instantiationService: IInstantiationService
B
Benjamin Pasero 已提交
586 587
	) {
		super(id, label);
588 589

		this.closeWindowAction = this.instantiationService.createInstance(CloseWindowAction);
B
Benjamin Pasero 已提交
590 591 592 593 594 595 596
	}

	protected abstract isQuickNavigate(): boolean;

	public run(): TPromise<void> {
		const currentWindowId = this.windowService.getCurrentWindowId();

597
		return this.windowsService.getWindows().then(windows => {
B
Benjamin Pasero 已提交
598
			const placeHolder = nls.localize('switchWindowPlaceHolder', "Select a window to switch to");
599
			const picks = windows.map(win => ({
600
				payload: win.id,
601
				resource: win.filename ? URI.file(win.filename) : win.folderPath ? URI.file(win.folderPath) : win.workspace ? URI.file(win.workspace.configPath) : void 0,
602
				fileKind: win.filename ? FileKind.FILE : win.workspace ? FileKind.ROOT_FOLDER : win.folderPath ? FileKind.FOLDER : FileKind.FILE,
B
Benjamin Pasero 已提交
603 604 605 606 607 608 609 610
				label: win.title,
				description: (currentWindowId === win.id) ? nls.localize('current', "Current Window") : void 0,
				run: () => {
					setTimeout(() => {
						// Bug: somehow when not running this code in a timeout, it is not possible to use this picker
						// with quick navigate keys (not able to trigger quick navigate once running it once).
						this.windowsService.showWindow(win.id).done(null, errors.onUnexpectedError);
					});
611 612
				},
				action: (!this.isQuickNavigate() && currentWindowId !== win.id) ? this.closeWindowAction : void 0
B
Benjamin Pasero 已提交
613 614 615
			} as IFilePickOpenEntry));

			this.quickOpenService.pick(picks, {
616
				contextKey: 'inWindowsPicker',
B
Benjamin Pasero 已提交
617 618 619 620 621 622
				autoFocus: { autoFocusFirstEntry: true },
				placeHolder,
				quickNavigateConfiguration: this.isQuickNavigate() ? { keybindings: this.keybindingService.lookupKeybindings(this.id) } : void 0
			});
		});
	}
623 624 625 626 627 628 629 630 631 632

	public dispose(): void {
		super.dispose();

		this.closeWindowAction.dispose();
	}
}

class CloseWindowAction extends Action implements IPickOpenAction {

M
Matt Bierner 已提交
633 634
	public static readonly ID = 'workbench.action.closeWindow';
	public static readonly LABEL = nls.localize('close', "Close Window");
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650

	constructor(
		@IWindowsService private windowsService: IWindowsService
	) {
		super(CloseWindowAction.ID, CloseWindowAction.LABEL);

		this.class = 'action-remove-from-recently-opened';
	}

	public run(item: IPickOpenItem): TPromise<boolean> {
		return this.windowsService.closeWindow(item.getPayload()).then(() => {
			item.remove();

			return true;
		});
	}
B
Benjamin Pasero 已提交
651 652 653 654
}

export class SwitchWindow extends BaseSwitchWindow {

655
	static readonly ID = 'workbench.action.switchWindow';
B
Benjamin Pasero 已提交
656
	static LABEL = nls.localize('switchWindow', "Switch Window...");
E
Erich Gamma 已提交
657 658 659 660

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
661 662 663
		@IWindowsService windowsService: IWindowsService,
		@IWindowService windowService: IWindowService,
		@IQuickOpenService quickOpenService: IQuickOpenService,
664 665
		@IKeybindingService keybindingService: IKeybindingService,
		@IInstantiationService instantiationService: IInstantiationService
B
Benjamin Pasero 已提交
666
	) {
667
		super(id, label, windowsService, windowService, quickOpenService, keybindingService, instantiationService);
B
Benjamin Pasero 已提交
668 669 670 671 672 673 674 675 676
	}

	protected isQuickNavigate(): boolean {
		return false;
	}
}

export class QuickSwitchWindow extends BaseSwitchWindow {

677
	static readonly ID = 'workbench.action.quickSwitchWindow';
B
Benjamin Pasero 已提交
678 679 680 681 682 683 684 685
	static LABEL = nls.localize('quickSwitchWindow', "Quick Switch Window...");

	constructor(
		id: string,
		label: string,
		@IWindowsService windowsService: IWindowsService,
		@IWindowService windowService: IWindowService,
		@IQuickOpenService quickOpenService: IQuickOpenService,
686 687
		@IKeybindingService keybindingService: IKeybindingService,
		@IInstantiationService instantiationService: IInstantiationService
B
Benjamin Pasero 已提交
688
	) {
689
		super(id, label, windowsService, windowService, quickOpenService, keybindingService, instantiationService);
B
Benjamin Pasero 已提交
690 691 692 693 694 695 696
	}

	protected isQuickNavigate(): boolean {
		return true;
	}
}

697 698
export const inRecentFilesPickerContextKey = 'inRecentFilesPicker';

B
Benjamin Pasero 已提交
699
export abstract class BaseOpenRecentAction extends Action {
700
	private removeAction: RemoveFromRecentlyOpened;
B
Benjamin Pasero 已提交
701 702 703 704 705 706 707 708

	constructor(
		id: string,
		label: string,
		private windowService: IWindowService,
		private quickOpenService: IQuickOpenService,
		private contextService: IWorkspaceContextService,
		private environmentService: IEnvironmentService,
709 710
		private keybindingService: IKeybindingService,
		instantiationService: IInstantiationService
E
Erich Gamma 已提交
711 712
	) {
		super(id, label);
713 714

		this.removeAction = instantiationService.createInstance(RemoveFromRecentlyOpened);
E
Erich Gamma 已提交
715 716
	}

B
Benjamin Pasero 已提交
717 718
	protected abstract isQuickNavigate(): boolean;

J
Joao Moreno 已提交
719
	public run(): TPromise<void> {
B
Benjamin Pasero 已提交
720
		return this.windowService.getRecentlyOpened()
721
			.then(({ workspaces, files }) => this.openRecent(workspaces, files));
B
Benjamin Pasero 已提交
722 723
	}

724
	private openRecent(recentWorkspaces: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)[], recentFiles: string[]): void {
725

726
		function toPick(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier, separator: ISeparator, fileKind: FileKind, environmentService: IEnvironmentService, removeAction?: RemoveFromRecentlyOpened): IFilePickOpenEntry {
B
Benjamin Pasero 已提交
727 728 729 730 731
			let path: string;
			let label: string;
			let description: string;
			if (isSingleFolderWorkspaceIdentifier(workspace)) {
				path = workspace;
B
Benjamin Pasero 已提交
732
				label = getBaseLabel(path);
733
				description = getPathLabel(paths.dirname(path), environmentService);
B
Benjamin Pasero 已提交
734 735
			} else {
				path = workspace.configPath;
B
Benjamin Pasero 已提交
736
				label = getWorkspaceLabel(workspace, environmentService);
737
				description = getPathLabel(paths.dirname(workspace.configPath), environmentService);
B
Benjamin Pasero 已提交
738
			}
B
Benjamin Pasero 已提交
739

B
Benjamin Pasero 已提交
740
			return {
B
Benjamin Pasero 已提交
741
				resource: URI.file(path),
742
				fileKind,
743 744
				label,
				description,
B
Benjamin Pasero 已提交
745
				separator,
B
Benjamin Pasero 已提交
746 747 748 749
				run: context => {
					setTimeout(() => {
						// Bug: somehow when not running this code in a timeout, it is not possible to use this picker
						// with quick navigate keys (not able to trigger quick navigate once running it once).
750
						runPick(path, fileKind === FileKind.FILE, context);
B
Benjamin Pasero 已提交
751
					});
752 753
				},
				action: removeAction
B
Benjamin Pasero 已提交
754 755 756
			};
		}

757
		const runPick = (path: string, isFile: boolean, context: IEntryRunContext) => {
758
			const forceNewWindow = context.keymods.ctrlCmd;
B
Benjamin Pasero 已提交
759
			this.windowService.openWindow([path], { forceNewWindow, forceOpenWorkspaceAsFile: isFile });
760
		};
B
Benjamin Pasero 已提交
761

762 763
		const workspacePicks: IFilePickOpenEntry[] = recentWorkspaces.map((workspace, index) => toPick(workspace, index === 0 ? { label: nls.localize('workspaces', "workspaces") } : void 0, isSingleFolderWorkspaceIdentifier(workspace) ? FileKind.FOLDER : FileKind.ROOT_FOLDER, this.environmentService, !this.isQuickNavigate() ? this.removeAction : void 0));
		const filePicks: IFilePickOpenEntry[] = recentFiles.map((p, index) => toPick(p, index === 0 ? { label: nls.localize('files', "files"), border: true } : void 0, FileKind.FILE, this.environmentService, !this.isQuickNavigate() ? this.removeAction : void 0));
B
Benjamin Pasero 已提交
764

765 766 767
		// focus second entry if the first recent workspace is the current workspace
		let autoFocusSecondEntry: boolean = recentWorkspaces[0] && this.contextService.isCurrentWorkspace(recentWorkspaces[0]);

768
		this.quickOpenService.pick([...workspacePicks, ...filePicks], {
769
			contextKey: inRecentFilesPickerContextKey,
770
			autoFocus: { autoFocusFirstEntry: !autoFocusSecondEntry, autoFocusSecondEntry: autoFocusSecondEntry },
B
Benjamin Pasero 已提交
771
			placeHolder: isMacintosh ? nls.localize('openRecentPlaceHolderMac', "Select to open (hold Cmd-key to open in new window)") : nls.localize('openRecentPlaceHolder', "Select to open (hold Ctrl-key to open in new window)"),
B
Benjamin Pasero 已提交
772 773
			matchOnDescription: true,
			quickNavigateConfiguration: this.isQuickNavigate() ? { keybindings: this.keybindingService.lookupKeybindings(this.id) } : void 0
B
Benjamin Pasero 已提交
774
		}).done(null, errors.onUnexpectedError);
E
Erich Gamma 已提交
775
	}
776 777 778 779 780 781 782 783

	public dispose(): void {
		super.dispose();

		this.removeAction.dispose();
	}
}

784
class RemoveFromRecentlyOpened extends Action implements IPickOpenAction {
785

M
Matt Bierner 已提交
786 787
	public static readonly ID = 'workbench.action.removeFromRecentlyOpened';
	public static readonly LABEL = nls.localize('remove', "Remove from Recently Opened");
788 789

	constructor(
790
		@IWindowsService private windowsService: IWindowsService
791 792 793 794 795 796
	) {
		super(RemoveFromRecentlyOpened.ID, RemoveFromRecentlyOpened.LABEL);

		this.class = 'action-remove-from-recently-opened';
	}

797 798 799
	public run(item: IPickOpenItem): TPromise<boolean> {
		return this.windowsService.removeFromRecentlyOpened([item.getResource().fsPath]).then(() => {
			item.remove();
800 801 802 803

			return true;
		});
	}
E
Erich Gamma 已提交
804 805
}

B
Benjamin Pasero 已提交
806 807
export class OpenRecentAction extends BaseOpenRecentAction {

M
Matt Bierner 已提交
808 809
	public static readonly ID = 'workbench.action.openRecent';
	public static readonly LABEL = nls.localize('openRecent', "Open Recent...");
B
Benjamin Pasero 已提交
810 811 812 813 814 815 816 817

	constructor(
		id: string,
		label: string,
		@IWindowService windowService: IWindowService,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IWorkspaceContextService contextService: IWorkspaceContextService,
		@IEnvironmentService environmentService: IEnvironmentService,
818 819
		@IKeybindingService keybindingService: IKeybindingService,
		@IInstantiationService instantiationService: IInstantiationService
B
Benjamin Pasero 已提交
820
	) {
B
Benjamin Pasero 已提交
821
		super(id, label, windowService, quickOpenService, contextService, environmentService, keybindingService, instantiationService);
B
Benjamin Pasero 已提交
822 823 824 825 826 827 828 829 830
	}

	protected isQuickNavigate(): boolean {
		return false;
	}
}

export class QuickOpenRecentAction extends BaseOpenRecentAction {

M
Matt Bierner 已提交
831 832
	public static readonly ID = 'workbench.action.quickOpenRecent';
	public static readonly LABEL = nls.localize('quickOpenRecent', "Quick Open Recent...");
B
Benjamin Pasero 已提交
833 834 835 836 837 838 839 840

	constructor(
		id: string,
		label: string,
		@IWindowService windowService: IWindowService,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IWorkspaceContextService contextService: IWorkspaceContextService,
		@IEnvironmentService environmentService: IEnvironmentService,
841 842
		@IKeybindingService keybindingService: IKeybindingService,
		@IInstantiationService instantiationService: IInstantiationService
B
Benjamin Pasero 已提交
843
	) {
B
Benjamin Pasero 已提交
844
		super(id, label, windowService, quickOpenService, contextService, environmentService, keybindingService, instantiationService);
B
Benjamin Pasero 已提交
845 846 847 848 849 850 851
	}

	protected isQuickNavigate(): boolean {
		return true;
	}
}

852 853
export class OpenIssueReporterAction extends Action {
	public static readonly ID = 'workbench.action.openIssueReporter';
854
	public static readonly LABEL = nls.localize({ key: 'reportIssueInEnglish', comment: ['Translate this to "Report Issue in English" in all languages please!'] }, "Report Issue");
855 856 857 858

	constructor(
		id: string,
		label: string,
859
		@IWorkbenchIssueService private issueService: IWorkbenchIssueService
860 861 862 863 864
	) {
		super(id, label);
	}

	public run(): TPromise<boolean> {
865 866
		return this.issueService.openReporter()
			.then(() => true);
867 868 869
	}
}

870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
export class OpenProcessExplorer extends Action {
	public static readonly ID = 'workbench.action.openProcessExplorer';
	public static readonly LABEL = nls.localize('openProcessExplorer', "Open Process Explorer");

	constructor(
		id: string,
		label: string,
		@IWorkbenchIssueService private issueService: IWorkbenchIssueService
	) {
		super(id, label);
	}

	public run(): TPromise<boolean> {
		return this.issueService.openProcessExplorer()
			.then(() => true);
	}
}

888 889 890 891 892 893 894
export class ReportPerformanceIssueUsingReporterAction extends Action {
	public static readonly ID = 'workbench.action.reportPerformanceIssueUsingReporter';
	public static readonly LABEL = nls.localize('reportPerformanceIssue', "Report Performance Issue");

	constructor(
		id: string,
		label: string,
895
		@IWorkbenchIssueService private issueService: IWorkbenchIssueService
896 897 898 899 900
	) {
		super(id, label);
	}

	public run(): TPromise<boolean> {
901 902 903
		// TODO: Reporter should send timings table as well
		return this.issueService.openReporter({ issueType: IssueType.PerformanceIssue })
			.then(() => true);
904 905 906
	}
}

907
// NOTE: This is still used when running --prof-startup, which already opens a dialog, so the reporter is not used.
908 909
export class ReportPerformanceIssueAction extends Action {

M
Matt Bierner 已提交
910 911
	public static readonly ID = 'workbench.action.reportPerformanceIssue';
	public static readonly LABEL = nls.localize('reportPerformanceIssue', "Report Performance Issue");
912 913 914 915 916 917 918 919 920 921 922

	constructor(
		id: string,
		label: string,
		@IIntegrityService private integrityService: IIntegrityService,
		@IEnvironmentService private environmentService: IEnvironmentService,
		@ITimerService private timerService: ITimerService
	) {
		super(id, label);
	}

923
	public run(appendix?: string): TPromise<boolean> {
924
		this.integrityService.isPure().then(res => {
925
			const issueUrl = this.generatePerformanceIssueUrl(product.reportIssueUrl, pkg.name, pkg.version, product.commit, product.date, res.isPure, appendix);
926 927 928

			window.open(issueUrl);
		});
929 930

		return TPromise.wrap(true);
931 932
	}

933 934 935 936 937 938 939 940 941
	private generatePerformanceIssueUrl(baseUrl: string, name: string, version: string, commit: string, date: string, isPure: boolean, appendix?: string): string {

		if (!appendix) {
			appendix = `Additional Steps to Reproduce (if any):

1.
2.`;
		}

942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
		let nodeModuleLoadTime: number;
		if (this.environmentService.performance) {
			nodeModuleLoadTime = this.computeNodeModulesLoadTime();
		}

		const metrics: IStartupMetrics = this.timerService.startupMetrics;

		const osVersion = `${os.type()} ${os.arch()} ${os.release()}`;
		const queryStringPrefix = baseUrl.indexOf('?') === -1 ? '?' : '&';
		const body = encodeURIComponent(
			`- VSCode Version: <code>${name} ${version}${isPure ? '' : ' **[Unsupported]**'} (${product.commit || 'Commit unknown'}, ${product.date || 'Date unknown'})</code>
- OS Version: <code>${osVersion}</code>
- CPUs: <code>${metrics.cpus.model} (${metrics.cpus.count} x ${metrics.cpus.speed})</code>
- Memory (System): <code>${(metrics.totalmem / (1024 * 1024 * 1024)).toFixed(2)}GB (${(metrics.freemem / (1024 * 1024 * 1024)).toFixed(2)}GB free)</code>
- Memory (Process): <code>${(metrics.meminfo.workingSetSize / 1024).toFixed(2)}MB working set (${(metrics.meminfo.peakWorkingSetSize / 1024).toFixed(2)}MB peak, ${(metrics.meminfo.privateBytes / 1024).toFixed(2)}MB private, ${(metrics.meminfo.sharedBytes / 1024).toFixed(2)}MB shared)</code>
- Load (avg): <code>${metrics.loadavg.map(l => Math.round(l)).join(', ')}</code>
958
- VM: <code>${metrics.isVMLikelyhood}%</code>
959
- Initial Startup: <code>${metrics.initialStartup ? 'yes' : 'no'}</code>
960
- Screen Reader: <code>${metrics.hasAccessibilitySupport ? 'yes' : 'no'}</code>
961 962 963 964 965 966 967
- Empty Workspace: <code>${metrics.emptyWorkbench ? 'yes' : 'no'}</code>
- Timings:

${this.generatePerformanceTable(nodeModuleLoadTime)}

---

968
${appendix}`
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994
		);

		return `${baseUrl}${queryStringPrefix}body=${body}`;
	}

	private computeNodeModulesLoadTime(): number {
		const stats = <ILoaderEvent[]>(<any>require).getStats();
		let total = 0;

		for (let i = 0, len = stats.length; i < len; i++) {
			if (stats[i].type === LoaderEventType.NodeEndNativeRequire) {
				if (stats[i - 1].type === LoaderEventType.NodeBeginNativeRequire && stats[i - 1].detail === stats[i].detail) {
					const dur = (stats[i].timestamp - stats[i - 1].timestamp);
					total += dur;
				}
			}
		}

		return Math.round(total);
	}

	private generatePerformanceTable(nodeModuleLoadTime?: number): string {
		let tableHeader = `|Component|Task|Time (ms)|
|---|---|---|`;

		const table = this.getStartupMetricsTable(nodeModuleLoadTime).map(e => {
995
			return `|${e.component}|${e.task}|${e.time}|`;
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
		}).join('\n');

		return `${tableHeader}\n${table}`;
	}

	private getStartupMetricsTable(nodeModuleLoadTime?: number): { component: string, task: string; time: number; }[] {
		const table: any[] = [];
		const metrics: IStartupMetrics = this.timerService.startupMetrics;

		if (metrics.initialStartup) {
			table.push({ component: 'main', task: 'start => app.isReady', time: metrics.timers.ellapsedAppReady });
			table.push({ component: 'main', task: 'app.isReady => window.loadUrl()', time: metrics.timers.ellapsedWindowLoad });
		}

		table.push({ component: 'renderer', task: 'window.loadUrl() => begin to require(workbench.main.js)', time: metrics.timers.ellapsedWindowLoadToRequire });
		table.push({ component: 'renderer', task: 'require(workbench.main.js)', time: metrics.timers.ellapsedRequire });

		if (nodeModuleLoadTime) {
			table.push({ component: 'renderer', task: '-> of which require() node_modules', time: nodeModuleLoadTime });
		}

		table.push({ component: 'renderer', task: 'create extension host => extensions onReady()', time: metrics.timers.ellapsedExtensions });
		table.push({ component: 'renderer', task: 'restore viewlet', time: metrics.timers.ellapsedViewletRestore });
		table.push({ component: 'renderer', task: 'restore editor view state', time: metrics.timers.ellapsedEditorRestore });
		table.push({ component: 'renderer', task: 'overall workbench load', time: metrics.timers.ellapsedWorkbench });
		table.push({ component: 'main + renderer', task: 'start => extensions ready', time: metrics.timers.ellapsedExtensionsReady });
		table.push({ component: 'main + renderer', task: 'start => workbench ready', time: metrics.ellapsed });

		return table;
	}
}

1028 1029
export class KeybindingsReferenceAction extends Action {

M
Matt Bierner 已提交
1030 1031
	public static readonly ID = 'workbench.action.keybindingsReference';
	public static readonly LABEL = nls.localize('keybindingsReference', "Keyboard Shortcuts Reference");
1032

1033
	private static readonly URL = isLinux ? product.keyboardShortcutsUrlLinux : isMacintosh ? product.keyboardShortcutsUrlMac : product.keyboardShortcutsUrlWin;
M
Matt Bierner 已提交
1034
	public static readonly AVAILABLE = !!KeybindingsReferenceAction.URL;
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048

	constructor(
		id: string,
		label: string
	) {
		super(id, label);
	}

	public run(): TPromise<void> {
		window.open(KeybindingsReferenceAction.URL);
		return null;
	}
}

C
Christof Marti 已提交
1049 1050
export class OpenDocumentationUrlAction extends Action {

M
Matt Bierner 已提交
1051 1052
	public static readonly ID = 'workbench.action.openDocumentationUrl';
	public static readonly LABEL = nls.localize('openDocumentationUrl', "Documentation");
C
Christof Marti 已提交
1053

1054
	private static readonly URL = product.documentationUrl;
M
Matt Bierner 已提交
1055
	public static readonly AVAILABLE = !!OpenDocumentationUrlAction.URL;
C
Christof Marti 已提交
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069

	constructor(
		id: string,
		label: string
	) {
		super(id, label);
	}

	public run(): TPromise<void> {
		window.open(OpenDocumentationUrlAction.URL);
		return null;
	}
}

1070 1071
export class OpenIntroductoryVideosUrlAction extends Action {

M
Matt Bierner 已提交
1072 1073
	public static readonly ID = 'workbench.action.openIntroductoryVideosUrl';
	public static readonly LABEL = nls.localize('openIntroductoryVideosUrl', "Introductory Videos");
1074

1075
	private static readonly URL = product.introductoryVideosUrl;
M
Matt Bierner 已提交
1076
	public static readonly AVAILABLE = !!OpenIntroductoryVideosUrlAction.URL;
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088

	constructor(
		id: string,
		label: string
	) {
		super(id, label);
	}

	public run(): TPromise<void> {
		window.open(OpenIntroductoryVideosUrlAction.URL);
		return null;
	}
1089
}
1090

1091 1092
export class OpenTipsAndTricksUrlAction extends Action {

M
Matt Bierner 已提交
1093 1094
	public static readonly ID = 'workbench.action.openTipsAndTricksUrl';
	public static readonly LABEL = nls.localize('openTipsAndTricksUrl', "Tips and Tricks");
1095

1096
	private static readonly URL = product.tipsAndTricksUrl;
M
Matt Bierner 已提交
1097
	public static readonly AVAILABLE = !!OpenTipsAndTricksUrlAction.URL;
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111

	constructor(
		id: string,
		label: string
	) {
		super(id, label);
	}

	public run(): TPromise<void> {
		window.open(OpenTipsAndTricksUrlAction.URL);
		return null;
	}
}

1112 1113
export class ToggleSharedProcessAction extends Action {

1114
	static readonly ID = 'workbench.action.toggleSharedProcess';
1115 1116 1117 1118 1119 1120 1121 1122 1123
	static LABEL = nls.localize('toggleSharedProcess', "Toggle Shared Process");

	constructor(id: string, label: string, @IWindowsService private windowsService: IWindowsService) {
		super(id, label);
	}

	run(): TPromise<void> {
		return this.windowsService.toggleSharedProcess();
	}
1124 1125
}

1126
export enum Direction {
S
sj.hwang 已提交
1127 1128 1129
	Next,
	Previous,
}
1130

S
sj.hwang 已提交
1131
export abstract class BaseNavigationAction extends Action {
1132

1133
	constructor(
S
sj.hwang 已提交
1134 1135
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1136
		@IEditorGroupsService protected editorGroupService: IEditorGroupsService,
S
sj.hwang 已提交
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
		@IPanelService protected panelService: IPanelService,
		@IPartService protected partService: IPartService,
		@IViewletService protected viewletService: IViewletService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const isEditorFocus = this.partService.hasFocus(Parts.EDITOR_PART);
		const isPanelFocus = this.partService.hasFocus(Parts.PANEL_PART);
		const isSidebarFocus = this.partService.hasFocus(Parts.SIDEBAR_PART);

1149 1150
		const isSidebarPositionLeft = this.partService.getSideBarPosition() === PartPosition.LEFT;
		const isPanelPositionDown = this.partService.getPanelPosition() === PartPosition.BOTTOM;
S
sj.hwang 已提交
1151 1152

		if (isEditorFocus) {
1153
			return this.navigateOnEditorFocus(isSidebarPositionLeft, isPanelPositionDown);
1154 1155
		}

S
sj.hwang 已提交
1156
		if (isPanelFocus) {
1157
			return this.navigateOnPanelFocus(isSidebarPositionLeft, isPanelPositionDown);
1158 1159
		}

S
sj.hwang 已提交
1160
		if (isSidebarFocus) {
1161
			return this.navigateOnSidebarFocus(isSidebarPositionLeft, isPanelPositionDown);
1162 1163
		}

S
sj.hwang 已提交
1164
		return TPromise.as(false);
1165 1166
	}

1167
	protected navigateOnEditorFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean | IViewlet | IPanel> {
S
sj.hwang 已提交
1168
		return TPromise.as(true);
1169 1170
	}

1171
	protected navigateOnPanelFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean | IPanel> {
S
sj.hwang 已提交
1172
		return TPromise.as(true);
1173 1174
	}

1175
	protected navigateOnSidebarFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean | IViewlet> {
S
sj.hwang 已提交
1176
		return TPromise.as(true);
1177 1178
	}

B
Benjamin Pasero 已提交
1179
	protected navigateToPanel(): TPromise<IPanel | boolean> {
S
sj.hwang 已提交
1180 1181
		if (!this.partService.isVisible(Parts.PANEL_PART)) {
			return TPromise.as(false);
1182 1183
		}

S
sj.hwang 已提交
1184
		const activePanelId = this.panelService.getActivePanel().getId();
B
Benjamin Pasero 已提交
1185

S
sj.hwang 已提交
1186
		return this.panelService.openPanel(activePanelId, true);
1187 1188
	}

B
Benjamin Pasero 已提交
1189
	protected navigateToSidebar(): TPromise<IViewlet | boolean> {
S
sj.hwang 已提交
1190 1191
		if (!this.partService.isVisible(Parts.SIDEBAR_PART)) {
			return TPromise.as(false);
1192 1193
		}

S
sj.hwang 已提交
1194
		const activeViewletId = this.viewletService.getActiveViewlet().getId();
B
Benjamin Pasero 已提交
1195

S
sj.hwang 已提交
1196
		return this.viewletService.openViewlet(activeViewletId, true);
1197 1198
	}

1199
	protected navigateAcrossEditorGroup(direction: GroupDirection): TPromise<boolean> {
B
Benjamin Pasero 已提交
1200
		const nextGroup = this.editorGroupService.findGroup({ direction }, this.editorGroupService.activeGroup);
1201
		if (nextGroup) {
B
Benjamin Pasero 已提交
1202
			nextGroup.focus();
1203

1204
			return TPromise.as(true);
1205 1206
		}

1207
		return TPromise.as(false);
1208 1209
	}

1210
	protected navigateToActiveEditorGroup(): TPromise<boolean> {
B
Benjamin Pasero 已提交
1211
		this.editorGroupService.activeGroup.focus();
B
Benjamin Pasero 已提交
1212

1213
		return TPromise.as(true);
1214 1215
	}
}
S
sj.hwang 已提交
1216 1217 1218

export class NavigateLeftAction extends BaseNavigationAction {

M
Matt Bierner 已提交
1219 1220
	public static readonly ID = 'workbench.action.navigateLeft';
	public static readonly LABEL = nls.localize('navigateLeft', "Navigate to the View on the Left");
S
sj.hwang 已提交
1221 1222 1223 1224

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1225
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
S
sj.hwang 已提交
1226 1227 1228 1229
		@IPanelService panelService: IPanelService,
		@IPartService partService: IPartService,
		@IViewletService viewletService: IViewletService
	) {
B
Benjamin Pasero 已提交
1230
		super(id, label, editorGroupService, panelService, partService, viewletService);
S
sj.hwang 已提交
1231 1232
	}

1233 1234
	protected navigateOnEditorFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean | IViewlet> {
		return this.navigateAcrossEditorGroup(GroupDirection.LEFT)
1235
			.then(didNavigate => {
1236 1237 1238 1239 1240
				if (didNavigate) {
					return TPromise.as(true);
				}

				if (isSidebarPositionLeft) {
1241 1242
					return this.navigateToSidebar();
				}
1243 1244

				return TPromise.as(false);
1245
			});
S
sj.hwang 已提交
1246 1247
	}

1248 1249
	protected navigateOnPanelFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean | IViewlet> {
		if (isPanelPositionDown && isSidebarPositionLeft) {
S
sj.hwang 已提交
1250 1251
			return this.navigateToSidebar();
		}
B
Benjamin Pasero 已提交
1252

1253 1254 1255 1256
		if (!isPanelPositionDown) {
			return this.navigateToActiveEditorGroup();
		}

S
sj.hwang 已提交
1257 1258 1259
		return TPromise.as(false);
	}

1260 1261 1262
	protected navigateOnSidebarFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean> {
		if (!isSidebarPositionLeft) {
			return this.navigateToActiveEditorGroup();
S
sj.hwang 已提交
1263
		}
B
Benjamin Pasero 已提交
1264

1265
		return TPromise.as(false);
S
sj.hwang 已提交
1266 1267
	}
}
1268 1269 1270

export class NavigateRightAction extends BaseNavigationAction {

M
Matt Bierner 已提交
1271 1272
	public static readonly ID = 'workbench.action.navigateRight';
	public static readonly LABEL = nls.localize('navigateRight', "Navigate to the View on the Right");
1273 1274 1275 1276

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1277
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
1278 1279 1280 1281
		@IPanelService panelService: IPanelService,
		@IPartService partService: IPartService,
		@IViewletService viewletService: IViewletService
	) {
B
Benjamin Pasero 已提交
1282
		super(id, label, editorGroupService, panelService, partService, viewletService);
1283 1284
	}

1285 1286
	protected navigateOnEditorFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean | IViewlet | IPanel> {
		return this.navigateAcrossEditorGroup(GroupDirection.RIGHT)
1287
			.then(didNavigate => {
1288 1289 1290 1291 1292 1293 1294 1295 1296
				if (didNavigate) {
					return TPromise.as(true);
				}

				if (!isPanelPositionDown) {
					return this.navigateToPanel();
				}

				if (!isSidebarPositionLeft) {
1297 1298
					return this.navigateToSidebar();
				}
1299 1300

				return TPromise.as(false);
1301
			});
1302 1303
	}

1304
	protected navigateOnPanelFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean | IViewlet> {
1305 1306 1307
		if (!isSidebarPositionLeft) {
			return this.navigateToSidebar();
		}
B
Benjamin Pasero 已提交
1308

1309 1310 1311
		return TPromise.as(false);
	}

1312 1313 1314
	protected navigateOnSidebarFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean> {
		if (isSidebarPositionLeft) {
			return this.navigateToActiveEditorGroup();
1315
		}
B
Benjamin Pasero 已提交
1316

1317
		return TPromise.as(false);
1318 1319
	}
}
S
sj.hwang 已提交
1320 1321 1322

export class NavigateUpAction extends BaseNavigationAction {

M
Matt Bierner 已提交
1323 1324
	public static readonly ID = 'workbench.action.navigateUp';
	public static readonly LABEL = nls.localize('navigateUp', "Navigate to the View Above");
S
sj.hwang 已提交
1325 1326 1327 1328

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1329
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
S
sj.hwang 已提交
1330 1331 1332 1333
		@IPanelService panelService: IPanelService,
		@IPartService partService: IPartService,
		@IViewletService viewletService: IViewletService
	) {
B
Benjamin Pasero 已提交
1334
		super(id, label, editorGroupService, panelService, partService, viewletService);
S
sj.hwang 已提交
1335 1336
	}

1337 1338
	protected navigateOnEditorFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean> {
		return this.navigateAcrossEditorGroup(GroupDirection.UP);
S
sj.hwang 已提交
1339 1340
	}

1341 1342 1343
	protected navigateOnPanelFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean> {
		if (isPanelPositionDown) {
			return this.navigateToActiveEditorGroup();
S
sj.hwang 已提交
1344
		}
1345 1346

		return TPromise.as(false);
S
sj.hwang 已提交
1347 1348
	}
}
S
sj.hwang 已提交
1349 1350 1351

export class NavigateDownAction extends BaseNavigationAction {

M
Matt Bierner 已提交
1352 1353
	public static readonly ID = 'workbench.action.navigateDown';
	public static readonly LABEL = nls.localize('navigateDown', "Navigate to the View Below");
S
sj.hwang 已提交
1354 1355 1356 1357

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1358
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
S
sj.hwang 已提交
1359 1360 1361 1362
		@IPanelService panelService: IPanelService,
		@IPartService partService: IPartService,
		@IViewletService viewletService: IViewletService
	) {
B
Benjamin Pasero 已提交
1363
		super(id, label, editorGroupService, panelService, partService, viewletService);
S
sj.hwang 已提交
1364 1365
	}

1366 1367
	protected navigateOnEditorFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): TPromise<boolean | IPanel> {
		return this.navigateAcrossEditorGroup(GroupDirection.DOWN)
1368 1369 1370 1371
			.then(didNavigate => {
				if (didNavigate) {
					return TPromise.as(true);
				}
1372 1373 1374 1375 1376 1377

				if (isPanelPositionDown) {
					return this.navigateToPanel();
				}

				return TPromise.as(false);
1378
			});
S
sj.hwang 已提交
1379 1380
	}
}
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400

// Resize focused view actions
export abstract class BaseResizeViewAction extends Action {

	// This is a media-size percentage
	protected static RESIZE_INCREMENT = 6.5;

	constructor(
		id: string,
		label: string,
		@IPartService protected partService: IPartService
	) {
		super(id, label);
	}

	protected resizePart(sizeChange: number): void {
		const isEditorFocus = this.partService.hasFocus(Parts.EDITOR_PART);
		const isSidebarFocus = this.partService.hasFocus(Parts.SIDEBAR_PART);
		const isPanelFocus = this.partService.hasFocus(Parts.PANEL_PART);

B
Benjamin Pasero 已提交
1401
		let part: Parts;
1402
		if (isSidebarFocus) {
B
Benjamin Pasero 已提交
1403 1404 1405 1406 1407
			part = Parts.SIDEBAR_PART;
		} else if (isPanelFocus) {
			part = Parts.PANEL_PART;
		} else if (isEditorFocus) {
			part = Parts.EDITOR_PART;
1408
		}
B
Benjamin Pasero 已提交
1409 1410 1411

		if (part) {
			this.partService.resizePart(part, sizeChange);
1412 1413 1414 1415 1416 1417
		}
	}
}

export class IncreaseViewSizeAction extends BaseResizeViewAction {

M
Matt Bierner 已提交
1418 1419
	public static readonly ID = 'workbench.action.increaseViewSize';
	public static readonly LABEL = nls.localize('increaseViewSize', "Increase Current View Size");
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436

	constructor(
		id: string,
		label: string,
		@IPartService partService: IPartService
	) {
		super(id, label, partService);
	}

	public run(): TPromise<boolean> {
		this.resizePart(BaseResizeViewAction.RESIZE_INCREMENT);
		return TPromise.as(true);
	}
}

export class DecreaseViewSizeAction extends BaseResizeViewAction {

M
Matt Bierner 已提交
1437 1438
	public static readonly ID = 'workbench.action.decreaseViewSize';
	public static readonly LABEL = nls.localize('decreaseViewSize', "Decrease Current View Size");
1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452

	constructor(
		id: string,
		label: string,
		@IPartService partService: IPartService

	) {
		super(id, label, partService);
	}

	public run(): TPromise<boolean> {
		this.resizePart(-BaseResizeViewAction.RESIZE_INCREMENT);
		return TPromise.as(true);
	}
1453 1454 1455 1456
}

export class ShowPreviousWindowTab extends Action {

M
Matt Bierner 已提交
1457 1458
	public static readonly ID = 'workbench.action.showPreviousWindowTab';
	public static readonly LABEL = nls.localize('showPreviousTab', "Show Previous Window Tab");
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474

	constructor(
		id: string,
		label: string,
		@IWindowsService private windowsService: IWindowsService
	) {
		super(ShowPreviousWindowTab.ID, ShowPreviousWindowTab.LABEL);
	}

	public run(): TPromise<boolean> {
		return this.windowsService.showPreviousWindowTab().then(() => true);
	}
}

export class ShowNextWindowTab extends Action {

M
Matt Bierner 已提交
1475 1476
	public static readonly ID = 'workbench.action.showNextWindowTab';
	public static readonly LABEL = nls.localize('showNextWindowTab', "Show Next Window Tab");
1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492

	constructor(
		id: string,
		label: string,
		@IWindowsService private windowsService: IWindowsService
	) {
		super(ShowNextWindowTab.ID, ShowNextWindowTab.LABEL);
	}

	public run(): TPromise<boolean> {
		return this.windowsService.showNextWindowTab().then(() => true);
	}
}

export class MoveWindowTabToNewWindow extends Action {

M
Matt Bierner 已提交
1493 1494
	public static readonly ID = 'workbench.action.moveWindowTabToNewWindow';
	public static readonly LABEL = nls.localize('moveWindowTabToNewWindow', "Move Window Tab to New Window");
1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510

	constructor(
		id: string,
		label: string,
		@IWindowsService private windowsService: IWindowsService
	) {
		super(MoveWindowTabToNewWindow.ID, MoveWindowTabToNewWindow.LABEL);
	}

	public run(): TPromise<boolean> {
		return this.windowsService.moveWindowTabToNewWindow().then(() => true);
	}
}

export class MergeAllWindowTabs extends Action {

M
Matt Bierner 已提交
1511 1512
	public static readonly ID = 'workbench.action.mergeAllWindowTabs';
	public static readonly LABEL = nls.localize('mergeAllWindowTabs', "Merge All Windows");
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528

	constructor(
		id: string,
		label: string,
		@IWindowsService private windowsService: IWindowsService
	) {
		super(MergeAllWindowTabs.ID, MergeAllWindowTabs.LABEL);
	}

	public run(): TPromise<boolean> {
		return this.windowsService.mergeAllWindowTabs().then(() => true);
	}
}

export class ToggleWindowTabsBar extends Action {

M
Matt Bierner 已提交
1529 1530
	public static readonly ID = 'workbench.action.toggleWindowTabsBar';
	public static readonly LABEL = nls.localize('toggleWindowTabsBar', "Toggle Window Tabs Bar");
1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542

	constructor(
		id: string,
		label: string,
		@IWindowsService private windowsService: IWindowsService
	) {
		super(ToggleWindowTabsBar.ID, ToggleWindowTabsBar.LABEL);
	}

	public run(): TPromise<boolean> {
		return this.windowsService.toggleWindowTabsBar().then(() => true);
	}
J
Joao Moreno 已提交
1543 1544
}

S
SteVen Batten 已提交
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659
export class OpenTwitterUrlAction extends Action {

	public static readonly ID = 'workbench.action.openTwitterUrl';
	public static LABEL = nls.localize('openTwitterUrl', "Join us on Twitter", product.applicationName);

	constructor(
		id: string,
		label: string
	) {
		super(id, label);
	}

	run(): TPromise<boolean> {
		if (product.twitterUrl) {
			return TPromise.as(shell.openExternal(product.twitterUrl));
		}

		return TPromise.as(false);
	}
}

export class OpenRequestFeatureUrlAction extends Action {

	public static readonly ID = 'workbench.action.openRequestFeatureUrl';
	public static LABEL = nls.localize('openUserVoiceUrl', "Search Feature Requests");

	constructor(
		id: string,
		label: string
	) {
		super(id, label);
	}

	run(): TPromise<boolean> {
		if (product.requestFeatureUrl) {
			return TPromise.as(shell.openExternal(product.requestFeatureUrl));
		}

		return TPromise.as(false);
	}
}

export class OpenLicenseUrlAction extends Action {

	public static readonly ID = 'workbench.action.openLicenseUrl';
	public static LABEL = nls.localize('openLicenseUrl', "View License");

	constructor(
		id: string,
		label: string
	) {
		super(id, label);
	}

	run(): TPromise<boolean> {
		if (product.licenseUrl) {
			if (language) {
				const queryArgChar = product.licenseUrl.indexOf('?') > 0 ? '&' : '?';
				return TPromise.as(shell.openExternal(`${product.licenseUrl}${queryArgChar}lang=${language}`));
			} else {
				return TPromise.as(shell.openExternal(product.licenseUrl));
			}
		}

		return TPromise.as(false);
	}
}


export class OpenPrivacyStatementUrlAction extends Action {

	public static readonly ID = 'workbench.action.openPrivacyStatementUrl';
	public static LABEL = nls.localize('openPrivacyStatement', "Privacy Statement");

	constructor(
		id: string,
		label: string
	) {
		super(id, label);
	}

	run(): TPromise<boolean> {
		if (product.privacyStatementUrl) {
			if (language) {
				const queryArgChar = product.privacyStatementUrl.indexOf('?') > 0 ? '&' : '?';
				return TPromise.as(shell.openExternal(`${product.privacyStatementUrl}${queryArgChar}lang=${language}`));
			} else {
				return TPromise.as(shell.openExternal(product.privacyStatementUrl));
			}
		}


		return TPromise.as(false);
	}
}

export class ShowAccessibilityOptionsAction extends Action {

	public static readonly ID = 'workbench.action.showAccessibilityOptions';
	public static LABEL = nls.localize('accessibilityOptions', "Accessibility Options");

	constructor(
		id: string,
		label: string,
		@IWindowsService private windowsService: IWindowsService
	) {
		super(id, label);
	}

	run(): TPromise<void> {
		return this.windowsService.openAccessibilityOptions();
	}
}


J
Joao Moreno 已提交
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
export class ShowAboutDialogAction extends Action {

	public static readonly ID = 'workbench.action.showAboutDialog';
	public static LABEL = nls.localize('about', "About {0}", product.applicationName);

	constructor(
		id: string,
		label: string,
		@IWindowsService private windowsService: IWindowsService
	) {
		super(id, label);
	}

	run(): TPromise<void> {
		return this.windowsService.openAboutDialog();
	}
J
Joao Moreno 已提交
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736
}

export class InspectContextKeysAction extends Action {

	public static readonly ID = 'workbench.action.inspectContextKeys';
	public static LABEL = nls.localize('inspect context keys', "Inspect Context Keys");

	constructor(
		id: string,
		label: string,
		@IContextKeyService private contextKeyService: IContextKeyService,
		@IWindowService private windowService: IWindowService,
	) {
		super(id, label);
	}

	run(): TPromise<void> {
		const disposables: IDisposable[] = [];

		const stylesheet = createStyleSheet();
		disposables.push(toDisposable(() => stylesheet.parentNode.removeChild(stylesheet)));
		createCSSRule('*', 'cursor: crosshair !important;', stylesheet);

		const hoverFeedback = document.createElement('div');
		document.body.appendChild(hoverFeedback);
		disposables.push(toDisposable(() => document.body.removeChild(hoverFeedback)));

		hoverFeedback.style.position = 'absolute';
		hoverFeedback.style.pointerEvents = 'none';
		hoverFeedback.style.backgroundColor = 'rgba(255, 0, 0, 0.5)';
		hoverFeedback.style.zIndex = '1000';

		const onMouseMove = domEvent(document.body, 'mousemove', true);
		disposables.push(onMouseMove(e => {
			const target = e.target as HTMLElement;
			const position = getDomNodePagePosition(target);

			hoverFeedback.style.top = `${position.top}px`;
			hoverFeedback.style.left = `${position.left}px`;
			hoverFeedback.style.width = `${position.width}px`;
			hoverFeedback.style.height = `${position.height}px`;
		}));

		const onMouseDown = once(domEvent(document.body, 'mousedown', true));
		onMouseDown(e => { e.preventDefault(); e.stopPropagation(); }, null, disposables);

		const onMouseUp = once(domEvent(document.body, 'mouseup', true));
		onMouseUp(e => {
			e.preventDefault();
			e.stopPropagation();

			const context = this.contextKeyService.getContext(e.target as HTMLElement) as Context;
			console.log(context.collectAllValues());
			this.windowService.openDevTools();

			dispose(disposables);
		}, null, disposables);

		return TPromise.as(null);
	}
}