editorActions.ts 46.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';
11
import { getCodeEditor } from 'vs/editor/browser/services/codeEditorService';
B
Benjamin Pasero 已提交
12
import { EditorInput, TextEditorOptions, EditorOptions, IEditorIdentifier, ActiveEditorMoveArguments, ActiveEditorMovePositioning, EditorCommands, ConfirmResult, IEditorCommandsContext } from 'vs/workbench/common/editor';
J
Johannes Rieken 已提交
13 14 15
import { QuickOpenEntryGroup } from 'vs/base/parts/quickopen/browser/quickOpenModel';
import { EditorQuickOpenEntry, EditorQuickOpenEntryGroup, IEditorQuickOpenEntry, QuickOpenAction } from 'vs/workbench/browser/quickopen';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
J
Johannes Rieken 已提交
16
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
J
Johannes Rieken 已提交
17
import { IPartService } from 'vs/workbench/services/part/common/partService';
B
Benjamin Pasero 已提交
18
import { Position, IEditor, Direction, IResourceInput, IEditorInput, POSITIONS } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
19 20 21 22
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IEditorGroupService, GroupArrangement } from 'vs/workbench/services/group/common/groupService';
import { ICommandService } from 'vs/platform/commands/common/commands';
23
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
C
22768  
Cristian 已提交
24
import { IWindowsService } from 'vs/platform/windows/common/windows';
25
import { CLOSE_EDITOR_COMMAND_ID, NAVIGATE_IN_GROUP_ONE_PREFIX, NAVIGATE_ALL_EDITORS_GROUP_PREFIX, NAVIGATE_IN_GROUP_THREE_PREFIX, NAVIGATE_IN_GROUP_TWO_PREFIX } from 'vs/workbench/browser/parts/editor/editorCommands';
26
import { INextEditorGroupsService, GroupDirection as SplitDirection, INextEditorGroup } from 'vs/workbench/services/editor/common/nextEditorGroupsService';
E
Erich Gamma 已提交
27

28
// TODo@grid this action should be removed in favour of the split vertical/horizontal actions
E
Erich Gamma 已提交
29 30
export class SplitEditorAction extends Action {

M
Matt Bierner 已提交
31 32
	public static readonly ID = 'workbench.action.splitEditor';
	public static readonly LABEL = nls.localize('splitEditor', "Split Editor");
33

34 35 36 37 38 39
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private editorGroupService: IEditorGroupService
	) {
I
isidor 已提交
40
		super(id, label, 'split-editor-action');
E
Erich Gamma 已提交
41 42
	}

B
Benjamin Pasero 已提交
43
	public run(context?: IEditorCommandsContext): TPromise<any> {
44 45
		let editorToSplit: IEditor;
		if (context) {
B
Benjamin Pasero 已提交
46 47
			const stacks = this.editorGroupService.getStacksModel();
			editorToSplit = this.editorService.getVisibleEditors()[stacks.positionOfGroup(stacks.getGroup(context.groupId))];
48 49 50
		} else {
			editorToSplit = this.editorService.getActiveEditor();
		}
E
Erich Gamma 已提交
51

52 53
		// Can only split with target editor
		if (!editorToSplit) {
A
Alex Dima 已提交
54
			return TPromise.as(true);
E
Erich Gamma 已提交
55 56 57
		}

		// Return if the editor to split does not support split editing
58
		if (editorToSplit.input instanceof EditorInput && !(<EditorInput>editorToSplit.input).supportsSplitEditor()) {
A
Alex Dima 已提交
59
			return TPromise.as(true);
E
Erich Gamma 已提交
60 61
		}

62 63
		// Options
		let options: EditorOptions;
S
Sandeep Somavarapu 已提交
64 65
		const codeEditor = getCodeEditor(editorToSplit);
		if (codeEditor) {
66
			options = TextEditorOptions.fromEditor(codeEditor);
67 68 69 70 71
		} else {
			options = new EditorOptions();
		}
		options.pinned = true;

E
Erich Gamma 已提交
72
		// Count editors
73 74
		const visibleEditors = this.editorService.getVisibleEditors();
		const editorCount = visibleEditors.length;
E
Erich Gamma 已提交
75 76 77 78
		let targetPosition: Position;

		switch (editorCount) {

B
Benjamin Pasero 已提交
79
			// Open split editor to the right/bottom of left/top one
E
Erich Gamma 已提交
80
			case 1:
81
				targetPosition = Position.TWO;
E
Erich Gamma 已提交
82 83 84 85 86
				break;

			// Special case two editors opened
			case 2:

B
Benjamin Pasero 已提交
87
				// Continue splitting to the right/bottom
88 89
				if (editorToSplit.position === Position.TWO) {
					targetPosition = Position.THREE;
E
Erich Gamma 已提交
90 91
				}

92
				// Push the second group to the right/bottom to make room for the splitted input
93
				else if (editorToSplit.position === Position.ONE) {
E
Erich Gamma 已提交
94 95
					options.preserveFocus = true;

96 97 98
					return this.editorService.openEditor(editorToSplit.input, options, Position.THREE).then(() => {
						this.editorGroupService.moveGroup(Position.THREE, Position.TWO);
						this.editorGroupService.focusGroup(Position.TWO);
E
Erich Gamma 已提交
99 100 101 102
					});
				}
		}

103 104
		// Only split if we have a target position to split to
		if (typeof targetPosition === 'number') {
105
			return this.editorService.openEditor(editorToSplit.input, options, targetPosition);
E
Erich Gamma 已提交
106 107
		}

A
Alex Dima 已提交
108
		return TPromise.as(true);
E
Erich Gamma 已提交
109 110 111
	}
}

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
export class BaseSplitEditorGroupAction extends Action {

	constructor(
		id: string,
		label: string,
		clazz: string,
		private direction: SplitDirection,
		private nextEditorGroupsService: INextEditorGroupsService
	) {
		super(id, label, clazz);
	}

