editorActions.ts 43.7 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 } from 'vs/workbench/browser/parts/editor/editorCommands';
23 24
import { IEditorGroupsService, IEditorGroup, GroupsArrangement, EditorsOrder, GroupLocation, GroupDirection, preferredGroupDirection } from 'vs/workbench/services/group/common/editorGroupsService';
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
export class BaseSplitEditorGroupAction extends Action {
29

30 31 32
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
33
		clazz: string,
34
		protected direction: GroupDirection,
35
		private editorGroupService: IEditorGroupsService
36
	) {
B
Benjamin Pasero 已提交
37
		super(id, label, clazz);
E
Erich Gamma 已提交
38 39
	}

40 41 42 43 44 45 46
	public run(context?: IEditorIdentifier & { event?: Event }): TPromise<any> {
		this.splitEditor(context ? context.groupId : void 0);

		return TPromise.as(true);
	}

	protected splitEditor(groupId?: number, direction = this.direction): void {
47
		let sourceGroup: IEditorGroup;
48 49
		if (typeof groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(groupId);
50
		} else {
B
Benjamin Pasero 已提交
51
			sourceGroup = this.editorGroupService.activeGroup;
52
		}
E
Erich Gamma 已提交
53

B
Benjamin Pasero 已提交
54
		// Add group
B
Benjamin Pasero 已提交
55
		const newGroup = this.editorGroupService.addGroup(sourceGroup, direction);
E
Erich Gamma 已提交
56

B
Benjamin Pasero 已提交
57
		// Split editor (if it can be split)
B
Benjamin Pasero 已提交
58
		if (sourceGroup.activeEditor && (sourceGroup.activeEditor as EditorInput).supportsSplitEditor()) {
B
Benjamin Pasero 已提交
59
			sourceGroup.copyEditor(sourceGroup.activeEditor, newGroup);
E
Erich Gamma 已提交
60
		}
B
Benjamin Pasero 已提交
61 62 63

		// Focus
		newGroup.focus();
E
Erich Gamma 已提交
64 65 66
	}
}

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

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

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

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

		this.updateAction();

		this.registerListeners();
	}

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

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

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

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

		return TPromise.as(true);
	}

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

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

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

export class SplitEditorGroupVerticalAction extends BaseSplitEditorGroupAction {

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

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

export class SplitEditorGroupHorizontalAction extends BaseSplitEditorGroupAction {

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

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

B
Benjamin Pasero 已提交
172
export class SplitEditorGroupLeftAction extends BaseSplitEditorGroupAction {
173

B
Benjamin Pasero 已提交
174
	public static readonly ID = 'workbench.action.splitEditorGroupLeft';
175
	public static readonly LABEL = nls.localize('splitEditorGroupLeft', "Split Editor Left");
176 177 178 179

	constructor(
		id: string,
		label: string,
180
		@IEditorGroupsService editorGroupService: IEditorGroupsService
181
	) {
B
Benjamin Pasero 已提交
182 183 184 185 186 187 188
		super(id, label, null, GroupDirection.LEFT, editorGroupService);
	}
}

export class SplitEditorGroupRightAction extends BaseSplitEditorGroupAction {

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

	constructor(
		id: string,
		label: string,
194
		@IEditorGroupsService editorGroupService: IEditorGroupsService
B
Benjamin Pasero 已提交
195 196 197 198 199 200 201 202
	) {
		super(id, label, null, GroupDirection.RIGHT, editorGroupService);
	}
}

export class SplitEditorGroupUpAction extends BaseSplitEditorGroupAction {

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

B
Benjamin Pasero 已提交
205 206 207
	constructor(
		id: string,
		label: string,
208
		@IEditorGroupsService editorGroupService: IEditorGroupsService
B
Benjamin Pasero 已提交
209 210
	) {
		super(id, label, null, GroupDirection.UP, editorGroupService);
211
	}
B
Benjamin Pasero 已提交
212
}
213

B
Benjamin Pasero 已提交
214
export class SplitEditorGroupDownAction extends BaseSplitEditorGroupAction {
215

B
Benjamin Pasero 已提交
216
	public static readonly ID = 'workbench.action.splitEditorGroupDown';
217
	public static readonly LABEL = nls.localize('splitEditorGroupDown', "Split Editor Down");
218

B
Benjamin Pasero 已提交
219 220 221
	constructor(
		id: string,
		label: string,
222
		@IEditorGroupsService editorGroupService: IEditorGroupsService
B
Benjamin Pasero 已提交
223 224
	) {
		super(id, label, null, GroupDirection.DOWN, editorGroupService);
225 226 227
	}
}

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

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

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

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

B
Benjamin Pasero 已提交
249 250 251 252 253
		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);
254

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

