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

J
Johannes Rieken 已提交
7
import { TPromise } from 'vs/base/common/winjs.base';
E
Erich Gamma 已提交
8
import nls = require('vs/nls');
J
Johannes Rieken 已提交
9
import { Action } from 'vs/base/common/actions';
10
import { mixin } from 'vs/base/common/objects';
S
Sandeep Somavarapu 已提交
11
import { getCodeEditor } from 'vs/editor/common/services/codeEditorService';
12
import { EditorInput, hasResource, TextEditorOptions, EditorOptions, IEditorIdentifier, IEditorContext, ActiveEditorMoveArguments, ActiveEditorMovePositioning, EditorCommands, ConfirmResult } from 'vs/workbench/common/editor';
J
Johannes Rieken 已提交
13 14 15
import { QuickOpenEntryGroup } from 'vs/base/parts/quickopen/browser/quickOpenModel';
import { EditorQuickOpenEntry, EditorQuickOpenEntryGroup, IEditorQuickOpenEntry, QuickOpenAction } from 'vs/workbench/browser/quickopen';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
J
Johannes Rieken 已提交
16
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
J
Johannes Rieken 已提交
17
import { IPartService } from 'vs/workbench/services/part/common/partService';
18
import { Position, IEditor, Direction, IResourceInput, IEditorInput, POSITIONS } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
19 20 21 22 23
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IEditorGroupService, GroupArrangement } from 'vs/workbench/services/group/common/groupService';
import { ICommandService } from 'vs/platform/commands/common/commands';
24
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
E
Erich Gamma 已提交
25 26 27

export class SplitEditorAction extends Action {

28 29 30
	public static ID = 'workbench.action.splitEditor';
	public static LABEL = nls.localize('splitEditor', "Split Editor");

31 32 33 34 35 36
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private editorGroupService: IEditorGroupService
	) {
I
isidor 已提交
37
		super(id, label, 'split-editor-action');
E
Erich Gamma 已提交
38 39
	}

B
Benjamin Pasero 已提交
40
	public run(context?: IEditorContext): TPromise<any> {
41 42 43 44 45 46
		let editorToSplit: IEditor;
		if (context) {
			editorToSplit = this.editorService.getVisibleEditors()[this.editorGroupService.getStacksModel().positionOfGroup(context.group)];
		} else {
			editorToSplit = this.editorService.getActiveEditor();
		}
E
Erich Gamma 已提交
47

48 49
		// Can only split with target editor
		if (!editorToSplit) {
A
Alex Dima 已提交
50
			return TPromise.as(true);
E
Erich Gamma 已提交
51 52 53
		}

		// Return if the editor to split does not support split editing
54
		if (editorToSplit.input instanceof EditorInput && !(<EditorInput>editorToSplit.input).supportsSplitEditor()) {
A
Alex Dima 已提交
55
			return TPromise.as(true);
E
Erich Gamma 已提交
56 57
		}

58 59
		// Options
		let options: EditorOptions;
S
Sandeep Somavarapu 已提交
60 61
		const codeEditor = getCodeEditor(editorToSplit);
		if (codeEditor) {
62
			options = new TextEditorOptions();
S
Sandeep Somavarapu 已提交
63
			(<TextEditorOptions>options).fromEditor(codeEditor);
64 65 66 67 68
		} else {
			options = new EditorOptions();
		}
		options.pinned = true;

E
Erich Gamma 已提交
69
		// Count editors
70 71
		const visibleEditors = this.editorService.getVisibleEditors();
		const editorCount = visibleEditors.length;
E
Erich Gamma 已提交
72 73 74 75
		let targetPosition: Position;

		switch (editorCount) {

B
Benjamin Pasero 已提交
76
			// Open split editor to the right/bottom of left/top one
E
Erich Gamma 已提交
77
			case 1:
78
				targetPosition = Position.TWO;
E
Erich Gamma 已提交
79 80 81 82 83
				break;

			// Special case two editors opened
			case 2:

B
Benjamin Pasero 已提交
84
				// Continue splitting to the right/bottom
85 86
				if (editorToSplit.position === Position.TWO) {
					targetPosition = Position.THREE;
E
Erich Gamma 已提交
87 88
				}

89
				// Push the second group to the right/bottom to make room for the splitted input
90
				else if (editorToSplit.position === Position.ONE) {
E
Erich Gamma 已提交
91 92
					options.preserveFocus = true;

93 94 95
					return this.editorService.openEditor(editorToSplit.input, options, Position.THREE).then(() => {
						this.editorGroupService.moveGroup(Position.THREE, Position.TWO);
						this.editorGroupService.focusGroup(Position.TWO);
E
Erich Gamma 已提交
96 97 98 99
					});
				}
		}

100 101
		// Only split if we have a target position to split to
		if (typeof targetPosition === 'number') {
102
			return this.editorService.openEditor(editorToSplit.input, options, targetPosition);
E
Erich Gamma 已提交
103 104
		}

A
Alex Dima 已提交
105
		return TPromise.as(true);
E
Erich Gamma 已提交
106 107 108
	}
}

B
Benjamin Pasero 已提交
109
export class NavigateBetweenGroupsAction extends Action {
110

B
Benjamin Pasero 已提交
111 112
	public static ID = 'workbench.action.navigateEditorGroups';
	public static LABEL = nls.localize('navigateEditorGroups', "Navigate Between Editor Groups");
E
Erich Gamma 已提交
113

114 115 116 117 118 119
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private editorGroupService: IEditorGroupService
	) {
E
Erich Gamma 已提交
120 121 122
		super(id, label);
	}

