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

J
Johannes Rieken 已提交
7
import { TPromise } from 'vs/base/common/winjs.base';
8
import * as nls from 'vs/nls';
J
Johannes Rieken 已提交
9
import { Action } from 'vs/base/common/actions';
10
import { mixin } from 'vs/base/common/objects';
B
Benjamin Pasero 已提交
11
import { IEditorInput, EditorInput, IEditorIdentifier, ConfirmResult, IEditorCommandsContext, CloseDirection } from 'vs/workbench/common/editor';
J
Johannes Rieken 已提交
12 13
import { QuickOpenEntryGroup } from 'vs/base/parts/quickopen/browser/quickOpenModel';
import { EditorQuickOpenEntry, EditorQuickOpenEntryGroup, IEditorQuickOpenEntry, QuickOpenAction } from 'vs/workbench/browser/quickopen';
J
Johannes Rieken 已提交
14
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
J
Johannes Rieken 已提交
15
import { IPartService } from 'vs/workbench/services/part/common/partService';
B
Benjamin Pasero 已提交
16
import { IResourceInput } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
17 18 19
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ICommandService } from 'vs/platform/commands/common/commands';
20
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
C
22768  
Cristian 已提交
21
import { IWindowsService } from 'vs/platform/windows/common/windows';
22
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 BaseSplitEditorGroupAction extends Action {
46

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

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

		return TPromise.as(true);
	}

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

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

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

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

75 76 77
	constructor(
		id: string,
		label: string,
78
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
79
		@IConfigurationService private configurationService: IConfigurationService
80
	) {
81
		super(id, label, null, preferredSideBySideGroupDirection(configurationService), editorGroupService);
82 83 84 85 86 87 88

		this.registerListeners();
	}

	private registerListeners(): void {
		this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => {
			if (e.affectsConfiguration('workbench.editor.openSideBySideDirection')) {
89
				this.direction = preferredSideBySideGroupDirection(this.configurationService);
90 91 92 93
			}
		}));
	}

94 95
	public run(context?: IEditorIdentifier): TPromise<any> {
		this.splitEditor(context ? context.groupId : void 0);
96 97 98 99

		return TPromise.as(true);
	}

100 101 102 103
	public dispose(): void {
		super.dispose();

		this.toDispose = dispose(this.toDispose);
104 105 106
	}
}

107
export class SplitEditorLeftAction extends ExecuteCommandAction {
108

109
	public static readonly ID = SPLIT_EDITOR_LEFT;
110
	public static readonly LABEL = nls.localize('splitEditorGroupLeft', "Split Editor Left");
111 112 113 114

	constructor(
		id: string,
		label: string,
115
		@ICommandService commandService: ICommandService
116
	) {
117
		super(id, label, SPLIT_EDITOR_LEFT, commandService);
B
Benjamin Pasero 已提交
118 119 120
	}
}

121
export class SplitEditorRightAction extends ExecuteCommandAction {
B
Benjamin Pasero 已提交
122

123
	public static readonly ID = SPLIT_EDITOR_RIGHT;
124
	public static readonly LABEL = nls.localize('splitEditorGroupRight', "Split Editor Right");
B
Benjamin Pasero 已提交
125 126 127 128

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

135
export class SplitEditorUpAction extends ExecuteCommandAction {
B
Benjamin Pasero 已提交
136

137
	public static readonly ID = SPLIT_EDITOR_UP;
138
	public static readonly LABEL = nls.localize('splitEditorGroupUp', "Split Editor Up");
139

B
Benjamin Pasero 已提交
140 141 142
	constructor(
		id: string,
		label: string,
143
		@ICommandService commandService: ICommandService
B
Benjamin Pasero 已提交
144
	) {
145
		super(id, label, SPLIT_EDITOR_UP, commandService);
146
	}
B
Benjamin Pasero 已提交
147
}
148

149
export class SplitEditorDownAction extends ExecuteCommandAction {
150

151
	public static readonly ID = SPLIT_EDITOR_DOWN;
152
	public static readonly LABEL = nls.localize('splitEditorGroupDown', "Split Editor Down");
153

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

163
export class JoinTwoGroupsAction extends Action {
I
initialshl 已提交
164

M
Matt Bierner 已提交
165 166
	public static readonly ID = 'workbench.action.joinTwoGroups';
	public static readonly LABEL = nls.localize('joinTwoGroups', "Join Editors of Two Groups");
I
initialshl 已提交
167 168 169 170