		return TPromise.as(true);
	}
}

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
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> {
		const firstGroup = this.editorGroupService.groups[0];
		while (this.editorGroupService.count > 1) {
			this.editorGroupService.mergeGroup(this.editorGroupService.findGroup({ location: GroupLocation.NEXT }, firstGroup), firstGroup);
		}

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
286
export class NavigateBetweenGroupsAction extends Action {
287

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

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

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

B
Benjamin Pasero 已提交
305
		nextGroup.focus();
306 307

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

311 312
export class FocusActiveGroupAction extends Action {

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

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

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

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

331 332
export class FocusFirstGroupAction extends Action {

M
Matt Bierner 已提交
333 334
	public static readonly ID = 'workbench.action.focusFirstEditorGroup';
	public static readonly LABEL = nls.localize('focusFirstEditorGroup', "Focus First Editor Group");
E
Erich Gamma 已提交
335 336 337 338

	constructor(
		id: string,
		label: string,
339
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
340 341 342 343
	) {
		super(id, label);
	}

344
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
345
		this.editorGroupService.findGroup({ location: GroupLocation.FIRST }).focus();
E
Erich Gamma 已提交
346

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

B
Benjamin Pasero 已提交
351 352 353 354
export class FocusLastGroupAction extends Action {

	public static readonly ID = 'workbench.action.focusLastEditorGroup';
	public static readonly LABEL = nls.localize('focusLastEditorGroup', "Focus Last Editor Group");
E
Erich Gamma 已提交
355 356 357 358

	constructor(
		id: string,
		label: string,
359
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
360 361 362 363
	) {
		super(id, label);
	}

364
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
365
		this.editorGroupService.findGroup({ location: GroupLocation.LAST }).focus();
E
Erich Gamma 已提交
366

A
Alex Dima 已提交
367
		return TPromise.as(true);
E
Erich Gamma 已提交
368 369 370
	}
}

B
Benjamin Pasero 已提交
371
export class FocusPreviousGroup extends Action {
372

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

376 377 378
	constructor(
		id: string,
		label: string,
379
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
380
	) {
E
Erich Gamma 已提交
381 382 383
		super(id, label);
	}

384
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
385 386 387
		const previousGroup = this.editorGroupService.findGroup({ location: GroupLocation.PREVIOUS });
		if (previousGroup) {
			previousGroup.focus();
E
Erich Gamma 已提交
388 389
		}

390
		return TPromise.as(true);
E
Erich Gamma 已提交
391 392 393
	}
}

B
Benjamin Pasero 已提交
394
export class FocusNextGroup extends Action {
395

M
Matt Bierner 已提交
396
	public static readonly ID = 'workbench.action.focusNextGroup';
B
Benjamin Pasero 已提交
397
	public static readonly LABEL = nls.localize('focusNextGroup', "Focus Next Editor Group");
398

E
Erich Gamma 已提交
399 400 401
	constructor(
		id: string,
		label: string,
402
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
403 404 405 406
	) {
		super(id, label);
	}

407
	public run(event?: any): TPromise<any> {
B
Benjamin Pasero 已提交
408 409 410
		const nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT });
		if (nextGroup) {
			nextGroup.focus();
E
Erich Gamma 已提交
411 412
		}

A
Alex Dima 已提交
413
		return TPromise.as(true);
E
Erich Gamma 已提交
414 415 416 417 418
	}
}

export class OpenToSideAction extends Action {

M
Matt Bierner 已提交
419 420
	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 已提交
421

422
	constructor(
423
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
424
		@IConfigurationService private configurationService: IConfigurationService
425
	) {
E
Erich Gamma 已提交
426 427
		super(OpenToSideAction.OPEN_TO_SIDE_ID, OpenToSideAction.OPEN_TO_SIDE_LABEL);

428 429 430 431
		this.updateClass();
	}

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

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

437
	public run(context: any): TPromise<any> {
B
Benjamin Pasero 已提交
438
		const entry = toEditorQuickOpenEntry(context);
E
Erich Gamma 已提交
439
		if (entry) {
440
			const input = entry.getInput();
B
Benjamin Pasero 已提交
441
			if (input instanceof EditorInput) {
B
Benjamin Pasero 已提交
442
				return this.editorService.openEditor(input, entry.getOptions(), SIDE_GROUP);
B
Benjamin Pasero 已提交
443 444
			}

445 446 447
			const resourceInput = input as IResourceInput;
			resourceInput.options = mixin(resourceInput.options, entry.getOptions());

B
Benjamin Pasero 已提交
448
			return this.editorService.openEditor(resourceInput, SIDE_GROUP);
E
Erich Gamma 已提交
449 450
		}

A
Alex Dima 已提交
451
		return TPromise.as(false);
E
Erich Gamma 已提交
452 453 454
	}
}