123
	public run(): TPromise<any> {
E
Erich Gamma 已提交
124 125

		// Can cycle split with active editor
126
		const activeEditor = this.editorService.getActiveEditor();
E
Erich Gamma 已提交
127
		if (!activeEditor) {
A
Alex Dima 已提交
128
			return TPromise.as(false);
E
Erich Gamma 已提交
129 130
		}

B
Benjamin Pasero 已提交
131
		// Cycle to the left/top and use module to start at 0 again
132 133 134
		const visibleEditors = this.editorService.getVisibleEditors();
		const editorCount = visibleEditors.length;
		const newIndex = (activeEditor.position + 1) % editorCount;
E
Erich Gamma 已提交
135

136
		this.editorGroupService.focusGroup(<Position>newIndex);
137 138

		return TPromise.as(true);
E
Erich Gamma 已提交
139 140 141
	}
}

142 143 144 145 146 147 148 149 150 151 152 153 154 155
export class FocusActiveGroupAction extends Action {

	public static ID = 'workbench.action.focusActiveEditorGroup';
	public static LABEL = nls.localize('focusActiveEditorGroup', "Focus Active Editor Group");

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
B
hygiene  
Benjamin Pasero 已提交
156 157
		const activeEditor = this.editorService.getActiveEditor();
		if (activeEditor) {
D
Daniel Imms 已提交
158
			activeEditor.focus();
B
hygiene  
Benjamin Pasero 已提交
159
		}
D
Daniel Imms 已提交
160

161
		return TPromise.as(true);
E
Erich Gamma 已提交
162 163 164
	}
}

165 166
export class FocusFirstGroupAction extends Action {

B
Benjamin Pasero 已提交
167
	public static ID = 'workbench.action.focusFirstEditorGroup';
168
	public static LABEL = nls.localize('focusFirstEditorGroup', "Focus First Editor Group");
E
Erich Gamma 已提交
169 170 171 172 173

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
174
		@IEditorGroupService private editorGroupService: IEditorGroupService,
175
		@IHistoryService private historyService: IHistoryService
E
Erich Gamma 已提交
176 177 178 179
	) {
		super(id, label);
	}

180
	public run(): TPromise<any> {
E
Erich Gamma 已提交
181

B
Benjamin Pasero 已提交
182
		// Find left/top editor and focus it
183
		const editors = this.editorService.getVisibleEditors();
B
Benjamin Pasero 已提交
184
		for (let editor of editors) {
185 186
			if (editor.position === Position.ONE) {
				this.editorGroupService.focusGroup(Position.ONE);
187 188

				return TPromise.as(true);
E
Erich Gamma 已提交
189 190 191 192
			}
		}

		// Since no editor is currently opened, try to open last history entry to the target side
193
		const history = this.historyService.getHistory();
B
Benjamin Pasero 已提交
194
		for (let input of history) {
E
Erich Gamma 已提交
195

196 197
			// For now only support to open files from history to the side
			if (input instanceof EditorInput) {
198
				if (hasResource(input, { filter: ['file', 'untitled'] })) {
199
					return this.editorService.openEditor(input, null, Position.ONE);
200 201
				}
			} else {
202
				return this.editorService.openEditor(input as IResourceInput, Position.ONE);
E
Erich Gamma 已提交
203 204 205
			}
		}

A
Alex Dima 已提交
206
		return TPromise.as(true);
E
Erich Gamma 已提交
207 208 209
	}
}

210
export abstract class BaseFocusSideGroupAction extends Action {
E
Erich Gamma 已提交
211 212 213 214 215

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
216
		@IEditorGroupService private editorGroupService: IEditorGroupService,
217
		@IHistoryService private historyService: IHistoryService
E
Erich Gamma 已提交
218 219 220 221 222 223 224 225
	) {
		super(id, label);
	}

	protected abstract getReferenceEditorSide(): Position;

	protected abstract getTargetEditorSide(): Position;

