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

J
Johannes Rieken 已提交
7
import { TPromise } from 'vs/base/common/winjs.base';
8
import * as nls from 'vs/nls';
J
Johannes Rieken 已提交
9
import { Action } from 'vs/base/common/actions';
10
import { mixin } from 'vs/base/common/objects';
B
Benjamin Pasero 已提交
11
import { IEditorInput, EditorInput, IEditorIdentifier, ConfirmResult, IEditorCommandsContext, CloseDirection } from 'vs/workbench/common/editor';
J
Johannes Rieken 已提交
12 13
import { QuickOpenEntryGroup } from 'vs/base/parts/quickopen/browser/quickOpenModel';
import { EditorQuickOpenEntry, EditorQuickOpenEntryGroup, IEditorQuickOpenEntry, QuickOpenAction } from 'vs/workbench/browser/quickopen';
J
Johannes Rieken 已提交
14
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
J
Johannes Rieken 已提交
15
import { IPartService } from 'vs/workbench/services/part/common/partService';
B
Benjamin Pasero 已提交
16
import { IResourceInput } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
17 18 19
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ICommandService } from 'vs/platform/commands/common/commands';
20
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
C
22768  
Cristian 已提交
21
import { IWindowsService } from 'vs/platform/windows/common/windows';
22
import { CLOSE_EDITOR_COMMAND_ID, NAVIGATE_ALL_EDITORS_GROUP_PREFIX, MOVE_ACTIVE_EDITOR_COMMAND_ID, NAVIGATE_IN_ACTIVE_GROUP_PREFIX, ActiveEditorMoveArguments, SPLIT_EDITOR_LEFT, SPLIT_EDITOR_RIGHT, SPLIT_EDITOR_UP, SPLIT_EDITOR_DOWN, splitEditor, LAYOUT_EDITOR_GROUPS_COMMAND_ID, mergeAllGroups } from 'vs/workbench/browser/parts/editor/editorCommands';
23
import { IEditorGroupsService, IEditorGroup, GroupsArrangement, EditorsOrder, GroupLocation, GroupDirection, preferredSideBySideGroupDirection, IFindGroupScope, GroupOrientation, EditorGroupLayout, GroupsOrder } from 'vs/workbench/services/group/common/editorGroupsService';
24
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
B
Benjamin Pasero 已提交
25
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
26
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
E
Erich Gamma 已提交
27

28 29 30 31 32 33 34 35 36 37 38 39
export class ExecuteCommandAction extends Action {

	constructor(
		id: string,
		label: string,
		private commandId: string,
		private commandService: ICommandService,
		private commandArgs?: any
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
40
	run(): TPromise<any> {
41 42 43 44
		return this.commandService.executeCommand(this.commandId, this.commandArgs);
	}
}

45
export class BaseSplitEditorAction extends Action {
46
	private toDispose: IDisposable[] = [];
47
	private direction: GroupDirection;
48

49 50 51
	constructor(
		id: string,
		label: string,
52 53
		protected editorGroupService: IEditorGroupsService,
		protected configurationService: IConfigurationService
54
	) {
55 56
		super(id, label);

57
		this.direction = this.getDirection();
58 59 60 61

		this.registerListeners();
	}

62 63 64 65
	protected getDirection(): GroupDirection {
		return preferredSideBySideGroupDirection(this.configurationService);
	}

66 67 68
	private registerListeners(): void {
		this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => {
			if (e.affectsConfiguration('workbench.editor.openSideBySideDirection')) {
69
				this.direction = preferredSideBySideGroupDirection(this.configurationService);
70 71 72 73
			}
		}));
	}

B
Benjamin Pasero 已提交
74
	run(context?: IEditorIdentifier): TPromise<any> {
75
		splitEditor(this.editorGroupService, this.direction, context);
76 77 78 79

		return TPromise.as(true);
	}

B
Benjamin Pasero 已提交
80
	dispose(): void {
81 82 83
		super.dispose();

		this.toDispose = dispose(this.toDispose);
84 85 86
	}
}

87 88
export class SplitEditorAction extends BaseSplitEditorAction {

B
Benjamin Pasero 已提交
89 90
	static readonly ID = 'workbench.action.splitEditor';
	static readonly LABEL = nls.localize('splitEditor', "Split Editor");
91 92 93 94 95 96 97 98 99 100 101 102 103

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IConfigurationService configurationService: IConfigurationService
	) {
		super(id, label, editorGroupService, configurationService);
	}
}

export class SplitEditorOrthogonalAction extends BaseSplitEditorAction {

B
Benjamin Pasero 已提交
104 105
	static readonly ID = 'workbench.action.splitEditorOrthogonal';
	static readonly LABEL = nls.localize('splitEditorOrthogonal', "Split Editor Orthogonal");
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IConfigurationService configurationService: IConfigurationService
	) {
		super(id, label, editorGroupService, configurationService);
	}

	protected getDirection(): GroupDirection {
		const direction = preferredSideBySideGroupDirection(this.configurationService);

		return direction === GroupDirection.RIGHT ? GroupDirection.DOWN : GroupDirection.RIGHT;
	}
}

123
export class SplitEditorLeftAction extends ExecuteCommandAction {
124

B
Benjamin Pasero 已提交
125 126
	static readonly ID = SPLIT_EDITOR_LEFT;
	static readonly LABEL = nls.localize('splitEditorGroupLeft', "Split Editor Left");
127 128 129 130

	constructor(
		id: string,
		label: string,
131
		@ICommandService commandService: ICommandService
132
	) {
133
		super(id, label, SPLIT_EDITOR_LEFT, commandService);
B
Benjamin Pasero 已提交
134 135 136
	}
}

137
export class SplitEditorRightAction extends ExecuteCommandAction {
B
Benjamin Pasero 已提交
138

B
Benjamin Pasero 已提交
139 140
	static readonly ID = SPLIT_EDITOR_RIGHT;
	static readonly LABEL = nls.localize('splitEditorGroupRight', "Split Editor Right");
B
Benjamin Pasero 已提交
141 142 143 144

	constructor(
		id: string,
		label: string,
145
		@ICommandService commandService: ICommandService
B
Benjamin Pasero 已提交
146
	) {
147
		super(id, label, SPLIT_EDITOR_RIGHT, commandService);
B
Benjamin Pasero 已提交
148 149 150
	}
}

151
export class SplitEditorUpAction extends ExecuteCommandAction {
B
Benjamin Pasero 已提交
152

B
Benjamin Pasero 已提交
153 154
	static readonly ID = SPLIT_EDITOR_UP;
	static readonly LABEL = nls.localize('splitEditorGroupUp', "Split Editor Up");
155

B
Benjamin Pasero 已提交
156 157 158
	constructor(
		id: string,
		label: string,
159
		@ICommandService commandService: ICommandService
B
Benjamin Pasero 已提交
160
	) {
161
		super(id, label, SPLIT_EDITOR_UP, commandService);
162
	}
B
Benjamin Pasero 已提交
163
}
164

165
export class SplitEditorDownAction extends ExecuteCommandAction {
166

B
Benjamin Pasero 已提交
167 168
	static readonly ID = SPLIT_EDITOR_DOWN;
	static readonly LABEL = nls.localize('splitEditorGroupDown', "Split Editor Down");
169

B
Benjamin Pasero 已提交
170 171 172
	constructor(
		id: string,
		label: string,
173
		@ICommandService commandService: ICommandService
B
Benjamin Pasero 已提交
174
	) {
175
		super(id, label, SPLIT_EDITOR_DOWN, commandService);
176 177 178
	}
}

