editorActions.ts 48.0 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, EditorGroupLayout, mergeAllGroups } from 'vs/workbench/browser/parts/editor/editorCommands';
23
import { IEditorGroupsService, IEditorGroup, GroupsArrangement, EditorsOrder, GroupLocation, GroupDirection, preferredSideBySideGroupDirection, IFindGroupScope, GroupOrientation } from 'vs/workbench/services/group/common/editorGroupsService';
24
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
B
Benjamin Pasero 已提交
25
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
26
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
E
Erich Gamma 已提交
27

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
export class ExecuteCommandAction extends Action {

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

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

45
export class 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 146
	public static readonly ID = 'workbench.action.joinTwoGroups';
	public static readonly LABEL = nls.localize('joinTwoGroups', "Join Editors of Two Groups");
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 165 166 167 168
		const targetGroup =
			this.editorGroupService.findGroup({ direction: GroupDirection.RIGHT }, sourceGroup) ||
			this.editorGroupService.findGroup({ direction: GroupDirection.DOWN }, sourceGroup) ||
			this.editorGroupService.findGroup({ direction: GroupDirection.UP }, sourceGroup) ||
			this.editorGroupService.findGroup({ direction: GroupDirection.LEFT }, sourceGroup);
169

B
Benjamin Pasero 已提交
170 171 172
		if (targetGroup && sourceGroup !== targetGroup) {
			this.editorGroupService.mergeGroup(sourceGroup, targetGroup);
		}
I
initialshl 已提交
173 174 175 176 177

		return TPromise.as(true);
	}
}

178 179 180 181 182 183 184 185 186 187 188 189 190 191
export class JoinAllGroupsAction extends Action {

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

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

	public run(context?: IEditorIdentifier): TPromise<any> {
192
		mergeAllGroups(this.editorGroupService);
193 194 195 196 197

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
198
export class NavigateBetweenGroupsAction extends Action {
199

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

203 204 205
	constructor(
		id: string,
		label: string,
206
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
207
	) {
E
Erich Gamma 已提交
208 209 210
		super(id, label);
	}

211
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
212 213 214
		let nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT });
		if (!nextGroup) {
			nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.FIRST });
E
Erich Gamma 已提交
215 216
		}

B
Benjamin Pasero 已提交
217
		nextGroup.focus();
218 219

		return TPromise.as(true);
E
Erich Gamma 已提交
220 221 222
	}
}

223 224
export class FocusActiveGroupAction extends Action {

M
Matt Bierner 已提交
225 226
	public static readonly ID = 'workbench.action.focusActiveEditorGroup';
	public static readonly LABEL = nls.localize('focusActiveEditorGroup', "Focus Active Editor Group");
227 228 229 230

	constructor(
		id: string,
		label: string,
231
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
232 233 234 235 236
	) {
		super(id, label);
	}

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

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

243
export abstract class BaseFocusGroupAction extends Action {
E
Erich Gamma 已提交
244 245 246 247

	constructor(
		id: string,
		label: string,
248
		private scope: IFindGroupScope,
249
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
250 251 252 253
	) {
		super(id, label);
	}

254
	public run(): TPromise<any> {
255 256 257 258
		const group = this.editorGroupService.findGroup(this.scope);
		if (group) {
			group.focus();
		}
E
Erich Gamma 已提交
259

A
Alex Dima 已提交
260
		return TPromise.as(true);
E
Erich Gamma 已提交
261 262 263
	}
}

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
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 已提交
279 280 281

	public static readonly ID = 'workbench.action.focusLastEditorGroup';
	public static readonly LABEL = nls.localize('focusLastEditorGroup', "Focus Last Editor Group");
E
Erich Gamma 已提交
282 283 284 285

	constructor(
		id: string,
		label: string,
286
		@IEditorGroupsService editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
287
	) {
288
		super(id, label, { location: GroupLocation.LAST }, editorGroupService);
E
Erich Gamma 已提交
289
	}
290
}
E
Erich Gamma 已提交
291

292
export class FocusNextGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
293

294 295 296 297 298 299 300 301 302
	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 已提交
303 304 305
	}
}

