editorActions.ts 48.5 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 23
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, EditorGroupLayout, mergeAllGroups } from 'vs/workbench/browser/parts/editor/editorCommands';
import { IEditorGroupsService, IEditorGroup, GroupsArrangement, EditorsOrder, GroupLocation, GroupDirection, preferredGroupDirection, IFindGroupScope, GroupOrientation } 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 40 41 42 43 44
export class ExecuteCommandAction extends Action {

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

	public run(): TPromise<any> {
		return this.commandService.executeCommand(this.commandId, this.commandArgs);
	}
}

45
export class BaseSplitEditorGroupAction extends Action {
46

47 48 49
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
50
		clazz: string,
51
		protected direction: GroupDirection,
52
		private editorGroupService: IEditorGroupsService
53
	) {
B
Benjamin Pasero 已提交
54
		super(id, label, clazz);
E
Erich Gamma 已提交
55 56
	}

57 58 59 60 61 62 63
	public run(context?: IEditorIdentifier & { event?: Event }): TPromise<any> {
		this.splitEditor(context ? context.groupId : void 0);

		return TPromise.as(true);
	}

	protected splitEditor(groupId?: number, direction = this.direction): void {
64
		splitEditor(this.editorGroupService, direction, { groupId });
E
Erich Gamma 已提交
65 66 67
	}
}

B
Benjamin Pasero 已提交
68 69 70 71
export class SplitEditorAction extends BaseSplitEditorGroupAction {

	public static readonly ID = 'workbench.action.splitEditor';
	public static readonly LABEL = nls.localize('splitEditor', "Split Editor");
72

73 74
	private toDispose: IDisposable[] = [];

75 76 77
	constructor(
		id: string,
		label: string,
78
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
79
		@IConfigurationService private configurationService: IConfigurationService
80
	) {
B
Benjamin Pasero 已提交
81
		super(id, label, null, preferredGroupDirection(configurationService), editorGroupService);
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117

		this.updateAction();

		this.registerListeners();
	}

	private updateAction(): void {
		switch (this.direction) {
			case GroupDirection.LEFT:
				this.label = SplitEditorGroupLeftAction.LABEL;
				this.class = 'split-editor-horizontal-action';
				break;
			case GroupDirection.RIGHT:
				this.label = SplitEditorGroupRightAction.LABEL;
				this.class = 'split-editor-horizontal-action';
				break;
			case GroupDirection.UP:
				this.label = SplitEditorGroupUpAction.LABEL;
				this.class = 'split-editor-vertical-action';
				break;
			case GroupDirection.DOWN:
				this.label = SplitEditorGroupDownAction.LABEL;
				this.class = 'split-editor-vertical-action';
				break;
		}
	}

	private registerListeners(): void {
		this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => {
			if (e.affectsConfiguration('workbench.editor.openSideBySideDirection')) {
				this.direction = preferredGroupDirection(this.configurationService);
				this.updateAction();
			}
		}));
	}

118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
	public run(context?: IEditorIdentifier & { event?: Event }): TPromise<any> {
		let direction = this.direction;
		if (context && context.event instanceof MouseEvent && (context.event.altKey)) {
			direction = this.alternateGroupDirection;
		}

		this.splitEditor(context ? context.groupId : void 0, direction);

		return TPromise.as(true);
	}

	private get alternateGroupDirection(): GroupDirection {
		switch (this.direction) {
			case GroupDirection.LEFT: return GroupDirection.UP;
			case GroupDirection.RIGHT: return GroupDirection.DOWN;
			case GroupDirection.UP: return GroupDirection.LEFT;
			case GroupDirection.DOWN: return GroupDirection.RIGHT;
		}
	}

138 139 140 141
	public dispose(): void {
		super.dispose();

		this.toDispose = dispose(this.toDispose);
142 143 144 145 146 147
	}
}

export class SplitEditorGroupVerticalAction extends BaseSplitEditorGroupAction {

	public static readonly ID = 'workbench.action.splitEditorGroupVertical';
148
	public static readonly LABEL = nls.localize('splitEditorGroupVertical', "Split Editor Vertically");
149 150 151 152

	constructor(
		id: string,
		label: string,
153
		@IEditorGroupsService editorGroupService: IEditorGroupsService
154
	) {
B
Benjamin Pasero 已提交
155
		super(id, label, 'split-editor-vertical-action', GroupDirection.DOWN, editorGroupService);
156 157 158 159 160 161
	}
}

export class SplitEditorGroupHorizontalAction extends BaseSplitEditorGroupAction {

	public static readonly ID = 'workbench.action.splitEditorGroupHorizontal';
162
	public static readonly LABEL = nls.localize('splitEditorGroupHorizontal', "Split Editor Horizontally");
163 164 165 166

	constructor(
		id: string,
		label: string,
167
		@IEditorGroupsService editorGroupService: IEditorGroupsService
168
	) {
B
Benjamin Pasero 已提交
169
		super(id, label, 'split-editor-horizontal-action', GroupDirection.RIGHT, editorGroupService);
170 171 172
	}
}

173
export class SplitEditorGroupLeftAction extends ExecuteCommandAction {
174

175
	public static readonly ID = SPLIT_EDITOR_LEFT;
176
	public static readonly LABEL = nls.localize('splitEditorGroupLeft', "Split Editor Left");
177 178 179 180

	constructor(
		id: string,
		label: string,
181
		@ICommandService commandService: ICommandService
182
	) {
183
		super(id, label, SPLIT_EDITOR_LEFT, commandService);
B
Benjamin Pasero 已提交
184 185 186
	}
}

187
export class SplitEditorGroupRightAction extends ExecuteCommandAction {
B
Benjamin Pasero 已提交
188

189
	public static readonly ID = SPLIT_EDITOR_RIGHT;
190
	public static readonly LABEL = nls.localize('splitEditorGroupRight', "Split Editor Right");
B
Benjamin Pasero 已提交
191 192 193 194