179
export class JoinTwoGroupsAction extends Action {
I
initialshl 已提交
180

B
Benjamin Pasero 已提交
181 182
	static readonly ID = 'workbench.action.joinTwoGroups';
	static readonly LABEL = nls.localize('joinTwoGroups', "Join Editor Group with Next Group");
I
initialshl 已提交
183 184 185 186

	constructor(
		id: string,
		label: string,
187
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
I
initialshl 已提交
188
	) {
189
		super(id, label);
I
initialshl 已提交
190 191
	}

B
Benjamin Pasero 已提交
192
	run(context?: IEditorIdentifier): TPromise<any> {
193
		let sourceGroup: IEditorGroup;
B
Benjamin Pasero 已提交
194 195
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
I
initialshl 已提交
196
		} else {
B
Benjamin Pasero 已提交
197
			sourceGroup = this.editorGroupService.activeGroup;
I
initialshl 已提交
198 199
		}

200 201 202 203 204 205 206 207
		const targetGroupDirections = [GroupDirection.RIGHT, GroupDirection.DOWN, GroupDirection.LEFT, GroupDirection.UP];
		for (let i = 0; i < targetGroupDirections.length; i++) {
			const targetGroup = this.editorGroupService.findGroup({ direction: targetGroupDirections[i] }, sourceGroup);
			if (targetGroup && sourceGroup !== targetGroup) {
				this.editorGroupService.mergeGroup(sourceGroup, targetGroup);

				return TPromise.as(true);
			}
B
Benjamin Pasero 已提交
208
		}
I
initialshl 已提交
209 210 211 212 213

		return TPromise.as(true);
	}
}

214 215
export class JoinAllGroupsAction extends Action {

B
Benjamin Pasero 已提交
216 217
	static readonly ID = 'workbench.action.joinAllGroups';
	static readonly LABEL = nls.localize('joinAllGroups', "Join All Editor Groups");
218 219 220 221 222 223 224 225 226

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
227
	run(context?: IEditorIdentifier): TPromise<any> {
228
		mergeAllGroups(this.editorGroupService);
229 230 231 232 233

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
234
export class NavigateBetweenGroupsAction extends Action {
235

B
Benjamin Pasero 已提交
236 237
	static readonly ID = 'workbench.action.navigateEditorGroups';
	static readonly LABEL = nls.localize('navigateEditorGroups', "Navigate Between Editor Groups");
E
Erich Gamma 已提交
238

239 240 241
	constructor(
		id: string,
		label: string,
242
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
243
	) {
E
Erich Gamma 已提交
244 245 246
		super(id, label);
	}

B
Benjamin Pasero 已提交
247
	run(): TPromise<any> {
B
Benjamin Pasero 已提交
248
		const nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT }, this.editorGroupService.activeGroup, true);
B
Benjamin Pasero 已提交
249
		nextGroup.focus();
250 251

		return TPromise.as(true);
E
Erich Gamma 已提交
252 253 254
	}
}

255 256
export class FocusActiveGroupAction extends Action {

B
Benjamin Pasero 已提交
257 258
	static readonly ID = 'workbench.action.focusActiveEditorGroup';
	static readonly LABEL = nls.localize('focusActiveEditorGroup', "Focus Active Editor Group");
259 260 261 262

	constructor(
		id: string,
		label: string,
263
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
264 265 266 267
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
268
	run(): TPromise<any> {
B
Benjamin Pasero 已提交
269
		this.editorGroupService.activeGroup.focus();
D
Daniel Imms 已提交
270

271
		return TPromise.as(true);
E
Erich Gamma 已提交
272 273 274
	}
}

275
export abstract class BaseFocusGroupAction extends Action {
E
Erich Gamma 已提交
276 277 278 279

	constructor(
		id: string,
		label: string,
280
		private scope: IFindGroupScope,
281
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
282 283 284 285
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
286
	run(): TPromise<any> {
B
Benjamin Pasero 已提交
287
		const group = this.editorGroupService.findGroup(this.scope, this.editorGroupService.activeGroup, true);
288 289 290
		if (group) {
			group.focus();
		}
E
Erich Gamma 已提交
291

A
Alex Dima 已提交
292
		return TPromise.as(true);
E
Erich Gamma 已提交
293 294 295
	}
}

296 297
export class FocusFirstGroupAction extends BaseFocusGroupAction {

B
Benjamin Pasero 已提交
298 299
	static readonly ID = 'workbench.action.focusFirstEditorGroup';
	static readonly LABEL = nls.localize('focusFirstEditorGroup', "Focus First Editor Group");
300 301 302 303 304 305 306 307 308 309 310

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService editorGroupService: IEditorGroupsService
	) {
		super(id, label, { location: GroupLocation.FIRST }, editorGroupService);
	}
}

export class FocusLastGroupAction extends BaseFocusGroupAction {
B
Benjamin Pasero 已提交
311

B
Benjamin Pasero 已提交
312 313
	static readonly ID = 'workbench.action.focusLastEditorGroup';
	static readonly LABEL = nls.localize('focusLastEditorGroup', "Focus Last Editor Group");
E
Erich Gamma 已提交
314 315 316 317

	constructor(
		id: string,
		label: string,
318
		@IEditorGroupsService editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
319
	) {
320
		super(id, label, { location: GroupLocation.LAST }, editorGroupService);
E
Erich Gamma 已提交
321
	}
322
}
E
Erich Gamma 已提交
323

324
export class FocusNextGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
325

B
Benjamin Pasero 已提交
326 327
	static readonly ID = 'workbench.action.focusNextGroup';
	static readonly LABEL = nls.localize('focusNextGroup', "Focus Next Editor Group");
328 329 330 331 332 333 334

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService editorGroupService: IEditorGroupsService
	) {
		super(id, label, { location: GroupLocation.NEXT }, editorGroupService);
E
Erich Gamma 已提交
335 336 337
	}
}

338
export class FocusPreviousGroup extends BaseFocusGroupAction {
339

B
Benjamin Pasero 已提交
340 341
	static readonly ID = 'workbench.action.focusPreviousGroup';
	static readonly LABEL = nls.localize('focusPreviousGroup', "Focus Previous Editor Group");
E
Erich Gamma 已提交
342

343 344 345
	constructor(
		id: string,
		label: string,
346
		@IEditorGroupsService editorGroupService: IEditorGroupsService
347
	) {
348
		super(id, label, { location: GroupLocation.PREVIOUS }, editorGroupService);
E
Erich Gamma 已提交
349
	}
350
}
E
Erich Gamma 已提交
351

352
export class FocusLeftGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
353

B
Benjamin Pasero 已提交
354 355
	static readonly ID = 'workbench.action.focusLeftGroup';
	static readonly LABEL = nls.localize('focusLeftGroup', "Focus Left Editor Group");
356 357 358 359 360 361 362

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService editorGroupService: IEditorGroupsService
	) {
		super(id, label, { direction: GroupDirection.LEFT }, editorGroupService);
E
Erich Gamma 已提交
363 364 365
	}
}

366
export class FocusRightGroup extends BaseFocusGroupAction {
367

B
Benjamin Pasero 已提交
368 369
	static readonly ID = 'workbench.action.focusRightGroup';
	static readonly LABEL = nls.localize('focusRightGroup', "Focus Right Editor Group");
370

E
Erich Gamma 已提交
371 372 373
	constructor(
		id: string,
		label: string,
374
		@IEditorGroupsService editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
375
	) {
376
		super(id, label, { direction: GroupDirection.RIGHT }, editorGroupService);
E
Erich Gamma 已提交
377
	}
378
}
E
Erich Gamma 已提交
379

380
export class FocusAboveGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
381

B
Benjamin Pasero 已提交
382 383
	static readonly ID = 'workbench.action.focusAboveGroup';
	static readonly LABEL = nls.localize('focusAboveGroup', "Focus Above Editor Group");