306
export class FocusPreviousGroup extends BaseFocusGroupAction {
307

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

311 312 313
	constructor(
		id: string,
		label: string,
314
		@IEditorGroupsService editorGroupService: IEditorGroupsService
315
	) {
316
		super(id, label, { location: GroupLocation.PREVIOUS }, editorGroupService);
E
Erich Gamma 已提交
317
	}
318
}
E
Erich Gamma 已提交
319

320
export class FocusLeftGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
321

322 323 324 325 326 327 328 329 330
	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 已提交
331 332 333
	}
}

334
export class FocusRightGroup extends BaseFocusGroupAction {
335

336 337
	public static readonly ID = 'workbench.action.focusRightGroup';
	public static readonly LABEL = nls.localize('focusRightGroup', "Focus Right Editor Group");
338

E
Erich Gamma 已提交
339 340 341
	constructor(
		id: string,
		label: string,
342
		@IEditorGroupsService editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
343
	) {
344
		super(id, label, { direction: GroupDirection.RIGHT }, editorGroupService);
E
Erich Gamma 已提交
345
	}
346
}
E
Erich Gamma 已提交
347

348
export class FocusAboveGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
349

350 351 352 353 354 355 356 357 358
	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 已提交
359 360 361
	}
}

362 363 364 365 366 367 368 369 370 371 372 373 374 375
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);
	}
}

376
export class OpenToSideFromQuickOpenAction extends Action {
E
Erich Gamma 已提交
377

M
Matt Bierner 已提交
378 379
	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 已提交
380

381
	constructor(
382
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
383
		@IConfigurationService private configurationService: IConfigurationService
384
	) {
385
		super(OpenToSideFromQuickOpenAction.OPEN_TO_SIDE_ID, OpenToSideFromQuickOpenAction.OPEN_TO_SIDE_LABEL);
E
Erich Gamma 已提交
386

387 388 389 390
		this.updateClass();
	}

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

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

396
	public run(context: any): TPromise<any> {
B
Benjamin Pasero 已提交
397
		const entry = toEditorQuickOpenEntry(context);
E
Erich Gamma 已提交
398
		if (entry) {
399
			const input = entry.getInput();
B
Benjamin Pasero 已提交
400
			if (input instanceof EditorInput) {
B
Benjamin Pasero 已提交
401
				return this.editorService.openEditor(input, entry.getOptions(), SIDE_GROUP);
B
Benjamin Pasero 已提交
402 403
			}

404 405 406
			const resourceInput = input as IResourceInput;
			resourceInput.options = mixin(resourceInput.options, entry.getOptions());

B
Benjamin Pasero 已提交
407
			return this.editorService.openEditor(resourceInput, SIDE_GROUP);
E
Erich Gamma 已提交
408 409
		}

A
Alex Dima 已提交
410
		return TPromise.as(false);
E
Erich Gamma 已提交
411 412 413
	}
}

414
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
415 416 417

	// QuickOpenEntryGroup
	if (element instanceof QuickOpenEntryGroup) {
418
		const group = <QuickOpenEntryGroup>element;
E
Erich Gamma 已提交
419 420 421 422 423 424 425 426 427 428 429 430 431 432
		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 {
433

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

437 438 439
	constructor(
		id: string,
		label: string,
I
isidor 已提交
440
		@ICommandService private commandService: ICommandService
441
	) {
I
isidor 已提交
442
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
443 444
	}

I
isidor 已提交
445
	public run(context?: IEditorCommandsContext): TPromise<any> {
446
		return this.commandService.executeCommand(CLOSE_EDITOR_COMMAND_ID, void 0, context);
E
Erich Gamma 已提交
447 448 449
	}
}

450 451 452 453 454 455 456 457
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,
458
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
459 460 461 462 463
	) {
		super(id, label, 'close-editor-action');
	}

	public run(context?: IEditorCommandsContext): TPromise<any> {
464
		let group: IEditorGroup;
465 466
		let editorIndex: number;
		if (context) {
467
			group = this.editorGroupService.getGroup(context.groupId);
468

469 470
			if (group) {
				editorIndex = context.editorIndex; // only allow editor at index if group is valid
471 472 473
			}
		}

474
		if (!group) {
475
			group = this.editorGroupService.activeGroup;
476 477
		}

478 479 480 481
		// Close specific editor in group
		if (typeof editorIndex === 'number') {
			const editorAtIndex = group.getEditor(editorIndex);
			if (editorAtIndex) {
482
				return group.closeEditor(editorAtIndex);
483 484 485 486 487
			}
		}

		// Otherwise close active editor in group
		if (group.activeEditor) {
488
			return group.closeEditor(group.activeEditor);
489 490 491 492 493 494
		}

		return TPromise.as(false);
	}
}