	constructor(
		id: string,
		label: string,
171
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
I
initialshl 已提交
172
	) {
173
		super(id, label);
I
initialshl 已提交
174 175
	}

176
	public run(context?: IEditorIdentifier): TPromise<any> {
177
		let sourceGroup: IEditorGroup;
B
Benjamin Pasero 已提交
178 179
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
I
initialshl 已提交
180
		} else {
B
Benjamin Pasero 已提交
181
			sourceGroup = this.editorGroupService.activeGroup;
I
initialshl 已提交
182 183
		}

B
Benjamin Pasero 已提交
184 185 186 187 188
		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);
189

B
Benjamin Pasero 已提交
190 191 192
		if (targetGroup && sourceGroup !== targetGroup) {
			this.editorGroupService.mergeGroup(sourceGroup, targetGroup);
		}
I
initialshl 已提交
193 194 195 196 197

		return TPromise.as(true);
	}
}

198 199 200 201 202 203 204 205 206 207 208 209 210 211
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> {
212
		mergeAllGroups(this.editorGroupService);
213 214 215 216 217

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
218
export class NavigateBetweenGroupsAction extends Action {
219

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

223 224 225
	constructor(
		id: string,
		label: string,
226
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
227
	) {
E
Erich Gamma 已提交
228 229 230
		super(id, label);
	}

231
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
232 233 234
		let nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT });
		if (!nextGroup) {
			nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.FIRST });
E
Erich Gamma 已提交
235 236
		}

B
Benjamin Pasero 已提交
237
		nextGroup.focus();
238 239

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

243 244
export class FocusActiveGroupAction extends Action {

M
Matt Bierner 已提交
245 246
	public static readonly ID = 'workbench.action.focusActiveEditorGroup';
	public static readonly LABEL = nls.localize('focusActiveEditorGroup', "Focus Active Editor Group");
247 248 249 250

	constructor(
		id: string,
		label: string,
251
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
252 253 254 255 256
	) {
		super(id, label);
	}

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

259
		return TPromise.as(true);
E
Erich Gamma 已提交
260 261 262
	}
}

263
export abstract class BaseFocusGroupAction extends Action {
E
Erich Gamma 已提交
264 265 266 267

	constructor(
		id: string,
		label: string,
268
		private scope: IFindGroupScope,
269
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
270 271 272 273
	) {
		super(id, label);
	}

274
	public run(): TPromise<any> {
275 276 277 278
		const group = this.editorGroupService.findGroup(this.scope);
		if (group) {
			group.focus();
		}
E
Erich Gamma 已提交
279

A
Alex Dima 已提交
280
		return TPromise.as(true);
E
Erich Gamma 已提交
281 282 283
	}
}

284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
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 已提交
299 300 301

	public static readonly ID = 'workbench.action.focusLastEditorGroup';
	public static readonly LABEL = nls.localize('focusLastEditorGroup', "Focus Last Editor Group");
E
Erich Gamma 已提交
302 303 304 305

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

312
export class FocusNextGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
313

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

326
export class FocusPreviousGroup extends BaseFocusGroupAction {
327

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

331 332 333
	constructor(
		id: string,
		label: string,
334
		@IEditorGroupsService editorGroupService: IEditorGroupsService
335
	) {
336
		super(id, label, { location: GroupLocation.PREVIOUS }, editorGroupService);
E
Erich Gamma 已提交
337
	}
338
}
E
Erich Gamma 已提交
339

340
export class FocusLeftGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
341

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

354
export class FocusRightGroup extends BaseFocusGroupAction {
355

356 357
	public static readonly ID = 'workbench.action.focusRightGroup';
	public static readonly LABEL = nls.localize('focusRightGroup', "Focus Right Editor Group");
358

E
Erich Gamma 已提交
359 360 361
	constructor(
		id: string,
		label: string,
362
		@IEditorGroupsService editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
363
	) {
364
		super(id, label, { direction: GroupDirection.RIGHT }, editorGroupService);
E
Erich Gamma 已提交
365
	}
366
}
E
Erich Gamma 已提交
367