	constructor(
		id: string,
		label: string,
195
		@ICommandService commandService: ICommandService
B
Benjamin Pasero 已提交
196
	) {
197
		super(id, label, SPLIT_EDITOR_RIGHT, commandService);
B
Benjamin Pasero 已提交
198 199 200
	}
}

201
export class SplitEditorGroupUpAction extends ExecuteCommandAction {
B
Benjamin Pasero 已提交
202

203
	public static readonly ID = SPLIT_EDITOR_UP;
204
	public static readonly LABEL = nls.localize('splitEditorGroupUp', "Split Editor Up");
205

B
Benjamin Pasero 已提交
206 207 208
	constructor(
		id: string,
		label: string,
209
		@ICommandService commandService: ICommandService
B
Benjamin Pasero 已提交
210
	) {
211
		super(id, label, SPLIT_EDITOR_UP, commandService);
212
	}
B
Benjamin Pasero 已提交
213
}
214

215
export class SplitEditorGroupDownAction extends ExecuteCommandAction {
216

217
	public static readonly ID = SPLIT_EDITOR_DOWN;
218
	public static readonly LABEL = nls.localize('splitEditorGroupDown', "Split Editor Down");
219

B
Benjamin Pasero 已提交
220 221 222
	constructor(
		id: string,
		label: string,
223
		@ICommandService commandService: ICommandService
B
Benjamin Pasero 已提交
224
	) {
225
		super(id, label, SPLIT_EDITOR_DOWN, commandService);
226 227 228
	}
}

229
export class JoinTwoGroupsAction extends Action {
I
initialshl 已提交
230

M
Matt Bierner 已提交
231 232
	public static readonly ID = 'workbench.action.joinTwoGroups';
	public static readonly LABEL = nls.localize('joinTwoGroups', "Join Editors of Two Groups");
I
initialshl 已提交
233 234 235 236

	constructor(
		id: string,
		label: string,
237
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
I
initialshl 已提交
238
	) {
239
		super(id, label);
I
initialshl 已提交
240 241
	}

242
	public run(context?: IEditorIdentifier): TPromise<any> {
243
		let sourceGroup: IEditorGroup;
B
Benjamin Pasero 已提交
244 245
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
I
initialshl 已提交
246
		} else {
B
Benjamin Pasero 已提交
247
			sourceGroup = this.editorGroupService.activeGroup;
I
initialshl 已提交
248 249
		}

B
Benjamin Pasero 已提交
250 251 252 253 254
		const targetGroup =
			this.editorGroupService.findGroup({ direction: GroupDirection.RIGHT }, sourceGroup) ||
			this.editorGroupService.findGroup({ direction: GroupDirection.DOWN }, sourceGroup) ||
			this.editorGroupService.findGroup({ direction: GroupDirection.UP }, sourceGroup) ||
			this.editorGroupService.findGroup({ direction: GroupDirection.LEFT }, sourceGroup);
255

B
Benjamin Pasero 已提交
256 257 258
		if (targetGroup && sourceGroup !== targetGroup) {
			this.editorGroupService.mergeGroup(sourceGroup, targetGroup);
		}
I
initialshl 已提交
259 260 261 262 263

		return TPromise.as(true);
	}
}

264 265 266 267 268 269 270 271 272 273 274 275 276 277
export class JoinAllGroupsAction extends Action {

	public static readonly ID = 'workbench.action.joinAllGroups';
	public static readonly LABEL = nls.localize('joinAllGroups', "Join Editors of All Groups");

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

	public run(context?: IEditorIdentifier): TPromise<any> {
278
		mergeAllGroups(this.editorGroupService);
279 280 281 282 283

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
284
export class NavigateBetweenGroupsAction extends Action {
285

M
Matt Bierner 已提交
286 287
	public static readonly ID = 'workbench.action.navigateEditorGroups';
	public static readonly LABEL = nls.localize('navigateEditorGroups', "Navigate Between Editor Groups");
E
Erich Gamma 已提交
288

289 290 291
	constructor(
		id: string,
		label: string,
292
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
293
	) {
E
Erich Gamma 已提交
294 295 296
		super(id, label);
	}

297
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
298 299 300
		let nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT });
		if (!nextGroup) {
			nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.FIRST });
E
Erich Gamma 已提交
301 302
		}

B
Benjamin Pasero 已提交
303
		nextGroup.focus();
304 305

		return TPromise.as(true);
E
Erich Gamma 已提交
306 307 308
	}
}

309 310
export class FocusActiveGroupAction extends Action {

M
Matt Bierner 已提交
311 312
	public static readonly ID = 'workbench.action.focusActiveEditorGroup';
	public static readonly LABEL = nls.localize('focusActiveEditorGroup', "Focus Active Editor Group");
313 314 315 316

	constructor(
		id: string,
		label: string,
317
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
318 319 320 321 322
	) {
		super(id, label);
	}

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

325
		return TPromise.as(true);
E
Erich Gamma 已提交
326 327 328
	}
}

329
export abstract class BaseFocusGroupAction extends Action {
E
Erich Gamma 已提交
330 331 332 333

	constructor(
		id: string,
		label: string,
334
		private scope: IFindGroupScope,
335
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
336 337 338 339
	) {
		super(id, label);
	}

340
	public run(): TPromise<any> {
341 342 343 344
		const group = this.editorGroupService.findGroup(this.scope);
		if (group) {
			group.focus();
		}
E
Erich Gamma 已提交
345

A
Alex Dima 已提交
346
		return TPromise.as(true);
E
Erich Gamma 已提交
347 348 349
	}
}

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
export class FocusFirstGroupAction extends BaseFocusGroupAction {

	public static readonly ID = 'workbench.action.focusFirstEditorGroup';
	public static readonly LABEL = nls.localize('focusFirstEditorGroup', "Focus First Editor Group");

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

export class FocusLastGroupAction extends BaseFocusGroupAction {
B
Benjamin Pasero 已提交
365 366 367

	public static readonly ID = 'workbench.action.focusLastEditorGroup';
	public static readonly LABEL = nls.localize('focusLastEditorGroup', "Focus Last Editor Group");
E
Erich Gamma 已提交
368 369 370 371

