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

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

28 29 30 31 32 33 34 35 36 37 38 39 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 SplitEditorAction extends Action {
B
Benjamin Pasero 已提交
46 47 48

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

50
	private toDispose: IDisposable[] = [];
51
	private direction: GroupDirection;
52

53 54 55
	constructor(
		id: string,
		label: string,
56
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
57
		@IConfigurationService private configurationService: IConfigurationService
58
	) {
59 60 61
		super(id, label);

		this.direction = preferredSideBySideGroupDirection(configurationService);
62 63 64 65 66 67 68

		this.registerListeners();
	}

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

74
	public run(context?: IEditorIdentifier): TPromise<any> {
75
		splitEditor(this.editorGroupService, this.direction, context);
76 77 78 79

		return TPromise.as(true);
	}

80 81 82 83
	public dispose(): void {
		super.dispose();

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

87
export class SplitEditorLeftAction extends ExecuteCommandAction {
88

89
	public static readonly ID = SPLIT_EDITOR_LEFT;
90
	public static readonly LABEL = nls.localize('splitEditorGroupLeft', "Split Editor Left");
91 92 93 94

	constructor(
		id: string,
		label: string,
95
		@ICommandService commandService: ICommandService
96
	) {
97
		super(id, label, SPLIT_EDITOR_LEFT, commandService);
B
Benjamin Pasero 已提交
98 99 100
	}
}

101
export class SplitEditorRightAction extends ExecuteCommandAction {
B
Benjamin Pasero 已提交
102

103
	public static readonly ID = SPLIT_EDITOR_RIGHT;
104
	public static readonly LABEL = nls.localize('splitEditorGroupRight', "Split Editor Right");
B
Benjamin Pasero 已提交
105 106 107 108

	constructor(
		id: string,
		label: string,
109
		@ICommandService commandService: ICommandService
B
Benjamin Pasero 已提交
110
	) {
111
		super(id, label, SPLIT_EDITOR_RIGHT, commandService);
B
Benjamin Pasero 已提交
112 113 114
	}
}

115
export class SplitEditorUpAction extends ExecuteCommandAction {
B
Benjamin Pasero 已提交
116

117
	public static readonly ID = SPLIT_EDITOR_UP;
118
	public static readonly LABEL = nls.localize('splitEditorGroupUp', "Split Editor Up");
119

B
Benjamin Pasero 已提交
120 121 122
	constructor(
		id: string,
		label: string,
123
		@ICommandService commandService: ICommandService
B
Benjamin Pasero 已提交
124
	) {
125
		super(id, label, SPLIT_EDITOR_UP, commandService);
126
	}
B
Benjamin Pasero 已提交
127
}
128

129
export class SplitEditorDownAction extends ExecuteCommandAction {
130

131
	public static readonly ID = SPLIT_EDITOR_DOWN;
132
	public static readonly LABEL = nls.localize('splitEditorGroupDown', "Split Editor Down");
133

B
Benjamin Pasero 已提交
134 135 136
	constructor(
		id: string,
		label: string,
137
		@ICommandService commandService: ICommandService
B
Benjamin Pasero 已提交
138
	) {
139
		super(id, label, SPLIT_EDITOR_DOWN, commandService);
140 141 142
	}
}

143
export class JoinTwoGroupsAction extends Action {
I
initialshl 已提交
144

M
Matt Bierner 已提交
145
	public static readonly ID = 'workbench.action.joinTwoGroups';
B
Benjamin Pasero 已提交
146
	public static readonly LABEL = nls.localize('joinTwoGroups', "Join Editor Group with Next Group");
I
initialshl 已提交
147 148 149 150

	constructor(
		id: string,
		label: string,
151
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
I
initialshl 已提交
152
	) {
153
		super(id, label);
I
initialshl 已提交
154 155
	}

156
	public run(context?: IEditorIdentifier): TPromise<any> {
157
		let sourceGroup: IEditorGroup;
B
Benjamin Pasero 已提交
158 159
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
I
initialshl 已提交
160
		} else {
B
Benjamin Pasero 已提交
161
			sourceGroup = this.editorGroupService.activeGroup;
I
initialshl 已提交
162 163
		}

B
Benjamin Pasero 已提交
164
		const targetGroup = this.editorGroupService.findGroup({ direction: GroupDirection.RIGHT }, sourceGroup) || this.editorGroupService.findGroup({ direction: GroupDirection.DOWN }, sourceGroup);
B
Benjamin Pasero 已提交
165 166 167
		if (targetGroup && sourceGroup !== targetGroup) {
			this.editorGroupService.mergeGroup(sourceGroup, targetGroup);
		}
I
initialshl 已提交
168 169 170 171 172

		return TPromise.as(true);
	}
}

173 174 175
export class JoinAllGroupsAction extends Action {

	public static readonly ID = 'workbench.action.joinAllGroups';
B
Benjamin Pasero 已提交
176
	public static readonly LABEL = nls.localize('joinAllGroups', "Join All Editor Groups");
177 178 179 180 181 182 183 184 185 186

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

	public run(context?: IEditorIdentifier): TPromise<any> {
187
		mergeAllGroups(this.editorGroupService);
188 189 190 191 192

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
193
export class NavigateBetweenGroupsAction extends Action {
194

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

198 199 200
	constructor(
		id: string,
		label: string,
201
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
202
	) {
E
Erich Gamma 已提交
203 204 205
		super(id, label);
	}

206
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
207
		const nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT }, this.editorGroupService.activeGroup, true);
B
Benjamin Pasero 已提交
208
		nextGroup.focus();
209 210

		return TPromise.as(true);
E
Erich Gamma 已提交
211 212 213
	}
}

