editorActions.ts 39.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 } from 'vs/workbench/browser/parts/editor/editorCommands';
23
import { INextEditorGroupsService, IEditorGroup, GroupsArrangement, EditorsOrder, GroupLocation, GroupDirection, preferredGroupDirection } from 'vs/workbench/services/group/common/nextEditorGroupsService';
B
Benjamin Pasero 已提交
24 25
import { INextEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/nextEditorService';
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,
B
Benjamin Pasero 已提交
35
		private editorGroupService: INextEditorGroupsService
36
	) {
B
Benjamin Pasero 已提交
37
		super(id, label, clazz);
E
Erich Gamma 已提交
38 39
	}

B
Benjamin Pasero 已提交
40
	public run(context?: IEditorIdentifier): TPromise<any> {
41
		let sourceGroup: IEditorGroup;
B
Benjamin Pasero 已提交
42 43
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
44
		} else {
B
Benjamin Pasero 已提交
45
			sourceGroup = this.editorGroupService.activeGroup;
46
		}
E
Erich Gamma 已提交
47

B
Benjamin Pasero 已提交
48 49
		// Add group
		const newGroup = this.editorGroupService.addGroup(sourceGroup, this.direction, { activate: true });
E
Erich Gamma 已提交
50

B
Benjamin Pasero 已提交
51 52 53 54 55
		// Split editor (if it can be split)
		if (sourceGroup.activeEditor) {
			if (sourceGroup.activeEditor instanceof EditorInput && !sourceGroup.activeEditor.supportsSplitEditor()) {
				return TPromise.as(true);
			}
E
Erich Gamma 已提交
56

B
Benjamin Pasero 已提交
57
			sourceGroup.copyEditor(sourceGroup.activeEditor, newGroup);
E
Erich Gamma 已提交
58 59
		}

A
Alex Dima 已提交
60
		return TPromise.as(true);
E
Erich Gamma 已提交
61 62 63
	}
}

B
Benjamin Pasero 已提交
64 65 66 67
export class SplitEditorAction extends BaseSplitEditorGroupAction {

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

69 70
	private toDispose: IDisposable[] = [];

71 72 73
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
74
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService,
75
		@IConfigurationService private configurationService: IConfigurationService
76
	) {
B
Benjamin Pasero 已提交
77
		super(id, label, null, preferredGroupDirection(configurationService), editorGroupService);
78 79 80 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 117

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

	public dispose(): void {
		super.dispose();

		this.toDispose = dispose(this.toDispose);
118 119 120 121 122 123 124 125 126 127 128
	}
}

export class SplitEditorGroupVerticalAction extends BaseSplitEditorGroupAction {

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

	constructor(
		id: string,
		label: string,
129
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService
130
	) {
B
Benjamin Pasero 已提交
131
		super(id, label, 'split-editor-vertical-action', GroupDirection.DOWN, editorGroupService);
132 133 134 135 136 137 138 139 140 141 142
	}
}

export class SplitEditorGroupHorizontalAction extends BaseSplitEditorGroupAction {

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

	constructor(
		id: string,
		label: string,
143
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService
144
	) {
B
Benjamin Pasero 已提交
145
		super(id, label, 'split-editor-horizontal-action', GroupDirection.RIGHT, editorGroupService);
146 147 148
	}
}

B
Benjamin Pasero 已提交
149
export class SplitEditorGroupLeftAction extends BaseSplitEditorGroupAction {
150

B
Benjamin Pasero 已提交
151 152
	public static readonly ID = 'workbench.action.splitEditorGroupLeft';
	public static readonly LABEL = nls.localize('splitEditorGroupLeft', "Split Editor Group Left");
153 154 155 156

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
157
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService
158
	) {
B
Benjamin Pasero 已提交
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
		super(id, label, null, GroupDirection.LEFT, editorGroupService);
	}
}