M
misoguy 已提交
495 496
export class RevertAndCloseEditorAction extends Action {

M
Matt Bierner 已提交
497 498
	public static readonly ID = 'workbench.action.revertAndCloseActiveEditor';
	public static readonly LABEL = nls.localize('revertAndCloseActiveEditor', "Revert and Close Editor");
M
misoguy 已提交
499 500 501 502

	constructor(
		id: string,
		label: string,
503
		@IEditorService private editorService: IEditorService
M
misoguy 已提交
504 505 506 507 508
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
509
		const activeControl = this.editorService.activeControl;
B
Benjamin Pasero 已提交
510
		if (activeControl) {
B
Benjamin Pasero 已提交
511
			const editor = activeControl.input;
512
			const group = activeControl.group;
B
Benjamin Pasero 已提交
513

514
			// first try a normal revert where the contents of the editor are restored
B
Benjamin Pasero 已提交
515
			return editor.revert().then(() => group.closeEditor(editor), error => {
516 517 518 519
				// 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 已提交
520
				return editor.revert({ soft: true }).then(() => group.closeEditor(editor));
521
			});
M
misoguy 已提交
522 523 524 525 526 527
		}

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
528
export class CloseLeftEditorsInGroupAction extends Action {
529

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

533 534 535
	constructor(
		id: string,
		label: string,
536
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
537
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
538
	) {
539 540 541
		super(id, label);
	}

542
	public run(context?: IEditorIdentifier): TPromise<any> {
B
Benjamin Pasero 已提交
543
		const { group, editor } = getTarget(this.editorService, this.editorGroupService, context);
B
Benjamin Pasero 已提交
544 545
		if (group && editor) {
			return group.closeEditors({ direction: CloseDirection.LEFT, except: editor });
546 547 548 549 550 551
		}

		return TPromise.as(false);
	}
}

552
function getTarget(editorService: IEditorService, editorGroupService: IEditorGroupsService, context?: IEditorIdentifier): { editor: IEditorInput, group: IEditorGroup } {
B
Benjamin Pasero 已提交
553 554 555 556 557 558 559 560
	if (context) {
		return { editor: context.editor, group: editorGroupService.getGroup(context.groupId) };
	}

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

561
export abstract class BaseCloseAllAction extends Action {
562

563 564 565
	constructor(
		id: string,
		label: string,
566 567
		clazz: string,
		private textFileService: ITextFileService
568
	) {
569
		super(id, label, clazz);
E
Erich Gamma 已提交
570 571
	}

572
	public run(): TPromise<any> {
573 574 575

		// Just close all if there are no or one dirty editor
		if (this.textFileService.getDirty().length < 2) {
576
			return this.doCloseAll();
577 578 579
		}

		// Otherwise ask for combined confirmation
580 581 582 583
		return this.textFileService.confirmSave().then(confirm => {
			if (confirm === ConfirmResult.CANCEL) {
				return void 0;
			}
584

585 586 587 588 589
			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));
590
			}
591

592 593
			return saveOrRevertPromise.then(success => {
				if (success) {
594
					return this.doCloseAll();
595 596 597 598
				}

				return void 0;
			});
599
		});
E
Erich Gamma 已提交
600
	}
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642

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

export class CloseAllEditorsAction extends BaseCloseAllAction {

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

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

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

export class CloseAllEditorGroupsAction extends BaseCloseAllAction {

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

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

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

645 646
export class CloseEditorsInOtherGroupsAction extends Action {

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

650 651 652
	constructor(
		id: string,
		label: string,
653
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
654
	) {
655 656 657
		super(id, label);
	}

658
	public run(context?: IEditorIdentifier): TPromise<any> {
I
isidor 已提交
659 660 661 662
		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);
663 664
			}

I
isidor 已提交
665 666
			return g.closeAllEditors();
		}));