384 385 386 387 388 389 390

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService editorGroupService: IEditorGroupsService
	) {
		super(id, label, { direction: GroupDirection.UP }, editorGroupService);
E
Erich Gamma 已提交
391 392 393
	}
}

394 395
export class FocusBelowGroup extends BaseFocusGroupAction {

B
Benjamin Pasero 已提交
396 397
	static readonly ID = 'workbench.action.focusBelowGroup';
	static readonly LABEL = nls.localize('focusBelowGroup', "Focus Below Editor Group");
398 399 400 401 402 403 404 405 406 407

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService editorGroupService: IEditorGroupsService
	) {
		super(id, label, { direction: GroupDirection.DOWN }, editorGroupService);
	}
}

408
export class OpenToSideFromQuickOpenAction extends Action {
E
Erich Gamma 已提交
409

B
Benjamin Pasero 已提交
410 411
	static readonly OPEN_TO_SIDE_ID = 'workbench.action.openToSide';
	static readonly OPEN_TO_SIDE_LABEL = nls.localize('openToSide', "Open to the Side");
E
Erich Gamma 已提交
412

413
	constructor(
414
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
415
		@IConfigurationService private configurationService: IConfigurationService
416
	) {
417
		super(OpenToSideFromQuickOpenAction.OPEN_TO_SIDE_ID, OpenToSideFromQuickOpenAction.OPEN_TO_SIDE_LABEL);
E
Erich Gamma 已提交
418

419 420 421
		this.updateClass();
	}

B
Benjamin Pasero 已提交
422
	updateClass(): void {
423
		const preferredDirection = preferredSideBySideGroupDirection(this.configurationService);
E
Erich Gamma 已提交
424

425
		this.class = (preferredDirection === GroupDirection.RIGHT) ? 'quick-open-sidebyside-vertical' : 'quick-open-sidebyside-horizontal';
E
Erich Gamma 已提交
426 427
	}

B
Benjamin Pasero 已提交
428
	run(context: any): TPromise<any> {
B
Benjamin Pasero 已提交
429
		const entry = toEditorQuickOpenEntry(context);
E
Erich Gamma 已提交
430
		if (entry) {
431
			const input = entry.getInput();
B
Benjamin Pasero 已提交
432
			if (input instanceof EditorInput) {
B
Benjamin Pasero 已提交
433
				return this.editorService.openEditor(input, entry.getOptions(), SIDE_GROUP);
B
Benjamin Pasero 已提交
434 435
			}

436 437 438
			const resourceInput = input as IResourceInput;
			resourceInput.options = mixin(resourceInput.options, entry.getOptions());

B
Benjamin Pasero 已提交
439
			return this.editorService.openEditor(resourceInput, SIDE_GROUP);
E
Erich Gamma 已提交
440 441
		}

A
Alex Dima 已提交
442
		return TPromise.as(false);
E
Erich Gamma 已提交
443 444 445
	}
}

446
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
447 448 449

	// QuickOpenEntryGroup
	if (element instanceof QuickOpenEntryGroup) {
450
		const group = <QuickOpenEntryGroup>element;
E
Erich Gamma 已提交
451 452 453 454 455 456 457 458 459 460 461 462 463 464
		if (group.getEntry()) {
			element = group.getEntry();
		}
	}

	// EditorQuickOpenEntry or EditorQuickOpenEntryGroup both implement IEditorQuickOpenEntry
	if (element instanceof EditorQuickOpenEntry || element instanceof EditorQuickOpenEntryGroup) {
		return element;
	}

	return null;
}

export class CloseEditorAction extends Action {
465

B
Benjamin Pasero 已提交
466 467
	static readonly ID = 'workbench.action.closeActiveEditor';
	static readonly LABEL = nls.localize('closeEditor', "Close Editor");
468

469 470 471
	constructor(
		id: string,
		label: string,
I
isidor 已提交
472
		@ICommandService private commandService: ICommandService
473
	) {
I
isidor 已提交
474
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
475 476
	}

B
Benjamin Pasero 已提交
477
	run(context?: IEditorCommandsContext): TPromise<any> {
478
		return this.commandService.executeCommand(CLOSE_EDITOR_COMMAND_ID, void 0, context);
E
Erich Gamma 已提交
479 480 481
	}
}

482 483
export class CloseOneEditorAction extends Action {

B
Benjamin Pasero 已提交
484 485
	static readonly ID = 'workbench.action.closeActiveEditor';
	static readonly LABEL = nls.localize('closeOneEditor', "Close");
486 487 488 489

	constructor(
		id: string,
		label: string,
490
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
491 492 493 494
	) {
		super(id, label, 'close-editor-action');
	}

B
Benjamin Pasero 已提交
495
	run(context?: IEditorCommandsContext): TPromise<any> {
496
		let group: IEditorGroup;
497 498
		let editorIndex: number;
		if (context) {
499
			group = this.editorGroupService.getGroup(context.groupId);
500

501 502
			if (group) {
				editorIndex = context.editorIndex; // only allow editor at index if group is valid
503 504 505
			}
		}

506
		if (!group) {
507
			group = this.editorGroupService.activeGroup;
508 509
		}

510 511 512 513
		// Close specific editor in group
		if (typeof editorIndex === 'number') {
			const editorAtIndex = group.getEditor(editorIndex);
			if (editorAtIndex) {
514
				return group.closeEditor(editorAtIndex);
515 516 517 518 519
			}
		}

		// Otherwise close active editor in group
		if (group.activeEditor) {
520
			return group.closeEditor(group.activeEditor);
521 522 523 524 525 526
		}

		return TPromise.as(false);
	}
}

M
misoguy 已提交
527 528
export class RevertAndCloseEditorAction extends Action {

B
Benjamin Pasero 已提交
529 530
	static readonly ID = 'workbench.action.revertAndCloseActiveEditor';
	static readonly LABEL = nls.localize('revertAndCloseActiveEditor', "Revert and Close Editor");
M
misoguy 已提交
531 532 533 534