	public run(context?: IEditorIdentifier): TPromise<any> {
		let group: INextEditorGroup;
		if (context && context.group) {
			group = this.nextEditorGroupsService.getGroup(context.group.id);
		}

		if (!group) {
			group = this.nextEditorGroupsService.activeGroup;
		}

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
		const activeEditor = group.activeEditor;
		if (!activeEditor) {
			return TPromise.as(false);
		}

		if (activeEditor instanceof EditorInput && !activeEditor.supportsSplitEditor()) {
			return TPromise.as(false);
		}

		// Add group
		const newGroup = this.nextEditorGroupsService.addGroup(group, this.direction);

		// Open editor
		let options: EditorOptions;
		const codeEditor = getCodeEditor(group.activeControl);
		if (codeEditor) {
			options = TextEditorOptions.fromEditor(codeEditor);
		} else {
			options = new EditorOptions();
		}
		options.pinned = true;
155

156
		newGroup.openEditor(activeEditor, options);
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189

		return TPromise.as(true);
	}
}

export class SplitEditorGroupVerticalAction extends BaseSplitEditorGroupAction {

	public static readonly ID = 'workbench.action.splitEditorGroupVertical';
	public static readonly LABEL = nls.localize('splitEditorGroupVertical', "Split Editor Group Vertically");

	constructor(
		id: string,
		label: string,
		@INextEditorGroupsService nextEditorGroupsService: INextEditorGroupsService
	) {
		super(id, label, 'split-editor-vertical-action', SplitDirection.DOWN, nextEditorGroupsService);
	}
}

export class SplitEditorGroupHorizontalAction extends BaseSplitEditorGroupAction {

	public static readonly ID = 'workbench.action.splitEditorGroupHorizontal';
	public static readonly LABEL = nls.localize('splitEditorGroupHorizontal', "Split Editor Group Horizontally");

	constructor(
		id: string,
		label: string,
		@INextEditorGroupsService nextEditorGroupsService: INextEditorGroupsService
	) {
		super(id, label, 'split-editor-horizontal-action', SplitDirection.RIGHT, nextEditorGroupsService);
	}
}

190
export class JoinTwoGroupsAction extends Action {
I
initialshl 已提交
191

M
Matt Bierner 已提交
192 193
	public static readonly ID = 'workbench.action.joinTwoGroups';
	public static readonly LABEL = nls.localize('joinTwoGroups', "Join Editors of Two Groups");
I
initialshl 已提交
194 195 196 197 198 199

	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService
	) {
200
		super(id, label);
I
initialshl 已提交
201 202
	}

203
	public run(context?: IEditorIdentifier): TPromise<any> {
I
initialshl 已提交
204

205
		const editorStacksModel = this.editorGroupService.getStacksModel();
I
initialshl 已提交
206 207

		// Return if has no other group to join to
208
		if (editorStacksModel.groups.length < 2) {
I
initialshl 已提交
209 210 211
			return TPromise.as(true);
		}

212 213 214 215 216 217 218 219 220
		let fromPosition: number;
		let toPosition: number;

		// Joining group is from context, or the active group
		if (context) {
			fromPosition = editorStacksModel.positionOfGroup(context.group);
		} else {
			fromPosition = editorStacksModel.positionOfGroup(editorStacksModel.activeGroup);
		}
I
initialshl 已提交
221

222 223 224
		// Target group is next group if joining from position one, otherwise it is the previous group
		if (fromPosition === Position.ONE) {
			toPosition = fromPosition + 1;
I
initialshl 已提交
225
		} else {
226
			toPosition = fromPosition - 1;
I
initialshl 已提交
227 228
		}

229 230
		const fromGroup = editorStacksModel.groupAt(fromPosition);
		const toGroup = editorStacksModel.groupAt(toPosition);
I
initialshl 已提交
231

232 233
		const activeEditor = fromGroup.activeEditor;
		const fromGroupEditors = fromGroup.getEditors();
I
initialshl 已提交
234

235 236 237 238 239 240 241 242 243 244 245
		// Insert the editors to the start if moving to the next group, otherwise insert to the end
		// If an editor exists in both groups, its index is respected as in the joining group
		const movingToNextGroup = fromPosition < toPosition;
		let index = movingToNextGroup ? 0 : toGroup.count;

		// Inactive and preserve focus options are used to prevent unnecessary switchings of active editor or group
		fromGroupEditors.forEach(e => {
			const inactive = e !== activeEditor;
			this.editorGroupService.moveEditor(e, fromPosition, toPosition, { index, inactive, preserveFocus: inactive });
			index = movingToNextGroup ? index + 1 : toGroup.count;
		});
I
initialshl 已提交
246

247 248
		// Focus may be lost when the joining group is closed, regain focus on the target group
		this.editorGroupService.focusGroup(toGroup);
I
initialshl 已提交
249 250 251 252 253

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
254
export class NavigateBetweenGroupsAction extends Action {
255

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

259 260 261 262 263 264
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private editorGroupService: IEditorGroupService
	) {
E
Erich Gamma 已提交
265 266 267
		super(id, label);
	}

268
	public run(): TPromise<any> {
E
Erich Gamma 已提交
269 270

		// Can cycle split with active editor
271
		const activeEditor = this.editorService.getActiveEditor();
E
Erich Gamma 已提交
272
		if (!activeEditor) {
A
Alex Dima 已提交
273
			return TPromise.as(false);
E
Erich Gamma 已提交
274 275
		}

B
Benjamin Pasero 已提交
276
		// Cycle to the left/top and use module to start at 0 again
277 278 279
		const visibleEditors = this.editorService.getVisibleEditors();
		const editorCount = visibleEditors.length;
		const newIndex = (activeEditor.position + 1) % editorCount;
E
Erich Gamma 已提交
280

281
		this.editorGroupService.focusGroup(<Position>newIndex);
282 283

		return TPromise.as(true);
E
Erich Gamma 已提交
284 285 286
	}
}