export class SplitEditorGroupRightAction extends BaseSplitEditorGroupAction {

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

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

export class SplitEditorGroupUpAction extends BaseSplitEditorGroupAction {

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

B
Benjamin Pasero 已提交
182 183 184 185 186 187
	constructor(
		id: string,
		label: string,
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService
	) {
		super(id, label, null, GroupDirection.UP, editorGroupService);
188
	}
B
Benjamin Pasero 已提交
189
}
190

B
Benjamin Pasero 已提交
191
export class SplitEditorGroupDownAction extends BaseSplitEditorGroupAction {
192

B
Benjamin Pasero 已提交
193 194
	public static readonly ID = 'workbench.action.splitEditorGroupDown';
	public static readonly LABEL = nls.localize('splitEditorGroupDown', "Split Editor Group Down");
195

B
Benjamin Pasero 已提交
196 197 198 199 200 201
	constructor(
		id: string,
		label: string,
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService
	) {
		super(id, label, null, GroupDirection.DOWN, editorGroupService);
202 203 204
	}
}

205
export class JoinTwoGroupsAction extends Action {
I
initialshl 已提交
206

M
Matt Bierner 已提交
207 208
	public static readonly ID = 'workbench.action.joinTwoGroups';
	public static readonly LABEL = nls.localize('joinTwoGroups', "Join Editors of Two Groups");
I
initialshl 已提交
209 210 211 212

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
213
		@INextEditorGroupsService private editorGroupService: INextEditorGroupsService
I
initialshl 已提交
214
	) {
215
		super(id, label);
I
initialshl 已提交
216 217
	}

218
	public run(context?: IEditorIdentifier): TPromise<any> {
219
		let sourceGroup: IEditorGroup;
B
Benjamin Pasero 已提交
220 221
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
I
initialshl 已提交
222
		} else {
B
Benjamin Pasero 已提交
223
			sourceGroup = this.editorGroupService.activeGroup;
I
initialshl 已提交
224 225
		}

B
Benjamin Pasero 已提交
226 227 228 229 230
		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);
231

B
Benjamin Pasero 已提交
232 233 234
		if (targetGroup && sourceGroup !== targetGroup) {
			this.editorGroupService.mergeGroup(sourceGroup, targetGroup);
		}
I
initialshl 已提交
235 236 237 238 239

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
240
export class NavigateBetweenGroupsAction extends Action {
241

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

245 246 247
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
248
		@INextEditorGroupsService private editorGroupService: INextEditorGroupsService
249
	) {
E
Erich Gamma 已提交
250 251 252
		super(id, label);
	}

253
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
254 255 256
		let nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT });
		if (!nextGroup) {
			nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.FIRST });
E
Erich Gamma 已提交
257 258
		}

B
Benjamin Pasero 已提交
259
		nextGroup.focus();
260 261

		return TPromise.as(true);
E
Erich Gamma 已提交
262 263 264
	}
}

265 266
export class FocusActiveGroupAction extends Action {

M
Matt Bierner 已提交
267 268
	public static readonly ID = 'workbench.action.focusActiveEditorGroup';
	public static readonly LABEL = nls.localize('focusActiveEditorGroup', "Focus Active Editor Group");
269 270 271 272

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
273
		@INextEditorGroupsService private editorGroupService: INextEditorGroupsService
274 275 276 277 278
	) {
		super(id, label);
	}

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

281
		return TPromise.as(true);
E
Erich Gamma 已提交
282 283 284
	}
}

285 286
export class FocusFirstGroupAction extends Action {

M
Matt Bierner 已提交
287 288
	public static readonly ID = 'workbench.action.focusFirstEditorGroup';
	public static readonly LABEL = nls.localize('focusFirstEditorGroup', "Focus First Editor Group");
E
Erich Gamma 已提交
289 290 291 292

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
293
		@INextEditorGroupsService private editorGroupService: INextEditorGroupsService
E
Erich Gamma 已提交
294 295 296 297
	) {
		super(id, label);
	}

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

A
Alex Dima 已提交
301
		return TPromise.as(true);
E
Erich Gamma 已提交
302 303 304
	}
}

B
Benjamin Pasero 已提交
305 306 307 308
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 已提交
309 310 311 312

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
313
		@INextEditorGroupsService private editorGroupService: INextEditorGroupsService
E
Erich Gamma 已提交
314 315 316 317
	) {
		super(id, label);
	}

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

A
Alex Dima 已提交
321
		return TPromise.as(true);
E
Erich Gamma 已提交
322 323 324
	}
}

B
Benjamin Pasero 已提交
325
export class FocusPreviousGroup extends Action {
326

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

330 331 332
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
333
		@INextEditorGroupsService private editorGroupService: INextEditorGroupsService
334
	) {
E
Erich Gamma 已提交
335 336 337
		super(id, label);
	}