	constructor(
		id: string,
		label: string,
535
		@IEditorService private editorService: IEditorService
M
misoguy 已提交
536 537 538 539
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
540
	run(): TPromise<any> {
B
Benjamin Pasero 已提交
541
		const activeControl = this.editorService.activeControl;
B
Benjamin Pasero 已提交
542
		if (activeControl) {
B
Benjamin Pasero 已提交
543
			const editor = activeControl.input;
544
			const group = activeControl.group;
B
Benjamin Pasero 已提交
545

546
			// first try a normal revert where the contents of the editor are restored
B
Benjamin Pasero 已提交
547
			return editor.revert().then(() => group.closeEditor(editor), error => {
548 549 550 551
				// if that fails, since we are about to close the editor, we accept that
				// the editor cannot be reverted and instead do a soft revert that just
				// enables us to close the editor. With this, a user can always close a
				// dirty editor even when reverting fails.
B
Benjamin Pasero 已提交
552
				return editor.revert({ soft: true }).then(() => group.closeEditor(editor));
553
			});
M
misoguy 已提交
554 555 556 557 558 559
		}

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
560
export class CloseLeftEditorsInGroupAction extends Action {
561

B
Benjamin Pasero 已提交
562 563
	static readonly ID = 'workbench.action.closeEditorsToTheLeft';
	static readonly LABEL = nls.localize('closeEditorsToTheLeft', "Close Editors to the Left in Group");
564

565 566 567
	constructor(
		id: string,
		label: string,
568
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
569
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
570
	) {
571 572 573
		super(id, label);
	}

B
Benjamin Pasero 已提交
574
	run(context?: IEditorIdentifier): TPromise<any> {
B
Benjamin Pasero 已提交
575
		const { group, editor } = getTarget(this.editorService, this.editorGroupService, context);
B
Benjamin Pasero 已提交
576 577
		if (group && editor) {
			return group.closeEditors({ direction: CloseDirection.LEFT, except: editor });
578 579 580 581 582 583
		}

		return TPromise.as(false);
	}
}

584
function getTarget(editorService: IEditorService, editorGroupService: IEditorGroupsService, context?: IEditorIdentifier): { editor: IEditorInput, group: IEditorGroup } {
B
Benjamin Pasero 已提交
585 586 587 588 589 590 591 592
	if (context) {
		return { editor: context.editor, group: editorGroupService.getGroup(context.groupId) };
	}

	// Fallback to active group
	return { group: editorGroupService.activeGroup, editor: editorGroupService.activeGroup.activeEditor };
}

593
export abstract class BaseCloseAllAction extends Action {
594

595 596 597
	constructor(
		id: string,
		label: string,
598
		clazz: string,
599 600
		private textFileService: ITextFileService,
		protected editorGroupService: IEditorGroupsService
601
	) {
602
		super(id, label, clazz);
E
Erich Gamma 已提交
603 604
	}

605 606 607 608 609 610 611 612 613 614 615 616 617 618
	protected get groupsToClose(): IEditorGroup[] {
		const groupsToClose: IEditorGroup[] = [];

		// Close editors in reverse order of their grid appearance so that the editor
		// group that is the first (top-left) remains. This helps to keep view state
		// for editors around that have been opened in this visually first group.
		const groups = this.editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE);
		for (let i = groups.length - 1; i >= 0; i--) {
			groupsToClose.push(groups[i]);
		}

		return groupsToClose;
	}

B
Benjamin Pasero 已提交
619
	run(): TPromise<any> {
620 621 622

		// Just close all if there are no or one dirty editor
		if (this.textFileService.getDirty().length < 2) {
623
			return this.doCloseAll();
624 625 626
		}

		// Otherwise ask for combined confirmation
627 628 629 630
		return this.textFileService.confirmSave().then(confirm => {
			if (confirm === ConfirmResult.CANCEL) {
				return void 0;
			}
631

632 633 634 635 636
			let saveOrRevertPromise: TPromise<boolean>;
			if (confirm === ConfirmResult.DONT_SAVE) {
				saveOrRevertPromise = this.textFileService.revertAll(null, { soft: true }).then(() => true);
			} else {
				saveOrRevertPromise = this.textFileService.saveAll(true).then(res => res.results.every(r => r.success));
637
			}
638

639 640
			return saveOrRevertPromise.then(success => {
				if (success) {
641
					return this.doCloseAll();
642 643 644 645
				}

				return void 0;
			});
646
		});
E
Erich Gamma 已提交
647
	}
648 649 650 651 652 653

	protected abstract doCloseAll(): TPromise<any>;
}

export class CloseAllEditorsAction extends BaseCloseAllAction {

B
Benjamin Pasero 已提交
654 655
	static readonly ID = 'workbench.action.closeAllEditors';
	static readonly LABEL = nls.localize('closeAllEditors', "Close All Editors");
656 657 658 659 660

	constructor(
		id: string,
		label: string,
		@ITextFileService textFileService: ITextFileService,
661
		@IEditorGroupsService editorGroupService: IEditorGroupsService
662
	) {
663
		super(id, label, 'action-close-all-files', textFileService, editorGroupService);
664 665 666
	}

	protected doCloseAll(): TPromise<any> {
667
		return TPromise.join(this.groupsToClose.map(g => g.closeAllEditors()));
668 669 670 671 672
	}
}

export class CloseAllEditorGroupsAction extends BaseCloseAllAction {

B
Benjamin Pasero 已提交
673 674
	static readonly ID = 'workbench.action.closeAllGroups';
	static readonly LABEL = nls.localize('closeAllGroups', "Close All Editor Groups");
675 676 677 678 679

	constructor(
		id: string,
		label: string,
		@ITextFileService textFileService: ITextFileService,
680
		@IEditorGroupsService editorGroupService: IEditorGroupsService
681
	) {
682
		super(id, label, void 0, textFileService, editorGroupService);
683 684 685
	}

	protected doCloseAll(): TPromise<any> {
686 687
		return TPromise.join(this.groupsToClose.map(g => g.closeAllEditors())).then(() => {
			this.groupsToClose.forEach(group => this.editorGroupService.removeGroup(group));
688 689
		});
	}
E
Erich Gamma 已提交
690 691
}

692 693
export class CloseEditorsInOtherGroupsAction extends Action {

B
Benjamin Pasero 已提交
694 695
	static readonly ID = 'workbench.action.closeEditorsInOtherGroups';
	static readonly LABEL = nls.localize('closeEditorsInOtherGroups', "Close Editors in Other Groups");
696

697 698 699
	constructor(
		id: string,
		label: string,
700
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
701
	) {
702 703 704
		super(id, label);
	}

B
Benjamin Pasero 已提交
705
	run(context?: IEditorIdentifier): TPromise<any> {
I
isidor 已提交
706
		const groupToSkip = context ? this.editorGroupService.getGroup(context.groupId) : this.editorGroupService.activeGroup;
707
		return TPromise.join(this.editorGroupService.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE).map(g => {
I
isidor 已提交
708 709
			if (g.id === groupToSkip.id) {
				return TPromise.as(null);
710 711
			}

I
isidor 已提交
712 713
			return g.closeAllEditors();
		}));
714 715 716
	}
}

717
export class BaseMoveGroupAction extends Action {
718

719 720 721
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
722
		private direction: GroupDirection,
723
		private editorGroupService: IEditorGroupsService
724
	) {
E
Erich Gamma 已提交
725 726 727
		super(id, label);
	}

B
Benjamin Pasero 已提交
728
	run(context?: IEditorIdentifier): TPromise<any> {
729
		let sourceGroup: IEditorGroup;
730 731 732 733
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
		} else {
			sourceGroup = this.editorGroupService.activeGroup;
734 735
		}

B
Benjamin Pasero 已提交
736
		const targetGroup = this.findTargetGroup(sourceGroup);
737
		if (targetGroup) {
B
Benjamin Pasero 已提交
738
			this.editorGroupService.moveGroup(sourceGroup, targetGroup, this.direction);
E
Erich Gamma 已提交
739 740
		}

741
		return TPromise.as(true);
E
Erich Gamma 已提交
742
	}
B
Benjamin Pasero 已提交
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769

	private findTargetGroup(sourceGroup: IEditorGroup): IEditorGroup {
		const targetNeighbours: GroupDirection[] = [this.direction];

		// Allow the target group to be in alternative locations to support more
		// scenarios of moving the group to the taret location.
		// Helps for https://github.com/Microsoft/vscode/issues/50741
		switch (this.direction) {
			case GroupDirection.LEFT:
			case GroupDirection.RIGHT:
				targetNeighbours.push(GroupDirection.UP, GroupDirection.DOWN);
				break;
			case GroupDirection.UP:
			case GroupDirection.DOWN:
				targetNeighbours.push(GroupDirection.LEFT, GroupDirection.RIGHT);
				break;
		}

		for (let i = 0; i < targetNeighbours.length; i++) {
			const targetNeighbour = this.editorGroupService.findGroup({ direction: targetNeighbours[i] }, sourceGroup);
			if (targetNeighbour) {
				return targetNeighbour;
			}
		}

		return void 0;
	}
E
Erich Gamma 已提交
770 771
}

772 773
export class MoveGroupLeftAction extends BaseMoveGroupAction {

B
Benjamin Pasero 已提交
774 775
	static readonly ID = 'workbench.action.moveActiveEditorGroupLeft';
	static readonly LABEL = nls.localize('moveActiveGroupLeft', "Move Editor Group Left");
776 777 778 779