368
export class FocusAboveGroup extends BaseFocusGroupAction {
E
Erich Gamma 已提交
369

370 371 372 373 374 375 376 377 378
	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 已提交
379 380 381
	}
}

382 383 384 385 386 387 388 389 390 391 392 393 394 395
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);
	}
}

396
export class OpenToSideFromQuickOpenAction extends Action {
E
Erich Gamma 已提交
397

M
Matt Bierner 已提交
398 399
	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 已提交
400

401
	constructor(
402
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
403
		@IConfigurationService private configurationService: IConfigurationService
404
	) {
405
		super(OpenToSideFromQuickOpenAction.OPEN_TO_SIDE_ID, OpenToSideFromQuickOpenAction.OPEN_TO_SIDE_LABEL);
E
Erich Gamma 已提交
406

407 408 409 410
		this.updateClass();
	}

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

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

416
	public run(context: any): TPromise<any> {
B
Benjamin Pasero 已提交
417
		const entry = toEditorQuickOpenEntry(context);
E
Erich Gamma 已提交
418
		if (entry) {
419
			const input = entry.getInput();
B
Benjamin Pasero 已提交
420
			if (input instanceof EditorInput) {
B
Benjamin Pasero 已提交
421
				return this.editorService.openEditor(input, entry.getOptions(), SIDE_GROUP);
B
Benjamin Pasero 已提交
422 423
			}

424 425 426
			const resourceInput = input as IResourceInput;
			resourceInput.options = mixin(resourceInput.options, entry.getOptions());

B
Benjamin Pasero 已提交
427
			return this.editorService.openEditor(resourceInput, SIDE_GROUP);
E
Erich Gamma 已提交
428 429
		}

A
Alex Dima 已提交
430
		return TPromise.as(false);
E
Erich Gamma 已提交
431 432 433
	}
}

434
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
435 436 437

	// QuickOpenEntryGroup
	if (element instanceof QuickOpenEntryGroup) {
438
		const group = <QuickOpenEntryGroup>element;
E
Erich Gamma 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451 452
		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 {
453

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

457 458 459
	constructor(
		id: string,
		label: string,
I
isidor 已提交
460
		@ICommandService private commandService: ICommandService
461
	) {
I
isidor 已提交
462
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
463 464
	}

I
isidor 已提交
465
	public run(context?: IEditorCommandsContext): TPromise<any> {
466
		return this.commandService.executeCommand(CLOSE_EDITOR_COMMAND_ID, void 0, context);
E
Erich Gamma 已提交
467 468 469
	}
}

470 471 472 473 474 475 476 477
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,
478
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
479 480 481 482 483
	) {
		super(id, label, 'close-editor-action');
	}

	public run(context?: IEditorCommandsContext): TPromise<any> {
484
		let group: IEditorGroup;
485 486
		let editorIndex: number;
		if (context) {
487
			group = this.editorGroupService.getGroup(context.groupId);
488

489 490
			if (group) {
				editorIndex = context.editorIndex; // only allow editor at index if group is valid
491 492 493
			}
		}

494
		if (!group) {
495
			group = this.editorGroupService.activeGroup;
496 497
		}

498 499 500 501
		// Close specific editor in group
		if (typeof editorIndex === 'number') {
			const editorAtIndex = group.getEditor(editorIndex);
			if (editorAtIndex) {
502
				return group.closeEditor(editorAtIndex);
503 504 505 506 507
			}
		}

		// Otherwise close active editor in group
		if (group.activeEditor) {
508
			return group.closeEditor(group.activeEditor);
509 510 511 512 513 514
		}

		return TPromise.as(false);
	}
}

M
misoguy 已提交
515 516
export class RevertAndCloseEditorAction extends Action {

M
Matt Bierner 已提交
517 518
	public static readonly ID = 'workbench.action.revertAndCloseActiveEditor';
	public static readonly LABEL = nls.localize('revertAndCloseActiveEditor', "Revert and Close Editor");
M
misoguy 已提交
519 520 521 522