667 668 669
	}
}

670
export class BaseMoveGroupAction extends Action {
671

672 673 674
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
675
		private direction: GroupDirection,
676
		private editorGroupService: IEditorGroupsService
677
	) {
E
Erich Gamma 已提交
678 679 680
		super(id, label);
	}

681
	public run(context?: IEditorIdentifier): TPromise<any> {
682
		let sourceGroup: IEditorGroup;
683 684 685 686
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
		} else {
			sourceGroup = this.editorGroupService.activeGroup;
687 688
		}

B
Benjamin Pasero 已提交
689
		const targetGroup = this.editorGroupService.findGroup({ direction: this.direction }, sourceGroup);
690
		if (targetGroup) {
B
Benjamin Pasero 已提交
691
			this.editorGroupService.moveGroup(sourceGroup, targetGroup, this.direction);
E
Erich Gamma 已提交
692 693
		}

694
		return TPromise.as(true);
E
Erich Gamma 已提交
695 696 697
	}
}

698 699 700 701 702 703 704 705
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,
706
		@IEditorGroupsService editorGroupService: IEditorGroupsService
707
	) {
B
Benjamin Pasero 已提交
708
		super(id, label, GroupDirection.LEFT, editorGroupService);
709 710 711 712
	}
}

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

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

717 718 719
	constructor(
		id: string,
		label: string,
720
		@IEditorGroupsService editorGroupService: IEditorGroupsService
721
	) {
B
Benjamin Pasero 已提交
722
		super(id, label, GroupDirection.RIGHT, editorGroupService);
723 724
	}
}
725

726
export class MoveGroupUpAction extends BaseMoveGroupAction {
727

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

731 732 733
	constructor(
		id: string,
		label: string,
734
		@IEditorGroupsService editorGroupService: IEditorGroupsService
735
	) {
B
Benjamin Pasero 已提交
736
		super(id, label, GroupDirection.UP, editorGroupService);
737 738 739 740 741 742 743 744 745 746 747
	}
}

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,
748
		@IEditorGroupsService editorGroupService: IEditorGroupsService
749
	) {
B
Benjamin Pasero 已提交
750
		super(id, label, GroupDirection.DOWN, editorGroupService);
E
Erich Gamma 已提交
751 752 753
	}
}

754
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
755

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

759
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
760 761 762
		super(id, label);
	}

763
	public run(): TPromise<any> {
764
		this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
765

A
Alex Dima 已提交
766
		return TPromise.as(false);
E
Erich Gamma 已提交
767 768 769
	}
}

770
export class EvenGroupWidthsAction extends Action {
E
Erich Gamma 已提交
771

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

775
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
776 777 778
		super(id, label);
	}

779
	public run(): TPromise<any> {
780
		this.editorGroupService.arrangeGroups(GroupsArrangement.EVEN);
E
Erich Gamma 已提交
781

A
Alex Dima 已提交
782
		return TPromise.as(false);
E
Erich Gamma 已提交
783 784 785
	}
}

786
export class MaximizeGroupAction extends Action {
787

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

791 792 793
	constructor(
		id: string,
		label: string,
794 795
		@IEditorService private editorService: IEditorService,
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
796 797 798 799 800
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

801
	public run(): TPromise<any> {
802 803 804
		if (this.editorService.activeEditor) {
			this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);

805
			return this.partService.setSideBarHidden(true);
806 807
		}

A
Alex Dima 已提交
808
		return TPromise.as(false);
809 810 811
	}
}

812 813
export abstract class BaseNavigateEditorAction extends Action {

814 815 816
	constructor(
		id: string,
		label: string,
817 818
		protected editorGroupService: IEditorGroupsService,
		protected editorService: IEditorService
819
	) {
820 821 822 823 824
		super(id, label);
	}