287 288
export class FocusActiveGroupAction extends Action {

M
Matt Bierner 已提交
289 290
	public static readonly ID = 'workbench.action.focusActiveEditorGroup';
	public static readonly LABEL = nls.localize('focusActiveEditorGroup', "Focus Active Editor Group");
291 292 293 294 295 296 297 298 299 300

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
B
hygiene  
Benjamin Pasero 已提交
301 302
		const activeEditor = this.editorService.getActiveEditor();
		if (activeEditor) {
D
Daniel Imms 已提交
303
			activeEditor.focus();
B
hygiene  
Benjamin Pasero 已提交
304
		}
D
Daniel Imms 已提交
305

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

310 311
export class FocusFirstGroupAction extends Action {

M
Matt Bierner 已提交
312 313
	public static readonly ID = 'workbench.action.focusFirstEditorGroup';
	public static readonly LABEL = nls.localize('focusFirstEditorGroup', "Focus First Editor Group");
E
Erich Gamma 已提交
314 315 316 317 318

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
319
		@IEditorGroupService private editorGroupService: IEditorGroupService,
320
		@IHistoryService private historyService: IHistoryService
E
Erich Gamma 已提交
321 322 323 324
	) {
		super(id, label);
	}

325
	public run(): TPromise<any> {
E
Erich Gamma 已提交
326

B
Benjamin Pasero 已提交
327
		// Find left/top editor and focus it
328
		const editors = this.editorService.getVisibleEditors();
B
Benjamin Pasero 已提交
329
		for (let editor of editors) {
330 331
			if (editor.position === Position.ONE) {
				this.editorGroupService.focusGroup(Position.ONE);
332 333

				return TPromise.as(true);
E
Erich Gamma 已提交
334 335 336 337
			}
		}

		// Since no editor is currently opened, try to open last history entry to the target side
338
		const history = this.historyService.getHistory();
339 340
		if (history.length > 0) {
			const input = history[0];
341
			if (input instanceof EditorInput) {
342
				return this.editorService.openEditor(input, null, Position.ONE);
E
Erich Gamma 已提交
343
			}
344 345

			return this.editorService.openEditor(input as IResourceInput, Position.ONE);
E
Erich Gamma 已提交
346 347
		}

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

352
export abstract class BaseFocusSideGroupAction extends Action {
E
Erich Gamma 已提交
353 354 355 356 357

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
358
		@IEditorGroupService private editorGroupService: IEditorGroupService,
359
		@IHistoryService private historyService: IHistoryService
E
Erich Gamma 已提交
360 361 362 363 364 365 366 367
	) {
		super(id, label);
	}

	protected abstract getReferenceEditorSide(): Position;

	protected abstract getTargetEditorSide(): Position;

368
	public run(): TPromise<any> {
E
Erich Gamma 已提交
369 370

		// Require at least the reference editor to be visible
371
		const editors = this.editorService.getVisibleEditors();
E
Erich Gamma 已提交
372 373
		let referenceEditor: IEditor;
		for (let i = 0; i < editors.length; i++) {
374
			const editor = editors[i];
E
Erich Gamma 已提交
375 376 377

			// Target editor exists so focus it
			if (editor.position === this.getTargetEditorSide()) {
378
				this.editorGroupService.focusGroup(editor.position);
379 380

				return TPromise.as(true);
E
Erich Gamma 已提交
381 382 383 384 385 386 387 388 389
			}

			// Remember reference editor
			if (editor.position === this.getReferenceEditorSide()) {
				referenceEditor = editor;
			}
		}

		// Require the reference editor to be visible and supporting split editor
390
		if (referenceEditor && (<EditorInput>referenceEditor.input).supportsSplitEditor()) {
391 392 393

			// Options
			let options: EditorOptions;
S
Sandeep Somavarapu 已提交
394 395
			const codeEditor = getCodeEditor(referenceEditor);
			if (codeEditor) {
396
				options = TextEditorOptions.fromEditor(codeEditor, { pinned: true });
397 398
			} else {
				options = EditorOptions.create({ pinned: true });
399 400 401
			}

			return this.editorService.openEditor(referenceEditor.input, options, this.getTargetEditorSide());
E
Erich Gamma 已提交
402 403 404 405
		}

		// Otherwise try to find a history entry to open to the target editor side
		else if (referenceEditor) {
406
			const history = this.historyService.getHistory();
B
Benjamin Pasero 已提交
407
			for (let input of history) {
B
Benjamin Pasero 已提交
408 409 410 411 412 413
				if (input instanceof EditorInput) {
					if (input.supportsSplitEditor()) {
						return this.editorService.openEditor(input, { pinned: true }, this.getTargetEditorSide());
					}
				} else {
					return this.editorService.openEditor({ resource: (input as IResourceInput).resource, options: { pinned: true } }, this.getTargetEditorSide());
E
Erich Gamma 已提交
414 415 416 417
				}
			}
		}

A
Alex Dima 已提交
418
		return TPromise.as(true);
E
Erich Gamma 已提交
419 420 421
	}
}

422 423
export class FocusSecondGroupAction extends BaseFocusSideGroupAction {

M
Matt Bierner 已提交
424 425
	public static readonly ID = 'workbench.action.focusSecondEditorGroup';
	public static readonly LABEL = nls.localize('focusSecondEditorGroup', "Focus Second Editor Group");
E
Erich Gamma 已提交
426 427 428 429 430

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService,
431
		@IEditorGroupService editorGroupService: IEditorGroupService,
432
		@IHistoryService historyService: IHistoryService
E
Erich Gamma 已提交
433
	) {
434
		super(id, label, editorService, editorGroupService, historyService);
E
Erich Gamma 已提交
435 436 437
	}

	protected getReferenceEditorSide(): Position {
438
		return Position.ONE;
E
Erich Gamma 已提交
439 440 441
	}

	protected getTargetEditorSide(): Position {
442
		return Position.TWO;
E
Erich Gamma 已提交
443 444 445
	}
}