	constructor(
		id: string,
		label: string,
523
		@IEditorService private editorService: IEditorService
M
misoguy 已提交
524 525 526 527 528
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
529
		const activeControl = this.editorService.activeControl;
B
Benjamin Pasero 已提交
530
		if (activeControl) {
B
Benjamin Pasero 已提交
531
			const editor = activeControl.input;
532
			const group = activeControl.group;
B
Benjamin Pasero 已提交
533

534
			// first try a normal revert where the contents of the editor are restored
B
Benjamin Pasero 已提交
535
			return editor.revert().then(() => group.closeEditor(editor), error => {
536 537 538 539
				// 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 已提交
540
				return editor.revert({ soft: true }).then(() => group.closeEditor(editor));
541
			});
M
misoguy 已提交
542 543 544 545 546 547
		}

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
548
export class CloseLeftEditorsInGroupAction extends Action {
549

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

553 554 555
	constructor(
		id: string,
		label: string,
556
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
557
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
558
	) {
559 560 561
		super(id, label);
	}

562
	public run(context?: IEditorIdentifier): TPromise<any> {
B
Benjamin Pasero 已提交
563
		const { group, editor } = getTarget(this.editorService, this.editorGroupService, context);
B
Benjamin Pasero 已提交
564 565
		if (group && editor) {
			return group.closeEditors({ direction: CloseDirection.LEFT, except: editor });
566 567 568 569 570 571
		}

		return TPromise.as(false);
	}
}

572
function getTarget(editorService: IEditorService, editorGroupService: IEditorGroupsService, context?: IEditorIdentifier): { editor: IEditorInput, group: IEditorGroup } {
B
Benjamin Pasero 已提交
573 574 575 576 577 578 579 580
	if (context) {
		return { editor: context.editor, group: editorGroupService.getGroup(context.groupId) };
	}

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

581
export abstract class BaseCloseAllAction extends Action {
582

583 584 585
	constructor(
		id: string,
		label: string,
586 587
		clazz: string,
		private textFileService: ITextFileService
588
	) {
589
		super(id, label, clazz);
E
Erich Gamma 已提交
590 591
	}

592
	public run(): TPromise<any> {
593 594 595

		// Just close all if there are no or one dirty editor
		if (this.textFileService.getDirty().length < 2) {
596
			return this.doCloseAll();
597 598 599
		}

		// Otherwise ask for combined confirmation
600 601 602 603
		return this.textFileService.confirmSave().then(confirm => {
			if (confirm === ConfirmResult.CANCEL) {
				return void 0;
			}
604

605 606 607 608 609
			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));
610
			}
611

612 613
			return saveOrRevertPromise.then(success => {
				if (success) {
614
					return this.doCloseAll();
615 616 617 618
				}

				return void 0;
			});
619
		});
E
Erich Gamma 已提交
620
	}
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662

	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 已提交
663 664
}

665 666
export class CloseEditorsInOtherGroupsAction extends Action {

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

670 671 672
	constructor(
		id: string,
		label: string,
673
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
674
	) {
675 676 677
		super(id, label);
	}

678
	public run(context?: IEditorIdentifier): TPromise<any> {
I
isidor 已提交
679 680 681 682
		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);
683 684
			}

I
isidor 已提交
685 686
			return g.closeAllEditors();
		}));
687 688 689
	}
}

690
export class BaseMoveGroupAction extends Action {
691

692 693 694
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
695
		private direction: GroupDirection,
696
		private editorGroupService: IEditorGroupsService
697
	) {
E
Erich Gamma 已提交
698 699 700
		super(id, label);
	}

701
	public run(context?: IEditorIdentifier): TPromise<any> {
702
		let sourceGroup: IEditorGroup;
703 704 705 706
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
		} else {
			sourceGroup = this.editorGroupService.activeGroup;
707 708
		}

B
Benjamin Pasero 已提交
709
		const targetGroup = this.editorGroupService.findGroup({ direction: this.direction }, sourceGroup);