214 215
export class FocusActiveGroupAction extends Action {

M
Matt Bierner 已提交
216 217
	public static readonly ID = 'workbench.action.focusActiveEditorGroup';
	public static readonly LABEL = nls.localize('focusActiveEditorGroup', "Focus Active Editor Group");
218 219 220 221

	constructor(
		id: string,
		label: string,
222
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
223 224 225 226 227
	) {
		super(id, label);
	}

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

230
		return TPromise.as(true);
E
Erich Gamma 已提交
231 232 233
	}
}

234
export abstract class BaseFocusGroupAction extends Action {
E
Erich Gamma 已提交
235 236 237 238

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

245
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
246
		const group = this.editorGroupService.findGroup(this.scope, this.editorGroupService.activeGroup, true);
247 248 249
		if (group) {
			group.focus();
		}
E
Erich Gamma 已提交
250

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

255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
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 已提交
270 271 272

	public static readonly ID = 'workbench.action.focusLastEditorGroup';
	public static readonly LABEL = nls.localize('focusLastEditorGroup', "Focus Last Editor Group");
E
Erich Gamma 已提交
273 274 275 276

	constructor(
		id: string,
		label: string,
277
		@IEditorGroupsService editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
278
	) {
279
		super(id, label, { location: GroupLocation.LAST }, editorGroupService);
E
Erich Gamma 已提交
280
	}
281
}
E
Erich Gamma 已提交
282

283
export class FocusNextGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
284

285 286 287 288 289 290 291 292 293
	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 已提交
294 295 296
	}
}

297
export class FocusPreviousGroup extends BaseFocusGroupAction {
298

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

302 303 304
	constructor(
		id: string,
		label: string,
305
		@IEditorGroupsService editorGroupService: IEditorGroupsService
306
	) {
307
		super(id, label, { location: GroupLocation.PREVIOUS }, editorGroupService);
E
Erich Gamma 已提交
308
	}
309
}
E
Erich Gamma 已提交
310

311
export class FocusLeftGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
312

313 314 315 316 317 318 319 320 321
	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 已提交
322 323 324
	}
}

325
export class FocusRightGroup extends BaseFocusGroupAction {
326

327 328
	public static readonly ID = 'workbench.action.focusRightGroup';
	public static readonly LABEL = nls.localize('focusRightGroup', "Focus Right Editor Group");
329

E
Erich Gamma 已提交
330 331 332
	constructor(
		id: string,
		label: string,
333
		@IEditorGroupsService editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
334
	) {
335
		super(id, label, { direction: GroupDirection.RIGHT }, editorGroupService);
E
Erich Gamma 已提交
336
	}
337
}
E
Erich Gamma 已提交
338

339
export class FocusAboveGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
340

341 342 343 344 345 346 347 348 349
	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 已提交
350 351 352
	}
}

353 354 355 356 357 358 359 360 361 362 363 364 365 366
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);
	}
}

367
export class OpenToSideFromQuickOpenAction extends Action {
E
Erich Gamma 已提交
368

M
Matt Bierner 已提交
369 370
	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 已提交
371

372
	constructor(
373
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
374
		@IConfigurationService private configurationService: IConfigurationService
375
	) {
376
		super(OpenToSideFromQuickOpenAction.OPEN_TO_SIDE_ID, OpenToSideFromQuickOpenAction.OPEN_TO_SIDE_LABEL);
E
Erich Gamma 已提交
377

378 379 380 381
		this.updateClass();
	}

	public updateClass(): void {
382
		const preferredDirection = preferredSideBySideGroupDirection(this.configurationService);
E
Erich Gamma 已提交
383

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

387
	public run(context: any): TPromise<any> {
B
Benjamin Pasero 已提交
388
		const entry = toEditorQuickOpenEntry(context);
E
Erich Gamma 已提交
389
		if (entry) {
390
			const input = entry.getInput();
B
Benjamin Pasero 已提交
391
			if (input instanceof EditorInput) {
B
Benjamin Pasero 已提交
392
				return this.editorService.openEditor(input, entry.getOptions(), SIDE_GROUP);
B
Benjamin Pasero 已提交
393 394
			}

395 396 397
			const resourceInput = input as IResourceInput;
			resourceInput.options = mixin(resourceInput.options, entry.getOptions());

B
Benjamin Pasero 已提交
398
			return this.editorService.openEditor(resourceInput, SIDE_GROUP);
E
Erich Gamma 已提交
399 400
		}

A
Alex Dima 已提交
401
		return TPromise.as(false);
E
Erich Gamma 已提交
402 403 404
	}
}

405
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
406 407 408