455
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
456 457 458

	// QuickOpenEntryGroup
	if (element instanceof QuickOpenEntryGroup) {
459
		const group = <QuickOpenEntryGroup>element;
E
Erich Gamma 已提交
460 461 462 463 464 465 466 467 468 469 470 471 472 473
		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 {
474

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

478 479 480
	constructor(
		id: string,
		label: string,
I
isidor 已提交
481
		@ICommandService private commandService: ICommandService
482
	) {
I
isidor 已提交
483
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
484 485
	}

I
isidor 已提交
486
	public run(context?: IEditorCommandsContext): TPromise<any> {
487
		return this.commandService.executeCommand(CLOSE_EDITOR_COMMAND_ID, void 0, context);
E
Erich Gamma 已提交
488 489 490
	}
}

491 492 493 494 495 496 497 498
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,
499
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
500 501 502 503 504
	) {
		super(id, label, 'close-editor-action');
	}

	public run(context?: IEditorCommandsContext): TPromise<any> {
505
		let group: IEditorGroup;
506 507
		let editorIndex: number;
		if (context) {
508
			group = this.editorGroupService.getGroup(context.groupId);
509

510 511
			if (group) {
				editorIndex = context.editorIndex; // only allow editor at index if group is valid
512 513 514
			}
		}

515
		if (!group) {
516
			group = this.editorGroupService.activeGroup;
517 518
		}

519 520 521 522
		// Close specific editor in group
		if (typeof editorIndex === 'number') {
			const editorAtIndex = group.getEditor(editorIndex);
			if (editorAtIndex) {
523
				return group.closeEditor(editorAtIndex);
524 525 526 527 528
			}
		}

		// Otherwise close active editor in group
		if (group.activeEditor) {
529
			return group.closeEditor(group.activeEditor);
530 531 532 533 534 535
		}

		return TPromise.as(false);
	}
}

M
misoguy 已提交
536 537
export class RevertAndCloseEditorAction extends Action {

M
Matt Bierner 已提交
538 539
	public static readonly ID = 'workbench.action.revertAndCloseActiveEditor';
	public static readonly LABEL = nls.localize('revertAndCloseActiveEditor', "Revert and Close Editor");
M
misoguy 已提交
540 541 542 543