	constructor(
		id: string,
		label: string,
780
		@IEditorGroupsService editorGroupService: IEditorGroupsService
781
	) {
B
Benjamin Pasero 已提交
782
		super(id, label, GroupDirection.LEFT, editorGroupService);
783 784 785 786
	}
}

export class MoveGroupRightAction extends BaseMoveGroupAction {
E
Erich Gamma 已提交
787

B
Benjamin Pasero 已提交
788 789
	static readonly ID = 'workbench.action.moveActiveEditorGroupRight';
	static readonly LABEL = nls.localize('moveActiveGroupRight', "Move Editor Group Right");
790

791 792 793
	constructor(
		id: string,
		label: string,
794
		@IEditorGroupsService editorGroupService: IEditorGroupsService
795
	) {
B
Benjamin Pasero 已提交
796
		super(id, label, GroupDirection.RIGHT, editorGroupService);
797 798
	}
}
799

800
export class MoveGroupUpAction extends BaseMoveGroupAction {
801

B
Benjamin Pasero 已提交
802 803
	static readonly ID = 'workbench.action.moveActiveEditorGroupUp';
	static readonly LABEL = nls.localize('moveActiveGroupUp', "Move Editor Group Up");
E
Erich Gamma 已提交
804

805 806 807
	constructor(
		id: string,
		label: string,
808
		@IEditorGroupsService editorGroupService: IEditorGroupsService
809
	) {
B
Benjamin Pasero 已提交
810
		super(id, label, GroupDirection.UP, editorGroupService);
811 812 813 814 815
	}
}

export class MoveGroupDownAction extends BaseMoveGroupAction {

B
Benjamin Pasero 已提交
816 817
	static readonly ID = 'workbench.action.moveActiveEditorGroupDown';
	static readonly LABEL = nls.localize('moveActiveGroupDown', "Move Editor Group Down");
818 819 820 821

	constructor(
		id: string,
		label: string,
822
		@IEditorGroupsService editorGroupService: IEditorGroupsService
823
	) {
B
Benjamin Pasero 已提交
824
		super(id, label, GroupDirection.DOWN, editorGroupService);
E
Erich Gamma 已提交
825 826 827
	}
}

828
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
829

B
Benjamin Pasero 已提交
830 831
	static readonly ID = 'workbench.action.minimizeOtherEditors';
	static readonly LABEL = nls.localize('minimizeOtherEditorGroups', "Maximize Editor Group");
832

833
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
834 835 836
		super(id, label);
	}

B
Benjamin Pasero 已提交
837
	run(): TPromise<any> {
838
		this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
839

A
Alex Dima 已提交
840
		return TPromise.as(false);
E
Erich Gamma 已提交
841 842 843
	}
}

B
Benjamin Pasero 已提交
844
export class ResetGroupSizesAction extends Action {
E
Erich Gamma 已提交
845

B
Benjamin Pasero 已提交
846 847
	static readonly ID = 'workbench.action.evenEditorWidths';
	static readonly LABEL = nls.localize('evenEditorGroups', "Reset Editor Group Sizes");
848

849
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
850 851 852
		super(id, label);
	}

B
Benjamin Pasero 已提交
853
	run(): TPromise<any> {
854
		this.editorGroupService.arrangeGroups(GroupsArrangement.EVEN);
E
Erich Gamma 已提交
855

A
Alex Dima 已提交
856
		return TPromise.as(false);
E
Erich Gamma 已提交
857 858 859
	}
}

860
export class MaximizeGroupAction extends Action {
861

B
Benjamin Pasero 已提交
862 863
	static readonly ID = 'workbench.action.maximizeEditor';
	static readonly LABEL = nls.localize('maximizeEditor', "Maximize Editor Group and Hide Sidebar");
864

865 866 867
	constructor(
		id: string,
		label: string,
868 869
		@IEditorService private editorService: IEditorService,
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
870 871 872 873 874
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
875
	run(): TPromise<any> {
876 877 878
		if (this.editorService.activeEditor) {
			this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);

879
			return this.partService.setSideBarHidden(true);
880 881
		}

A
Alex Dima 已提交
882
		return TPromise.as(false);
883 884 885
	}
}

886 887
export abstract class BaseNavigateEditorAction extends Action {

888 889 890
	constructor(
		id: string,
		label: string,
891 892
		protected editorGroupService: IEditorGroupsService,
		protected editorService: IEditorService
893
	) {
894 895 896
		super(id, label);
	}

B
Benjamin Pasero 已提交
897
	run(): TPromise<any> {
898
		const result = this.navigate();
899 900
		if (!result) {
			return TPromise.as(false);
901 902
		}

903 904 905 906 907 908 909
		const { groupId, editor } = result;
		if (!editor) {
			return TPromise.as(false);
		}

		const group = this.editorGroupService.getGroup(groupId);
		return group.openEditor(editor);
910 911 912 913 914 915 916
	}

	protected abstract navigate(): IEditorIdentifier;
}

export class OpenNextEditor extends BaseNavigateEditorAction {

B
Benjamin Pasero 已提交
917 918
	static readonly ID = 'workbench.action.nextEditor';
	static readonly LABEL = nls.localize('openNextEditor', "Open Next Editor");
919

920 921 922
	constructor(
		id: string,
		label: string,
923 924
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
925 926
	) {
		super(id, label, editorGroupService, editorService);
927 928 929
	}

	protected navigate(): IEditorIdentifier {
930 931 932 933 934 935 936 937 938 939

		// Navigate in active group if possible
		const activeGroup = this.editorGroupService.activeGroup;
		const activeGroupEditors = activeGroup.getEditors(EditorsOrder.SEQUENTIAL);
		const activeEditorIndex = activeGroupEditors.indexOf(activeGroup.activeEditor);
		if (activeEditorIndex + 1 < activeGroupEditors.length) {
			return { editor: activeGroupEditors[activeEditorIndex + 1], groupId: activeGroup.id };
		}

		// Otherwise try in next group
B
Benjamin Pasero 已提交
940
		const nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT }, this.editorGroupService.activeGroup, true);
941 942 943 944 945 946
		if (nextGroup) {
			const previousGroupEditors = nextGroup.getEditors(EditorsOrder.SEQUENTIAL);
			return { editor: previousGroupEditors[0], groupId: nextGroup.id };
		}

		return void 0;
947 948 949 950 951
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

B
Benjamin Pasero 已提交
952 953
	static readonly ID = 'workbench.action.previousEditor';
	static readonly LABEL = nls.localize('openPreviousEditor', "Open Previous Editor");
954

955 956 957
	constructor(
		id: string,
		label: string,
958 959
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
960 961
	) {
		super(id, label, editorGroupService, editorService);
962 963 964
	}

	protected navigate(): IEditorIdentifier {
965 966 967 968 969 970 971 972 973 974

		// Navigate in active group if possible
		const activeGroup = this.editorGroupService.activeGroup;
		const activeGroupEditors = activeGroup.getEditors(EditorsOrder.SEQUENTIAL);
		const activeEditorIndex = activeGroupEditors.indexOf(activeGroup.activeEditor);
		if (activeEditorIndex > 0) {
			return { editor: activeGroupEditors[activeEditorIndex - 1], groupId: activeGroup.id };
		}

		// Otherwise try in previous group
B
Benjamin Pasero 已提交
975
		const previousGroup = this.editorGroupService.findGroup({ location: GroupLocation.PREVIOUS }, this.editorGroupService.activeGroup, true);
976 977 978 979 980 981
		if (previousGroup) {
			const previousGroupEditors = previousGroup.getEditors(EditorsOrder.SEQUENTIAL);
			return { editor: previousGroupEditors[previousGroupEditors.length - 1], groupId: previousGroup.id };
		}

		return void 0;
982 983 984 985 986
	}
}