	constructor(
		id: string,
		label: string,
372
		@IEditorGroupsService editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
373
	) {
374
		super(id, label, { location: GroupLocation.LAST }, editorGroupService);
E
Erich Gamma 已提交
375
	}
376
}
E
Erich Gamma 已提交
377

378
export class FocusNextGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
379

380 381 382 383 384 385 386 387 388
	public static readonly ID = 'workbench.action.focusNextGroup';
	public static readonly LABEL = nls.localize('focusNextGroup', "Focus Next Editor Group");

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

392
export class FocusPreviousGroup extends BaseFocusGroupAction {
393

M
Matt Bierner 已提交
394
	public static readonly ID = 'workbench.action.focusPreviousGroup';
B
Benjamin Pasero 已提交
395
	public static readonly LABEL = nls.localize('focusPreviousGroup', "Focus Previous Editor Group");
E
Erich Gamma 已提交
396

397 398 399
	constructor(
		id: string,
		label: string,
400
		@IEditorGroupsService editorGroupService: IEditorGroupsService
401
	) {
402
		super(id, label, { location: GroupLocation.PREVIOUS }, editorGroupService);
E
Erich Gamma 已提交
403
	}
404
}
E
Erich Gamma 已提交
405

406
export class FocusLeftGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
407

408 409 410 411 412 413 414 415 416
	public static readonly ID = 'workbench.action.focusLeftGroup';
	public static readonly LABEL = nls.localize('focusLeftGroup', "Focus Left Editor Group");

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

420
export class FocusRightGroup extends BaseFocusGroupAction {
421

422 423
	public static readonly ID = 'workbench.action.focusRightGroup';
	public static readonly LABEL = nls.localize('focusRightGroup', "Focus Right Editor Group");
424

E
Erich Gamma 已提交
425 426 427
	constructor(
		id: string,
		label: string,
428
		@IEditorGroupsService editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
429
	) {
430
		super(id, label, { direction: GroupDirection.RIGHT }, editorGroupService);
E
Erich Gamma 已提交
431
	}
432
}
E
Erich Gamma 已提交
433

434
export class FocusAboveGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
435

436 437 438 439 440 441 442 443 444
	public static readonly ID = 'workbench.action.focusAboveGroup';
	public static readonly LABEL = nls.localize('focusAboveGroup', "Focus Above Editor Group");

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

448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
export class FocusBelowGroup extends BaseFocusGroupAction {

	public static readonly ID = 'workbench.action.focusBelowGroup';
	public static readonly LABEL = nls.localize('focusBelowGroup', "Focus Below Editor Group");

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


E
Erich Gamma 已提交
463 464
export class OpenToSideAction extends Action {

M
Matt Bierner 已提交
465 466
	public static readonly OPEN_TO_SIDE_ID = 'workbench.action.openToSide';
	public static readonly OPEN_TO_SIDE_LABEL = nls.localize('openToSide', "Open to the Side");
E
Erich Gamma 已提交
467

468
	constructor(
469
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
470
		@IConfigurationService private configurationService: IConfigurationService
471
	) {
E
Erich Gamma 已提交
472 473
		super(OpenToSideAction.OPEN_TO_SIDE_ID, OpenToSideAction.OPEN_TO_SIDE_LABEL);

474 475 476 477
		this.updateClass();
	}

	public updateClass(): void {
B
Benjamin Pasero 已提交
478
		const preferredDirection = preferredGroupDirection(this.configurationService);
E
Erich Gamma 已提交
479

B
Benjamin Pasero 已提交
480
		this.class = (preferredDirection === GroupDirection.LEFT || preferredDirection === GroupDirection.RIGHT) ? 'quick-open-sidebyside-vertical' : 'quick-open-sidebyside-horizontal';
E
Erich Gamma 已提交
481 482
	}

483
	public run(context: any): TPromise<any> {
B
Benjamin Pasero 已提交
484
		const entry = toEditorQuickOpenEntry(context);
E
Erich Gamma 已提交
485
		if (entry) {
486
			const input = entry.getInput();
B
Benjamin Pasero 已提交
487
			if (input instanceof EditorInput) {
B
Benjamin Pasero 已提交
488
				return this.editorService.openEditor(input, entry.getOptions(), SIDE_GROUP);
B
Benjamin Pasero 已提交
489 490
			}

491 492 493
			const resourceInput = input as IResourceInput;
			resourceInput.options = mixin(resourceInput.options, entry.getOptions());

B
Benjamin Pasero 已提交
494
			return this.editorService.openEditor(resourceInput, SIDE_GROUP);
E
Erich Gamma 已提交
495 496
		}

A
Alex Dima 已提交
497
		return TPromise.as(false);
E
Erich Gamma 已提交
498 499 500
	}
}

501
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
502 503 504