	constructor(
		id: string,
		label: string,
544
		@IEditorService private editorService: IEditorService
M
misoguy 已提交
545 546 547 548 549
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
550
		const activeControl = this.editorService.activeControl;
B
Benjamin Pasero 已提交
551
		if (activeControl) {
B
Benjamin Pasero 已提交
552
			const editor = activeControl.input;
553
			const group = activeControl.group;
B
Benjamin Pasero 已提交
554

555
			// first try a normal revert where the contents of the editor are restored
B
Benjamin Pasero 已提交
556
			return editor.revert().then(() => group.closeEditor(editor), error => {
557 558 559 560
				// 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 已提交
561
				return editor.revert({ soft: true }).then(() => group.closeEditor(editor));
562
			});
M
misoguy 已提交
563 564 565 566 567 568
		}

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
569
export class CloseLeftEditorsInGroupAction extends Action {
570

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

574 575 576
	constructor(
		id: string,
		label: string,
577
		@IEditorService private editorService: IEditorService,
B
Benjamin Pasero 已提交
578
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
579
	) {
580 581 582
		super(id, label);
	}

583
	public run(context?: IEditorIdentifier): TPromise<any> {
B
Benjamin Pasero 已提交
584
		const { group, editor } = getTarget(this.editorService, this.editorGroupService, context);
B
Benjamin Pasero 已提交
585 586
		if (group && editor) {
			return group.closeEditors({ direction: CloseDirection.LEFT, except: editor });
587 588 589 590 591 592
		}

		return TPromise.as(false);
	}
}

593
function getTarget(editorService: IEditorService, editorGroupService: IEditorGroupsService, context?: IEditorIdentifier): { editor: IEditorInput, group: IEditorGroup } {
B
Benjamin Pasero 已提交
594 595 596 597 598 599 600 601
	if (context) {
		return { editor: context.editor, group: editorGroupService.getGroup(context.groupId) };
	}

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

602
export abstract class BaseCloseAllAction extends Action {
603

604 605 606
	constructor(
		id: string,
		label: string,
607 608
		clazz: string,
		private textFileService: ITextFileService
609
	) {
610
		super(id, label, clazz);
E
Erich Gamma 已提交
611 612
	}

613
	public run(): TPromise<any> {
614 615 616

		// Just close all if there are no or one dirty editor
		if (this.textFileService.getDirty().length < 2) {
617
			return this.doCloseAll();
618 619 620
		}

		// Otherwise ask for combined confirmation
621 622 623 624
		return this.textFileService.confirmSave().then(confirm => {
			if (confirm === ConfirmResult.CANCEL) {
				return void 0;
			}
625

626 627 628 629 630
			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));
631
			}
632

633 634
			return saveOrRevertPromise.then(success => {
				if (success) {
635
					return this.doCloseAll();
636 637 638 639
				}

				return void 0;
			});
640
		});
E
Erich Gamma 已提交
641
	}
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683

	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 已提交
684 685
}

686 687
export class CloseEditorsInOtherGroupsAction extends Action {

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

691 692 693
	constructor(
		id: string,
		label: string,
694
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
695
	) {
696 697 698
		super(id, label);
	}

699
	public run(context?: IEditorIdentifier): TPromise<any> {
I
isidor 已提交
700 701 702 703
		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);
704 705
			}

I
isidor 已提交
706 707
			return g.closeAllEditors();
		}));
708 709 710
	}
}

711
export class BaseMoveGroupAction extends Action {
712

713 714 715
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
716
		private direction: GroupDirection,
717
		private editorGroupService: IEditorGroupsService
718
	) {
E
Erich Gamma 已提交
719 720 721
		super(id, label);
	}

722
	public run(context?: IEditorIdentifier): TPromise<any> {
723
		let sourceGroup: IEditorGroup;
724 725 726 727
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
		} else {
			sourceGroup = this.editorGroupService.activeGroup;
728 729
		}

B
Benjamin Pasero 已提交
730
		const targetGroup = this.editorGroupService.findGroup({ direction: this.direction }, sourceGroup);
731
		if (targetGroup) {
B
Benjamin Pasero 已提交
732
			this.editorGroupService.moveGroup(sourceGroup, targetGroup, this.direction);
E
Erich Gamma 已提交
733 734
		}

735
		return TPromise.as(true);
E
Erich Gamma 已提交
736 737 738
	}
}

739 740 741 742 743 744 745 746
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,
747
		@IEditorGroupsService editorGroupService: IEditorGroupsService
748
	) {
B
Benjamin Pasero 已提交
749
		super(id, label, GroupDirection.LEFT, editorGroupService);
750 751 752 753
	}
}

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

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

758 759 760
	constructor(
		id: string,
		label: string,
761
		@IEditorGroupsService editorGroupService: IEditorGroupsService
762
	) {
B
Benjamin Pasero 已提交
763
		super(id, label, GroupDirection.RIGHT, editorGroupService);
764 765
	}
}
766

767
export class MoveGroupUpAction extends BaseMoveGroupAction {
768

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

772 773 774
	constructor(
		id: string,
		label: string,
775
		@IEditorGroupsService editorGroupService: IEditorGroupsService
776
	) {
B
Benjamin Pasero 已提交
777
		super(id, label, GroupDirection.UP, editorGroupService);
778 779 780 781 782 783 784 785 786 787 788
	}
}

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,
789
		@IEditorGroupsService editorGroupService: IEditorGroupsService
790
	) {
B
Benjamin Pasero 已提交
791
		super(id, label, GroupDirection.DOWN, editorGroupService);
E
Erich Gamma 已提交
792 793 794
	}
}

795
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
796

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

800
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
801 802 803
		super(id, label);
	}

804
	public run(): TPromise<any> {
805
		this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
806

A
Alex Dima 已提交
807
		return TPromise.as(false);
E
Erich Gamma 已提交
808 809 810
	}
}