export class OpenNextEditorInGroup extends BaseNavigateEditorAction {

B
Benjamin Pasero 已提交
987 988
	static readonly ID = 'workbench.action.nextEditorInGroup';
	static readonly LABEL = nls.localize('nextEditorInGroup', "Open Next Editor in Group");
989 990 991 992

	constructor(
		id: string,
		label: string,
993 994
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
995 996 997 998 999
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
1000 1001 1002 1003 1004
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);
		const index = editors.indexOf(group.activeEditor);

		return { editor: index + 1 < editors.length ? editors[index + 1] : editors[0], groupId: group.id };
1005 1006 1007 1008 1009
	}
}

export class OpenPreviousEditorInGroup extends BaseNavigateEditorAction {

B
Benjamin Pasero 已提交
1010 1011
	static readonly ID = 'workbench.action.previousEditorInGroup';
	static readonly LABEL = nls.localize('openPreviousEditorInGroup', "Open Previous Editor in Group");
1012 1013 1014 1015

	constructor(
		id: string,
		label: string,
1016 1017
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);
		const index = editors.indexOf(group.activeEditor);

		return { editor: index > 0 ? editors[index - 1] : editors[editors.length - 1], groupId: group.id };
	}
}

export class OpenFirstEditorInGroup extends BaseNavigateEditorAction {

B
Benjamin Pasero 已提交
1033 1034
	static readonly ID = 'workbench.action.firstEditorInGroup';
	static readonly LABEL = nls.localize('firstEditorInGroup', "Open First Editor in Group");
1035 1036 1037 1038

	constructor(
		id: string,
		label: string,
1039 1040
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1041 1042 1043 1044 1045
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
1046 1047 1048 1049
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[0], groupId: group.id };
1050
	}
B
Benjamin Pasero 已提交
1051 1052
}

1053 1054
export class OpenLastEditorInGroup extends BaseNavigateEditorAction {

B
Benjamin Pasero 已提交
1055 1056
	static readonly ID = 'workbench.action.lastEditorInGroup';
	static readonly LABEL = nls.localize('lastEditorInGroup', "Open Last Editor in Group");
1057 1058 1059 1060

	constructor(
		id: string,
		label: string,
1061 1062
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1063 1064 1065 1066 1067
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
1068 1069 1070 1071
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[editors.length - 1], groupId: group.id };
1072 1073 1074
	}
}

B
Benjamin Pasero 已提交
1075 1076
export class NavigateForwardAction extends Action {

B
Benjamin Pasero 已提交
1077 1078
	static readonly ID = 'workbench.action.navigateForward';
	static readonly LABEL = nls.localize('navigateNext', "Go Forward");
B
Benjamin Pasero 已提交
1079 1080 1081 1082 1083

	constructor(id: string, label: string, @IHistoryService private historyService: IHistoryService) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
1084
	run(): TPromise<any> {
B
Benjamin Pasero 已提交
1085 1086 1087 1088 1089 1090 1091 1092
		this.historyService.forward();

		return TPromise.as(null);
	}
}

export class NavigateBackwardsAction extends Action {

B
Benjamin Pasero 已提交
1093 1094
	static readonly ID = 'workbench.action.navigateBack';
	static readonly LABEL = nls.localize('navigatePrevious', "Go Back");
B
Benjamin Pasero 已提交
1095 1096 1097 1098 1099

	constructor(id: string, label: string, @IHistoryService private historyService: IHistoryService) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
1100
	run(): TPromise<any> {
B
Benjamin Pasero 已提交
1101 1102 1103 1104
		this.historyService.back();

		return TPromise.as(null);
	}
I
isidor 已提交
1105
}
1106

1107 1108
export class NavigateLastAction extends Action {

B
Benjamin Pasero 已提交
1109 1110
	static readonly ID = 'workbench.action.navigateLast';
	static readonly LABEL = nls.localize('navigateLast', "Go Last");
1111 1112 1113 1114 1115

	constructor(id: string, label: string, @IHistoryService private historyService: IHistoryService) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
1116
	run(): TPromise<any> {
1117 1118 1119 1120 1121 1122
		this.historyService.last();

		return TPromise.as(null);
	}
}

1123 1124
export class ReopenClosedEditorAction extends Action {

B
Benjamin Pasero 已提交
1125 1126
	static readonly ID = 'workbench.action.reopenClosedEditor';
	static readonly LABEL = nls.localize('reopenClosedEditor', "Reopen Closed Editor");
1127 1128 1129 1130

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1131
		@IHistoryService private historyService: IHistoryService
1132 1133 1134 1135
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
1136
	run(): TPromise<any> {
1137
		this.historyService.reopenLastClosedEditor();
1138 1139 1140

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
1141 1142
}

1143
export class ClearRecentFilesAction extends Action {
C
22768  
Cristian 已提交
1144

B
Benjamin Pasero 已提交
1145 1146
	static readonly ID = 'workbench.action.clearRecentFiles';
	static readonly LABEL = nls.localize('clearRecentFiles', "Clear Recently Opened");
C
22768  
Cristian 已提交
1147 1148 1149 1150

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1151 1152
		@IWindowsService private windowsService: IWindowsService,
		@IHistoryService private historyService: IHistoryService
C
22768  
Cristian 已提交
1153 1154 1155 1156
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
1157
	run(): TPromise<any> {
B
Benjamin Pasero 已提交
1158 1159

		// Clear global recently opened
B
Benjamin Pasero 已提交
1160
		this.windowsService.clearRecentlyOpened();
C
22768  
Cristian 已提交
1161

B
Benjamin Pasero 已提交
1162 1163 1164
		// Clear workspace specific recently opened
		this.historyService.clearRecentlyOpened();

C
22768  
Cristian 已提交
1165 1166 1167 1168
		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
1169
export class ShowEditorsInActiveGroupAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
1170

B
Benjamin Pasero 已提交
1171 1172
	static readonly ID = 'workbench.action.showEditorsInActiveGroup';
	static readonly LABEL = nls.localize('showEditorsInActiveGroup', "Show Editors in Active Group");
B
Benjamin Pasero 已提交
1173

1174 1175 1176
	constructor(
		actionId: string,
		actionLabel: string,
1177
		@IQuickOpenService quickOpenService: IQuickOpenService
1178
	) {
B
Benjamin Pasero 已提交
1179
		super(actionId, actionLabel, NAVIGATE_IN_ACTIVE_GROUP_PREFIX, quickOpenService);
1180
	}
B
Benjamin Pasero 已提交
1181 1182
}

B
Benjamin Pasero 已提交
1183 1184
export class ShowAllEditorsAction extends QuickOpenAction {

B
Benjamin Pasero 已提交
1185 1186
	static readonly ID = 'workbench.action.showAllEditors';
	static readonly LABEL = nls.localize('showAllEditors', "Show All Editors");
B
Benjamin Pasero 已提交
1187 1188 1189 1190 1191 1192

	constructor(actionId: string, actionLabel: string, @IQuickOpenService quickOpenService: IQuickOpenService) {
		super(actionId, actionLabel, NAVIGATE_ALL_EDITORS_GROUP_PREFIX, quickOpenService);
	}
}

1193
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1194 1195 1196 1197 1198

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1199
		@IKeybindingService private keybindingService: IKeybindingService
B
Benjamin Pasero 已提交
1200 1201 1202 1203
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
1204
	run(): TPromise<any> {
1205
		const keys = this.keybindingService.lookupKeybindings(this.id);
B
Benjamin Pasero 已提交
1206

1207

B
Benjamin Pasero 已提交
1208 1209

		this.quickOpenService.show(NAVIGATE_IN_ACTIVE_GROUP_PREFIX, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1210 1211 1212 1213 1214

		return TPromise.as(true);
	}
}

1215 1216
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

B
Benjamin Pasero 已提交
1217 1218
	static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditorInGroup';
	static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditorInGroup', "Open Previous Recently Used Editor in Group");
1219 1220 1221 1222 1223

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1224
		@IKeybindingService keybindingService: IKeybindingService
1225
	) {
B
Benjamin Pasero 已提交
1226
		super(id, label, quickOpenService, keybindingService);
1227 1228 1229 1230 1231
	}
}

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