226
	public run(): TPromise<any> {
E
Erich Gamma 已提交
227 228

		// Require at least the reference editor to be visible
229
		const editors = this.editorService.getVisibleEditors();
E
Erich Gamma 已提交
230 231
		let referenceEditor: IEditor;
		for (let i = 0; i < editors.length; i++) {
232
			const editor = editors[i];
E
Erich Gamma 已提交
233 234 235

			// Target editor exists so focus it
			if (editor.position === this.getTargetEditorSide()) {
236
				this.editorGroupService.focusGroup(editor.position);
237 238

				return TPromise.as(true);
E
Erich Gamma 已提交
239 240 241 242 243 244 245 246 247
			}

			// Remember reference editor
			if (editor.position === this.getReferenceEditorSide()) {
				referenceEditor = editor;
			}
		}

		// Require the reference editor to be visible and supporting split editor
248
		if (referenceEditor && (<EditorInput>referenceEditor.input).supportsSplitEditor()) {
249 250 251

			// Options
			let options: EditorOptions;
S
Sandeep Somavarapu 已提交
252 253
			const codeEditor = getCodeEditor(referenceEditor);
			if (codeEditor) {
254
				options = new TextEditorOptions();
255
				options.pinned = true;
S
Sandeep Somavarapu 已提交
256
				(<TextEditorOptions>options).fromEditor(codeEditor);
257 258
			} else {
				options = EditorOptions.create({ pinned: true });
259 260 261
			}

			return this.editorService.openEditor(referenceEditor.input, options, this.getTargetEditorSide());
E
Erich Gamma 已提交
262 263 264 265
		}

		// Otherwise try to find a history entry to open to the target editor side
		else if (referenceEditor) {
266
			const history = this.historyService.getHistory();
B
Benjamin Pasero 已提交
267
			for (let input of history) {
E
Erich Gamma 已提交
268 269

				// For now only support to open files from history to the side
270
				if (input instanceof EditorInput) {
271
					if (hasResource(input, { filter: ['file', 'untitled'] })) {
272 273 274 275
						return this.editorService.openEditor(input, { pinned: true }, this.getTargetEditorSide());
					}
				} else {
					return this.editorService.openEditor({ resource: (input as IResourceInput).resource, options: { pinned: true } }, this.getTargetEditorSide());
E
Erich Gamma 已提交
276 277 278 279
				}
			}
		}

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

284 285
export class FocusSecondGroupAction extends BaseFocusSideGroupAction {

B
Benjamin Pasero 已提交
286
	public static ID = 'workbench.action.focusSecondEditorGroup';
287
	public static LABEL = nls.localize('focusSecondEditorGroup', "Focus Second Editor Group");
E
Erich Gamma 已提交
288 289 290 291 292

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService,
293
		@IEditorGroupService editorGroupService: IEditorGroupService,
294
		@IHistoryService historyService: IHistoryService
E
Erich Gamma 已提交
295
	) {
296
		super(id, label, editorService, editorGroupService, historyService);
E
Erich Gamma 已提交
297 298 299
	}

	protected getReferenceEditorSide(): Position {
300
		return Position.ONE;
E
Erich Gamma 已提交
301 302 303
	}

	protected getTargetEditorSide(): Position {
304
		return Position.TWO;
E
Erich Gamma 已提交
305 306 307
	}
}

308 309
export class FocusThirdGroupAction extends BaseFocusSideGroupAction {

B
Benjamin Pasero 已提交
310
	public static ID = 'workbench.action.focusThirdEditorGroup';
311
	public static LABEL = nls.localize('focusThirdEditorGroup', "Focus Third Editor Group");
E
Erich Gamma 已提交
312 313 314 315 316

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService,
317
		@IEditorGroupService editorGroupService: IEditorGroupService,
318
		@IHistoryService historyService: IHistoryService
E
Erich Gamma 已提交
319
	) {
320
		super(id, label, editorService, editorGroupService, historyService);
E
Erich Gamma 已提交
321 322 323
	}

	protected getReferenceEditorSide(): Position {
324
		return Position.TWO;
E
Erich Gamma 已提交
325 326 327
	}

	protected getTargetEditorSide(): Position {
328
		return Position.THREE;
E
Erich Gamma 已提交
329 330 331
	}
}

B
Benjamin Pasero 已提交
332
export class FocusPreviousGroup extends Action {
333

B
Benjamin Pasero 已提交
334 335
	public static ID = 'workbench.action.focusPreviousGroup';
	public static LABEL = nls.localize('focusPreviousGroup', "Focus Previous Group");
E
Erich Gamma 已提交
336

337 338 339 340 341 342
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
343 344 345
		super(id, label);
	}

346
	public run(): TPromise<any> {
E
Erich Gamma 已提交
347 348

		// Require an active editor
349
		const activeEditor = this.editorService.getActiveEditor();
E
Erich Gamma 已提交
350
		if (!activeEditor) {
A
Alex Dima 已提交
351
			return TPromise.as(true);
E
Erich Gamma 已提交
352 353 354
		}


B
Benjamin Pasero 已提交
355
		// Find the next position to the left/top
356 357 358
		let nextPosition: Position = Position.ONE;
		if (activeEditor.position === Position.THREE) {
			nextPosition = Position.TWO;
359 360 361 362
		} else if (activeEditor.position === Position.ONE) {
			// Get the last active position
			const lastPosition = this.editorGroupService.getStacksModel().groups.length - 1;
			nextPosition = lastPosition;
E
Erich Gamma 已提交
363 364 365
		}

		// Focus next position if provided
366
		this.editorGroupService.focusGroup(nextPosition);
367 368

		return TPromise.as(true);
E
Erich Gamma 已提交
369 370 371
	}
}

B
Benjamin Pasero 已提交
372
export class FocusNextGroup extends Action {
373

B
Benjamin Pasero 已提交
374 375
	public static ID = 'workbench.action.focusNextGroup';
	public static LABEL = nls.localize('focusNextGroup', "Focus Next Group");
376

E
Erich Gamma 已提交
377 378 379 380 381 382 383 384 385 386 387
	private navigateActions: Action[];

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IInstantiationService instantiationService: IInstantiationService
	) {
		super(id, label);

		this.navigateActions = [];
388 389 390
		this.navigateActions[Position.ONE] = instantiationService.createInstance(FocusFirstGroupAction, FocusFirstGroupAction.ID, FocusFirstGroupAction.LABEL);
		this.navigateActions[Position.TWO] = instantiationService.createInstance(FocusSecondGroupAction, FocusSecondGroupAction.ID, FocusSecondGroupAction.LABEL);
		this.navigateActions[Position.THREE] = instantiationService.createInstance(FocusThirdGroupAction, FocusThirdGroupAction.ID, FocusThirdGroupAction.LABEL);
E
Erich Gamma 已提交
391 392
	}