811
export class EvenGroupWidthsAction extends Action {
E
Erich Gamma 已提交
812

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

816
	constructor(id: string, label: string, @IEditorGroupsService private editorGroupService: IEditorGroupsService) {
E
Erich Gamma 已提交
817 818 819
		super(id, label);
	}

820
	public run(): TPromise<any> {
821
		this.editorGroupService.arrangeGroups(GroupsArrangement.EVEN);
E
Erich Gamma 已提交
822

A
Alex Dima 已提交
823
		return TPromise.as(false);
E
Erich Gamma 已提交
824 825 826
	}
}

827
export class MaximizeGroupAction extends Action {
828

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

832 833 834
	constructor(
		id: string,
		label: string,
835 836
		@IEditorService private editorService: IEditorService,
		@IEditorGroupsService private editorGroupService: IEditorGroupsService,
837 838 839 840 841
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

842
	public run(): TPromise<any> {
843 844 845
		if (this.editorService.activeEditor) {
			this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);

846
			return this.partService.setSideBarHidden(true);
847 848
		}

A
Alex Dima 已提交
849
		return TPromise.as(false);
850 851 852
	}
}

853 854
export abstract class BaseNavigateEditorAction extends Action {

855 856 857
	constructor(
		id: string,
		label: string,
858 859
		protected editorGroupService: IEditorGroupsService,
		protected editorService: IEditorService
860
	) {
861 862 863 864 865
		super(id, label);
	}

	public run(): TPromise<any> {
		const result = this.navigate();
866 867
		if (!result) {
			return TPromise.as(false);
868 869
		}

870 871 872 873 874 875 876
		const { groupId, editor } = result;
		if (!editor) {
			return TPromise.as(false);
		}

		const group = this.editorGroupService.getGroup(groupId);
		return group.openEditor(editor);
877 878 879 880 881 882 883
	}

	protected abstract navigate(): IEditorIdentifier;
}

export class OpenNextEditor extends BaseNavigateEditorAction {

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

887 888 889
	constructor(
		id: string,
		label: string,
890 891
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
892 893
	) {
		super(id, label, editorGroupService, editorService);
894 895 896
	}

	protected navigate(): IEditorIdentifier {
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913

		// 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;
914 915 916 917 918
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

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

922 923 924
	constructor(
		id: string,
		label: string,
925 926
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
927 928
	) {
		super(id, label, editorGroupService, editorService);
929 930 931
	}

	protected navigate(): IEditorIdentifier {
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948

		// 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;
949 950 951 952 953
	}
}

export class OpenNextEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
954 955
	public static readonly ID = 'workbench.action.nextEditorInGroup';
	public static readonly LABEL = nls.localize('nextEditorInGroup', "Open Next Editor in Group");
956 957 958 959

	constructor(
		id: string,
		label: string,
960 961
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
962 963 964 965 966
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
967 968 969 970 971
		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 };
972 973 974 975 976
	}
}

export class OpenPreviousEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
977 978
	public static readonly ID = 'workbench.action.previousEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousEditorInGroup', "Open Previous Editor in Group");
979 980 981 982

	constructor(
		id: string,
		label: string,
983 984
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
	) {
		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,
1006 1007
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1008 1009 1010 1011 1012
	) {
		super(id, label, editorGroupService, editorService);
	}

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

		return { editor: editors[0], groupId: group.id };
1017
	}
B
Benjamin Pasero 已提交
1018 1019
}

1020 1021 1022 1023 1024 1025 1026 1027
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,
1028 1029
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
		@IEditorService editorService: IEditorService
1030 1031 1032 1033 1034
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
1035 1036 1037 1038
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[editors.length - 1], groupId: group.id };
1039 1040 1041
	}
}

B
Benjamin Pasero 已提交
1042 1043
export class NavigateForwardAction extends Action {

M
Matt Bierner 已提交
1044 1045
	public static readonly ID = 'workbench.action.navigateForward';
	public static readonly LABEL = nls.localize('navigateNext', "Go Forward");
B
Benjamin Pasero 已提交
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059

	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 已提交
1060 1061
	public static readonly ID = 'workbench.action.navigateBack';
	public static readonly LABEL = nls.localize('navigatePrevious', "Go Back");
B
Benjamin Pasero 已提交
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071

	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 已提交
1072
}
1073