338
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
339 340 341
		const previousGroup = this.editorGroupService.findGroup({ location: GroupLocation.PREVIOUS });
		if (previousGroup) {
			previousGroup.focus();
E
Erich Gamma 已提交
342 343
		}

344
		return TPromise.as(true);
E
Erich Gamma 已提交
345 346 347
	}
}

B
Benjamin Pasero 已提交
348
export class FocusNextGroup extends Action {
349

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

E
Erich Gamma 已提交
353 354 355
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
356
		@INextEditorGroupsService private editorGroupService: INextEditorGroupsService
E
Erich Gamma 已提交
357 358 359 360
	) {
		super(id, label);
	}

361
	public run(event?: any): TPromise<any> {
B
Benjamin Pasero 已提交
362 363 364
		const nextGroup = this.editorGroupService.findGroup({ location: GroupLocation.NEXT });
		if (nextGroup) {
			nextGroup.focus();
E
Erich Gamma 已提交
365 366
		}

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

export class OpenToSideAction extends Action {

M
Matt Bierner 已提交
373 374
	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 已提交
375

376
	constructor(
B
Benjamin Pasero 已提交
377 378
		@INextEditorService private editorService: INextEditorService,
		@IConfigurationService private configurationService: IConfigurationService
379
	) {
E
Erich Gamma 已提交
380 381
		super(OpenToSideAction.OPEN_TO_SIDE_ID, OpenToSideAction.OPEN_TO_SIDE_LABEL);

382 383 384 385
		this.updateClass();
	}

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

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

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

399 400 401
			const resourceInput = input as IResourceInput;
			resourceInput.options = mixin(resourceInput.options, entry.getOptions());

B
Benjamin Pasero 已提交
402
			return this.editorService.openEditor(resourceInput, SIDE_GROUP);
E
Erich Gamma 已提交
403 404
		}

A
Alex Dima 已提交
405
		return TPromise.as(false);
E
Erich Gamma 已提交
406 407 408
	}
}

409
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
410 411 412

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

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

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

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

445 446 447 448 449 450 451 452
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,
453
		@INextEditorGroupsService private editorGroupService: INextEditorGroupsService
454 455 456 457 458
	) {
		super(id, label, 'close-editor-action');
	}

	public run(context?: IEditorCommandsContext): TPromise<any> {
459
		let group: IEditorGroup;
460 461
		let editorIndex: number;
		if (context) {
462
			group = this.editorGroupService.getGroup(context.groupId);
463

464 465
			if (group) {
				editorIndex = context.editorIndex; // only allow editor at index if group is valid
466 467 468
			}
		}

469
		if (!group) {
470
			group = this.editorGroupService.activeGroup;
471 472
		}

473 474 475 476
		// Close specific editor in group
		if (typeof editorIndex === 'number') {
			const editorAtIndex = group.getEditor(editorIndex);
			if (editorAtIndex) {
477
				return group.closeEditor(editorAtIndex);
478 479 480 481 482
			}
		}

		// Otherwise close active editor in group
		if (group.activeEditor) {
483
			return group.closeEditor(group.activeEditor);
484 485 486 487 488 489
		}

		return TPromise.as(false);
	}
}

M
misoguy 已提交
490 491
export class RevertAndCloseEditorAction extends Action {

M
Matt Bierner 已提交
492 493
	public static readonly ID = 'workbench.action.revertAndCloseActiveEditor';
	public static readonly LABEL = nls.localize('revertAndCloseActiveEditor', "Revert and Close Editor");
M
misoguy 已提交
494 495 496 497