393
	public run(event?: any): TPromise<any> {
E
Erich Gamma 已提交
394

B
Benjamin Pasero 已提交
395
		// Find the next position to the right/bottom to use
E
Erich Gamma 已提交
396
		let nextPosition: Position;
397
		const activeEditor = this.editorService.getActiveEditor();
398 399 400

		const lastPosition = POSITIONS[POSITIONS.length - 1];
		if (!activeEditor || activeEditor.position === lastPosition) {
401 402 403 404 405
			nextPosition = Position.ONE;
		} else if (activeEditor.position === Position.ONE) {
			nextPosition = Position.TWO;
		} else if (activeEditor.position === Position.TWO) {
			nextPosition = Position.THREE;
E
Erich Gamma 已提交
406 407 408
		}

		// Run the action for the target next position
409
		if (typeof nextPosition === 'number' && this.navigateActions[nextPosition]) {
E
Erich Gamma 已提交
410 411 412
			return this.navigateActions[nextPosition].run(event);
		}

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

export class OpenToSideAction extends Action {

	public static OPEN_TO_SIDE_ID = 'workbench.action.openToSide';
	public static OPEN_TO_SIDE_LABEL = nls.localize('openToSide', "Open to the Side");

422 423
	constructor(
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
424
		@IEditorGroupService private editorGroupService: IEditorGroupService
425
	) {
E
Erich Gamma 已提交
426 427 428
		super(OpenToSideAction.OPEN_TO_SIDE_ID, OpenToSideAction.OPEN_TO_SIDE_LABEL);

		this.updateEnablement();
429 430 431 432
		this.updateClass();
	}

	public updateClass(): void {
433
		const editorGroupLayoutVertical = (this.editorGroupService.getGroupOrientation() !== 'horizontal');
434

435
		this.class = editorGroupLayoutVertical ? 'quick-open-sidebyside-vertical' : 'quick-open-sidebyside-horizontal';
E
Erich Gamma 已提交
436 437 438
	}

	private updateEnablement(): void {
439
		const activeEditor = this.editorService.getActiveEditor();
440
		this.enabled = (!activeEditor || activeEditor.position !== Position.THREE);
E
Erich Gamma 已提交
441 442
	}

443
	public run(context: any): TPromise<any> {
E
Erich Gamma 已提交
444 445
		let entry = toEditorQuickOpenEntry(context);
		if (entry) {
446
			const input = entry.getInput();
B
Benjamin Pasero 已提交
447
			if (input instanceof EditorInput) {
448
				return this.editorService.openEditor(input, entry.getOptions(), true);
B
Benjamin Pasero 已提交
449 450
			}

451 452 453 454
			const resourceInput = input as IResourceInput;
			resourceInput.options = mixin(resourceInput.options, entry.getOptions());

			return this.editorService.openEditor(resourceInput, true);
E
Erich Gamma 已提交
455 456
		}

A
Alex Dima 已提交
457
		return TPromise.as(false);
E
Erich Gamma 已提交
458 459 460
	}
}

461
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
462 463 464

	// QuickOpenEntryGroup
	if (element instanceof QuickOpenEntryGroup) {
465
		const group = <QuickOpenEntryGroup>element;
E
Erich Gamma 已提交
466 467 468 469 470 471 472 473 474 475 476 477 478 479
		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 {
480

B
Benjamin Pasero 已提交
481
	public static ID = 'workbench.action.closeActiveEditor';
482 483
	public static LABEL = nls.localize('closeEditor', "Close Editor");

484 485 486 487 488 489
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
I
isidor 已提交
490
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
491 492
	}

B
Benjamin Pasero 已提交
493
	public run(context?: IEditorContext): TPromise<any> {
494
		const position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
495

496
		// Close Active Editor
497
		if (typeof position !== 'number') {
498
			const activeEditor = this.editorService.getActiveEditor();
B
Benjamin Pasero 已提交
499
			if (activeEditor) {
500
				return this.editorService.closeEditor(activeEditor.position, activeEditor.input);
B
Benjamin Pasero 已提交
501
			}
502 503
		}

I
isidor 已提交
504
		let input = context ? context.editor : null;
I
isidor 已提交
505
		if (!input) {
B
Benjamin Pasero 已提交
506

I
isidor 已提交
507
			// Get Top Editor at Position
508
			const visibleEditors = this.editorService.getVisibleEditors();
I
isidor 已提交
509
			if (visibleEditors[position]) {
510
				input = visibleEditors[position].input;
I
isidor 已提交
511 512 513 514 515
			}
		}

		if (input) {
			return this.editorService.closeEditor(position, input);
E
Erich Gamma 已提交
516 517
		}

A
Alex Dima 已提交
518
		return TPromise.as(false);
E
Erich Gamma 已提交
519 520 521
	}
}

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

B
Benjamin Pasero 已提交
524 525
	public static ID = 'workbench.action.closeEditorsToTheLeft';
	public static LABEL = nls.localize('closeEditorsToTheLeft', "Close Editors to the Left");
526

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

B
Benjamin Pasero 已提交
536
	public run(context?: IEditorContext): TPromise<any> {
537
		const editor = getTarget(this.editorService, this.groupService, context);
B
Benjamin Pasero 已提交
538 539
		if (editor) {
			return this.editorService.closeEditors(editor.position, editor.input, Direction.LEFT);
540 541 542 543 544 545 546 547
		}

		return TPromise.as(false);
	}
}

export class CloseRightEditorsInGroupAction extends Action {

B
Benjamin Pasero 已提交
548 549
	public static ID = 'workbench.action.closeEditorsToTheRight';
	public static LABEL = nls.localize('closeEditorsToTheRight', "Close Editors to the Right");
550

B
Benjamin Pasero 已提交
551 552 553 554 555 556
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private groupService: IEditorGroupService
	) {
557 558 559
		super(id, label);
	}