446 447
export class FocusThirdGroupAction extends BaseFocusSideGroupAction {

M
Matt Bierner 已提交
448 449
	public static readonly ID = 'workbench.action.focusThirdEditorGroup';
	public static readonly LABEL = nls.localize('focusThirdEditorGroup', "Focus Third Editor Group");
E
Erich Gamma 已提交
450 451 452 453 454

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService,
455
		@IEditorGroupService editorGroupService: IEditorGroupService,
456
		@IHistoryService historyService: IHistoryService
E
Erich Gamma 已提交
457
	) {
458
		super(id, label, editorService, editorGroupService, historyService);
E
Erich Gamma 已提交
459 460 461
	}

	protected getReferenceEditorSide(): Position {
462
		return Position.TWO;
E
Erich Gamma 已提交
463 464 465
	}

	protected getTargetEditorSide(): Position {
466
		return Position.THREE;
E
Erich Gamma 已提交
467 468 469
	}
}

B
Benjamin Pasero 已提交
470
export class FocusPreviousGroup extends Action {
471

M
Matt Bierner 已提交
472 473
	public static readonly ID = 'workbench.action.focusPreviousGroup';
	public static readonly LABEL = nls.localize('focusPreviousGroup', "Focus Previous Group");
E
Erich Gamma 已提交
474

475 476 477 478 479 480
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
481 482 483
		super(id, label);
	}

484
	public run(): TPromise<any> {
E
Erich Gamma 已提交
485 486

		// Require an active editor
487
		const activeEditor = this.editorService.getActiveEditor();
E
Erich Gamma 已提交
488
		if (!activeEditor) {
A
Alex Dima 已提交
489
			return TPromise.as(true);
E
Erich Gamma 已提交
490 491
		}

492 493
		const stacks = this.editorGroupService.getStacksModel();
		const groupCount = stacks.groups.length;
E
Erich Gamma 已提交
494

495 496 497
		// Nothing to do if the only group
		if (groupCount === 1) {
			return TPromise.as(true);
E
Erich Gamma 已提交
498 499
		}

500 501 502
		// Nevigate to the previous group or to the last group if the first group is active
		const newPositionIndex = (activeEditor.position + groupCount - 1) % groupCount;
		this.editorGroupService.focusGroup(<Position>newPositionIndex);
503 504

		return TPromise.as(true);
E
Erich Gamma 已提交
505 506 507
	}
}

B
Benjamin Pasero 已提交
508
export class FocusNextGroup extends Action {
509

M
Matt Bierner 已提交
510 511
	public static readonly ID = 'workbench.action.focusNextGroup';
	public static readonly LABEL = nls.localize('focusNextGroup', "Focus Next Group");
512

E
Erich Gamma 已提交
513 514 515
	constructor(
		id: string,
		label: string,
516 517
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
E
Erich Gamma 已提交
518 519 520 521
	) {
		super(id, label);
	}

522
	public run(event?: any): TPromise<any> {
E
Erich Gamma 已提交
523

524
		const activeEditor = this.editorService.getActiveEditor();
525

526 527
		if (!activeEditor) {
			return TPromise.as(true);
E
Erich Gamma 已提交
528 529
		}

530 531 532 533 534 535
		const stacks = this.editorGroupService.getStacksModel();
		const groupCount = stacks.groups.length;

		// Nowhere to switch if the only group
		if (groupCount === 1) {
			return TPromise.as(true);
E
Erich Gamma 已提交
536 537
		}

538 539 540 541
		// Nevigate to the next group or to the first group if the last group is active
		const newPositionIndex = (activeEditor.position + 1) % groupCount;
		this.editorGroupService.focusGroup(<Position>newPositionIndex);

A
Alex Dima 已提交
542
		return TPromise.as(true);
E
Erich Gamma 已提交
543 544 545 546 547
	}
}

export class OpenToSideAction extends Action {

M
Matt Bierner 已提交
548 549
	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 已提交
550

551 552
	constructor(
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
553
		@IEditorGroupService private editorGroupService: IEditorGroupService
554
	) {
E
Erich Gamma 已提交
555 556 557
		super(OpenToSideAction.OPEN_TO_SIDE_ID, OpenToSideAction.OPEN_TO_SIDE_LABEL);

		this.updateEnablement();
558 559 560 561
		this.updateClass();
	}

	public updateClass(): void {
562
		const editorGroupLayoutVertical = (this.editorGroupService.getGroupOrientation() !== 'horizontal');
563

564
		this.class = editorGroupLayoutVertical ? 'quick-open-sidebyside-vertical' : 'quick-open-sidebyside-horizontal';
E
Erich Gamma 已提交
565 566 567
	}

	private updateEnablement(): void {
568
		const activeEditor = this.editorService.getActiveEditor();
569
		this.enabled = (!activeEditor || activeEditor.position !== Position.THREE);
E
Erich Gamma 已提交
570 571
	}

572
	public run(context: any): TPromise<any> {
E
Erich Gamma 已提交
573 574
		let entry = toEditorQuickOpenEntry(context);
		if (entry) {
575
			const input = entry.getInput();
B
Benjamin Pasero 已提交
576
			if (input instanceof EditorInput) {
577
				return this.editorService.openEditor(input, entry.getOptions(), true);
B
Benjamin Pasero 已提交
578 579
			}

580 581 582 583
			const resourceInput = input as IResourceInput;
			resourceInput.options = mixin(resourceInput.options, entry.getOptions());

			return this.editorService.openEditor(resourceInput, true);
E
Erich Gamma 已提交
584 585
		}

A
Alex Dima 已提交
586
		return TPromise.as(false);
E
Erich Gamma 已提交
587 588 589
	}
}