	public run(): TPromise<any> {
		const result = this.navigate();
825 826
		if (!result) {
			return TPromise.as(false);
827 828
		}

829 830 831 832 833 834 835
		const { groupId, editor } = result;
		if (!editor) {
			return TPromise.as(false);
		}

		const group = this.editorGroupService.getGroup(groupId);
		return group.openEditor(editor);
836 837 838 839 840 841 842
	}

	protected abstract navigate(): IEditorIdentifier;
}

export class OpenNextEditor extends BaseNavigateEditorAction {

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

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

	protected navigate(): IEditorIdentifier {
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872

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

		// Otherwise try in next group
		const nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT });
		if (nextGroup) {
			const previousGroupEditors = nextGroup.getEditors(EditorsOrder.SEQUENTIAL);
			return { editor: previousGroupEditors[0], groupId: nextGroup.id };
		}

		return void 0;
873 874 875 876 877
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

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

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

	protected navigate(): IEditorIdentifier {
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907

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

		// Otherwise try in previous group
		const previousGroup = this.editorGroupService.findGroup({ location: GroupLocation.PREVIOUS });
		if (previousGroup) {
			const previousGroupEditors = previousGroup.getEditors(EditorsOrder.SEQUENTIAL);
			return { editor: previousGroupEditors[previousGroupEditors.length - 1], groupId: previousGroup.id };
		}

		return void 0;
908 909 910 911 912
	}
}

export class OpenNextEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
913 914
	public static readonly ID = 'workbench.action.nextEditorInGroup';
	public static readonly LABEL = nls.localize('nextEditorInGroup', "Open Next Editor in Group");
915 916 917 918

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

	protected navigate(): IEditorIdentifier {
926 927 928 929 930
		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 };
931 932 933 934 935
	}
}

export class OpenPreviousEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
936 937
	public static readonly ID = 'workbench.action.previousEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousEditorInGroup', "Open Previous Editor in Group");
938 939 940 941

	constructor(
		id: string,
		label: string,
942 943
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
	) {
		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,
965 966
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
967 968 969 970 971
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
972 973 974 975
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[0], groupId: group.id };
976
	}
B
Benjamin Pasero 已提交
977 978
}

979 980 981 982 983 984 985 986
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,
987 988
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
989 990 991 992 993
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
994 995 996 997
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[editors.length - 1], groupId: group.id };
998 999 1000
	}
}

B
Benjamin Pasero 已提交
1001 1002
export class NavigateForwardAction extends Action {

M
Matt Bierner 已提交
1003 1004
	public static readonly ID = 'workbench.action.navigateForward';
	public static readonly LABEL = nls.localize('navigateNext', "Go Forward");
B
Benjamin Pasero 已提交
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018

	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 已提交
1019 1020
	public static readonly ID = 'workbench.action.navigateBack';
	public static readonly LABEL = nls.localize('navigatePrevious', "Go Back");
B
Benjamin Pasero 已提交
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030

	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 已提交
1031
}
1032

1033 1034
export class NavigateLastAction extends Action {

M
Matt Bierner 已提交
1035 1036
	public static readonly ID = 'workbench.action.navigateLast';
	public static readonly LABEL = nls.localize('navigateLast', "Go Last");
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048

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

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

		return TPromise.as(null);
	}
}

1049 1050
export class ReopenClosedEditorAction extends Action {

M
Matt Bierner 已提交
1051 1052
	public static readonly ID = 'workbench.action.reopenClosedEditor';
	public static readonly LABEL = nls.localize('reopenClosedEditor', "Reopen Closed Editor");
1053 1054 1055 1056

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1057
		@IHistoryService private historyService: IHistoryService
1058 1059 1060 1061 1062
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1063
		this.historyService.reopenLastClosedEditor();
1064 1065 1066

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
1067 1068
}