B
Benjamin Pasero 已提交
560
	public run(context?: IEditorContext): TPromise<any> {
561
		const editor = getTarget(this.editorService, this.groupService, context);
B
Benjamin Pasero 已提交
562 563
		if (editor) {
			return this.editorService.closeEditors(editor.position, editor.input, Direction.RIGHT);
564 565 566 567 568 569
		}

		return TPromise.as(false);
	}
}

E
Erich Gamma 已提交
570 571
export class CloseAllEditorsAction extends Action {

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

575 576 577 578 579 580
	constructor(
		id: string,
		label: string,
		@ITextFileService private textFileService: ITextFileService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
I
isidor 已提交
581
		super(id, label, 'action-close-all-files');
E
Erich Gamma 已提交
582 583
	}

584
	public run(): TPromise<any> {
585 586 587 588 589 590 591 592 593 594 595 596 597 598

		// Just close all if there are no or one dirty editor
		if (this.textFileService.getDirty().length < 2) {
			return this.editorService.closeAllEditors();
		}

		// Otherwise ask for combined confirmation
		const confirm = this.textFileService.confirmSave();
		if (confirm === ConfirmResult.CANCEL) {
			return;
		}

		let saveOrRevertPromise: TPromise<boolean>;
		if (confirm === ConfirmResult.DONT_SAVE) {
599
			saveOrRevertPromise = this.textFileService.revertAll(null, { soft: true }).then(() => true);
600 601 602 603 604 605 606 607 608
		} else {
			saveOrRevertPromise = this.textFileService.saveAll(true).then(res => res.results.every(r => r.success));
		}

		return saveOrRevertPromise.then(success => {
			if (success) {
				return this.editorService.closeAllEditors();
			}
		});
E
Erich Gamma 已提交
609 610 611
	}
}

612 613 614 615 616
export class CloseEditorsInOtherGroupsAction extends Action {

	public static ID = 'workbench.action.closeEditorsInOtherGroups';
	public static LABEL = nls.localize('closeEditorsInOtherGroups', "Close Editors in Other Groups");

617 618 619 620 621 622
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
623 624 625
		super(id, label);
	}

B
Benjamin Pasero 已提交
626
	public run(context?: IEditorContext): TPromise<any> {
627
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
628
		if (typeof position !== 'number') {
629
			const activeEditor = this.editorService.getActiveEditor();
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
			if (activeEditor) {
				position = activeEditor.position;
			}
		}

		if (typeof position === 'number') {
			return this.editorService.closeAllEditors(position);
		}

		return TPromise.as(false);
	}
}

export class CloseOtherEditorsInGroupAction extends Action {

	public static ID = 'workbench.action.closeOtherEditors';
B
Benjamin Pasero 已提交
646
	public static LABEL = nls.localize('closeOtherEditorsInGroup', "Close Other Editors");
E
Erich Gamma 已提交
647

648 649 650 651 652 653
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
654 655 656
		super(id, label);
	}

B
Benjamin Pasero 已提交
657
	public run(context?: IEditorContext): TPromise<any> {
658
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
I
isidor 已提交
659
		let input = context ? context.editor : null;
I
isidor 已提交
660 661

		// If position or input are not passed in take the position and input of the active editor.
662 663
		const active = this.editorService.getActiveEditor();
		if (active) {
I
isidor 已提交
664
			position = typeof position === 'number' ? position : active.position;
665
			input = input ? input : <EditorInput>active.input;
I
isidor 已提交
666 667 668 669
		}

		if (typeof position === 'number' && input) {
			return this.editorService.closeEditors(position, input);
670 671 672
		}

		return TPromise.as(false);
E
Erich Gamma 已提交
673 674 675
	}
}

B
Benjamin Pasero 已提交
676
export class CloseEditorsInGroupAction extends Action {
I
isidor 已提交
677

B
Benjamin Pasero 已提交
678 679
	public static ID = 'workbench.action.closeEditorsInGroup';
	public static LABEL = nls.localize('closeEditorsInGroup', "Close All Editors in Group");
I
isidor 已提交
680

681 682 683 684 685 686
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
B
Benjamin Pasero 已提交
687
		super(id, label);
I
isidor 已提交
688 689
	}

B
Benjamin Pasero 已提交
690
	public run(context?: IEditorContext): TPromise<any> {
691
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
I
isidor 已提交
692
		if (typeof position !== 'number') {
693
			const activeEditor = this.editorService.getActiveEditor();
I
isidor 已提交
694 695 696 697 698 699 700 701
			if (activeEditor) {
				position = activeEditor.position;
			}
		}

		if (typeof position === 'number') {
			return this.editorService.closeEditors(position);
		}
B
Benjamin Pasero 已提交
702 703

		return TPromise.as(false);
I
isidor 已提交
704 705 706
	}
}

B
Benjamin Pasero 已提交
707
export class MoveGroupLeftAction extends Action {
E
Erich Gamma 已提交
708

B
Benjamin Pasero 已提交
709
	public static ID = 'workbench.action.moveActiveEditorGroupLeft';
710 711
	public static LABEL = nls.localize('moveActiveGroupLeft', "Move Editor Group Left");

712 713 714 715 716 717
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
718 719 720
		super(id, label);
	}