	constructor(
		id: string,
		label: string,
498
		@INextEditorService private editorService: INextEditorService
M
misoguy 已提交
499 500 501 502 503
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
504 505 506
		const activeControl = this.editorService.activeControl;
		if (activeControl && activeControl.input) {
			const editor = activeControl.input;
507
			const group = activeControl.group;
B
Benjamin Pasero 已提交
508

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

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
523
export class CloseLeftEditorsInGroupAction extends Action {
524

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

528 529 530
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
531 532
		@INextEditorService private editorService: INextEditorService,
		@INextEditorGroupsService private groupService: INextEditorGroupsService
533
	) {
534 535 536
		super(id, label);
	}

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

		return TPromise.as(false);
	}
}

547
function getTarget(editorService: INextEditorService, editorGroupService: INextEditorGroupsService, context?: IEditorIdentifier): { editor: IEditorInput, group: IEditorGroup } {
B
Benjamin Pasero 已提交
548 549 550 551 552 553 554 555
	if (context) {
		return { editor: context.editor, group: editorGroupService.getGroup(context.groupId) };
	}

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

E
Erich Gamma 已提交
556 557
export class CloseAllEditorsAction extends Action {

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

561 562 563 564
	constructor(
		id: string,
		label: string,
		@ITextFileService private textFileService: ITextFileService,
I
isidor 已提交
565
		@INextEditorGroupsService private editorGroupService: INextEditorGroupsService
566
	) {
I
isidor 已提交
567
		super(id, label, 'action-close-all-files');
E
Erich Gamma 已提交
568 569
	}

570
	public run(): TPromise<any> {
571 572 573

		// Just close all if there are no or one dirty editor
		if (this.textFileService.getDirty().length < 2) {
I
isidor 已提交
574
			return TPromise.join(this.editorGroupService.groups.map(g => g.closeAllEditors()));
575 576 577
		}

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

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

590 591
			return saveOrRevertPromise.then(success => {
				if (success) {
I
isidor 已提交
592
					return TPromise.join(this.editorGroupService.groups.map(g => g.closeAllEditors()));
593 594 595 596
				}

				return void 0;
			});
597
		});
E
Erich Gamma 已提交
598 599 600
	}
}

601 602
export class CloseEditorsInOtherGroupsAction extends Action {

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

606 607 608
	constructor(
		id: string,
		label: string,
I
isidor 已提交
609
		@INextEditorGroupsService private editorGroupService: INextEditorGroupsService,
610
	) {
611 612 613
		super(id, label);
	}

614
	public run(context?: IEditorIdentifier): TPromise<any> {
I
isidor 已提交
615 616 617 618
		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);
619 620
			}

I
isidor 已提交
621 622
			return g.closeAllEditors();
		}));
623 624 625
	}
}

626
export class BaseMoveGroupAction extends Action {
627

628 629 630
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
631
		private direction: GroupDirection,
632
		private editorGroupService: INextEditorGroupsService
633
	) {
E
Erich Gamma 已提交
634 635 636
		super(id, label);
	}

637
	public run(context?: IEditorIdentifier): TPromise<any> {
638
		let sourceGroup: IEditorGroup;
639 640 641 642
		if (context && typeof context.groupId === 'number') {
			sourceGroup = this.editorGroupService.getGroup(context.groupId);
		} else {
			sourceGroup = this.editorGroupService.activeGroup;
643 644
		}

B
Benjamin Pasero 已提交
645
		const targetGroup = this.editorGroupService.findGroup({ direction: this.direction }, sourceGroup);
646
		if (targetGroup) {
B
Benjamin Pasero 已提交
647
			this.editorGroupService.moveGroup(sourceGroup, targetGroup, this.direction);
E
Erich Gamma 已提交
648 649
		}

650
		return TPromise.as(true);
E
Erich Gamma 已提交
651 652 653
	}
}

654 655 656 657 658 659 660 661 662 663
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,
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService
	) {
B
Benjamin Pasero 已提交
664
		super(id, label, GroupDirection.LEFT, editorGroupService);
665 666 667 668
	}
}

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

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

673 674 675
	constructor(
		id: string,
		label: string,
676
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService
677
	) {
B
Benjamin Pasero 已提交
678
		super(id, label, GroupDirection.RIGHT, editorGroupService);
679 680
	}
}
681

682
export class MoveGroupUpAction extends BaseMoveGroupAction {
683

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

687 688 689 690 691
	constructor(
		id: string,
		label: string,
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService
	) {
B
Benjamin Pasero 已提交
692
		super(id, label, GroupDirection.UP, editorGroupService);
693 694 695 696 697 698 699 700 701 702 703 704 705
	}
}

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,
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService
	) {
B
Benjamin Pasero 已提交
706
		super(id, label, GroupDirection.DOWN, editorGroupService);
E
Erich Gamma 已提交
707 708 709
	}
}

710
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
711

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

715
	constructor(id: string, label: string, @INextEditorGroupsService private editorGroupService: INextEditorGroupsService) {
E
Erich Gamma 已提交
716 717 718
		super(id, label);
	}