	// QuickOpenEntryGroup
	if (element instanceof QuickOpenEntryGroup) {
409
		const group = <QuickOpenEntryGroup>element;
E
Erich Gamma 已提交
410 411 412 413 414 415 416 417 418 419 420 421 422 423
		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 {
424

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

428 429 430
	constructor(
		id: string,
		label: string,
I
isidor 已提交
431
		@ICommandService private commandService: ICommandService
432
	) {
I
isidor 已提交
433
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
434 435
	}

I
isidor 已提交
436
	public run(context?: IEditorCommandsContext): TPromise<any> {
437
		return this.commandService.executeCommand(CLOSE_EDITOR_COMMAND_ID, void 0, context);
E
Erich Gamma 已提交
438 439 440
	}
}

441 442 443 444 445 446 447 448
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,
449
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
450 451 452 453 454
	) {
		super(id, label, 'close-editor-action');
	}

	public run(context?: IEditorCommandsContext): TPromise<any> {
455
		let group: IEditorGroup;
456 457
		let editorIndex: number;
		if (context) {
458
			group = this.editorGroupService.getGroup(context.groupId);
459

460 461
			if (group) {
				editorIndex = context.editorIndex; // only allow editor at index if group is valid
462 463 464
			}
		}

465
		if (!group) {
466
			group = this.editorGroupService.activeGroup;
467 468
		}

469 470 471 472
		// Close specific editor in group
		if (typeof editorIndex === 'number') {
			const editorAtIndex = group.getEditor(editorIndex);
			if (editorAtIndex) {
473
				return group.closeEditor(editorAtIndex);
474 475 476 477 478
			}
		}

		// Otherwise close active editor in group
		if (group.activeEditor) {
479
			return group.closeEditor(group.activeEditor);
480 481 482 483 484 485
		}

		return TPromise.as(false);
	}
}

M
misoguy 已提交
486 487
export class RevertAndCloseEditorAction extends Action {

M
Matt Bierner 已提交
488 489
	public static readonly ID = 'workbench.action.revertAndCloseActiveEditor';
	public static readonly LABEL = nls.localize('revertAndCloseActiveEditor', "Revert and Close Editor");
M
misoguy 已提交
490 491 492 493

	constructor(
		id: string,
		label: string,
494
		@IEditorService private editorService: IEditorService
M
misoguy 已提交
495 496 497 498 499
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
500
		const activeControl = this.editorService.activeControl;
B
Benjamin Pasero 已提交
501
		if (activeControl) {
B
Benjamin Pasero 已提交
502
			const editor = activeControl.input;
503
			const group = activeControl.group;
B
Benjamin Pasero 已提交
504

505
			// first try a normal revert where the contents of the editor are restored
B
Benjamin Pasero 已提交
506
			return editor.revert().then(() => group.closeEditor(editor), error => {
507 508 509 510
				// 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 已提交
511
				return editor.revert({ soft: true }).then(() => group.closeEditor(editor));
512
			});
M
misoguy 已提交
513 514 515 516 517 518
		}

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
519
export class CloseLeftEditorsInGroupAction extends Action {
520

M
Matt Bierner 已提交
521
	public static readonly ID = 'workbench.action.closeEditorsToTheLeft';
B
Benjamin Pasero 已提交
522
	public static readonly LABEL = nls.localize('closeEditorsToTheLeft', "Close Editors to the Left in Group");
523

524 525 526
	constructor(
		id: string,
		label: string,
527
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
528
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
529
	) {
530 531 532
		super(id, label);
	}

533
	public run(context?: IEditorIdentifier): TPromise<any> {
B
Benjamin Pasero 已提交
534
		const { group, editor } = getTarget(this.editorService, this.editorGroupService, context);
B
Benjamin Pasero 已提交
535 536
		if (group && editor) {
			return group.closeEditors({ direction: CloseDirection.LEFT, except: editor });
537 538 539 540 541 542
		}

		return TPromise.as(false);
	}
}

543
function getTarget(editorService: IEditorService, editorGroupService: IEditorGroupsService, context?: IEditorIdentifier): { editor: IEditorInput, group: IEditorGroup } {
B
Benjamin Pasero 已提交
544 545 546 547 548 549 550 551
	if (context) {
		return { editor: context.editor, group: editorGroupService.getGroup(context.groupId) };
	}

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

552
export abstract class BaseCloseAllAction extends Action {
553

554 555 556
	constructor(
		id: string,
		label: string,
557
		clazz: string,
558 559
		private textFileService: ITextFileService,
		protected editorGroupService: IEditorGroupsService
560
	) {
561
		super(id, label, clazz);
E
Erich Gamma 已提交
562 563
	}

564 565 566 567 568 569 570 571 572 573 574 575 576 577
	protected get groupsToClose(): IEditorGroup[] {
		const groupsToClose: IEditorGroup[] = [];

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

		return groupsToClose;
	}

578
	public run(): TPromise<any> {
579 580 581

		// Just close all if there are no or one dirty editor
		if (this.textFileService.getDirty().length < 2) {
582
			return this.doCloseAll();
583 584 585
		}

		// Otherwise ask for combined confirmation
586 587 588 589
		return this.textFileService.confirmSave().then(confirm => {
			if (confirm === ConfirmResult.CANCEL) {
				return void 0;
			}
590

591 592 593 594 595
			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));
596
			}
597

598 599
			return saveOrRevertPromise.then(success => {
				if (success) {
600
					return this.doCloseAll();
601 602 603 604
				}

				return void 0;
			});
605
		});
E
Erich Gamma 已提交
606
	}
607 608 609 610 611 612 613 614 615 616 617 618 619

	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,
620
		@IEditorGroupsService editorGroupService: IEditorGroupsService
621
	) {
622
		super(id, label, 'action-close-all-files', textFileService, editorGroupService);
623 624 625
	}

	protected doCloseAll(): TPromise<any> {
626
		return TPromise.join(this.groupsToClose.map(g => g.closeAllEditors()));
627 628 629 630 631
	}
}