B
Benjamin Pasero 已提交
721
	public run(context?: IEditorContext): TPromise<any> {
722
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
723
		if (typeof position !== 'number') {
724
			const activeEditor = this.editorService.getActiveEditor();
725
			if (activeEditor && (activeEditor.position === Position.TWO || activeEditor.position === Position.THREE)) {
726 727 728 729 730
				position = activeEditor.position;
			}
		}

		if (typeof position === 'number') {
731
			const newPosition = (position === Position.TWO) ? Position.ONE : Position.TWO;
E
Erich Gamma 已提交
732

B
Benjamin Pasero 已提交
733
			// Move group
734
			this.editorGroupService.moveGroup(position, newPosition);
E
Erich Gamma 已提交
735 736
		}

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

B
Benjamin Pasero 已提交
741
export class MoveGroupRightAction extends Action {
E
Erich Gamma 已提交
742

B
Benjamin Pasero 已提交
743
	public static ID = 'workbench.action.moveActiveEditorGroupRight';
744 745
	public static LABEL = nls.localize('moveActiveGroupRight', "Move Editor Group Right");

746 747 748 749 750 751
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
752 753 754
		super(id, label);
	}

B
Benjamin Pasero 已提交
755
	public run(context?: IEditorContext): TPromise<any> {
756
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
757
		if (typeof position !== 'number') {
758 759
			const activeEditor = this.editorService.getActiveEditor();
			const editors = this.editorService.getVisibleEditors();
760

761
			if ((editors.length === 2 && activeEditor.position === Position.ONE) || (editors.length === 3 && activeEditor.position !== Position.THREE)) {
762 763 764 765 766
				position = activeEditor.position;
			}
		}

		if (typeof position === 'number') {
767
			const newPosition = (position === Position.ONE) ? Position.TWO : Position.THREE;
E
Erich Gamma 已提交
768

B
Benjamin Pasero 已提交
769
			// Move group
770
			this.editorGroupService.moveGroup(position, newPosition);
E
Erich Gamma 已提交
771 772
		}

A
Alex Dima 已提交
773
		return TPromise.as(false);
E
Erich Gamma 已提交
774 775 776
	}
}

777
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
778

779 780 781
	public static ID = 'workbench.action.minimizeOtherEditors';
	public static LABEL = nls.localize('minimizeOtherEditorGroups', "Minimize Other Editor Groups");

782
	constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
E
Erich Gamma 已提交
783 784 785
		super(id, label);
	}

786
	public run(): TPromise<any> {
787
		this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
788

A
Alex Dima 已提交
789
		return TPromise.as(false);
E
Erich Gamma 已提交
790 791 792
	}
}

793
export class EvenGroupWidthsAction extends Action {
E
Erich Gamma 已提交
794

795 796 797
	public static ID = 'workbench.action.evenEditorWidths';
	public static LABEL = nls.localize('evenEditorGroups', "Even Editor Group Widths");

798
	constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
E
Erich Gamma 已提交
799 800 801
		super(id, label);
	}

802
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
803
		this.editorGroupService.arrangeGroups(GroupArrangement.EVEN);
E
Erich Gamma 已提交
804

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