	// QuickOpenEntryGroup
	if (element instanceof QuickOpenEntryGroup) {
505
		const group = <QuickOpenEntryGroup>element;
E
Erich Gamma 已提交
506 507 508 509 510 511 512 513 514 515 516 517 518 519
		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 {
520

M
Matt Bierner 已提交
521 522
	public static readonly ID = 'workbench.action.closeActiveEditor';
	public static readonly LABEL = nls.localize('closeEditor', "Close Editor");
523

524 525 526
	constructor(
		id: string,
		label: string,
I
isidor 已提交
527
		@ICommandService private commandService: ICommandService
528
	) {
I
isidor 已提交
529
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
530 531
	}

I
isidor 已提交
532
	public run(context?: IEditorCommandsContext): TPromise<any> {
533
		return this.commandService.executeCommand(CLOSE_EDITOR_COMMAND_ID, void 0, context);
E
Erich Gamma 已提交
534 535 536
	}
}

537 538 539 540 541 542 543 544
export class CloseOneEditorAction extends Action {

	public static readonly ID = 'workbench.action.closeActiveEditor';
	public static readonly LABEL = nls.localize('closeOneEditor', "Close");

	constructor(
		id: string,
		label: string,
545
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
546 547 548 549 550
	) {
		super(id, label, 'close-editor-action');
	}

	public run(context?: IEditorCommandsContext): TPromise<any> {
551
		let group: IEditorGroup;
552 553
		let editorIndex: number;
		if (context) {
554
			group = this.editorGroupService.getGroup(context.groupId);
555

556 557
			if (group) {
				editorIndex = context.editorIndex; // only allow editor at index if group is valid
558 559 560
			}
		}

561
		if (!group) {
562
			group = this.editorGroupService.activeGroup;
563 564
		}

565 566 567 568
		// Close specific editor in group
		if (typeof editorIndex === 'number') {
			const editorAtIndex = group.getEditor(editorIndex);
			if (editorAtIndex) {
569
				return group.closeEditor(editorAtIndex);
570 571 572 573 574
			}
		}

		// Otherwise close active editor in group
		if (group.activeEditor) {
575
			return group.closeEditor(group.activeEditor);
576 577 578 579 580 581
		}

		return TPromise.as(false);
	}
}

M
misoguy 已提交
582 583
export class RevertAndCloseEditorAction extends Action {

M
Matt Bierner 已提交
584 585
	public static readonly ID = 'workbench.action.revertAndCloseActiveEditor';
	public static readonly LABEL = nls.localize('revertAndCloseActiveEditor', "Revert and Close Editor");
M
misoguy 已提交
586 587 588 589

	constructor(
		id: string,
		label: string,
590
		@IEditorService private editorService: IEditorService
M
misoguy 已提交
591 592 593 594 595
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
596
		const activeControl = this.editorService.activeControl;
B
Benjamin Pasero 已提交
597
		if (activeControl) {
B
Benjamin Pasero 已提交
598
			const editor = activeControl.input;
599
			const group = activeControl.group;
B
Benjamin Pasero 已提交
600

601
			// first try a normal revert where the contents of the editor are restored
B
Benjamin Pasero 已提交
602
			return editor.revert().then(() => group.closeEditor(editor), error => {
603 604 605 606
				// 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 已提交
607
				return editor.revert({ soft: true }).then(() => group.closeEditor(editor));
608
			});
M
misoguy 已提交
609 610 611 612 613 614
		}

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
615
export class CloseLeftEditorsInGroupAction extends Action {
616

M
Matt Bierner 已提交
617 618
	public static readonly ID = 'workbench.action.closeEditorsToTheLeft';
	public static readonly LABEL = nls.localize('closeEditorsToTheLeft', "Close Editors to the Left");
619

620 621 622
	constructor(
		id: string,
		label: string,
623
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
624
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
625
	) {
626 627 628
		super(id, label);
	}

629
	public run(context?: IEditorIdentifier): TPromise<any> {
B
Benjamin Pasero 已提交
630
		const { group, editor } = getTarget(this.editorService, this.editorGroupService, context);
B
Benjamin Pasero 已提交
631 632
		if (group && editor) {
			return group.closeEditors({ direction: CloseDirection.LEFT, except: editor });
633 634 635 636 637 638
		}

		return TPromise.as(false);
	}
}

639
function getTarget(editorService: IEditorService, editorGroupService: IEditorGroupsService, context?: IEditorIdentifier): { editor: IEditorInput, group: IEditorGroup } {
B
Benjamin Pasero 已提交
640 641 642 643 644 645 646 647
	if (context) {
		return { editor: context.editor, group: editorGroupService.getGroup(context.groupId) };
	}

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

648
export abstract class BaseCloseAllAction extends Action {
649

650 651 652
	constructor(
		id: string,
		label: string,
653 654
		clazz: string,
		private textFileService: ITextFileService
655
	) {
656
		super(id, label, clazz);
E
Erich Gamma 已提交
657 658
	}

659
	public run(): TPromise<any> {
660 661 662

		// Just close all if there are no or one dirty editor
		if (this.textFileService.getDirty().length < 2) {
663
			return this.doCloseAll();
664 665 666
		}

		// Otherwise ask for combined confirmation
667 668 669 670
		return this.textFileService.confirmSave().then(confirm => {
			if (confirm === ConfirmResult.CANCEL) {
				return void 0;
			}
671

672 673 674 675 676
			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));
677
			}
678

679 680
			return saveOrRevertPromise.then(success => {
				if (success) {
681
					return this.doCloseAll();
682 683 684 685
				}

				return void 0;
			});
686
		});
E
Erich Gamma 已提交
687
	}
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729

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

export class CloseAllEditorsAction extends BaseCloseAllAction {

	public static readonly ID = 'workbench.action.closeAllEditors';
	public static readonly LABEL = nls.localize('closeAllEditors', "Close All Editors");

	constructor(
		id: string,
		label: string,
		@ITextFileService textFileService: ITextFileService,
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
	) {
		super(id, label, 'action-close-all-files', textFileService);
	}

	protected doCloseAll(): TPromise<any> {
		return TPromise.join(this.editorGroupService.groups.map(g => g.closeAllEditors()));
	}
}

export class CloseAllEditorGroupsAction extends BaseCloseAllAction {

	public static readonly ID = 'workbench.action.closeAllEditorGroups';
	public static readonly LABEL = nls.localize('closeAllGroups', "Close All Editor Groups");

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

	protected doCloseAll(): TPromise<any> {
		return TPromise.join(this.editorGroupService.groups.map(g => g.closeAllEditors())).then(() => {
			this.editorGroupService.groups.forEach(group => this.editorGroupService.removeGroup(group));
		});
	}
E
Erich Gamma 已提交
730 731
}

732 733
export class CloseEditorsInOtherGroupsAction extends Action {

M
Matt Bierner 已提交
734 735
	public static readonly ID = 'workbench.action.closeEditorsInOtherGroups';
	public static readonly LABEL = nls.localize('closeEditorsInOtherGroups', "Close Editors in Other Groups");
736

737 738 739
	constructor(
		id: string,
		label: string,
740
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
741
	) {
742 743 744
		super(id, label);
	}

745
	public run(context?: IEditorIdentifier): TPromise<any> {
I
isidor 已提交
746 747 748 749
		const groupToSkip = context ? this.editorGroupService.getGroup(context.groupId) : this.editorGroupService.activeGroup;
		return TPromise.join(this.editorGroupService.groups.map(g => {
			if (g.id === groupToSkip.id) {
				return TPromise.as(null);
750 751
			}

I
isidor 已提交
752 753
			return g.closeAllEditors();
		}));
754 755 756
	}
}

757
export class BaseMoveGroupAction extends Action {
758

759 760 761
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
762
		private direction: GroupDirection,
763
		private editorGroupService: IEditorGroupsService
764
	) {
E
Erich Gamma 已提交
765 766 767
		super(id, label);
	}

768
	public run(context?: IEditorIdentifier): TPromise<any> {
769
		let sourceGroup: IEditorGroup;
770 771 772 773
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
		} else {
			sourceGroup = this.editorGroupService.activeGroup;
774 775
		}

B
Benjamin Pasero 已提交
776
		const targetGroup = this.editorGroupService.findGroup({ direction: this.direction }, sourceGroup);
777
		if (targetGroup) {
B
Benjamin Pasero 已提交
778
			this.editorGroupService.moveGroup(sourceGroup, targetGroup, this.direction);
E
Erich Gamma 已提交
779 780
		}

781
		return TPromise.as(true);
E
Erich Gamma 已提交
782 783 784
	}
}

785 786 787 788 789 790 791 792
export class MoveGroupLeftAction extends BaseMoveGroupAction {