1069
export class ClearRecentFilesAction extends Action {
C
22768  
Cristian 已提交
1070

M
Matt Bierner 已提交
1071 1072
	public static readonly ID = 'workbench.action.clearRecentFiles';
	public static readonly LABEL = nls.localize('clearRecentFiles', "Clear Recently Opened");
C
22768  
Cristian 已提交
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082

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

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
1083
		this.windowsService.clearRecentlyOpened();
C
22768  
Cristian 已提交
1084 1085 1086 1087 1088

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
1089
export class ShowEditorsInActiveGroupAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
1090

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

1094 1095 1096
	constructor(
		actionId: string,
		actionLabel: string,
1097
		@IQuickOpenService quickOpenService: IQuickOpenService
1098
	) {
B
Benjamin Pasero 已提交
1099
		super(actionId, actionLabel, NAVIGATE_IN_ACTIVE_GROUP_PREFIX, quickOpenService);
1100
	}
B
Benjamin Pasero 已提交
1101 1102
}

B
Benjamin Pasero 已提交
1103 1104
export class ShowAllEditorsAction extends QuickOpenAction {

M
Matt Bierner 已提交
1105 1106
	public static readonly ID = 'workbench.action.showAllEditors';
	public static readonly LABEL = nls.localize('showAllEditors', "Show All Editors");
B
Benjamin Pasero 已提交
1107 1108 1109 1110 1111 1112

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

1113
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1114 1115 1116 1117 1118

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

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

1127

B
Benjamin Pasero 已提交
1128 1129

		this.quickOpenService.show(NAVIGATE_IN_ACTIVE_GROUP_PREFIX, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1130 1131 1132 1133 1134

		return TPromise.as(true);
	}
}

1135 1136
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1137 1138
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditorInGroup', "Open Previous Recently Used Editor in Group");
1139 1140 1141 1142 1143

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1144
		@IKeybindingService keybindingService: IKeybindingService
1145
	) {
B
Benjamin Pasero 已提交
1146
		super(id, label, quickOpenService, keybindingService);
1147 1148 1149 1150 1151
	}
}

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1152 1153
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditorInGroup', "Open Next Recently Used Editor in Group");
1154 1155 1156 1157 1158

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1159
		@IKeybindingService keybindingService: IKeybindingService
1160
	) {
B
Benjamin Pasero 已提交
1161
		super(id, label, quickOpenService, keybindingService);
1162 1163 1164
	}
}

1165
export class OpenPreviousEditorFromHistoryAction extends Action {
B
Benjamin Pasero 已提交
1166

M
Matt Bierner 已提交
1167 1168
	public static readonly ID = 'workbench.action.openPreviousEditorFromHistory';
	public static readonly LABEL = nls.localize('navigateEditorHistoryByInput', "Open Previous Editor from History");
B
Benjamin Pasero 已提交
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179

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

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

B
Benjamin Pasero 已提交
1182
		this.quickOpenService.show(null, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1183 1184 1185 1186 1187

		return TPromise.as(true);
	}
}

1188 1189
export class OpenNextRecentlyUsedEditorAction extends Action {

M
Matt Bierner 已提交
1190 1191
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditor', "Open Next Recently Used Editor");
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205

	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 已提交
1206 1207
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditor', "Open Previous Recently Used Editor");
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219

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

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

		return TPromise.as(null);
	}
}

1220 1221
export class ClearEditorHistoryAction extends Action {

M
Matt Bierner 已提交
1222 1223
	public static readonly ID = 'workbench.action.clearEditorHistory';
	public static readonly LABEL = nls.localize('clearEditorHistory', "Clear Editor History");
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234

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

	public run(): TPromise<any> {

1235
		// Editor history
1236 1237 1238 1239 1240 1241
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1242
export class MoveEditorLeftInGroupAction extends ExecuteCommandAction {
1243

M
Matt Bierner 已提交
1244 1245
	public static readonly ID = 'workbench.action.moveEditorLeftInGroup';
	public static readonly LABEL = nls.localize('moveEditorLeft', "Move Editor Left");
1246 1247 1248 1249

	constructor(
		id: string,
		label: string,
1250
		@ICommandService commandService: ICommandService
1251
	) {
1252
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'left' } as ActiveEditorMoveArguments);
1253 1254 1255
	}
}