B
Benjamin Pasero 已提交
1232 1233
	static readonly ID = 'workbench.action.openNextRecentlyUsedEditorInGroup';
	static readonly LABEL = nls.localize('openNextRecentlyUsedEditorInGroup', "Open Next Recently Used Editor in Group");
1234 1235 1236 1237 1238

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1239
		@IKeybindingService keybindingService: IKeybindingService
1240
	) {
B
Benjamin Pasero 已提交
1241
		super(id, label, quickOpenService, keybindingService);
1242 1243 1244
	}
}

1245
export class OpenPreviousEditorFromHistoryAction extends Action {
B
Benjamin Pasero 已提交
1246

B
Benjamin Pasero 已提交
1247 1248
	static readonly ID = 'workbench.action.openPreviousEditorFromHistory';
	static readonly LABEL = nls.localize('navigateEditorHistoryByInput', "Open Previous Editor from History");
B
Benjamin Pasero 已提交
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
		@IKeybindingService private keybindingService: IKeybindingService
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
1259
	run(): TPromise<any> {
1260
		const keys = this.keybindingService.lookupKeybindings(this.id);
B
Benjamin Pasero 已提交
1261

B
Benjamin Pasero 已提交
1262
		this.quickOpenService.show(null, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1263 1264 1265 1266 1267

		return TPromise.as(true);
	}
}

1268 1269
export class OpenNextRecentlyUsedEditorAction extends Action {

B
Benjamin Pasero 已提交
1270 1271
	static readonly ID = 'workbench.action.openNextRecentlyUsedEditor';
	static readonly LABEL = nls.localize('openNextRecentlyUsedEditor', "Open Next Recently Used Editor");
1272 1273 1274 1275 1276

	constructor(id: string, label: string, @IHistoryService private historyService: IHistoryService) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
1277
	run(): TPromise<any> {
1278 1279 1280 1281 1282 1283 1284 1285
		this.historyService.forward(true);

		return TPromise.as(null);
	}
}

export class OpenPreviousRecentlyUsedEditorAction extends Action {

B
Benjamin Pasero 已提交
1286 1287
	static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditor';
	static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditor', "Open Previous Recently Used Editor");
1288 1289 1290 1291 1292

	constructor(id: string, label: string, @IHistoryService private historyService: IHistoryService) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
1293
	run(): TPromise<any> {
1294 1295 1296 1297 1298 1299
		this.historyService.back(true);

		return TPromise.as(null);
	}
}

1300 1301
export class ClearEditorHistoryAction extends Action {

B
Benjamin Pasero 已提交
1302 1303
	static readonly ID = 'workbench.action.clearEditorHistory';
	static readonly LABEL = nls.localize('clearEditorHistory', "Clear Editor History");
1304 1305 1306 1307 1308 1309 1310 1311 1312

	constructor(
		id: string,
		label: string,
		@IHistoryService private historyService: IHistoryService
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
1313
	run(): TPromise<any> {
1314

1315
		// Editor history
1316 1317 1318 1319 1320 1321
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1322
export class MoveEditorLeftInGroupAction extends ExecuteCommandAction {
1323

B
Benjamin Pasero 已提交
1324 1325
	static readonly ID = 'workbench.action.moveEditorLeftInGroup';
	static readonly LABEL = nls.localize('moveEditorLeft', "Move Editor Left");
1326 1327 1328 1329

	constructor(
		id: string,
		label: string,
1330
		@ICommandService commandService: ICommandService
1331
	) {
1332
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'left' } as ActiveEditorMoveArguments);
1333 1334 1335
	}
}

1336
export class MoveEditorRightInGroupAction extends ExecuteCommandAction {
1337

B
Benjamin Pasero 已提交
1338 1339
	static readonly ID = 'workbench.action.moveEditorRightInGroup';
	static readonly LABEL = nls.localize('moveEditorRight', "Move Editor Right");
1340 1341 1342 1343

	constructor(
		id: string,
		label: string,
1344
		@ICommandService commandService: ICommandService
1345
	) {
1346
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'right' } as ActiveEditorMoveArguments);
1347 1348 1349
	}
}

1350
export class MoveEditorToPreviousGroupAction extends ExecuteCommandAction {
1351

B
Benjamin Pasero 已提交
1352 1353
	static readonly ID = 'workbench.action.moveEditorToPreviousGroup';
	static readonly LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
1354 1355 1356 1357

	constructor(
		id: string,
		label: string,
1358
		@ICommandService commandService: ICommandService
1359
	) {
1360
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'previous', by: 'group' } as ActiveEditorMoveArguments);
1361
	}
1362
}
1363

1364
export class MoveEditorToNextGroupAction extends ExecuteCommandAction {
1365

B
Benjamin Pasero 已提交
1366 1367
	static readonly ID = 'workbench.action.moveEditorToNextGroup';
	static readonly LABEL = nls.localize('moveEditorToNextGroup', "Move Editor into Next Group");
1368 1369 1370 1371 1372 1373 1374

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'next', by: 'group' } as ActiveEditorMoveArguments);
1375 1376 1377
	}
}

1378
export class MoveEditorToAboveGroupAction extends ExecuteCommandAction {
1379

B
Benjamin Pasero 已提交
1380 1381
	static readonly ID = 'workbench.action.moveEditorToAboveGroup';
	static readonly LABEL = nls.localize('moveEditorToAboveGroup', "Move Editor into Above Group");
1382 1383 1384 1385

	constructor(
		id: string,
		label: string,
1386
		@ICommandService commandService: ICommandService
1387
	) {
1388
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'up', by: 'group' } as ActiveEditorMoveArguments);
1389
	}
1390
}
1391

1392
export class MoveEditorToBelowGroupAction extends ExecuteCommandAction {
1393

B
Benjamin Pasero 已提交
1394 1395
	static readonly ID = 'workbench.action.moveEditorToBelowGroup';
	static readonly LABEL = nls.localize('moveEditorToBelowGroup', "Move Editor into Below Group");
1396 1397 1398 1399 1400 1401 1402

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'down', by: 'group' } as ActiveEditorMoveArguments);
1403 1404 1405
	}
}

1406
export class MoveEditorToLeftGroupAction extends ExecuteCommandAction {
1407

B
Benjamin Pasero 已提交
1408 1409
	static readonly ID = 'workbench.action.moveEditorToLeftGroup';
	static readonly LABEL = nls.localize('moveEditorToLeftGroup', "Move Editor into Left Group");
1410 1411 1412 1413

	constructor(
		id: string,
		label: string,
1414
		@ICommandService commandService: ICommandService
1415
	) {
1416
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'left', by: 'group' } as ActiveEditorMoveArguments);
1417
	}
1418
}
1419

1420
export class MoveEditorToRightGroupAction extends ExecuteCommandAction {
1421

B
Benjamin Pasero 已提交
1422 1423
	static readonly ID = 'workbench.action.moveEditorToRightGroup';
	static readonly LABEL = nls.localize('moveEditorToRightGroup', "Move Editor into Right Group");
1424 1425 1426 1427 1428 1429 1430

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'right', by: 'group' } as ActiveEditorMoveArguments);
1431 1432 1433
	}
}