	public static readonly ID = 'workbench.action.moveActiveEditorGroupLeft';
	public static readonly LABEL = nls.localize('moveActiveGroupLeft', "Move Editor Group Left");

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

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

M
Matt Bierner 已提交
801 802
	public static readonly ID = 'workbench.action.moveActiveEditorGroupRight';
	public static readonly LABEL = nls.localize('moveActiveGroupRight', "Move Editor Group Right");
803

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

813
export class MoveGroupUpAction extends BaseMoveGroupAction {
814

815 816
	public static readonly ID = 'workbench.action.moveActiveEditorGroupUp';
	public static readonly LABEL = nls.localize('moveActiveGroupUp', "Move Editor Group Up");
E
Erich Gamma 已提交
817

818 819 820
	constructor(
		id: string,
		label: string,
821
		@IEditorGroupsService editorGroupService: IEditorGroupsService
822
	) {
B
Benjamin Pasero 已提交
823
		super(id, label, GroupDirection.UP, editorGroupService);
824 825 826 827 828 829 830 831 832 833 834
	}
}

export class MoveGroupDownAction extends BaseMoveGroupAction {

	public static readonly ID = 'workbench.action.moveActiveEditorGroupDown';
	public static readonly LABEL = nls.localize('moveActiveGroupDown', "Move Editor Group Down");

	constructor(
		id: string,
		label: string,
835
		@IEditorGroupsService editorGroupService: IEditorGroupsService
836
	) {
B
Benjamin Pasero 已提交
837
		super(id, label, GroupDirection.DOWN, editorGroupService);
E
Erich Gamma 已提交
838 839 840
	}
}

841
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
842

M
Matt Bierner 已提交
843 844
	public static readonly ID = 'workbench.action.minimizeOtherEditors';
	public static readonly LABEL = nls.localize('minimizeOtherEditorGroups', "Minimize Other Editor Groups");
845

846
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
847 848 849
		super(id, label);
	}

850
	public run(): TPromise<any> {
851
		this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
852

A
Alex Dima 已提交
853
		return TPromise.as(false);
E
Erich Gamma 已提交
854 855 856
	}
}

857
export class EvenGroupWidthsAction extends Action {
E
Erich Gamma 已提交
858

M
Matt Bierner 已提交
859 860
	public static readonly ID = 'workbench.action.evenEditorWidths';
	public static readonly LABEL = nls.localize('evenEditorGroups', "Even Editor Group Widths");
861

862
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
863 864 865
		super(id, label);
	}

866
	public run(): TPromise<any> {
867
		this.editorGroupService.arrangeGroups(GroupsArrangement.EVEN);
E
Erich Gamma 已提交
868

A
Alex Dima 已提交
869
		return TPromise.as(false);
E
Erich Gamma 已提交
870 871 872
	}
}

873
export class MaximizeGroupAction extends Action {
874

M
Matt Bierner 已提交
875 876
	public static readonly ID = 'workbench.action.maximizeEditor';
	public static readonly LABEL = nls.localize('maximizeEditor', "Maximize Editor Group and Hide Sidebar");
877

878 879 880
	constructor(
		id: string,
		label: string,
881 882
		@IEditorService private editorService: IEditorService,
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
883 884 885 886 887
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

888
	public run(): TPromise<any> {
889 890 891
		if (this.editorService.activeEditor) {
			this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);

892
			return this.partService.setSideBarHidden(true);
893 894
		}

A
Alex Dima 已提交
895
		return TPromise.as(false);
896 897 898
	}
}

899 900
export abstract class BaseNavigateEditorAction extends Action {

901 902 903
	constructor(
		id: string,
		label: string,
904 905
		protected editorGroupService: IEditorGroupsService,
		protected editorService: IEditorService
906
	) {
907 908 909 910 911
		super(id, label);
	}

	public run(): TPromise<any> {
		const result = this.navigate();
912 913
		if (!result) {
			return TPromise.as(false);
914 915
		}

916 917 918 919 920 921 922
		const { groupId, editor } = result;
		if (!editor) {
			return TPromise.as(false);
		}

		const group = this.editorGroupService.getGroup(groupId);
		return group.openEditor(editor);
923 924 925 926 927 928 929
	}

	protected abstract navigate(): IEditorIdentifier;
}

export class OpenNextEditor extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
930 931
	public static readonly ID = 'workbench.action.nextEditor';
	public static readonly LABEL = nls.localize('openNextEditor', "Open Next Editor");
932