1256
export class MoveEditorRightInGroupAction extends ExecuteCommandAction {
1257

M
Matt Bierner 已提交
1258 1259
	public static readonly ID = 'workbench.action.moveEditorRightInGroup';
	public static readonly LABEL = nls.localize('moveEditorRight', "Move Editor Right");
1260 1261 1262 1263

	constructor(
		id: string,
		label: string,
1264
		@ICommandService commandService: ICommandService
1265
	) {
1266
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'right' } as ActiveEditorMoveArguments);
1267 1268 1269
	}
}

1270
export class MoveEditorToPreviousGroupAction extends ExecuteCommandAction {
1271

M
Matt Bierner 已提交
1272 1273
	public static readonly ID = 'workbench.action.moveEditorToPreviousGroup';
	public static readonly LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
1274 1275 1276 1277

	constructor(
		id: string,
		label: string,
1278
		@ICommandService commandService: ICommandService
1279
	) {
1280
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'previous', by: 'group' } as ActiveEditorMoveArguments);
1281
	}
1282
}
1283

1284
export class MoveEditorToNextGroupAction extends ExecuteCommandAction {
1285

1286 1287 1288 1289 1290 1291 1292 1293 1294
	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);
1295 1296 1297
	}
}

1298
export class MoveEditorToAboveGroupAction extends ExecuteCommandAction {
1299

1300 1301
	public static readonly ID = 'workbench.action.moveEditorToAboveGroup';
	public static readonly LABEL = nls.localize('moveEditorToAboveGroup', "Move Editor into Above Group");
1302 1303 1304 1305

	constructor(
		id: string,
		label: string,
1306
		@ICommandService commandService: ICommandService
1307
	) {
1308
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'up', by: 'group' } as ActiveEditorMoveArguments);
1309
	}
1310
}
1311

1312
export class MoveEditorToBelowGroupAction extends ExecuteCommandAction {
1313

1314 1315 1316 1317 1318 1319 1320 1321 1322
	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);
1323 1324 1325
	}
}

1326
export class MoveEditorToLeftGroupAction extends ExecuteCommandAction {
1327

1328 1329
	public static readonly ID = 'workbench.action.moveEditorToLeftGroup';
	public static readonly LABEL = nls.localize('moveEditorToLeftGroup', "Move Editor into Left Group");
1330 1331 1332 1333

	constructor(
		id: string,
		label: string,
1334
		@ICommandService commandService: ICommandService
1335
	) {
1336
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'left', by: 'group' } as ActiveEditorMoveArguments);
1337
	}
1338
}
1339

1340
export class MoveEditorToRightGroupAction extends ExecuteCommandAction {
1341

1342 1343 1344 1345 1346 1347 1348 1349 1350
	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);
1351 1352 1353
	}
}

1354
export class MoveEditorToFirstGroupAction extends ExecuteCommandAction {
1355

1356 1357
	public static readonly ID = 'workbench.action.moveEditorToFirstGroup';
	public static readonly LABEL = nls.localize('moveEditorToFirstGroup', "Move Editor into First Group");
1358 1359 1360 1361

	constructor(
		id: string,
		label: string,
1362
		@ICommandService commandService: ICommandService
1363
	) {
1364
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'first', by: 'group' } as ActiveEditorMoveArguments);
1365
	}
1366
}
1367

1368
export class MoveEditorToLastGroupAction extends ExecuteCommandAction {
1369

1370 1371 1372 1373 1374 1375 1376 1377 1378
	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);
1379 1380 1381
	}
}

1382
export class EditorLayoutSingleAction extends ExecuteCommandAction {
1383

1384 1385
	public static readonly ID = 'workbench.action.editorLayoutSingle';
	public static readonly LABEL = nls.localize('editorLayoutSingle', "Single Column Editor Layout");
1386 1387 1388 1389

	constructor(
		id: string,
		label: string,
1390
		@ICommandService commandService: ICommandService
1391
	) {
1392
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}] } as EditorGroupLayout);
1393
	}
1394
}
1395

1396
export class EditorLayoutTwoColumnsAction extends ExecuteCommandAction {
1397

1398 1399 1400 1401 1402 1403 1404 1405 1406
	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);