590
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
591 592 593

	// QuickOpenEntryGroup
	if (element instanceof QuickOpenEntryGroup) {
594
		const group = <QuickOpenEntryGroup>element;
E
Erich Gamma 已提交
595 596 597 598 599 600 601 602 603 604 605 606 607 608
		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 {
609

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

613 614 615
	constructor(
		id: string,
		label: string,
I
isidor 已提交
616
		@ICommandService private commandService: ICommandService
617
	) {
I
isidor 已提交
618
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
619 620
	}

I
isidor 已提交
621
	public run(context?: IEditorCommandsContext): TPromise<any> {
622
		return this.commandService.executeCommand(CLOSE_EDITOR_COMMAND_ID, void 0, context);
E
Erich Gamma 已提交
623 624 625
	}
}

626 627 628 629 630 631 632 633
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,
634
		@INextEditorGroupsService private nextEditorGroupsService: INextEditorGroupsService
635 636 637 638 639
	) {
		super(id, label, 'close-editor-action');
	}

	public run(context?: IEditorCommandsContext): TPromise<any> {
640 641 642 643
		let group: INextEditorGroup;
		let editorIndex: number;
		if (context) {
			group = this.nextEditorGroupsService.getGroup(context.groupId);
644

645 646
			if (group) {
				editorIndex = context.editorIndex; // only allow editor at index if group is valid
647 648 649
			}
		}

650 651
		if (!group) {
			group = this.nextEditorGroupsService.activeGroup;
652 653
		}

654 655 656 657 658 659 660 661 662 663 664
		// Close specific editor in group
		if (typeof editorIndex === 'number') {
			const editorAtIndex = group.getEditor(editorIndex);
			if (editorAtIndex) {
				return group.closeEditor(editorAtIndex) as TPromise;
			}
		}

		// Otherwise close active editor in group
		if (group.activeEditor) {
			return group.closeEditor(group.activeEditor) as TPromise;
665 666 667 668 669 670
		}

		return TPromise.as(false);
	}
}

M
misoguy 已提交
671 672
export class RevertAndCloseEditorAction extends Action {

M
Matt Bierner 已提交
673 674
	public static readonly ID = 'workbench.action.revertAndCloseActiveEditor';
	public static readonly LABEL = nls.localize('revertAndCloseActiveEditor', "Revert and Close Editor");
M
misoguy 已提交
675 676 677 678 679 680 681 682 683 684 685

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const activeEditor = this.editorService.getActiveEditor();
B
Benjamin Pasero 已提交
686 687 688 689
		if (activeEditor && activeEditor.input) {
			const input = activeEditor.input;
			const position = activeEditor.position;

690 691 692 693 694 695 696 697
			// first try a normal revert where the contents of the editor are restored
			return activeEditor.input.revert().then(() => this.editorService.closeEditor(position, input), error => {
				// 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.
				return activeEditor.input.revert({ soft: true }).then(() => this.editorService.closeEditor(position, input));
			});
M
misoguy 已提交
698 699 700 701 702 703
		}

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
704
export class CloseLeftEditorsInGroupAction extends Action {
705

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

709 710 711
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
712 713
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private groupService: IEditorGroupService
714
	) {
715 716 717
		super(id, label);
	}

718
	public run(context?: IEditorIdentifier): TPromise<any> {
719
		const editor = getTarget(this.editorService, this.groupService, context);
B
Benjamin Pasero 已提交
720
		if (editor) {
B
Benjamin Pasero 已提交
721
			return this.editorService.closeEditors(editor.position, { except: editor.input, direction: Direction.LEFT });
722 723 724 725 726 727
		}

		return TPromise.as(false);
	}
}

E
Erich Gamma 已提交
728 729
export class CloseAllEditorsAction extends Action {

M
Matt Bierner 已提交
730 731
	public static readonly ID = 'workbench.action.closeAllEditors';
	public static readonly LABEL = nls.localize('closeAllEditors', "Close All Editors");
732

733 734 735 736 737 738
	constructor(
		id: string,
		label: string,
		@ITextFileService private textFileService: ITextFileService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
I
isidor 已提交
739
		super(id, label, 'action-close-all-files');
E
Erich Gamma 已提交
740 741
	}

742
	public run(): TPromise<any> {
743 744 745

		// Just close all if there are no or one dirty editor
		if (this.textFileService.getDirty().length < 2) {
B
Benjamin Pasero 已提交
746
			return this.editorService.closeEditors();
747 748 749
		}

		// Otherwise ask for combined confirmation
750 751 752 753
		return this.textFileService.confirmSave().then(confirm => {
			if (confirm === ConfirmResult.CANCEL) {
				return void 0;
			}
754

755 756 757 758 759
			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));
760
			}
761

762 763
			return saveOrRevertPromise.then(success => {
				if (success) {
B
Benjamin Pasero 已提交
764
					return this.editorService.closeEditors();
765 766 767 768
				}

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

773 774
export class CloseEditorsInOtherGroupsAction extends Action {

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

778 779 780 781 782 783
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
784 785 786
		super(id, label);
	}

787
	public run(context?: IEditorIdentifier): TPromise<any> {
788
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
789
		if (typeof position !== 'number') {
790
			const activeEditor = this.editorService.getActiveEditor();
791 792 793 794 795 796
			if (activeEditor) {
				position = activeEditor.position;
			}
		}

		if (typeof position === 'number') {
B
Benjamin Pasero 已提交
797
			return this.editorService.closeEditors(POSITIONS.filter(p => p !== position));
798 799 800 801 802 803
		}

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
804
export class MoveGroupLeftAction extends Action {
E
Erich Gamma 已提交
805

M
Matt Bierner 已提交
806 807
	public static readonly ID = 'workbench.action.moveActiveEditorGroupLeft';
	public static readonly LABEL = nls.localize('moveActiveGroupLeft', "Move Editor Group Left");
808

809 810 811 812 813 814
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
815 816 817
		super(id, label);
	}

818
	public run(context?: IEditorIdentifier): TPromise<any> {
819
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
820
		if (typeof position !== 'number') {
821
			const activeEditor = this.editorService.getActiveEditor();
822
			if (activeEditor && (activeEditor.position === Position.TWO || activeEditor.position === Position.THREE)) {
823 824 825 826 827
				position = activeEditor.position;
			}
		}

		if (typeof position === 'number') {
828
			const newPosition = (position === Position.TWO) ? Position.ONE : Position.TWO;
E
Erich Gamma 已提交
829

B
Benjamin Pasero 已提交
830
			// Move group
831
			this.editorGroupService.moveGroup(position, newPosition);
E
Erich Gamma 已提交
832 833
		}

A
Alex Dima 已提交
834
		return TPromise.as(false);
E
Erich Gamma 已提交
835 836 837
	}
}

B
Benjamin Pasero 已提交
838
export class MoveGroupRightAction extends Action {
E
Erich Gamma 已提交
839

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

843 844 845 846 847 848
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
849 850 851
		super(id, label);
	}

852
	public run(context?: IEditorIdentifier): TPromise<any> {
853
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
854
		if (typeof position !== 'number') {
855 856
			const activeEditor = this.editorService.getActiveEditor();
			const editors = this.editorService.getVisibleEditors();
857

858
			if ((editors.length === 2 && activeEditor.position === Position.ONE) || (editors.length === 3 && activeEditor.position !== Position.THREE)) {
859 860 861 862 863
				position = activeEditor.position;
			}
		}

		if (typeof position === 'number') {
864
			const newPosition = (position === Position.ONE) ? Position.TWO : Position.THREE;
E
Erich Gamma 已提交
865

B
Benjamin Pasero 已提交
866
			// Move group
867
			this.editorGroupService.moveGroup(position, newPosition);
E
Erich Gamma 已提交
868 869
		}

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

874
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
875

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

879
	constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
E
Erich Gamma 已提交
880 881 882
		super(id, label);
	}

883
	public run(): TPromise<any> {
884
		this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
885

A
Alex Dima 已提交
886
		return TPromise.as(false);
E
Erich Gamma 已提交
887 888 889
	}
}

890
export class EvenGroupWidthsAction extends Action {
E
Erich Gamma 已提交
891

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

895
	constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
E
Erich Gamma 已提交
896 897 898
		super(id, label);
	}

899
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
900
		this.editorGroupService.arrangeGroups(GroupArrangement.EVEN);
E
Erich Gamma 已提交
901

A
Alex Dima 已提交
902
		return TPromise.as(false);
E
Erich Gamma 已提交
903 904 905
	}
}