710
		if (targetGroup) {
B
Benjamin Pasero 已提交
711
			this.editorGroupService.moveGroup(sourceGroup, targetGroup, this.direction);
E
Erich Gamma 已提交
712 713
		}

714
		return TPromise.as(true);
E
Erich Gamma 已提交
715 716 717
	}
}

718 719 720 721 722 723 724 725
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,
726
		@IEditorGroupsService editorGroupService: IEditorGroupsService
727
	) {
B
Benjamin Pasero 已提交
728
		super(id, label, GroupDirection.LEFT, editorGroupService);
729 730 731 732
	}
}

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

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

737 738 739
	constructor(
		id: string,
		label: string,
740
		@IEditorGroupsService editorGroupService: IEditorGroupsService
741
	) {
B
Benjamin Pasero 已提交
742
		super(id, label, GroupDirection.RIGHT, editorGroupService);
743 744
	}
}
745

746
export class MoveGroupUpAction extends BaseMoveGroupAction {
747

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

751 752 753
	constructor(
		id: string,
		label: string,
754
		@IEditorGroupsService editorGroupService: IEditorGroupsService
755
	) {
B
Benjamin Pasero 已提交
756
		super(id, label, GroupDirection.UP, editorGroupService);
757 758 759 760 761 762 763 764 765 766 767
	}
}

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,
768
		@IEditorGroupsService editorGroupService: IEditorGroupsService
769
	) {
B
Benjamin Pasero 已提交
770
		super(id, label, GroupDirection.DOWN, editorGroupService);
E
Erich Gamma 已提交
771 772 773
	}
}

774
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
775

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

779
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
780 781 782
		super(id, label);
	}

783
	public run(): TPromise<any> {
784
		this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
785

A
Alex Dima 已提交
786
		return TPromise.as(false);
E
Erich Gamma 已提交
787 788 789
	}
}

790
export class EvenGroupWidthsAction extends Action {
E
Erich Gamma 已提交
791

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

795
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
796 797 798
		super(id, label);
	}

799
	public run(): TPromise<any> {
800
		this.editorGroupService.arrangeGroups(GroupsArrangement.EVEN);
E
Erich Gamma 已提交
801

A
Alex Dima 已提交
802
		return TPromise.as(false);
E
Erich Gamma 已提交
803 804 805
	}
}

806
export class MaximizeGroupAction extends Action {
807

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

811 812 813
	constructor(
		id: string,
		label: string,
814 815
		@IEditorService private editorService: IEditorService,
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
816 817 818 819 820
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

821
	public run(): TPromise<any> {
822 823 824
		if (this.editorService.activeEditor) {
			this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);

825
			return this.partService.setSideBarHidden(true);
826 827
		}

A
Alex Dima 已提交
828
		return TPromise.as(false);
829 830 831
	}
}

832 833
export abstract class BaseNavigateEditorAction extends Action {

834 835 836
	constructor(
		id: string,
		label: string,
837 838
		protected editorGroupService: IEditorGroupsService,
		protected editorService: IEditorService
839
	) {
840 841 842 843 844
		super(id, label);
	}

	public run(): TPromise<any> {
		const result = this.navigate();
845 846
		if (!result) {
			return TPromise.as(false);
847 848
		}

849 850 851 852 853 854 855
		const { groupId, editor } = result;
		if (!editor) {
			return TPromise.as(false);
		}

		const group = this.editorGroupService.getGroup(groupId);
		return group.openEditor(editor);
856 857 858 859 860 861 862
	}

	protected abstract navigate(): IEditorIdentifier;
}

export class OpenNextEditor extends BaseNavigateEditorAction {

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

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

	protected navigate(): IEditorIdentifier {
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892

		// 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;
893 894 895 896 897
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

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

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

	protected navigate(): IEditorIdentifier {
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927

		// 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;
928 929 930 931 932
	}
}

export class OpenNextEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
933 934
	public static readonly ID = 'workbench.action.nextEditorInGroup';
	public static readonly LABEL = nls.localize('nextEditorInGroup', "Open Next Editor in Group");
935 936 937 938

	constructor(
		id: string,
		label: string,
939 940
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
941 942 943 944 945
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
946 947 948 949 950
		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 };
951 952 953 954 955
	}
}