719
	public run(): TPromise<any> {
720
		this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
721

A
Alex Dima 已提交
722
		return TPromise.as(false);
E
Erich Gamma 已提交
723 724 725
	}
}

726
export class EvenGroupWidthsAction extends Action {
E
Erich Gamma 已提交
727

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

731
	constructor(id: string, label: string, @INextEditorGroupsService private editorGroupService: INextEditorGroupsService) {
E
Erich Gamma 已提交
732 733 734
		super(id, label);
	}

735
	public run(): TPromise<any> {
736
		this.editorGroupService.arrangeGroups(GroupsArrangement.EVEN);
E
Erich Gamma 已提交
737

A
Alex Dima 已提交
738
		return TPromise.as(false);
E
Erich Gamma 已提交
739 740 741
	}
}

742
export class MaximizeGroupAction extends Action {
743

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

747 748 749
	constructor(
		id: string,
		label: string,
750 751
		@INextEditorService private editorService: INextEditorService,
		@INextEditorGroupsService private editorGroupService: INextEditorGroupsService,
752 753 754 755 756
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

757
	public run(): TPromise<any> {
758 759 760
		if (this.editorService.activeEditor) {
			this.editorGroupService.arrangeGroups(GroupsArrangement.MINIMIZE_OTHERS);

761
			return this.partService.setSideBarHidden(true);
762 763
		}

A
Alex Dima 已提交
764
		return TPromise.as(false);
765 766 767
	}
}

768 769
export abstract class BaseNavigateEditorAction extends Action {

770 771 772
	constructor(
		id: string,
		label: string,
773 774
		protected editorGroupService: INextEditorGroupsService,
		protected editorService: INextEditorService
775
	) {
776 777 778 779 780
		super(id, label);
	}

	public run(): TPromise<any> {
		const result = this.navigate();
781 782
		if (!result) {
			return TPromise.as(false);
783 784
		}

785 786 787 788 789 790 791
		const { groupId, editor } = result;
		if (!editor) {
			return TPromise.as(false);
		}

		const group = this.editorGroupService.getGroup(groupId);
		return group.openEditor(editor);
792 793 794 795 796 797 798
	}

	protected abstract navigate(): IEditorIdentifier;
}

export class OpenNextEditor extends BaseNavigateEditorAction {

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

802 803 804
	constructor(
		id: string,
		label: string,
805 806
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService,
		@INextEditorService editorService: INextEditorService
807 808
	) {
		super(id, label, editorGroupService, editorService);
809 810 811
	}

	protected navigate(): IEditorIdentifier {
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828

		// 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;
829 830 831 832 833
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

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

837 838 839
	constructor(
		id: string,
		label: string,
840 841
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService,
		@INextEditorService editorService: INextEditorService
842 843
	) {
		super(id, label, editorGroupService, editorService);
844 845 846
	}

	protected navigate(): IEditorIdentifier {
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863

		// 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;
864 865 866 867 868
	}
}

export class OpenNextEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
869 870
	public static readonly ID = 'workbench.action.nextEditorInGroup';
	public static readonly LABEL = nls.localize('nextEditorInGroup', "Open Next Editor in Group");
871 872 873 874

	constructor(
		id: string,
		label: string,
875 876
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService,
		@INextEditorService editorService: INextEditorService
877 878 879 880 881
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
882 883 884 885 886
		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 };
887 888 889 890 891
	}
}

export class OpenPreviousEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
892 893
	public static readonly ID = 'workbench.action.previousEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousEditorInGroup', "Open Previous Editor in Group");
894 895 896 897

	constructor(
		id: string,
		label: string,
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService,
		@INextEditorService editorService: INextEditorService
	) {
		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,
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService,
		@INextEditorService editorService: INextEditorService
923 924 925 926 927
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
928 929 930 931
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[0], groupId: group.id };
932
	}
B
Benjamin Pasero 已提交
933 934
}

935 936 937 938 939 940 941 942
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,
943 944
		@INextEditorGroupsService editorGroupService: INextEditorGroupsService,
		@INextEditorService editorService: INextEditorService
945 946 947 948 949
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
950 951 952 953
		const group = this.editorGroupService.activeGroup;
		const editors = group.getEditors(EditorsOrder.SEQUENTIAL);

		return { editor: editors[editors.length - 1], groupId: group.id };
954 955 956
	}
}