933 934 935
	constructor(
		id: string,
		label: string,
936 937
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
938 939
	) {
		super(id, label, editorGroupService, editorService);
940 941 942
	}

	protected navigate(): IEditorIdentifier {
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959

		// 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
		const nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT });
		if (nextGroup) {
			const previousGroupEditors = nextGroup.getEditors(EditorsOrder.SEQUENTIAL);
			return { editor: previousGroupEditors[0], groupId: nextGroup.id };
		}

		return void 0;
960 961 962 963 964
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
965 966
	public static readonly ID = 'workbench.action.previousEditor';
	public static readonly LABEL = nls.localize('openPreviousEditor', "Open Previous Editor");
967

968 969 970
	constructor(
		id: string,
		label: string,
971 972
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
973 974
	) {
		super(id, label, editorGroupService, editorService);
975 976 977
	}

	protected navigate(): IEditorIdentifier {
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994

		// 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
		const previousGroup = this.editorGroupService.findGroup({ location: GroupLocation.PREVIOUS });
		if (previousGroup) {
			const previousGroupEditors = previousGroup.getEditors(EditorsOrder.SEQUENTIAL);
			return { editor: previousGroupEditors[previousGroupEditors.length - 1], groupId: previousGroup.id };
		}

		return void 0;
995 996 997 998 999
	}
}

export class OpenNextEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
1000 1001
	public static readonly ID = 'workbench.action.nextEditorInGroup';
	public static readonly LABEL = nls.localize('nextEditorInGroup', "Open Next Editor in Group");
1002 1003 1004 1005

	constructor(
		id: string,
		label: string,
1006 1007
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1008 1009 1010 1011 1012
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
1013 1014 1015 1016 1017
		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 };
1018 1019 1020 1021 1022
	}
}

export class OpenPreviousEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
1023 1024
	public static readonly ID = 'workbench.action.previousEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousEditorInGroup', "Open Previous Editor in Group");
1025 1026 1027 1028

	constructor(
		id: string,
		label: string,
1029 1030
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
	) {
		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 {

	public static readonly ID = 'workbench.action.firstEditorInGroup';
	public static readonly LABEL = nls.localize('firstEditorInGroup', "Open First Editor in Group");

	constructor(
		id: string,
		label: string,
1052 1053
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1054 1055 1056 1057 1058
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
1059 1060 1061 1062
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[0], groupId: group.id };
1063
	}
B
Benjamin Pasero 已提交
1064 1065
}

1066 1067 1068 1069 1070 1071 1072 1073
export class OpenLastEditorInGroup extends BaseNavigateEditorAction {

	public static readonly ID = 'workbench.action.lastEditorInGroup';
	public static readonly LABEL = nls.localize('lastEditorInGroup', "Open Last Editor in Group");

	constructor(
		id: string,
		label: string,
1074 1075
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1076 1077 1078 1079 1080
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
1081 1082 1083 1084
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[editors.length - 1], groupId: group.id };
1085 1086 1087
	}
}

B
Benjamin Pasero 已提交
1088 1089
export class NavigateForwardAction extends Action {

M
Matt Bierner 已提交
1090 1091
	public static readonly ID = 'workbench.action.navigateForward';
	public static readonly LABEL = nls.localize('navigateNext', "Go Forward");
B
Benjamin Pasero 已提交
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105

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

	public run(): TPromise<any> {
		this.historyService.forward();

		return TPromise.as(null);
	}
}

export class NavigateBackwardsAction extends Action {

M
Matt Bierner 已提交
1106 1107
	public static readonly ID = 'workbench.action.navigateBack';
	public static readonly LABEL = nls.localize('navigatePrevious', "Go Back");
B
Benjamin Pasero 已提交
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117

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

	public run(): TPromise<any> {
		this.historyService.back();

		return TPromise.as(null);
	}
I
isidor 已提交
1118
}
1119

1120 1121
export class NavigateLastAction extends Action {

M
Matt Bierner 已提交
1122 1123
	public static readonly ID = 'workbench.action.navigateLast';
	public static readonly LABEL = nls.localize('navigateLast', "Go Last");
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135

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

	public run(): TPromise<any> {
		this.historyService.last();

		return TPromise.as(null);
	}
}

1136 1137
export class ReopenClosedEditorAction extends Action {

M
Matt Bierner 已提交
1138 1139
	public static readonly ID = 'workbench.action.reopenClosedEditor';
	public static readonly LABEL = nls.localize('reopenClosedEditor', "Reopen Closed Editor");
1140 1141 1142 1143

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1144
		@IHistoryService private historyService: IHistoryService
1145 1146 1147 1148 1149
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1150
		this.historyService.reopenLastClosedEditor();
1151 1152 1153

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
1154 1155
}

1156
export class ClearRecentFilesAction extends Action {
C
22768  
Cristian 已提交
1157

M
Matt Bierner 已提交
1158 1159
	public static readonly ID = 'workbench.action.clearRecentFiles';
	public static readonly LABEL = nls.localize('clearRecentFiles', "Clear Recently Opened");
C
22768  
Cristian 已提交
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169

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

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
1170
		this.windowsService.clearRecentlyOpened();
C
22768  
Cristian 已提交
1171 1172 1173 1174 1175

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
1176
export class ShowEditorsInActiveGroupAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
1177

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

1181 1182 1183
	constructor(
		actionId: string,
		actionLabel: string,
1184
		@IQuickOpenService quickOpenService: IQuickOpenService
1185
	) {
B
Benjamin Pasero 已提交
1186
		super(actionId, actionLabel, NAVIGATE_IN_ACTIVE_GROUP_PREFIX, quickOpenService);
1187
	}
B
Benjamin Pasero 已提交
1188 1189
}

B
Benjamin Pasero 已提交
1190 1191
export class ShowAllEditorsAction extends QuickOpenAction {

M
Matt Bierner 已提交
1192 1193
	public static readonly ID = 'workbench.action.showAllEditors';
	public static readonly LABEL = nls.localize('showAllEditors', "Show All Editors");
B
Benjamin Pasero 已提交
1194 1195 1196 1197 1198 1199

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

1200
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1201 1202 1203 1204 1205

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1206
		@IKeybindingService private keybindingService: IKeybindingService
B
Benjamin Pasero 已提交
1207 1208 1209 1210 1211
	) {
		super(id, label);
	}

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