export class OpenPreviousEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
956 957
	public static readonly ID = 'workbench.action.previousEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousEditorInGroup', "Open Previous Editor in Group");
958 959 960 961

	constructor(
		id: string,
		label: string,
962 963
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
	) {
		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,
985 986
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
987 988 989 990 991
	) {
		super(id, label, editorGroupService, editorService);
	}

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

		return { editor: editors[0], groupId: group.id };
996
	}
B
Benjamin Pasero 已提交
997 998
}

999 1000 1001 1002 1003 1004 1005 1006
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,
1007 1008
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1009 1010 1011 1012 1013
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
1014 1015 1016 1017
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[editors.length - 1], groupId: group.id };
1018 1019 1020
	}
}

B
Benjamin Pasero 已提交
1021 1022
export class NavigateForwardAction extends Action {

M
Matt Bierner 已提交
1023 1024
	public static readonly ID = 'workbench.action.navigateForward';
	public static readonly LABEL = nls.localize('navigateNext', "Go Forward");
B
Benjamin Pasero 已提交
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038

	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 已提交
1039 1040
	public static readonly ID = 'workbench.action.navigateBack';
	public static readonly LABEL = nls.localize('navigatePrevious', "Go Back");
B
Benjamin Pasero 已提交
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050

	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 已提交
1051
}
1052

1053 1054
export class NavigateLastAction extends Action {

M
Matt Bierner 已提交
1055 1056
	public static readonly ID = 'workbench.action.navigateLast';
	public static readonly LABEL = nls.localize('navigateLast', "Go Last");
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068

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

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

		return TPromise.as(null);
	}
}

1069 1070
export class ReopenClosedEditorAction extends Action {

M
Matt Bierner 已提交
1071 1072
	public static readonly ID = 'workbench.action.reopenClosedEditor';
	public static readonly LABEL = nls.localize('reopenClosedEditor', "Reopen Closed Editor");
1073 1074 1075 1076

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1077
		@IHistoryService private historyService: IHistoryService
1078 1079 1080 1081 1082
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1083
		this.historyService.reopenLastClosedEditor();
1084 1085 1086

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
1087 1088
}

1089
export class ClearRecentFilesAction extends Action {
C
22768  
Cristian 已提交
1090

M
Matt Bierner 已提交
1091 1092
	public static readonly ID = 'workbench.action.clearRecentFiles';
	public static readonly LABEL = nls.localize('clearRecentFiles', "Clear Recently Opened");
C
22768  
Cristian 已提交
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102

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

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
1103
		this.windowsService.clearRecentlyOpened();
C
22768  
Cristian 已提交
1104 1105 1106 1107 1108

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
1109
export class ShowEditorsInActiveGroupAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
1110

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

1114 1115 1116
	constructor(
		actionId: string,
		actionLabel: string,
1117
		@IQuickOpenService quickOpenService: IQuickOpenService
1118
	) {
B
Benjamin Pasero 已提交
1119
		super(actionId, actionLabel, NAVIGATE_IN_ACTIVE_GROUP_PREFIX, quickOpenService);
1120
	}
B
Benjamin Pasero 已提交
1121 1122
}

B
Benjamin Pasero 已提交
1123 1124
export class ShowAllEditorsAction extends QuickOpenAction {

M
Matt Bierner 已提交
1125 1126
	public static readonly ID = 'workbench.action.showAllEditors';
	public static readonly LABEL = nls.localize('showAllEditors', "Show All Editors");
B
Benjamin Pasero 已提交
1127 1128 1129 1130 1131 1132

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

1133
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1134 1135 1136 1137 1138

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1139
		@IKeybindingService private keybindingService: IKeybindingService
B
Benjamin Pasero 已提交
1140 1141 1142 1143 1144
	) {
		super(id, label);
	}

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

1147

B
Benjamin Pasero 已提交
1148 1149

		this.quickOpenService.show(NAVIGATE_IN_ACTIVE_GROUP_PREFIX, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1150 1151 1152 1153 1154

		return TPromise.as(true);
	}
}