1074 1075
export class NavigateLastAction extends Action {

M
Matt Bierner 已提交
1076 1077
	public static readonly ID = 'workbench.action.navigateLast';
	public static readonly LABEL = nls.localize('navigateLast', "Go Last");
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089

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

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

		return TPromise.as(null);
	}
}

1090 1091
export class ReopenClosedEditorAction extends Action {

M
Matt Bierner 已提交
1092 1093
	public static readonly ID = 'workbench.action.reopenClosedEditor';
	public static readonly LABEL = nls.localize('reopenClosedEditor', "Reopen Closed Editor");
1094 1095 1096 1097

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1098
		@IHistoryService private historyService: IHistoryService
1099 1100 1101 1102 1103
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1104
		this.historyService.reopenLastClosedEditor();
1105 1106 1107

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
1108 1109
}

1110
export class ClearRecentFilesAction extends Action {
C
22768  
Cristian 已提交
1111

M
Matt Bierner 已提交
1112 1113
	public static readonly ID = 'workbench.action.clearRecentFiles';
	public static readonly LABEL = nls.localize('clearRecentFiles', "Clear Recently Opened");
C
22768  
Cristian 已提交
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123

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

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
1124
		this.windowsService.clearRecentlyOpened();
C
22768  
Cristian 已提交
1125 1126 1127 1128 1129

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
1130
export class ShowEditorsInActiveGroupAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
1131

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

1135 1136 1137
	constructor(
		actionId: string,
		actionLabel: string,
1138
		@IQuickOpenService quickOpenService: IQuickOpenService
1139
	) {
B
Benjamin Pasero 已提交
1140
		super(actionId, actionLabel, NAVIGATE_IN_ACTIVE_GROUP_PREFIX, quickOpenService);
1141
	}
B
Benjamin Pasero 已提交
1142 1143
}

B
Benjamin Pasero 已提交
1144 1145
export class ShowAllEditorsAction extends QuickOpenAction {

M
Matt Bierner 已提交
1146 1147
	public static readonly ID = 'workbench.action.showAllEditors';
	public static readonly LABEL = nls.localize('showAllEditors', "Show All Editors");
B
Benjamin Pasero 已提交
1148 1149 1150 1151 1152 1153

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

1154
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1155 1156 1157 1158 1159

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

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

1168

B
Benjamin Pasero 已提交
1169 1170

		this.quickOpenService.show(NAVIGATE_IN_ACTIVE_GROUP_PREFIX, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1171 1172 1173 1174 1175

		return TPromise.as(true);
	}
}

1176 1177
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1178 1179
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditorInGroup', "Open Previous Recently Used Editor in Group");
1180 1181 1182 1183 1184

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1185
		@IKeybindingService keybindingService: IKeybindingService
1186
	) {
B
Benjamin Pasero 已提交
1187
		super(id, label, quickOpenService, keybindingService);
1188 1189 1190 1191 1192
	}
}

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1193 1194
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditorInGroup', "Open Next Recently Used Editor in Group");
1195 1196 1197 1198 1199

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1200
		@IKeybindingService keybindingService: IKeybindingService
1201
	) {
B
Benjamin Pasero 已提交
1202
		super(id, label, quickOpenService, keybindingService);
1203 1204 1205
	}
}

1206
export class OpenPreviousEditorFromHistoryAction extends Action {
B
Benjamin Pasero 已提交
1207

M
Matt Bierner 已提交
1208 1209
	public static readonly ID = 'workbench.action.openPreviousEditorFromHistory';
	public static readonly LABEL = nls.localize('navigateEditorHistoryByInput', "Open Previous Editor from History");
B
Benjamin Pasero 已提交
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220

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

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

B
Benjamin Pasero 已提交
1223
		this.quickOpenService.show(null, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1224 1225 1226 1227 1228

		return TPromise.as(true);
	}
}

1229 1230
export class OpenNextRecentlyUsedEditorAction extends Action {

M
Matt Bierner 已提交
1231 1232
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditor', "Open Next Recently Used Editor");
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246

	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 已提交
1247 1248
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditor', "Open Previous Recently Used Editor");
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260

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

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

		return TPromise.as(null);
	}
}

1261 1262
export class ClearEditorHistoryAction extends Action {

M
Matt Bierner 已提交
1263 1264
	public static readonly ID = 'workbench.action.clearEditorHistory';
	public static readonly LABEL = nls.localize('clearEditorHistory', "Clear Editor History");
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275

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