B
Benjamin Pasero 已提交
957 958
export class NavigateForwardAction extends Action {

M
Matt Bierner 已提交
959 960
	public static readonly ID = 'workbench.action.navigateForward';
	public static readonly LABEL = nls.localize('navigateNext', "Go Forward");
B
Benjamin Pasero 已提交
961 962 963 964 965 966 967 968 969 970 971 972 973 974

	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 已提交
975 976
	public static readonly ID = 'workbench.action.navigateBack';
	public static readonly LABEL = nls.localize('navigatePrevious', "Go Back");
B
Benjamin Pasero 已提交
977 978 979 980 981 982 983 984 985 986

	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 已提交
987
}
988

989 990
export class NavigateLastAction extends Action {

M
Matt Bierner 已提交
991 992
	public static readonly ID = 'workbench.action.navigateLast';
	public static readonly LABEL = nls.localize('navigateLast', "Go Last");
993 994 995 996 997 998 999 1000 1001 1002 1003 1004

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

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

		return TPromise.as(null);
	}
}

1005 1006
export class ReopenClosedEditorAction extends Action {

M
Matt Bierner 已提交
1007 1008
	public static readonly ID = 'workbench.action.reopenClosedEditor';
	public static readonly LABEL = nls.localize('reopenClosedEditor', "Reopen Closed Editor");
1009 1010 1011 1012

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
1013
		@IHistoryService private historyService: IHistoryService
1014 1015 1016 1017 1018
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1019
		this.historyService.reopenLastClosedEditor();
1020 1021 1022

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
1023 1024
}

1025
export class ClearRecentFilesAction extends Action {
C
22768  
Cristian 已提交
1026

M
Matt Bierner 已提交
1027 1028
	public static readonly ID = 'workbench.action.clearRecentFiles';
	public static readonly LABEL = nls.localize('clearRecentFiles', "Clear Recently Opened");
C
22768  
Cristian 已提交
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038

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

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
1039
		this.windowsService.clearRecentlyOpened();
C
22768  
Cristian 已提交
1040 1041 1042 1043 1044

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
1045
export class ShowEditorsInActiveGroupAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
1046

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

1050 1051 1052
	constructor(
		actionId: string,
		actionLabel: string,
1053
		@IQuickOpenService quickOpenService: IQuickOpenService
1054
	) {
B
Benjamin Pasero 已提交
1055
		super(actionId, actionLabel, NAVIGATE_IN_ACTIVE_GROUP_PREFIX, quickOpenService);
1056
	}
B
Benjamin Pasero 已提交
1057 1058
}

B
Benjamin Pasero 已提交
1059 1060
export class ShowAllEditorsAction extends QuickOpenAction {

M
Matt Bierner 已提交
1061 1062
	public static readonly ID = 'workbench.action.showAllEditors';
	public static readonly LABEL = nls.localize('showAllEditors', "Show All Editors");
B
Benjamin Pasero 已提交
1063 1064 1065 1066 1067 1068

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

1069
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1070 1071 1072 1073 1074

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1075
		@IKeybindingService private keybindingService: IKeybindingService
B
Benjamin Pasero 已提交
1076 1077 1078 1079 1080
	) {
		super(id, label);
	}

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

1083

B
Benjamin Pasero 已提交
1084 1085

		this.quickOpenService.show(NAVIGATE_IN_ACTIVE_GROUP_PREFIX, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1086 1087 1088 1089 1090

		return TPromise.as(true);
	}
}

1091 1092
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1093 1094
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditorInGroup', "Open Previous Recently Used Editor in Group");
1095 1096 1097 1098 1099

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1100
		@IKeybindingService keybindingService: IKeybindingService
1101
	) {
B
Benjamin Pasero 已提交
1102
		super(id, label, quickOpenService, keybindingService);
1103 1104 1105 1106 1107
	}
}

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1108 1109
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditorInGroup', "Open Next Recently Used Editor in Group");
1110 1111 1112 1113 1114

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
B
Benjamin Pasero 已提交
1115
		@IKeybindingService keybindingService: IKeybindingService
1116
	) {
B
Benjamin Pasero 已提交
1117
		super(id, label, quickOpenService, keybindingService);
1118 1119 1120
	}
}