1214

B
Benjamin Pasero 已提交
1215 1216

		this.quickOpenService.show(NAVIGATE_IN_ACTIVE_GROUP_PREFIX, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1217 1218 1219 1220 1221

		return TPromise.as(true);
	}
}

1222 1223
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1224 1225
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditorInGroup', "Open Previous Recently Used Editor in Group");
1226 1227 1228 1229 1230

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1231
		@IKeybindingService keybindingService: IKeybindingService
1232
	) {
B
Benjamin Pasero 已提交
1233
		super(id, label, quickOpenService, keybindingService);
1234 1235 1236 1237 1238
	}
}

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1239 1240
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditorInGroup', "Open Next Recently Used Editor in Group");
1241 1242 1243 1244 1245

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1246
		@IKeybindingService keybindingService: IKeybindingService
1247
	) {
B
Benjamin Pasero 已提交
1248
		super(id, label, quickOpenService, keybindingService);
1249 1250 1251
	}
}

1252
export class OpenPreviousEditorFromHistoryAction extends Action {
B
Benjamin Pasero 已提交
1253

M
Matt Bierner 已提交
1254 1255
	public static readonly ID = 'workbench.action.openPreviousEditorFromHistory';
	public static readonly LABEL = nls.localize('navigateEditorHistoryByInput', "Open Previous Editor from History");
B
Benjamin Pasero 已提交
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266

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

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

B
Benjamin Pasero 已提交
1269
		this.quickOpenService.show(null, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1270 1271 1272 1273 1274

		return TPromise.as(true);
	}
}

1275 1276
export class OpenNextRecentlyUsedEditorAction extends Action {

M
Matt Bierner 已提交
1277 1278
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditor', "Open Next Recently Used Editor");
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292

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

	public run(): TPromise<any> {
		this.historyService.forward(true);

		return TPromise.as(null);
	}
}

export class OpenPreviousRecentlyUsedEditorAction extends Action {

M
Matt Bierner 已提交
1293 1294
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditor', "Open Previous Recently Used Editor");
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306

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

	public run(): TPromise<any> {
		this.historyService.back(true);

		return TPromise.as(null);
	}
}

1307 1308
export class ClearEditorHistoryAction extends Action {

M
Matt Bierner 已提交
1309 1310
	public static readonly ID = 'workbench.action.clearEditorHistory';
	public static readonly LABEL = nls.localize('clearEditorHistory', "Clear Editor History");
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321

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

	public run(): TPromise<any> {

1322
		// Editor history
1323 1324 1325 1326 1327 1328
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1329
export class MoveEditorLeftInGroupAction extends ExecuteCommandAction {
1330

M
Matt Bierner 已提交
1331 1332
	public static readonly ID = 'workbench.action.moveEditorLeftInGroup';
	public static readonly LABEL = nls.localize('moveEditorLeft', "Move Editor Left");
1333 1334 1335 1336

	constructor(
		id: string,
		label: string,
1337
		@ICommandService commandService: ICommandService
1338
	) {
1339
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'left' } as ActiveEditorMoveArguments);
1340 1341 1342
	}
}

1343
export class MoveEditorRightInGroupAction extends ExecuteCommandAction {
1344

M
Matt Bierner 已提交
1345 1346
	public static readonly ID = 'workbench.action.moveEditorRightInGroup';
	public static readonly LABEL = nls.localize('moveEditorRight', "Move Editor Right");
1347 1348 1349 1350

	constructor(
		id: string,
		label: string,
1351
		@ICommandService commandService: ICommandService
1352
	) {
1353
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'right' } as ActiveEditorMoveArguments);
1354 1355 1356
	}
}

1357
export class MoveEditorToPreviousGroupAction extends ExecuteCommandAction {
1358

M
Matt Bierner 已提交
1359 1360
	public static readonly ID = 'workbench.action.moveEditorToPreviousGroup';
	public static readonly LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
1361 1362 1363 1364

	constructor(
		id: string,
		label: string,
1365
		@ICommandService commandService: ICommandService
1366
	) {
1367
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'previous', by: 'group' } as ActiveEditorMoveArguments);
1368
	}
1369
}
1370

1371
export class MoveEditorToNextGroupAction extends ExecuteCommandAction {
1372

1373 1374 1375 1376 1377 1378 1379 1380 1381
	public static readonly ID = 'workbench.action.moveEditorToNextGroup';
	public static readonly LABEL = nls.localize('moveEditorToNextGroup', "Move Editor into Next Group");

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'next', by: 'group' } as ActiveEditorMoveArguments);
1382 1383 1384
	}
}

1385
export class MoveEditorToAboveGroupAction extends ExecuteCommandAction {
1386

1387 1388
	public static readonly ID = 'workbench.action.moveEditorToAboveGroup';
	public static readonly LABEL = nls.localize('moveEditorToAboveGroup', "Move Editor into Above Group");
1389 1390 1391 1392

	constructor(
		id: string,
		label: string,
1393
		@ICommandService commandService: ICommandService
1394
	) {
1395
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'up', by: 'group' } as ActiveEditorMoveArguments);
1396
	}
1397
}
1398

1399
export class MoveEditorToBelowGroupAction extends ExecuteCommandAction {
1400

1401 1402 1403 1404 1405 1406 1407 1408 1409
	public static readonly ID = 'workbench.action.moveEditorToBelowGroup';
	public static readonly LABEL = nls.localize('moveEditorToBelowGroup', "Move Editor into Below Group");

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'down', by: 'group' } as ActiveEditorMoveArguments);
1410 1411 1412
	}
}

1413
export class MoveEditorToLeftGroupAction extends ExecuteCommandAction {
1414

1415 1416
	public static readonly ID = 'workbench.action.moveEditorToLeftGroup';
	public static readonly LABEL = nls.localize('moveEditorToLeftGroup', "Move Editor into Left Group");
1417 1418 1419 1420