809
export class MaximizeGroupAction extends Action {
810

811 812 813
	public static ID = 'workbench.action.maximizeEditor';
	public static LABEL = nls.localize('maximizeEditor', "Maximize Editor Group and Hide Sidebar");

814 815 816 817
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
818
		@IEditorGroupService private editorGroupService: IEditorGroupService,
819 820 821 822 823
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

824
	public run(): TPromise<any> {
825
		if (this.editorService.getActiveEditor()) {
826
			this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
827
			return this.partService.setSideBarHidden(true);
828 829
		}

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

B
Benjamin Pasero 已提交
834
export class KeepEditorAction extends Action {
835

B
Benjamin Pasero 已提交
836 837
	public static ID = 'workbench.action.keepEditor';
	public static LABEL = nls.localize('keepEditor', "Keep Editor");
838 839 840 841

	constructor(
		id: string,
		label: string,
842
		@IEditorGroupService private editorGroupService: IEditorGroupService,
843 844 845 846 847
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
848
	public run(context?: IEditorContext): TPromise<any> {
849
		const target = getTarget(this.editorService, this.editorGroupService, context);
B
Benjamin Pasero 已提交
850 851
		if (target) {
			this.editorGroupService.pinEditor(target.position, target.input);
852 853 854 855 856 857
		}

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
858 859 860 861 862 863 864 865 866 867 868 869 870
function getTarget(editorService: IWorkbenchEditorService, editorGroupService: IEditorGroupService, context?: IEditorContext): { input: IEditorInput, position: Position } {
	if (context) {
		return { input: context.editor, position: editorGroupService.getStacksModel().positionOfGroup(context.group) };
	}

	const activeEditor = editorService.getActiveEditor();
	if (activeEditor) {
		return { input: activeEditor.input, position: activeEditor.position };
	}

	return null;
}

871 872
export abstract class BaseNavigateEditorAction extends Action {

873 874 875 876 877 878
	constructor(
		id: string,
		label: string,
		protected editorGroupService: IEditorGroupService,
		protected editorService: IWorkbenchEditorService
	) {
879 880 881 882
		super(id, label);
	}

	public run(): TPromise<any> {
883
		const model = this.editorGroupService.getStacksModel();
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
		const result = this.navigate();
		if (result) {
			return this.editorService.openEditor(result.editor, null, model.positionOfGroup(result.group));
		}

		return TPromise.as(false);
	}

	protected abstract navigate(): IEditorIdentifier;
}

export class OpenNextEditor extends BaseNavigateEditorAction {

	public static ID = 'workbench.action.nextEditor';
	public static LABEL = nls.localize('openNextEditor', "Open Next Editor");

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

	protected navigate(): IEditorIdentifier {
910
		return this.editorGroupService.getStacksModel().next(true /* jump groups */);
911 912 913 914 915 916 917 918
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

	public static ID = 'workbench.action.previousEditor';
	public static LABEL = nls.localize('openPreviousEditor', "Open Previous Editor");

919 920 921 922 923 924 925
	constructor(
		id: string,
		label: string,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, editorGroupService, editorService);
926 927 928
	}

	protected navigate(): IEditorIdentifier {
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
		return this.editorGroupService.getStacksModel().previous(true /* jump groups */);
	}
}

export class OpenNextEditorInGroup extends BaseNavigateEditorAction {

	public static ID = 'workbench.action.nextEditorInGroup';
	public static LABEL = nls.localize('nextEditorInGroup', "Open Next Editor in Group");

	constructor(
		id: string,
		label: string,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
		return this.editorGroupService.getStacksModel().next(false /* do NOT jump groups */);
	}
}

export class OpenPreviousEditorInGroup extends BaseNavigateEditorAction {

	public static ID = 'workbench.action.previousEditorInGroup';
	public static LABEL = nls.localize('openPreviousEditorInGroup', "Open Previous Editor in Group");

	constructor(
		id: string,
		label: string,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, editorGroupService, editorService);
	}

	protected navigate(): IEditorIdentifier {
		return this.editorGroupService.getStacksModel().previous(false /* do NOT jump groups */);
968
	}
B
Benjamin Pasero 已提交
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
}

export class NavigateForwardAction extends Action {

	public static ID = 'workbench.action.navigateForward';
	public static LABEL = nls.localize('navigateNext', "Go Forward");

	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 {

	public static ID = 'workbench.action.navigateBack';
	public static LABEL = nls.localize('navigatePrevious', "Go Back");

	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 已提交
1001
}
1002 1003 1004 1005 1006 1007 1008 1009 1010

export class ReopenClosedEditorAction extends Action {

	public static ID = 'workbench.action.reopenClosedEditor';
	public static LABEL = nls.localize('reopenClosedEditor', "Reopen Closed Editor");

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

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

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
1021 1022
}

1023
export const NAVIGATE_IN_GROUP_ONE_PREFIX = 'edt one ';
B
Benjamin Pasero 已提交
1024

1025
export class ShowEditorsInGroupOneAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
1026

1027 1028
	public static ID = 'workbench.action.showEditorsInFirstGroup';
	public static LABEL = nls.localize('showEditorsInFirstGroup', "Show Editors in First Group");
B
Benjamin Pasero 已提交
1029

1030 1031 1032
	constructor(
		actionId: string,
		actionLabel: string,
1033
		@IQuickOpenService quickOpenService: IQuickOpenService
1034
	) {
1035
		super(actionId, actionLabel, NAVIGATE_IN_GROUP_ONE_PREFIX, quickOpenService);
1036 1037

		this.class = 'show-group-editors-action';
B
Benjamin Pasero 已提交
1038
	}
1039
}
1040

1041
export const NAVIGATE_IN_GROUP_TWO_PREFIX = 'edt two ';
1042

1043
export class ShowEditorsInGroupTwoAction extends QuickOpenAction {
1044

1045 1046
	public static ID = 'workbench.action.showEditorsInSecondGroup';
	public static LABEL = nls.localize('showEditorsInSecondGroup', "Show Editors in Second Group");
1047 1048 1049 1050

	constructor(
		actionId: string,
		actionLabel: string,
1051
		@IQuickOpenService quickOpenService: IQuickOpenService
1052
	) {
1053
		super(actionId, actionLabel, NAVIGATE_IN_GROUP_TWO_PREFIX, quickOpenService);
1054 1055

		this.class = 'show-group-editors-action';
1056 1057
	}
}
1058

1059
export const NAVIGATE_IN_GROUP_THREE_PREFIX = 'edt three ';
1060

1061
export class ShowEditorsInGroupThreeAction extends QuickOpenAction {
1062

1063 1064
	public static ID = 'workbench.action.showEditorsInThirdGroup';
	public static LABEL = nls.localize('showEditorsInThirdGroup', "Show Editors in Third Group");
1065 1066 1067 1068

	constructor(
		actionId: string,
		actionLabel: string,
1069
		@IQuickOpenService quickOpenService: IQuickOpenService
1070
	) {
1071
		super(actionId, actionLabel, NAVIGATE_IN_GROUP_THREE_PREFIX, quickOpenService);
1072 1073

		this.class = 'show-group-editors-action';
1074
	}
B
Benjamin Pasero 已提交
1075 1076
}

B
Benjamin Pasero 已提交
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
export class ShowEditorsInGroupAction extends Action {

	public static ID = 'workbench.action.showEditorsInGroup';
	public static LABEL = nls.localize('showEditorsInGroup', "Show Editors in Group");

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

	public run(context?: IEditorContext): TPromise<any> {
		const stacks = this.editorGroupService.getStacksModel();
		const groupCount = stacks.groups.length;
		if (groupCount <= 1 || !context) {
			return this.quickOpenService.show(NAVIGATE_ALL_EDITORS_GROUP_PREFIX);
		}

		switch (stacks.positionOfGroup(context.group)) {
1099
			case Position.TWO:
B
Benjamin Pasero 已提交
1100
				return this.quickOpenService.show(NAVIGATE_IN_GROUP_TWO_PREFIX);
1101
			case Position.THREE:
1102
				return this.quickOpenService.show(NAVIGATE_IN_GROUP_THREE_PREFIX);
B
Benjamin Pasero 已提交
1103 1104
		}

1105
		return this.quickOpenService.show(NAVIGATE_IN_GROUP_ONE_PREFIX);
B
Benjamin Pasero 已提交
1106 1107 1108
	}
}

1109
export const NAVIGATE_ALL_EDITORS_GROUP_PREFIX = 'edt ';
B
Benjamin Pasero 已提交
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120

export class ShowAllEditorsAction extends QuickOpenAction {

	public static ID = 'workbench.action.showAllEditors';
	public static LABEL = nls.localize('showAllEditors', "Show All Editors");

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

1121
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1122 1123 1124 1125 1126

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
1127
		@IKeybindingService private keybindingService: IKeybindingService,
1128
		@IEditorGroupService private editorGroupService: IEditorGroupService
B
Benjamin Pasero 已提交
1129 1130 1131 1132 1133
	) {
		super(id, label);
	}

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

1136
		const stacks = this.editorGroupService.getStacksModel();
1137 1138
		if (stacks.activeGroup) {
			const activePosition = stacks.positionOfGroup(stacks.activeGroup);
1139
			let prefix = NAVIGATE_IN_GROUP_ONE_PREFIX;
1140

B
Benjamin Pasero 已提交
1141
			if (activePosition === Position.TWO) {
1142
				prefix = NAVIGATE_IN_GROUP_TWO_PREFIX;
B
Benjamin Pasero 已提交
1143
			} else if (activePosition === Position.THREE) {
1144
				prefix = NAVIGATE_IN_GROUP_THREE_PREFIX;
1145 1146
			}

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

		return TPromise.as(true);
	}
}

1154 1155 1156
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

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

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IKeybindingService keybindingService: IKeybindingService,
1164
		@IEditorGroupService editorGroupService: IEditorGroupService
1165
	) {
1166
		super(id, label, quickOpenService, keybindingService, editorGroupService);
1167 1168 1169 1170 1171 1172
	}
}

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