1155 1156
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1157 1158
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditorInGroup', "Open Previous Recently Used Editor in Group");
1159 1160 1161 1162 1163

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1164
		@IKeybindingService keybindingService: IKeybindingService
1165
	) {
B
Benjamin Pasero 已提交
1166
		super(id, label, quickOpenService, keybindingService);
1167 1168 1169 1170 1171
	}
}

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

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

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

1185
export class OpenPreviousEditorFromHistoryAction extends Action {
B
Benjamin Pasero 已提交
1186

M
Matt Bierner 已提交
1187 1188
	public static readonly ID = 'workbench.action.openPreviousEditorFromHistory';
	public static readonly LABEL = nls.localize('navigateEditorHistoryByInput', "Open Previous Editor from History");
B
Benjamin Pasero 已提交
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199

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

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

B
Benjamin Pasero 已提交
1202
		this.quickOpenService.show(null, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1203 1204 1205 1206 1207

		return TPromise.as(true);
	}
}

1208 1209
export class OpenNextRecentlyUsedEditorAction extends Action {

M
Matt Bierner 已提交
1210 1211
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditor', "Open Next Recently Used Editor");
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225

	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 已提交
1226 1227
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditor', "Open Previous Recently Used Editor");
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239

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

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

		return TPromise.as(null);
	}
}

1240 1241
export class ClearEditorHistoryAction extends Action {

M
Matt Bierner 已提交
1242 1243
	public static readonly ID = 'workbench.action.clearEditorHistory';
	public static readonly LABEL = nls.localize('clearEditorHistory', "Clear Editor History");
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254

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

	public run(): TPromise<any> {

1255
		// Editor history
1256 1257 1258 1259 1260 1261
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1262
export class MoveEditorLeftInGroupAction extends ExecuteCommandAction {
1263

M
Matt Bierner 已提交
1264 1265
	public static readonly ID = 'workbench.action.moveEditorLeftInGroup';
	public static readonly LABEL = nls.localize('moveEditorLeft', "Move Editor Left");
1266 1267 1268 1269

	constructor(
		id: string,
		label: string,
1270
		@ICommandService commandService: ICommandService
1271
	) {
1272
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'left' } as ActiveEditorMoveArguments);
1273 1274 1275
	}
}

1276
export class MoveEditorRightInGroupAction extends ExecuteCommandAction {
1277

M
Matt Bierner 已提交
1278 1279
	public static readonly ID = 'workbench.action.moveEditorRightInGroup';
	public static readonly LABEL = nls.localize('moveEditorRight', "Move Editor Right");
1280 1281 1282 1283

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

1290
export class MoveEditorToPreviousGroupAction extends ExecuteCommandAction {
1291

M
Matt Bierner 已提交
1292 1293
	public static readonly ID = 'workbench.action.moveEditorToPreviousGroup';
	public static readonly LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
1294 1295 1296 1297

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

1304
export class MoveEditorToNextGroupAction extends ExecuteCommandAction {
1305

1306 1307 1308 1309 1310 1311 1312 1313 1314
	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);
1315 1316 1317
	}
}

1318
export class MoveEditorToAboveGroupAction extends ExecuteCommandAction {
1319

1320 1321
	public static readonly ID = 'workbench.action.moveEditorToAboveGroup';
	public static readonly LABEL = nls.localize('moveEditorToAboveGroup', "Move Editor into Above Group");
1322 1323 1324 1325

	constructor(
		id: string,
		label: string,
1326
		@ICommandService commandService: ICommandService
1327
	) {
1328
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'up', by: 'group' } as ActiveEditorMoveArguments);
1329
	}
1330
}
1331

1332
export class MoveEditorToBelowGroupAction extends ExecuteCommandAction {
1333

1334 1335 1336 1337 1338 1339 1340 1341 1342
	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);
1343 1344 1345
	}
}

1346
export class MoveEditorToLeftGroupAction extends ExecuteCommandAction {
1347

1348 1349
	public static readonly ID = 'workbench.action.moveEditorToLeftGroup';
	public static readonly LABEL = nls.localize('moveEditorToLeftGroup', "Move Editor into Left Group");
1350 1351 1352 1353