export class CloseAllEditorGroupsAction extends BaseCloseAllAction {

B
Benjamin Pasero 已提交
632
	public static readonly ID = 'workbench.action.closeAllGroups';
633 634 635 636 637 638
	public static readonly LABEL = nls.localize('closeAllGroups', "Close All Editor Groups");

	constructor(
		id: string,
		label: string,
		@ITextFileService textFileService: ITextFileService,
639
		@IEditorGroupsService editorGroupService: IEditorGroupsService
640
	) {
641
		super(id, label, void 0, textFileService, editorGroupService);
642 643 644
	}

	protected doCloseAll(): TPromise<any> {
645 646
		return TPromise.join(this.groupsToClose.map(g => g.closeAllEditors())).then(() => {
			this.groupsToClose.forEach(group => this.editorGroupService.removeGroup(group));
647 648
		});
	}
E
Erich Gamma 已提交
649 650
}

651 652
export class CloseEditorsInOtherGroupsAction extends Action {

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

656 657 658
	constructor(
		id: string,
		label: string,
659
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
660
	) {
661 662 663
		super(id, label);
	}

664
	public run(context?: IEditorIdentifier): TPromise<any> {
I
isidor 已提交
665 666 667 668
		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);
669 670
			}

I
isidor 已提交
671 672
			return g.closeAllEditors();
		}));
673 674 675
	}
}

676
export class BaseMoveGroupAction extends Action {
677

678 679 680
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
681
		private direction: GroupDirection,
682
		private editorGroupService: IEditorGroupsService
683
	) {
E
Erich Gamma 已提交
684 685 686
		super(id, label);
	}

687
	public run(context?: IEditorIdentifier): TPromise<any> {
688
		let sourceGroup: IEditorGroup;
689 690 691 692
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
		} else {
			sourceGroup = this.editorGroupService.activeGroup;
693 694
		}

B
Benjamin Pasero 已提交
695
		const targetGroup = this.findTargetGroup(sourceGroup);
696
		if (targetGroup) {
B
Benjamin Pasero 已提交
697
			this.editorGroupService.moveGroup(sourceGroup, targetGroup, this.direction);
E
Erich Gamma 已提交
698 699
		}

700
		return TPromise.as(true);
E
Erich Gamma 已提交
701
	}
B
Benjamin Pasero 已提交
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

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

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

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

		return void 0;
	}
E
Erich Gamma 已提交
729 730
}

731 732 733 734 735 736 737 738
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,
739
		@IEditorGroupsService editorGroupService: IEditorGroupsService
740
	) {
B
Benjamin Pasero 已提交
741
		super(id, label, GroupDirection.LEFT, editorGroupService);
742 743 744 745
	}
}

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

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

750 751 752
	constructor(
		id: string,
		label: string,
753
		@IEditorGroupsService editorGroupService: IEditorGroupsService
754
	) {
B
Benjamin Pasero 已提交
755
		super(id, label, GroupDirection.RIGHT, editorGroupService);
756 757
	}
}
758

759
export class MoveGroupUpAction extends BaseMoveGroupAction {
760

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

764 765 766
	constructor(
		id: string,
		label: string,
767
		@IEditorGroupsService editorGroupService: IEditorGroupsService
768
	) {
B
Benjamin Pasero 已提交
769
		super(id, label, GroupDirection.UP, editorGroupService);
770 771 772 773 774 775 776 777 778 779 780
	}
}

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,
781
		@IEditorGroupsService editorGroupService: IEditorGroupsService