1407 1408 1409
	}
}

1410
export class EditorLayoutThreeColumnsAction extends ExecuteCommandAction {
1411

1412 1413
	public static readonly ID = 'workbench.action.editorLayoutThreeColumns';
	public static readonly LABEL = nls.localize('editorLayoutThreeColumns', "Three Columns Editor Layout");
1414 1415 1416 1417

	constructor(
		id: string,
		label: string,
1418
		@ICommandService commandService: ICommandService
1419
	) {
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
		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);
1435
	}
1436
}
1437

1438
export class EditorLayoutThreeRowsAction extends ExecuteCommandAction {
1439

1440 1441 1442 1443 1444 1445 1446 1447 1448
	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);
1449
	}
D
Daniel Imms 已提交
1450
}
1451

1452
export class EditorLayoutTwoByTwoGridAction extends ExecuteCommandAction {
1453

1454 1455
	public static readonly ID = 'workbench.action.editorLayoutTwoByTwoGrid';
	public static readonly LABEL = nls.localize('editorLayoutTwoByTwoGrid', "Grid Editor Layout (2x2)");
1456 1457 1458 1459

	constructor(
		id: string,
		label: string,
1460
		@ICommandService commandService: ICommandService
1461
	) {
1462
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{ groups: [{}, {}] }, { groups: [{}, {}] }] } as EditorGroupLayout);
1463
	}
1464
}
1465

B
Benjamin Pasero 已提交
1466
export class EditorLayoutTwoColumnsBottomAction extends ExecuteCommandAction {
1467

B
Benjamin Pasero 已提交
1468 1469
	public static readonly ID = 'workbench.action.editorLayoutTwoColumnsBottom';
	public static readonly LABEL = nls.localize('editorLayoutTwoColumnsBottom', "Two Columns Bottom Editor Layout");
1470 1471 1472 1473 1474 1475

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
B
Benjamin Pasero 已提交
1476
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, { groups: [{}, {}] }], orientation: GroupOrientation.VERTICAL } as EditorGroupLayout);
1477 1478 1479
	}
}

B
Benjamin Pasero 已提交
1480
export class EditorLayoutTwoColumnsRightAction extends ExecuteCommandAction {
1481

B
Benjamin Pasero 已提交
1482 1483
	public static readonly ID = 'workbench.action.editorLayoutTwoColumnsRight';
	public static readonly LABEL = nls.localize('editorLayoutTwoColumnsRight', "Two Columns Right Editor Layout");
1484 1485 1486 1487

	constructor(
		id: string,
		label: string,
1488
		@ICommandService commandService: ICommandService
1489
	) {
B
Benjamin Pasero 已提交
1490
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, { groups: [{}, {}] }], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
1491
	}
1492
}
1493

1494
export class EditorLayoutGoldenRatioAction extends ExecuteCommandAction {
1495

1496 1497 1498 1499 1500 1501 1502 1503 1504
	public static readonly ID = 'workbench.action.editorLayoutGoldenRatio';
	public static readonly LABEL = nls.localize('editorLayoutGoldenRatio', "Golden Ratio Editor Layout");

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{ size: 0.618 }, { size: 0.382, groups: [{ size: 0.618 }, { size: 0.382 }] }], orientation: GroupOrientation.HORIZONTAL } as EditorGroupLayout);
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 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
}

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 {

	public static readonly ID = 'workbench.action.newEditorGroupLeft';
	public static readonly LABEL = nls.localize('newEditorGroupLeft', "New Editor Group to the Left");

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

export class NewEditorGroupRightAction extends BaseCreateEditorGroupAction {

	public static readonly ID = 'workbench.action.newEditorGroupRight';
	public static readonly LABEL = nls.localize('newEditorGroupRight', "New Editor Group to the Right");

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

export class NewEditorGroupAboveAction extends BaseCreateEditorGroupAction {

	public static readonly ID = 'workbench.action.newEditorGroupAbove';
	public static readonly LABEL = nls.localize('newEditorGroupAbove', "New Editor Group Above");

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

export class NewEditorGroupBelowAction extends BaseCreateEditorGroupAction {

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

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