	public run(): TPromise<any> {

1276
		// Editor history
1277 1278 1279 1280 1281 1282
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1283 1284
export class MoveEditorLeftInGroupAction extends Action {

M
Matt Bierner 已提交
1285 1286
	public static readonly ID = 'workbench.action.moveEditorLeftInGroup';
	public static readonly LABEL = nls.localize('moveEditorLeft', "Move Editor Left");
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296

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

	public run(): TPromise<any> {
1297 1298
		const args: ActiveEditorMoveArguments = { to: 'left' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
1299 1300 1301 1302 1303 1304 1305

		return TPromise.as(true);
	}
}

export class MoveEditorRightInGroupAction extends Action {

M
Matt Bierner 已提交
1306 1307
	public static readonly ID = 'workbench.action.moveEditorRightInGroup';
	public static readonly LABEL = nls.localize('moveEditorRight', "Move Editor Right");
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317

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

	public run(): TPromise<any> {
1318 1319
		const args: ActiveEditorMoveArguments = { to: 'right' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
1320 1321 1322 1323 1324

		return TPromise.as(true);
	}
}

1325
export class MoveEditorToPreviousGroupAction extends Action {
1326

M
Matt Bierner 已提交
1327 1328
	public static readonly ID = 'workbench.action.moveEditorToPreviousGroup';
	public static readonly LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
1329 1330 1331 1332

	constructor(
		id: string,
		label: string,
1333
		@ICommandService private commandService: ICommandService
1334 1335 1336 1337 1338
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1339 1340
		const args: ActiveEditorMoveArguments = { to: 'previous', by: 'group' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
1341 1342 1343 1344 1345

		return TPromise.as(true);
	}
}

1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429
export class MoveEditorToUpwardsGroupAction extends Action {

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

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

	public run(): TPromise<any> {
		const args: ActiveEditorMoveArguments = { to: 'up', by: 'group' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);

		return TPromise.as(true);
	}
}

export class MoveEditorToDownwardsGroupAction extends Action {

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

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

	public run(): TPromise<any> {
		const args: ActiveEditorMoveArguments = { to: 'down', by: 'group' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);

		return TPromise.as(true);
	}
}

export class MoveEditorToLeftGroupAction extends Action {

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

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

	public run(): TPromise<any> {
		const args: ActiveEditorMoveArguments = { to: 'left', by: 'group' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);

		return TPromise.as(true);
	}
}

export class MoveEditorToRightGroupAction extends Action {

	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 private commandService: ICommandService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const args: ActiveEditorMoveArguments = { to: 'right', by: 'group' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);

		return TPromise.as(true);
	}
}

1430
export class MoveEditorToNextGroupAction extends Action {
1431

M
Matt Bierner 已提交
1432 1433
	public static readonly ID = 'workbench.action.moveEditorToNextGroup';
	public static readonly LABEL = nls.localize('moveEditorToNextGroup', "Move Editor into Next Group");
1434 1435 1436 1437

	constructor(
		id: string,
		label: string,
1438
		@ICommandService private commandService: ICommandService
1439 1440 1441 1442 1443
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1444 1445
		const args: ActiveEditorMoveArguments = { to: 'next', by: 'group' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
1446

1447 1448
		return TPromise.as(true);
	}
D
Daniel Imms 已提交
1449
}
1450

1451 1452 1453 1454
export class MoveEditorToFirstGroupAction extends Action {

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

	constructor(
		id: string,
		label: string,
1459
		@ICommandService private commandService: ICommandService
1460 1461 1462 1463 1464
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1465 1466
		const args: ActiveEditorMoveArguments = { to: 'first', by: 'group' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
1467 1468 1469 1470 1471

		return TPromise.as(true);
	}
}

1472
export class MoveEditorToLastGroupAction extends Action {
1473

1474 1475
	public static readonly ID = 'workbench.action.moveEditorToLastGroup';
	public static readonly LABEL = nls.localize('moveEditorToLastGroup', "Move Editor into Last Group");
1476 1477 1478 1479

	constructor(
		id: string,
		label: string,
1480
		@ICommandService private commandService: ICommandService
1481
	) {
1482
		super(id, label);
1483 1484
	}

1485 1486 1487
	public run(): TPromise<any> {
		const args: ActiveEditorMoveArguments = { to: 'last', by: 'group' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
1488

1489
		return TPromise.as(true);
1490
	}
1491
}