782
	) {
B
Benjamin Pasero 已提交
783
		super(id, label, GroupDirection.DOWN, editorGroupService);
E
Erich Gamma 已提交
784 785 786
	}
}

787
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
788

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

792
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
793 794 795
		super(id, label);
	}

796
	public run(): TPromise<any> {
797
		this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
798

A
Alex Dima 已提交
799
		return TPromise.as(false);
E
Erich Gamma 已提交
800 801 802
	}
}

B
Benjamin Pasero 已提交
803
export class ResetGroupSizesAction extends Action {
E
Erich Gamma 已提交
804

M
Matt Bierner 已提交
805
	public static readonly ID = 'workbench.action.evenEditorWidths';
B
Benjamin Pasero 已提交
806
	public static readonly LABEL = nls.localize('evenEditorGroups', "Reset Editor Group Sizes");
807

808
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
809 810 811
		super(id, label);
	}

812
	public run(): TPromise<any> {
813
		this.editorGroupService.arrangeGroups(GroupsArrangement.EVEN);
E
Erich Gamma 已提交
814

A
Alex Dima 已提交
815
		return TPromise.as(false);
E
Erich Gamma 已提交
816 817 818
	}
}

819
export class MaximizeGroupAction extends Action {
820

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

824 825 826
	constructor(
		id: string,
		label: string,
827 828
		@IEditorService private editorService: IEditorService,
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
829 830 831 832 833
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

834
	public run(): TPromise<any> {
835 836 837
		if (this.editorService.activeEditor) {
			this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);

838
			return this.partService.setSideBarHidden(true);
839 840
		}

A
Alex Dima 已提交
841
		return TPromise.as(false);
842 843 844
	}
}

845 846
export abstract class BaseNavigateEditorAction extends Action {

847 848 849
	constructor(
		id: string,
		label: string,
850 851
		protected editorGroupService: IEditorGroupsService,
		protected editorService: IEditorService
852
	) {
853 854 855 856 857
		super(id, label);
	}

	public run(): TPromise<any> {
		const result = this.navigate();
858 859
		if (!result) {
			return TPromise.as(false);
860 861
		}

862 863 864 865 866 867 868
		const { groupId, editor } = result;
		if (!editor) {
			return TPromise.as(false);
		}

		const group = this.editorGroupService.getGroup(groupId);
		return group.openEditor(editor);
869 870 871 872 873 874 875
	}

	protected abstract navigate(): IEditorIdentifier;
}

export class OpenNextEditor extends BaseNavigateEditorAction {

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

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

	protected navigate(): IEditorIdentifier {
889 890 891 892 893 894 895 896 897 898

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

		// Otherwise try in next group
B
Benjamin Pasero 已提交
899
		const nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT }, this.editorGroupService.activeGroup, true);
900 901 902 903 904 905
		if (nextGroup) {
			const previousGroupEditors = nextGroup.getEditors(EditorsOrder.SEQUENTIAL);
			return { editor: previousGroupEditors[0], groupId: nextGroup.id };
		}

		return void 0;
906 907 908 909 910
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

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

914 915 916
	constructor(
		id: string,
		label: string,
917 918
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
919 920
	) {
		super(id, label, editorGroupService, editorService);
921 922 923
	}

	protected navigate(): IEditorIdentifier {
924 925 926 927 928 929 930 931 932 933

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

		// Otherwise try in previous group
B
Benjamin Pasero 已提交
934
		const previousGroup = this.editorGroupService.findGroup({ location: GroupLocation.PREVIOUS }, this.editorGroupService.activeGroup, true);
935 936 937 938 939 940
		if (previousGroup) {
			const previousGroupEditors = previousGroup.getEditors(EditorsOrder.SEQUENTIAL);
			return { editor: previousGroupEditors[previousGroupEditors.length - 1], groupId: previousGroup.id };
		}

		return void 0;
941 942 943 944 945
	}
}

export class OpenNextEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
946 947
	public static readonly ID = 'workbench.action.nextEditorInGroup';
	public static readonly LABEL = nls.localize('nextEditorInGroup', "Open Next Editor in Group");
948 949 950 951

	constructor(
		id: string,
		label: string,
952 953
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
954 955 956 957 958
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
959 960 961 962 963
		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 };
964 965 966 967 968
	}
}

export class OpenPreviousEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
969 970
	public static readonly ID = 'workbench.action.previousEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousEditorInGroup', "Open Previous Editor in Group");
971 972 973 974

	constructor(
		id: string,
		label: string,
975 976
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
	) {
		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,
998 999
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1000 1001 1002 1003 1004
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
1005 1006 1007 1008
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[0], groupId: group.id };
1009
	}
B
Benjamin Pasero 已提交
1010 1011
}