	public static ID = 'workbench.action.openNextRecentlyUsedEditorInGroup';
1173
	public static LABEL = nls.localize('openNextRecentlyUsedEditorInGroup', "Open Next Recently Used Editor in Group");
1174 1175 1176 1177 1178 1179

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IKeybindingService keybindingService: IKeybindingService,
1180
		@IEditorGroupService editorGroupService: IEditorGroupService
1181
	) {
1182
		super(id, label, quickOpenService, keybindingService, editorGroupService);
1183 1184 1185
	}
}

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

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

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

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

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

		return TPromise.as(true);
	}
}

1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
export class ClearEditorHistoryAction extends Action {

	public static ID = 'workbench.action.clearEditorHistory';
	public static LABEL = nls.localize('clearEditorHistory', "Clear Editor History");

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

	public run(): TPromise<any> {

1224
		// Editor history
1225 1226 1227 1228 1229 1230
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
export class FocusLastEditorInStackAction extends Action {

	public static ID = 'workbench.action.openLastEditorInGroup';
	public static LABEL = nls.localize('focusLastEditorInStack', "Open Last Editor in Group");

	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const active = this.editorService.getActiveEditor();
		if (active) {
			const group = this.editorGroupService.getStacksModel().groupAt(active.position);
			const editor = group.getEditor(group.count - 1);

			if (editor) {
				return this.editorService.openEditor(editor);
			}
		}

1256 1257 1258 1259
		return TPromise.as(true);
	}
}

1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
export class MoveEditorLeftInGroupAction extends Action {

	public static ID = 'workbench.action.moveEditorLeftInGroup';
	public static LABEL = nls.localize('moveEditorLeft', "Move Editor Left");

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

	public run(): TPromise<any> {
		const args: ActiveEditorMoveArguments = {
1275
			to: ActiveEditorMovePositioning.LEFT
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
		};
		this.commandService.executeCommand(EditorCommands.MoveActiveEditor, args);

		return TPromise.as(true);
	}
}

export class MoveEditorRightInGroupAction extends Action {

	public static ID = 'workbench.action.moveEditorRightInGroup';
	public static LABEL = nls.localize('moveEditorRight', "Move Editor Right");

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

	public run(): TPromise<any> {
		const args: ActiveEditorMoveArguments = {
1298
			to: ActiveEditorMovePositioning.RIGHT
1299 1300 1301 1302 1303 1304 1305
		};
		this.commandService.executeCommand(EditorCommands.MoveActiveEditor, args);

		return TPromise.as(true);
	}
}

1306
export class MoveEditorToPreviousGroupAction extends Action {
1307

1308 1309
	public static ID = 'workbench.action.moveEditorToPreviousGroup';
	public static LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321

	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const activeEditor = this.editorService.getActiveEditor();
1322
		if (activeEditor && activeEditor.position !== Position.ONE) {
1323 1324 1325 1326 1327 1328 1329
			this.editorGroupService.moveEditor(activeEditor.input, activeEditor.position, activeEditor.position - 1);
		}

		return TPromise.as(true);
	}
}

1330
export class MoveEditorToNextGroupAction extends Action {
1331

1332 1333
	public static ID = 'workbench.action.moveEditorToNextGroup';
	public static LABEL = nls.localize('moveEditorToNextGroup', "Move Editor into Next Group");
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345

	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		const activeEditor = this.editorService.getActiveEditor();
1346
		if (activeEditor && activeEditor.position !== Position.THREE) {
1347 1348 1349
			this.editorGroupService.moveEditor(activeEditor.input, activeEditor.position, activeEditor.position + 1);
		}

1350 1351
		return TPromise.as(true);
	}
D
Daniel Imms 已提交
1352
}