906
export class MaximizeGroupAction extends Action {
907

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

911 912 913 914
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
915
		@IEditorGroupService private editorGroupService: IEditorGroupService,
916 917 918 919 920
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

921
	public run(): TPromise<any> {
922
		if (this.editorService.getActiveEditor()) {
923
			this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
924
			return this.partService.setSideBarHidden(true);
925 926
		}

A
Alex Dima 已提交
927
		return TPromise.as(false);
928 929 930
	}
}

931
function getTarget(editorService: IWorkbenchEditorService, editorGroupService: IEditorGroupService, context?: IEditorIdentifier): { input: IEditorInput, position: Position } {
B
Benjamin Pasero 已提交
932 933 934 935 936 937 938 939 940 941 942 943
	if (context) {
		return { input: context.editor, position: editorGroupService.getStacksModel().positionOfGroup(context.group) };
	}

	const activeEditor = editorService.getActiveEditor();
	if (activeEditor) {
		return { input: activeEditor.input, position: activeEditor.position };
	}

	return null;
}

944 945
export abstract class BaseNavigateEditorAction extends Action {

946 947 948 949 950 951
	constructor(
		id: string,
		label: string,
		protected editorGroupService: IEditorGroupService,
		protected editorService: IWorkbenchEditorService
	) {
952 953 954 955
		super(id, label);
	}

	public run(): TPromise<any> {
956
		const model = this.editorGroupService.getStacksModel();
957 958 959 960 961 962 963 964 965 966 967 968 969
		const result = this.navigate();
		if (result) {
			return this.editorService.openEditor(result.editor, null, model.positionOfGroup(result.group));
		}

		return TPromise.as(false);
	}

	protected abstract navigate(): IEditorIdentifier;
}

export class OpenNextEditor extends BaseNavigateEditorAction {

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

973 974 975 976 977 978 979
	constructor(
		id: string,
		label: string,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, editorGroupService, editorService);
980 981 982
	}

	protected navigate(): IEditorIdentifier {
983
		return this.editorGroupService.getStacksModel().next(true /* jump groups */);
984 985 986 987 988
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

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

992 993 994 995 996 997 998
	constructor(
		id: string,
		label: string,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, editorGroupService, editorService);
999 1000 1001
	}

	protected navigate(): IEditorIdentifier {
1002 1003 1004 1005 1006 1007
		return this.editorGroupService.getStacksModel().previous(true /* jump groups */);
	}
}

export class OpenNextEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
1008 1009
	public static readonly ID = 'workbench.action.nextEditorInGroup';
	public static readonly LABEL = nls.localize('nextEditorInGroup', "Open Next Editor in Group");
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026

	constructor(
		id: string,
		label: string,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
		return this.editorGroupService.getStacksModel().next(false /* do NOT jump groups */);
	}
}

export class OpenPreviousEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
1027 1028
	public static readonly ID = 'workbench.action.previousEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousEditorInGroup', "Open Previous Editor in Group");
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040

	constructor(
		id: string,
		label: string,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
		return this.editorGroupService.getStacksModel().previous(false /* do NOT jump groups */);
1041
	}
B
Benjamin Pasero 已提交
1042 1043
}

1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
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,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
		return this.editorGroupService.getStacksModel().last();
	}
}

B
Benjamin Pasero 已提交
1063 1064
export class NavigateForwardAction extends Action {

M
Matt Bierner 已提交
1065 1066
	public static readonly ID = 'workbench.action.navigateForward';
	public static readonly LABEL = nls.localize('navigateNext', "Go Forward");
B
Benjamin Pasero 已提交
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080

	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 已提交
1081 1082
	public static readonly ID = 'workbench.action.navigateBack';
	public static readonly LABEL = nls.localize('navigatePrevious', "Go Back");
B
Benjamin Pasero 已提交
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092

	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 已提交
1093
}
1094