1012 1013 1014 1015 1016 1017 1018 1019
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,
1020 1021
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1022 1023 1024 1025 1026
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
1027 1028 1029 1030
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[editors.length - 1], groupId: group.id };
1031 1032 1033
	}
}

B
Benjamin Pasero 已提交
1034 1035
export class NavigateForwardAction extends Action {

M
Matt Bierner 已提交
1036 1037
	public static readonly ID = 'workbench.action.navigateForward';
	public static readonly LABEL = nls.localize('navigateNext', "Go Forward");
B
Benjamin Pasero 已提交
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051

	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 已提交
1052 1053
	public static readonly ID = 'workbench.action.navigateBack';
	public static readonly LABEL = nls.localize('navigatePrevious', "Go Back");
B
Benjamin Pasero 已提交
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063

	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 已提交
1064
}
1065

1066 1067
export class NavigateLastAction extends Action {

M
Matt Bierner 已提交
1068 1069
	public static readonly ID = 'workbench.action.navigateLast';
	public static readonly LABEL = nls.localize('navigateLast', "Go Last");
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081

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

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

		return TPromise.as(null);
	}
}

1082 1083
export class ReopenClosedEditorAction extends Action {

M
Matt Bierner 已提交
1084 1085
	public static readonly ID = 'workbench.action.reopenClosedEditor';
	public static readonly LABEL = nls.localize('reopenClosedEditor', "Reopen Closed Editor");
1086 1087 1088 1089

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1090
		@IHistoryService private historyService: IHistoryService
1091 1092 1093 1094 1095
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1096
		this.historyService.reopenLastClosedEditor();
1097 1098 1099

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
1100 1101
}

1102
export class ClearRecentFilesAction extends Action {
C
22768  
Cristian 已提交
1103

M
Matt Bierner 已提交
1104 1105
	public static readonly ID = 'workbench.action.clearRecentFiles';
	public static readonly LABEL = nls.localize('clearRecentFiles', "Clear Recently Opened");
C
22768  
Cristian 已提交
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115

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

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
1116
		this.windowsService.clearRecentlyOpened();
C
22768  
Cristian 已提交
1117 1118 1119 1120 1121

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
1122
export class ShowEditorsInActiveGroupAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
1123

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

1127 1128 1129
	constructor(
		actionId: string,
		actionLabel: string,
1130
		@IQuickOpenService quickOpenService: IQuickOpenService
1131
	) {
B
Benjamin Pasero 已提交
1132
		super(actionId, actionLabel, NAVIGATE_IN_ACTIVE_GROUP_PREFIX, quickOpenService);
1133
	}
B
Benjamin Pasero 已提交
1134 1135
}

B
Benjamin Pasero 已提交
1136 1137
export class ShowAllEditorsAction extends QuickOpenAction {

M
Matt Bierner 已提交
1138 1139
	public static readonly ID = 'workbench.action.showAllEditors';
	public static readonly LABEL = nls.localize('showAllEditors', "Show All Editors");
B
Benjamin Pasero 已提交
1140 1141 1142 1143 1144 1145

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

1146
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1147 1148 1149 1150 1151

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1152
		@IKeybindingService private keybindingService: IKeybindingService
B
Benjamin Pasero 已提交
1153 1154 1155 1156 1157
	) {
		super(id, label);
	}

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

1160

B
Benjamin Pasero 已提交
1161 1162

		this.quickOpenService.show(NAVIGATE_IN_ACTIVE_GROUP_PREFIX, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1163 1164 1165 1166 1167

		return TPromise.as(true);
	}
}

1168 1169
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1170 1171
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditorInGroup', "Open Previous Recently Used Editor in Group");
1172 1173 1174 1175 1176

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1177
		@IKeybindingService keybindingService: IKeybindingService
1178
	) {
B
Benjamin Pasero 已提交
1179
		super(id, label, quickOpenService, keybindingService);
1180 1181 1182 1183 1184
	}
}

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1185 1186
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditorInGroup', "Open Next Recently Used Editor in Group");
1187 1188 1189 1190 1191

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1192
		@IKeybindingService keybindingService: IKeybindingService
1193
	) {
B
Benjamin Pasero 已提交
1194
		super(id, label, quickOpenService, keybindingService);
1195 1196 1197
	}
}

1198
export class OpenPreviousEditorFromHistoryAction extends Action {
B
Benjamin Pasero 已提交
1199

M
Matt Bierner 已提交
1200 1201
	public static readonly ID = 'workbench.action.openPreviousEditorFromHistory';
	public static readonly LABEL = nls.localize('navigateEditorHistoryByInput', "Open Previous Editor from History");
B
Benjamin Pasero 已提交
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212

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

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

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

		return TPromise.as(true);
	}
}

1221 1222
export class OpenNextRecentlyUsedEditorAction extends Action {

M
Matt Bierner 已提交
1223 1224
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditor', "Open Next Recently Used Editor");
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238

	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 已提交
1239 1240
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditor', "Open Previous Recently Used Editor");
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252

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

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