1434
export class MoveEditorToFirstGroupAction extends ExecuteCommandAction {
1435

B
Benjamin Pasero 已提交
1436 1437
	static readonly ID = 'workbench.action.moveEditorToFirstGroup';
	static readonly LABEL = nls.localize('moveEditorToFirstGroup', "Move Editor into First Group");
1438 1439 1440 1441

	constructor(
		id: string,
		label: string,
1442
		@ICommandService commandService: ICommandService
1443
	) {
1444
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'first', by: 'group' } as ActiveEditorMoveArguments);
1445
	}
1446
}
1447

1448
export class MoveEditorToLastGroupAction extends ExecuteCommandAction {
1449

B
Benjamin Pasero 已提交
1450 1451
	static readonly ID = 'workbench.action.moveEditorToLastGroup';
	static readonly LABEL = nls.localize('moveEditorToLastGroup', "Move Editor into Last Group");
1452 1453 1454 1455 1456 1457 1458

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'last', by: 'group' } as ActiveEditorMoveArguments);
1459 1460 1461
	}
}

1462
export class EditorLayoutSingleAction extends ExecuteCommandAction {
1463

B
Benjamin Pasero 已提交
1464 1465
	static readonly ID = 'workbench.action.editorLayoutSingle';
	static readonly LABEL = nls.localize('editorLayoutSingle', "Single Column Editor Layout");
1466 1467 1468 1469

	constructor(
		id: string,
		label: string,
1470
		@ICommandService commandService: ICommandService
1471
	) {
1472
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}] } as EditorGroupLayout);
1473
	}
1474
}
1475

1476
export class EditorLayoutTwoColumnsAction extends ExecuteCommandAction {
1477

B
Benjamin Pasero 已提交
1478 1479
	static readonly ID = 'workbench.action.editorLayoutTwoColumns';
	static readonly LABEL = nls.localize('editorLayoutTwoColumns', "Two Columns Editor Layout");
1480 1481 1482 1483 1484 1485 1486

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, {}], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
1487 1488 1489
	}
}

1490
export class EditorLayoutThreeColumnsAction extends ExecuteCommandAction {
1491

B
Benjamin Pasero 已提交
1492 1493
	static readonly ID = 'workbench.action.editorLayoutThreeColumns';
	static readonly LABEL = nls.localize('editorLayoutThreeColumns', "Three Columns Editor Layout");
1494 1495 1496 1497

	constructor(
		id: string,
		label: string,
1498
		@ICommandService commandService: ICommandService
1499
	) {
1500 1501 1502 1503 1504 1505
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, {}, {}], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
	}
}

export class EditorLayoutTwoRowsAction extends ExecuteCommandAction {

B
Benjamin Pasero 已提交
1506 1507
	static readonly ID = 'workbench.action.editorLayoutTwoRows';
	static readonly LABEL = nls.localize('editorLayoutTwoRows', "Two Rows Editor Layout");
1508 1509 1510 1511 1512 1513 1514

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, {}], orientation: GroupOrientation.VERTICAL } as EditorGroupLayout);
1515
	}
1516
}
1517

1518
export class EditorLayoutThreeRowsAction extends ExecuteCommandAction {
1519

B
Benjamin Pasero 已提交
1520 1521
	static readonly ID = 'workbench.action.editorLayoutThreeRows';
	static readonly LABEL = nls.localize('editorLayoutThreeRows', "Three Rows Editor Layout");
1522 1523 1524 1525 1526 1527 1528

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, {}, {}], orientation: GroupOrientation.VERTICAL } as EditorGroupLayout);
1529
	}
D
Daniel Imms 已提交
1530
}
1531

1532
export class EditorLayoutTwoByTwoGridAction extends ExecuteCommandAction {
1533

B
Benjamin Pasero 已提交
1534 1535
	static readonly ID = 'workbench.action.editorLayoutTwoByTwoGrid';
	static readonly LABEL = nls.localize('editorLayoutTwoByTwoGrid', "Grid Editor Layout (2x2)");
1536 1537 1538 1539

	constructor(
		id: string,
		label: string,
1540
		@ICommandService commandService: ICommandService
1541
	) {
1542
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{ groups: [{}, {}] }, { groups: [{}, {}] }] } as EditorGroupLayout);
1543
	}
1544
}
1545

B
Benjamin Pasero 已提交
1546
export class EditorLayoutTwoColumnsBottomAction extends ExecuteCommandAction {
1547

B
Benjamin Pasero 已提交
1548 1549
	static readonly ID = 'workbench.action.editorLayoutTwoColumnsBottom';
	static readonly LABEL = nls.localize('editorLayoutTwoColumnsBottom', "Two Columns Bottom Editor Layout");
1550 1551 1552 1553 1554 1555

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
B
Benjamin Pasero 已提交
1556
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, { groups: [{}, {}] }], orientation: GroupOrientation.VERTICAL } as EditorGroupLayout);
1557 1558 1559
	}
}

B
Benjamin Pasero 已提交
1560
export class EditorLayoutTwoRowsRightAction extends ExecuteCommandAction {
1561

B
Benjamin Pasero 已提交
1562 1563
	static readonly ID = 'workbench.action.editorLayoutTwoRowsRight';
	static readonly LABEL = nls.localize('editorLayoutTwoRowsRight', "Two Rows Right Editor Layout");
1564 1565 1566 1567

	constructor(
		id: string,
		label: string,
1568
		@ICommandService commandService: ICommandService
1569
	) {
B
Benjamin Pasero 已提交
1570
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, { groups: [{}, {}] }], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
1571
	}
1572
}
1573

1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584
export class BaseCreateEditorGroupAction extends Action {

	constructor(
		id: string,
		label: string,
		private direction: GroupDirection,
		private editorGroupService: IEditorGroupsService
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
1585
	run(): TPromise<any> {
1586 1587 1588 1589 1590 1591 1592 1593
		this.editorGroupService.addGroup(this.editorGroupService.activeGroup, this.direction, { activate: true });

		return TPromise.as(true);
	}
}

export class NewEditorGroupLeftAction extends BaseCreateEditorGroupAction {

B
Benjamin Pasero 已提交
1594 1595
	static readonly ID = 'workbench.action.newGroupLeft';
	static readonly LABEL = nls.localize('newEditorLeft', "New Editor Group to the Left");
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService editorGroupService: IEditorGroupsService
	) {
		super(id, label, GroupDirection.LEFT, editorGroupService);
	}
}

export class NewEditorGroupRightAction extends BaseCreateEditorGroupAction {

B
Benjamin Pasero 已提交
1608 1609
	static readonly ID = 'workbench.action.newGroupRight';
	static readonly LABEL = nls.localize('newEditorRight', "New Editor Group to the Right");
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService editorGroupService: IEditorGroupsService
	) {
		super(id, label, GroupDirection.RIGHT, editorGroupService);
	}
}

export class NewEditorGroupAboveAction extends BaseCreateEditorGroupAction {

B
Benjamin Pasero 已提交
1622 1623
	static readonly ID = 'workbench.action.newGroupAbove';
	static readonly LABEL = nls.localize('newEditorAbove', "New Editor Group Above");
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService editorGroupService: IEditorGroupsService
	) {
		super(id, label, GroupDirection.UP, editorGroupService);
	}
}

export class NewEditorGroupBelowAction extends BaseCreateEditorGroupAction {

B
Benjamin Pasero 已提交
1636 1637
	static readonly ID = 'workbench.action.newGroupBelow';
	static readonly LABEL = nls.localize('newEditorBelow', "New Editor Group Below");
1638 1639 1640 1641 1642 1643 1644 1645

	constructor(
		id: string,
		label: string,
		@IEditorGroupsService editorGroupService: IEditorGroupsService
	) {
		super(id, label, GroupDirection.DOWN, editorGroupService);
	}
I
isidor 已提交
1646
}