1095 1096
export class NavigateLastAction extends Action {

M
Matt Bierner 已提交
1097 1098
	public static readonly ID = 'workbench.action.navigateLast';
	public static readonly LABEL = nls.localize('navigateLast', "Go Last");
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110

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

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

		return TPromise.as(null);
	}
}

1111 1112
export class ReopenClosedEditorAction extends Action {

M
Matt Bierner 已提交
1113 1114
	public static readonly ID = 'workbench.action.reopenClosedEditor';
	public static readonly LABEL = nls.localize('reopenClosedEditor', "Reopen Closed Editor");
1115 1116 1117 1118

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1119
		@IHistoryService private historyService: IHistoryService
1120 1121 1122 1123 1124
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1125
		this.historyService.reopenLastClosedEditor();
1126 1127 1128

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
1129 1130
}

1131
export class ClearRecentFilesAction extends Action {
C
22768  
Cristian 已提交
1132

M
Matt Bierner 已提交
1133 1134
	public static readonly ID = 'workbench.action.clearRecentFiles';
	public static readonly LABEL = nls.localize('clearRecentFiles', "Clear Recently Opened");
C
22768  
Cristian 已提交
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144

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

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
1145
		this.windowsService.clearRecentlyOpened();
C
22768  
Cristian 已提交
1146 1147 1148 1149 1150

		return TPromise.as(false);
	}
}

1151
export class ShowEditorsInGroupOneAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
1152

M
Matt Bierner 已提交
1153 1154
	public static readonly ID = 'workbench.action.showEditorsInFirstGroup';
	public static readonly LABEL = nls.localize('showEditorsInFirstGroup', "Show Editors in First Group");
B
Benjamin Pasero 已提交
1155

1156 1157 1158
	constructor(
		actionId: string,
		actionLabel: string,
1159
		@IQuickOpenService quickOpenService: IQuickOpenService
1160
	) {
1161
		super(actionId, actionLabel, NAVIGATE_IN_GROUP_ONE_PREFIX, quickOpenService);
1162 1163

		this.class = 'show-group-editors-action';
B
Benjamin Pasero 已提交
1164
	}
1165
}
1166

1167
export class ShowEditorsInGroupTwoAction extends QuickOpenAction {
1168

M
Matt Bierner 已提交
1169 1170
	public static readonly ID = 'workbench.action.showEditorsInSecondGroup';
	public static readonly LABEL = nls.localize('showEditorsInSecondGroup', "Show Editors in Second Group");
1171 1172 1173 1174

	constructor(
		actionId: string,
		actionLabel: string,
1175
		@IQuickOpenService quickOpenService: IQuickOpenService
1176
	) {
1177
		super(actionId, actionLabel, NAVIGATE_IN_GROUP_TWO_PREFIX, quickOpenService);
1178 1179

		this.class = 'show-group-editors-action';
1180 1181
	}
}
1182

1183
export class ShowEditorsInGroupThreeAction extends QuickOpenAction {
1184

M
Matt Bierner 已提交
1185 1186
	public static readonly ID = 'workbench.action.showEditorsInThirdGroup';
	public static readonly LABEL = nls.localize('showEditorsInThirdGroup', "Show Editors in Third Group");
1187 1188 1189 1190

	constructor(
		actionId: string,
		actionLabel: string,
1191
		@IQuickOpenService quickOpenService: IQuickOpenService
1192
	) {
1193
		super(actionId, actionLabel, NAVIGATE_IN_GROUP_THREE_PREFIX, quickOpenService);
1194 1195

		this.class = 'show-group-editors-action';
1196
	}
B
Benjamin Pasero 已提交
1197 1198
}

B
Benjamin Pasero 已提交
1199 1200
export class ShowAllEditorsAction extends QuickOpenAction {

M
Matt Bierner 已提交
1201 1202
	public static readonly ID = 'workbench.action.showAllEditors';
	public static readonly LABEL = nls.localize('showAllEditors', "Show All Editors");
B
Benjamin Pasero 已提交
1203 1204 1205 1206 1207 1208

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

1209
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1210 1211 1212 1213 1214

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
1215
		@IKeybindingService private keybindingService: IKeybindingService,
1216
		@IEditorGroupService private editorGroupService: IEditorGroupService
B
Benjamin Pasero 已提交
1217 1218 1219 1220 1221
	) {
		super(id, label);
	}

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

1224
		const stacks = this.editorGroupService.getStacksModel();
1225 1226
		if (stacks.activeGroup) {
			const activePosition = stacks.positionOfGroup(stacks.activeGroup);
1227
			let prefix = NAVIGATE_IN_GROUP_ONE_PREFIX;
1228

B
Benjamin Pasero 已提交
1229
			if (activePosition === Position.TWO) {
1230
				prefix = NAVIGATE_IN_GROUP_TWO_PREFIX;
B
Benjamin Pasero 已提交
1231
			} else if (activePosition === Position.THREE) {
1232
				prefix = NAVIGATE_IN_GROUP_THREE_PREFIX;
1233 1234
			}

B
Benjamin Pasero 已提交
1235
			this.quickOpenService.show(prefix, { quickNavigateConfiguration: { keybindings: keys } });
1236
		}
B
Benjamin Pasero 已提交
1237 1238 1239 1240 1241

		return TPromise.as(true);
	}
}

1242 1243
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1244 1245
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditorInGroup', "Open Previous Recently Used Editor in Group");
1246 1247 1248 1249 1250 1251

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IKeybindingService keybindingService: IKeybindingService,
1252
		@IEditorGroupService editorGroupService: IEditorGroupService
1253
	) {
1254
		super(id, label, quickOpenService, keybindingService, editorGroupService);
1255 1256 1257 1258 1259
	}
}

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1260 1261
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditorInGroup', "Open Next Recently Used Editor in Group");
1262 1263 1264 1265 1266 1267

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IKeybindingService keybindingService: IKeybindingService,
1268
		@IEditorGroupService editorGroupService: IEditorGroupService
1269
	) {
1270
		super(id, label, quickOpenService, keybindingService, editorGroupService);
1271 1272 1273
	}
}