		return TPromise.as(null);
	}
}

1253 1254
export class ClearEditorHistoryAction extends Action {

M
Matt Bierner 已提交
1255 1256
	public static readonly ID = 'workbench.action.clearEditorHistory';
	public static readonly LABEL = nls.localize('clearEditorHistory', "Clear Editor History");
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267

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

	public run(): TPromise<any> {

1268
		// Editor history
1269 1270 1271 1272 1273 1274
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1275
export class MoveEditorLeftInGroupAction extends ExecuteCommandAction {
1276

M
Matt Bierner 已提交
1277 1278
	public static readonly ID = 'workbench.action.moveEditorLeftInGroup';
	public static readonly LABEL = nls.localize('moveEditorLeft', "Move Editor Left");
1279 1280 1281 1282

	constructor(
		id: string,
		label: string,
1283
		@ICommandService commandService: ICommandService
1284
	) {
1285
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'left' } as ActiveEditorMoveArguments);
1286 1287 1288
	}
}

1289
export class MoveEditorRightInGroupAction extends ExecuteCommandAction {
1290

M
Matt Bierner 已提交
1291 1292
	public static readonly ID = 'workbench.action.moveEditorRightInGroup';
	public static readonly LABEL = nls.localize('moveEditorRight', "Move Editor Right");
1293 1294 1295 1296

	constructor(
		id: string,
		label: string,
1297
		@ICommandService commandService: ICommandService
1298
	) {
1299
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'right' } as ActiveEditorMoveArguments);
1300 1301 1302
	}
}

1303
export class MoveEditorToPreviousGroupAction extends ExecuteCommandAction {
1304

M
Matt Bierner 已提交
1305 1306
	public static readonly ID = 'workbench.action.moveEditorToPreviousGroup';
	public static readonly LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
1307 1308 1309 1310

	constructor(
		id: string,
		label: string,
1311
		@ICommandService commandService: ICommandService
1312
	) {
1313
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'previous', by: 'group' } as ActiveEditorMoveArguments);
1314
	}
1315
}
1316

1317
export class MoveEditorToNextGroupAction extends ExecuteCommandAction {
1318

1319 1320 1321 1322 1323 1324 1325 1326 1327
	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);
1328 1329 1330
	}
}

1331
export class MoveEditorToAboveGroupAction extends ExecuteCommandAction {
1332

1333 1334
	public static readonly ID = 'workbench.action.moveEditorToAboveGroup';
	public static readonly LABEL = nls.localize('moveEditorToAboveGroup', "Move Editor into Above Group");
1335 1336 1337 1338

	constructor(
		id: string,
		label: string,
1339
		@ICommandService commandService: ICommandService
1340
	) {
1341
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'up', by: 'group' } as ActiveEditorMoveArguments);
1342
	}
1343
}
1344

1345
export class MoveEditorToBelowGroupAction extends ExecuteCommandAction {
1346

1347 1348 1349 1350 1351 1352 1353 1354 1355
	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);
1356 1357 1358
	}
}

1359
export class MoveEditorToLeftGroupAction extends ExecuteCommandAction {
1360

1361 1362
	public static readonly ID = 'workbench.action.moveEditorToLeftGroup';
	public static readonly LABEL = nls.localize('moveEditorToLeftGroup', "Move Editor into Left Group");
1363 1364 1365 1366

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

1373
export class MoveEditorToRightGroupAction extends ExecuteCommandAction {
1374

1375 1376 1377 1378 1379 1380 1381 1382 1383
	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);
1384 1385 1386
	}
}

1387
export class MoveEditorToFirstGroupAction extends ExecuteCommandAction {
1388

1389 1390
	public static readonly ID = 'workbench.action.moveEditorToFirstGroup';
	public static readonly LABEL = nls.localize('moveEditorToFirstGroup', "Move Editor into First Group");
1391 1392 1393 1394

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

1401
export class MoveEditorToLastGroupAction extends ExecuteCommandAction {
1402

1403 1404 1405 1406 1407 1408 1409 1410 1411
	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);
1412 1413 1414
	}
}

1415
export class EditorLayoutSingleAction extends ExecuteCommandAction {
1416

1417 1418
	public static readonly ID = 'workbench.action.editorLayoutSingle';
	public static readonly LABEL = nls.localize('editorLayoutSingle', "Single Column Editor Layout");
1419 1420 1421 1422

	constructor(
		id: string,
		label: string,
1423
		@ICommandService commandService: ICommandService
1424
	) {
1425
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}] } as EditorGroupLayout);
1426
	}
1427
}
1428

1429
export class EditorLayoutTwoColumnsAction extends ExecuteCommandAction {
1430

1431 1432 1433 1434 1435 1436 1437 1438 1439
	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);
1440 1441 1442
	}
}