	constructor(
		id: string,
		label: string,
1354
		@ICommandService commandService: ICommandService
1355
	) {
1356
		super(id, label, MOVE_ACTIVE_EDITOR_COMMAND_ID, commandService, { to: 'left', by: 'group' } as ActiveEditorMoveArguments);
1357
	}
1358
}
1359

1360
export class MoveEditorToRightGroupAction extends ExecuteCommandAction {
1361

1362 1363 1364 1365 1366 1367 1368 1369 1370
	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);
1371 1372 1373
	}
}

1374
export class MoveEditorToFirstGroupAction extends ExecuteCommandAction {
1375

1376 1377
	public static readonly ID = 'workbench.action.moveEditorToFirstGroup';
	public static readonly LABEL = nls.localize('moveEditorToFirstGroup', "Move Editor into First Group");
1378 1379 1380 1381

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

1388
export class MoveEditorToLastGroupAction extends ExecuteCommandAction {
1389

1390 1391 1392 1393 1394 1395 1396 1397 1398
	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);
1399 1400 1401
	}
}

1402
export class EditorLayoutSingleAction extends ExecuteCommandAction {
1403

1404 1405
	public static readonly ID = 'workbench.action.editorLayoutSingle';
	public static readonly LABEL = nls.localize('editorLayoutSingle', "Single Column Editor Layout");
1406 1407 1408 1409

	constructor(
		id: string,
		label: string,
1410
		@ICommandService commandService: ICommandService
1411
	) {
1412
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}] } as EditorGroupLayout);
1413
	}
1414
}
1415

1416
export class EditorLayoutTwoColumnsAction extends ExecuteCommandAction {
1417

1418 1419 1420 1421 1422 1423 1424 1425 1426
	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);
1427 1428 1429
	}
}

1430
export class EditorLayoutThreeColumnsAction extends ExecuteCommandAction {
1431

1432 1433
	public static readonly ID = 'workbench.action.editorLayoutThreeColumns';
	public static readonly LABEL = nls.localize('editorLayoutThreeColumns', "Three Columns Editor Layout");
1434 1435 1436 1437

	constructor(
		id: string,
		label: string,
1438
		@ICommandService commandService: ICommandService
1439
	) {
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454
		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);
1455
	}
1456
}
1457

1458
export class EditorLayoutThreeRowsAction extends ExecuteCommandAction {
1459

1460 1461 1462 1463 1464 1465 1466 1467 1468
	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);
1469
	}
D
Daniel Imms 已提交
1470
}
1471

1472
export class EditorLayoutTwoByTwoGridAction extends ExecuteCommandAction {
1473

1474 1475
	public static readonly ID = 'workbench.action.editorLayoutTwoByTwoGrid';
	public static readonly LABEL = nls.localize('editorLayoutTwoByTwoGrid', "Grid Editor Layout (2x2)");
1476 1477 1478 1479

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

B
Benjamin Pasero 已提交
1486
export class EditorLayoutTwoColumnsBottomAction extends ExecuteCommandAction {
1487

B
Benjamin Pasero 已提交
1488 1489
	public static readonly ID = 'workbench.action.editorLayoutTwoColumnsBottom';
	public static readonly LABEL = nls.localize('editorLayoutTwoColumnsBottom', "Two Columns Bottom Editor Layout");
1490 1491 1492 1493 1494 1495

	constructor(
		id: string,
		label: string,
		@ICommandService commandService: ICommandService
	) {
B
Benjamin Pasero 已提交
1496
		super(id, label, LAYOUT_EDITOR_GROUPS_COMMAND_ID, commandService, { groups: [{}, { groups: [{}, {}] }], orientation: GroupOrientation.VERTICAL } as EditorGroupLayout);
1497 1498 1499
	}
}

B
Benjamin Pasero 已提交
1500
export class EditorLayoutTwoColumnsRightAction extends ExecuteCommandAction {
1501

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

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

1514
export class EditorLayoutGoldenRatioAction extends ExecuteCommandAction {
1515

1516 1517 1518 1519 1520 1521 1522 1523 1524
	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);
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 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
}

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);
	}
1600
}