1274
export class OpenPreviousEditorFromHistoryAction extends Action {
B
Benjamin Pasero 已提交
1275

M
Matt Bierner 已提交
1276 1277
	public static readonly ID = 'workbench.action.openPreviousEditorFromHistory';
	public static readonly LABEL = nls.localize('navigateEditorHistoryByInput', "Open Previous Editor from History");
B
Benjamin Pasero 已提交
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288

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

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

B
Benjamin Pasero 已提交
1291
		this.quickOpenService.show(null, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1292 1293 1294 1295 1296

		return TPromise.as(true);
	}
}

1297 1298
export class OpenNextRecentlyUsedEditorAction extends Action {

M
Matt Bierner 已提交
1299 1300
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditor', "Open Next Recently Used Editor");
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314

	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 已提交
1315 1316
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditor', "Open Previous Recently Used Editor");
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328

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

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

		return TPromise.as(null);
	}
}

1329 1330
export class ClearEditorHistoryAction extends Action {

M
Matt Bierner 已提交
1331 1332
	public static readonly ID = 'workbench.action.clearEditorHistory';
	public static readonly LABEL = nls.localize('clearEditorHistory', "Clear Editor History");
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343

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

	public run(): TPromise<any> {

1344
		// Editor history
1345 1346 1347 1348 1349 1350
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1351 1352
export class FocusLastEditorInStackAction extends Action {

M
Matt Bierner 已提交
1353 1354
	public static readonly ID = 'workbench.action.openLastEditorInGroup';
	public static readonly LABEL = nls.localize('focusLastEditorInStack', "Open Last Editor in Group");
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375

	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const active = this.editorService.getActiveEditor();
		if (active) {
			const group = this.editorGroupService.getStacksModel().groupAt(active.position);
			const editor = group.getEditor(group.count - 1);

			if (editor) {
				return this.editorService.openEditor(editor);
			}
		}

1376 1377 1378 1379
		return TPromise.as(true);
	}
}

1380 1381
export class MoveEditorLeftInGroupAction extends Action {

M
Matt Bierner 已提交
1382 1383
	public static readonly ID = 'workbench.action.moveEditorLeftInGroup';
	public static readonly LABEL = nls.localize('moveEditorLeft', "Move Editor Left");
1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394

	constructor(
		id: string,
		label: string,
		@ICommandService private commandService: ICommandService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const args: ActiveEditorMoveArguments = {
1395
			to: ActiveEditorMovePositioning.LEFT
1396 1397 1398 1399 1400 1401 1402 1403 1404
		};
		this.commandService.executeCommand(EditorCommands.MoveActiveEditor, args);

		return TPromise.as(true);
	}
}

export class MoveEditorRightInGroupAction extends Action {

M
Matt Bierner 已提交
1405 1406
	public static readonly ID = 'workbench.action.moveEditorRightInGroup';
	public static readonly LABEL = nls.localize('moveEditorRight', "Move Editor Right");
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417

	constructor(
		id: string,
		label: string,
		@ICommandService private commandService: ICommandService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const args: ActiveEditorMoveArguments = {
1418
			to: ActiveEditorMovePositioning.RIGHT
1419 1420 1421 1422 1423 1424 1425
		};
		this.commandService.executeCommand(EditorCommands.MoveActiveEditor, args);

		return TPromise.as(true);
	}
}

1426
export class MoveEditorToPreviousGroupAction extends Action {
1427

M
Matt Bierner 已提交
1428 1429
	public static readonly ID = 'workbench.action.moveEditorToPreviousGroup';
	public static readonly LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441

	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const activeEditor = this.editorService.getActiveEditor();
1442
		if (activeEditor && activeEditor.position !== Position.ONE) {
1443 1444 1445 1446 1447 1448 1449
			this.editorGroupService.moveEditor(activeEditor.input, activeEditor.position, activeEditor.position - 1);
		}

		return TPromise.as(true);
	}
}

1450
export class MoveEditorToNextGroupAction extends Action {
1451

M
Matt Bierner 已提交
1452 1453
	public static readonly ID = 'workbench.action.moveEditorToNextGroup';
	public static readonly LABEL = nls.localize('moveEditorToNextGroup', "Move Editor into Next Group");
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465

	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const activeEditor = this.editorService.getActiveEditor();
1466
		if (activeEditor && activeEditor.position !== Position.THREE) {
1467 1468 1469
			this.editorGroupService.moveEditor(activeEditor.input, activeEditor.position, activeEditor.position + 1);
		}

1470 1471
		return TPromise.as(true);
	}
D
Daniel Imms 已提交
1472
}
1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538

export abstract class MoveEditorToSpecificGroup extends Action {

	constructor(
		id: string,
		label: string,
		private position: Position,
		private editorGroupService: IEditorGroupService,
		private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const activeEditor = this.editorService.getActiveEditor();
		if (activeEditor && activeEditor.position !== this.position) {
			this.editorGroupService.moveEditor(activeEditor.input, activeEditor.position, this.position);
		}

		return TPromise.as(true);
	}
}

export class MoveEditorToFirstGroupAction extends MoveEditorToSpecificGroup {

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

	constructor(
		id: string,
		label: string,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, Position.ONE, editorGroupService, editorService);
	}
}

export class MoveEditorToSecondGroupAction extends MoveEditorToSpecificGroup {

	public static readonly ID = 'workbench.action.moveEditorToSecondGroup';
	public static readonly LABEL = nls.localize('moveEditorToSecondGroup', "Move Editor into Second Group");

	constructor(
		id: string,
		label: string,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, Position.TWO, editorGroupService, editorService);
	}
}

export class MoveEditorToThirdGroupAction extends MoveEditorToSpecificGroup {

	public static readonly ID = 'workbench.action.moveEditorToThirdGroup';
	public static readonly LABEL = nls.localize('moveEditorToThirdGroup', "Move Editor into Third Group");

	constructor(
		id: string,
		label: string,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, Position.THREE, editorGroupService, editorService);
	}
1539
}