	constructor(
		id: string,
		label: string,
1421
		@ICommandService commandService: ICommandService
1422
	) {
1423
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'left', by: 'group' } as ActiveEditorMoveArguments);
1424
	}
1425
}
1426

1427
export class MoveEditorToRightGroupAction extends ExecuteCommandAction {
1428

1429 1430 1431 1432 1433 1434 1435 1436 1437
	public static readonly ID = 'workbench.action.moveEditorToRightGroup';
	public static readonly LABEL = nls.localize('moveEditorToRightGroup', "Move Editor into Right Group");

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'right', by: 'group' } as ActiveEditorMoveArguments);
1438 1439 1440
	}
}

1441
export class MoveEditorToFirstGroupAction extends ExecuteCommandAction {
1442

1443 1444
	public static readonly ID = 'workbench.action.moveEditorToFirstGroup';
	public static readonly LABEL = nls.localize('moveEditorToFirstGroup', "Move Editor into First Group");
1445 1446 1447 1448

	constructor(
		id: string,
		label: string,
1449
		@ICommandService commandService: ICommandService
1450
	) {
1451
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'first', by: 'group' } as ActiveEditorMoveArguments);
1452
	}
1453
}
1454

1455
export class MoveEditorToLastGroupAction extends ExecuteCommandAction {
1456

1457 1458 1459 1460 1461 1462 1463 1464 1465
	public static readonly ID = 'workbench.action.moveEditorToLastGroup';
	public static readonly LABEL = nls.localize('moveEditorToLastGroup', "Move Editor into Last Group");

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'last', by: 'group' } as ActiveEditorMoveArguments);
1466 1467 1468
	}
}

1469
export class EditorLayoutSingleAction extends ExecuteCommandAction {
1470

1471 1472
	public static readonly ID = 'workbench.action.editorLayoutSingle';
	public static readonly LABEL = nls.localize('editorLayoutSingle', "Single Column Editor Layout");
1473 1474 1475 1476

	constructor(
		id: string,
		label: string,
1477
		@ICommandService commandService: ICommandService
1478
	) {
1479
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}] } as EditorGroupLayout);
1480
	}
1481
}
1482

1483
export class EditorLayoutTwoColumnsAction extends ExecuteCommandAction {
1484

1485 1486 1487 1488 1489 1490 1491 1492 1493
	public static readonly ID = 'workbench.action.editorLayoutTwoColumns';
	public static readonly LABEL = nls.localize('editorLayoutTwoColumns', "Two Columns Editor Layout");

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

1497
export class EditorLayoutThreeColumnsAction extends ExecuteCommandAction {
1498

1499 1500
	public static readonly ID = 'workbench.action.editorLayoutThreeColumns';
	public static readonly LABEL = nls.localize('editorLayoutThreeColumns', "Three Columns Editor Layout");
1501 1502 1503 1504

	constructor(
		id: string,
		label: string,
1505
		@ICommandService commandService: ICommandService
1506
	) {
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, {}, {}], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
	}
}

export class EditorLayoutTwoRowsAction extends ExecuteCommandAction {

	public static readonly ID = 'workbench.action.editorLayoutTwoRows';
	public static readonly LABEL = nls.localize('editorLayoutTwoRows', "Two Rows Editor Layout");

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

1525
export class EditorLayoutThreeRowsAction extends ExecuteCommandAction {
1526

1527 1528 1529 1530 1531 1532 1533 1534 1535
	public static readonly ID = 'workbench.action.editorLayoutThreeRows';
	public static readonly LABEL = nls.localize('editorLayoutThreeRows', "Three Rows Editor Layout");

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

1539
export class EditorLayoutTwoByTwoGridAction extends ExecuteCommandAction {
1540

1541 1542
	public static readonly ID = 'workbench.action.editorLayoutTwoByTwoGrid';
	public static readonly LABEL = nls.localize('editorLayoutTwoByTwoGrid', "Grid Editor Layout (2x2)");
1543 1544 1545 1546

	constructor(
		id: string,
		label: string,
1547
		@ICommandService commandService: ICommandService
1548
	) {
1549
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{ groups: [{}, {}] }, { groups: [{}, {}] }] } as EditorGroupLayout);
1550
	}
1551
}
1552

B
Benjamin Pasero 已提交
1553
export class EditorLayoutTwoColumnsBottomAction extends ExecuteCommandAction {
1554

B
Benjamin Pasero 已提交
1555 1556
	public static readonly ID = 'workbench.action.editorLayoutTwoColumnsBottom';
	public static readonly LABEL = nls.localize('editorLayoutTwoColumnsBottom', "Two Columns Bottom Editor Layout");
1557 1558 1559 1560 1561 1562

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
B
Benjamin Pasero 已提交
1563
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, { groups: [{}, {}] }], orientation: GroupOrientation.VERTICAL } as EditorGroupLayout);
1564 1565 1566
	}
}

B
Benjamin Pasero 已提交
1567
export class EditorLayoutTwoColumnsRightAction extends ExecuteCommandAction {
1568

B
Benjamin Pasero 已提交
1569 1570
	public static readonly ID = 'workbench.action.editorLayoutTwoColumnsRight';
	public static readonly LABEL = nls.localize('editorLayoutTwoColumnsRight', "Two Columns Right Editor Layout");
1571 1572 1573 1574

	constructor(
		id: string,
		label: string,
1575
		@ICommandService commandService: ICommandService
1576
	) {
B
Benjamin Pasero 已提交
1577
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, { groups: [{}, {}] }], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
1578
	}
1579
}
1580

1581
export class EditorLayoutGoldenRatioAction extends ExecuteCommandAction {
1582

1583 1584 1585 1586 1587 1588 1589 1590 1591
	public static readonly ID = 'workbench.action.editorLayoutGoldenRatio';
	public static readonly LABEL = nls.localize('editorLayoutGoldenRatio', "Golden Ratio Editor Layout");

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{ size: 0.618 }, { size: 0.382, groups: [{ size: 0.618 }, { size: 0.382 }] }], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
1592
	}
1593
}