1121
export class OpenPreviousEditorFromHistoryAction extends Action {
B
Benjamin Pasero 已提交
1122

M
Matt Bierner 已提交
1123 1124
	public static readonly ID = 'workbench.action.openPreviousEditorFromHistory';
	public static readonly LABEL = nls.localize('navigateEditorHistoryByInput', "Open Previous Editor from History");
B
Benjamin Pasero 已提交
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135

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

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

B
Benjamin Pasero 已提交
1138
		this.quickOpenService.show(null, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1139 1140 1141 1142 1143

		return TPromise.as(true);
	}
}

1144 1145
export class OpenNextRecentlyUsedEditorAction extends Action {

M
Matt Bierner 已提交
1146 1147
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditor', "Open Next Recently Used Editor");
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161

	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 已提交
1162 1163
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditor', "Open Previous Recently Used Editor");
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175

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

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

		return TPromise.as(null);
	}
}

1176 1177
export class ClearEditorHistoryAction extends Action {

M
Matt Bierner 已提交
1178 1179
	public static readonly ID = 'workbench.action.clearEditorHistory';
	public static readonly LABEL = nls.localize('clearEditorHistory', "Clear Editor History");
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190

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

	public run(): TPromise<any> {

1191
		// Editor history
1192 1193 1194 1195 1196 1197
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1198 1199
export class MoveEditorLeftInGroupAction extends Action {

M
Matt Bierner 已提交
1200 1201
	public static readonly ID = 'workbench.action.moveEditorLeftInGroup';
	public static readonly LABEL = nls.localize('moveEditorLeft', "Move Editor Left");
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211

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

	public run(): TPromise<any> {
1212 1213
		const args: ActiveEditorMoveArguments = { to: 'left' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
1214 1215 1216 1217 1218 1219 1220

		return TPromise.as(true);
	}
}

export class MoveEditorRightInGroupAction extends Action {

M
Matt Bierner 已提交
1221 1222
	public static readonly ID = 'workbench.action.moveEditorRightInGroup';
	public static readonly LABEL = nls.localize('moveEditorRight', "Move Editor Right");
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232

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

	public run(): TPromise<any> {
1233 1234
		const args: ActiveEditorMoveArguments = { to: 'right' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
1235 1236 1237 1238 1239

		return TPromise.as(true);
	}
}

1240
export class MoveEditorToPreviousGroupAction extends Action {
1241

M
Matt Bierner 已提交
1242 1243
	public static readonly ID = 'workbench.action.moveEditorToPreviousGroup';
	public static readonly LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
1244 1245 1246 1247

	constructor(
		id: string,
		label: string,
1248
		@ICommandService private commandService: ICommandService
1249 1250 1251 1252 1253
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1254 1255
		const args: ActiveEditorMoveArguments = { to: 'previous', by: 'group' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
1256 1257 1258 1259 1260

		return TPromise.as(true);
	}
}

1261
export class MoveEditorToNextGroupAction extends Action {
1262

M
Matt Bierner 已提交
1263 1264
	public static readonly ID = 'workbench.action.moveEditorToNextGroup';
	public static readonly LABEL = nls.localize('moveEditorToNextGroup', "Move Editor into Next Group");
1265 1266 1267 1268

	constructor(
		id: string,
		label: string,
1269
		@ICommandService private commandService: ICommandService
1270 1271 1272 1273 1274
	) {
		super(id, label);
	}

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

1278 1279
		return TPromise.as(true);
	}
D
Daniel Imms 已提交
1280
}
1281

1282 1283 1284 1285
export class MoveEditorToFirstGroupAction extends Action {

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

	constructor(
		id: string,
		label: string,
1290
		@ICommandService private commandService: ICommandService
1291 1292 1293 1294 1295
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1296 1297
		const args: ActiveEditorMoveArguments = { to: 'first', by: 'group' };
		this.commandService.executeCommand(MOVE_ACTIVE_EDITOR_COMMAND_ID, args);
1298 1299 1300 1301 1302

		return TPromise.as(true);
	}
}

1303
export class MoveEditorToLastGroupAction extends Action {
1304

1305 1306
	public static readonly ID = 'workbench.action.moveEditorToLastGroup';
	public static readonly LABEL = nls.localize('moveEditorToLastGroup', "Move Editor into Last Group");
1307 1308 1309 1310

	constructor(
		id: string,
		label: string,
1311
		@ICommandService private commandService: ICommandService
1312
	) {
1313
		super(id, label);
1314 1315
	}

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

1320
		return TPromise.as(true);
1321
	}
1322
}