1443
export class EditorLayoutThreeColumnsAction extends ExecuteCommandAction {
1444

1445 1446
	public static readonly ID = 'workbench.action.editorLayoutThreeColumns';
	public static readonly LABEL = nls.localize('editorLayoutThreeColumns', "Three Columns Editor Layout");
1447 1448 1449 1450

	constructor(
		id: string,
		label: string,
1451
		@ICommandService commandService: ICommandService
1452
	) {
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
		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);
1468
	}
1469
}
1470

1471
export class EditorLayoutThreeRowsAction extends ExecuteCommandAction {
1472

1473 1474 1475 1476 1477 1478 1479 1480 1481
	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);
1482
	}
D
Daniel Imms 已提交
1483
}
1484

1485
export class EditorLayoutTwoByTwoGridAction extends ExecuteCommandAction {
1486

1487 1488
	public static readonly ID = 'workbench.action.editorLayoutTwoByTwoGrid';
	public static readonly LABEL = nls.localize('editorLayoutTwoByTwoGrid', "Grid Editor Layout (2x2)");
1489 1490 1491 1492

	constructor(
		id: string,
		label: string,
1493
		@ICommandService commandService: ICommandService
1494
	) {
1495
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{ groups: [{}, {}] }, { groups: [{}, {}] }] } as EditorGroupLayout);
1496
	}
1497
}
1498

B
Benjamin Pasero 已提交
1499
export class EditorLayoutTwoColumnsBottomAction extends ExecuteCommandAction {
1500

B
Benjamin Pasero 已提交
1501 1502
	public static readonly ID = 'workbench.action.editorLayoutTwoColumnsBottom';
	public static readonly LABEL = nls.localize('editorLayoutTwoColumnsBottom', "Two Columns Bottom Editor Layout");
1503 1504 1505 1506 1507 1508

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
B
Benjamin Pasero 已提交
1509
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, { groups: [{}, {}] }], orientation: GroupOrientation.VERTICAL } as EditorGroupLayout);
1510 1511 1512
	}
}

B
Benjamin Pasero 已提交
1513
export class EditorLayoutTwoColumnsRightAction extends ExecuteCommandAction {
1514

B
Benjamin Pasero 已提交
1515 1516
	public static readonly ID = 'workbench.action.editorLayoutTwoColumnsRight';
	public static readonly LABEL = nls.localize('editorLayoutTwoColumnsRight', "Two Columns Right Editor Layout");
1517 1518 1519 1520

	constructor(
		id: string,
		label: string,
1521
		@ICommandService commandService: ICommandService
1522
	) {
B
Benjamin Pasero 已提交
1523
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, { groups: [{}, {}] }], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
1524
	}
1525
}
1526

1527
export class EditorLayoutCenteredAction extends Action {
1528

1529 1530
	public static readonly ID = 'workbench.action.editorLayoutCentered';
	public static readonly LABEL = nls.localize('editorLayoutCentered', "Centered Editor Layout");
1531 1532 1533 1534

	constructor(
		id: string,
		label: string,
1535 1536
		@IPartService private partService: IPartService,
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
1537
	) {
1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551
		super(id, label);
	}

	public run(): TPromise<any> {

		// Ensure we can enter centered editor layout even if there are more than 1 groups
		if (this.editorGroupService.count > 1) {
			mergeAllGroups(this.editorGroupService);
		}

		// Center editor layout
		this.partService.centerEditorLayout(true);

		return TPromise.as(true);
1552
	}
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574
}

export class BaseCreateEditorGroupAction extends Action {

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

	public run(): TPromise<any> {
		this.editorGroupService.addGroup(this.editorGroupService.activeGroup, this.direction, { activate: true });

		return TPromise.as(true);
	}
}

export class NewEditorGroupLeftAction extends BaseCreateEditorGroupAction {

B
Benjamin Pasero 已提交
1575 1576
	public static readonly ID = 'workbench.action.newGroupLeft';
	public static readonly LABEL = nls.localize('newEditorLeft', "New Editor Group to the Left");
1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588

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

export class NewEditorGroupRightAction extends BaseCreateEditorGroupAction {

B
Benjamin Pasero 已提交
1589 1590
	public static readonly ID = 'workbench.action.newGroupRight';
	public static readonly LABEL = nls.localize('newEditorRight', "New Editor Group to the Right");
1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602

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

export class NewEditorGroupAboveAction extends BaseCreateEditorGroupAction {

B
Benjamin Pasero 已提交
1603 1604
	public static readonly ID = 'workbench.action.newGroupAbove';
	public static readonly LABEL = nls.localize('newEditorAbove', "New Editor Group Above");
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616

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

export class NewEditorGroupBelowAction extends BaseCreateEditorGroupAction {

B
Benjamin Pasero 已提交
1617 1618
	public static readonly ID = 'workbench.action.newGroupBelow';
	public static readonly LABEL = nls.localize('newEditorBelow', "New Editor Group Below");
1619 1620 1621 1622 1623 1624 1625 1626

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