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

7
import {TPromise} from 'vs/base/common/winjs.base';
E
Erich Gamma 已提交
8
import nls = require('vs/nls');
9
import {Action} from 'vs/base/common/actions';
10
import {EditorInput, getUntitledOrFileResource, TextEditorOptions, EditorOptions, IEditorIdentifier, IEditorContext, ActiveEditorMoveArguments, ActiveEditorMovePositioning, EditorCommands} from 'vs/workbench/common/editor';
E
Erich Gamma 已提交
11
import {QuickOpenEntryGroup} from 'vs/base/parts/quickopen/browser/quickOpenModel';
B
Benjamin Pasero 已提交
12
import {EditorQuickOpenEntry, EditorQuickOpenEntryGroup, IEditorQuickOpenEntry, QuickOpenAction} from 'vs/workbench/browser/quickopen';
13
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
14
import {IQuickOpenService, IPickOpenEntry} from 'vs/workbench/services/quickopen/common/quickOpenService';
15
import {IPartService} from 'vs/workbench/services/part/common/partService';
B
Benjamin Pasero 已提交
16
import {Position, IEditor, Direction, IResourceInput, IEditorInput} from 'vs/platform/editor/common/editor';
E
Erich Gamma 已提交
17
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
B
Benjamin Pasero 已提交
18
import {IHistoryService} from 'vs/workbench/services/history/common/history';
19
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
20
import {IEditorGroupService, GroupArrangement} from 'vs/workbench/services/group/common/groupService';
21
import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor';
22
import {ICommandService} from 'vs/platform/commands/common/commands';
E
Erich Gamma 已提交
23 24 25

export class SplitEditorAction extends Action {

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

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

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

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

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

56 57
		// Options
		let options: EditorOptions;
58
		if (editorToSplit instanceof BaseTextEditor) {
59
			options = new TextEditorOptions();
60
			(<TextEditorOptions>options).fromEditor(editorToSplit.getControl());
61 62 63 64 65
		} else {
			options = new EditorOptions();
		}
		options.pinned = true;

E
Erich Gamma 已提交
66
		// Count editors
67 68
		const visibleEditors = this.editorService.getVisibleEditors();
		const editorCount = visibleEditors.length;
E
Erich Gamma 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81
		let targetPosition: Position;

		switch (editorCount) {

			// Open split editor to the right of left one
			case 1:
				targetPosition = Position.CENTER;
				break;

			// Special case two editors opened
			case 2:

				// Continue splitting to the right
82
				if (editorToSplit.position === Position.CENTER) {
E
Erich Gamma 已提交
83 84 85
					targetPosition = Position.RIGHT;
				}

86
				// Push the center group to the right to make room for the splitted input
87
				else if (editorToSplit.position === Position.LEFT) {
E
Erich Gamma 已提交
88 89
					options.preserveFocus = true;

90
					return this.editorService.openEditor(editorToSplit.input, options, Position.RIGHT).then(() => {
91 92
						this.editorGroupService.moveGroup(Position.RIGHT, Position.CENTER);
						this.editorGroupService.focusGroup(Position.CENTER);
E
Erich Gamma 已提交
93 94 95 96
					});
				}
		}

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

A
Alex Dima 已提交
102
		return TPromise.as(true);
E
Erich Gamma 已提交
103 104 105
	}
}

B
Benjamin Pasero 已提交
106
export class NavigateBetweenGroupsAction extends Action {
107

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

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

120
	public run(): TPromise<any> {
E
Erich Gamma 已提交
121 122

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

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

133
		this.editorGroupService.focusGroup(<Position>newIndex);
134 135

		return TPromise.as(true);
E
Erich Gamma 已提交
136 137 138
	}
}

139 140 141 142 143 144 145 146 147 148 149 150 151 152
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> {
D
Daniel Imms 已提交
153 154 155 156 157
 		const activeEditor = this.editorService.getActiveEditor();
 		if (activeEditor) {
			activeEditor.focus();
 		}

158
		return TPromise.as(true);
E
Erich Gamma 已提交
159 160 161
	}
}

162 163
export class FocusFirstGroupAction extends Action {

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

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

177
	public run(): TPromise<any> {
E
Erich Gamma 已提交
178 179

		// Find left editor and focus it
180
		const editors = this.editorService.getVisibleEditors();
B
Benjamin Pasero 已提交
181
		for (let editor of editors) {
E
Erich Gamma 已提交
182
			if (editor.position === Position.LEFT) {
183
				this.editorGroupService.focusGroup(Position.LEFT);
184 185

				return TPromise.as(true);
E
Erich Gamma 已提交
186 187 188 189
			}
		}

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

			// For now only support to open resources from history to the side
			if (!!getUntitledOrFileResource(input)) {
195
				return this.editorService.openEditor(input, null, Position.LEFT);
E
Erich Gamma 已提交
196 197 198
			}
		}

A
Alex Dima 已提交
199
		return TPromise.as(true);
E
Erich Gamma 已提交
200 201 202
	}
}

203
export abstract class BaseFocusSideGroupAction extends Action {
E
Erich Gamma 已提交
204 205 206 207 208

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
209
		@IEditorGroupService private editorGroupService: IEditorGroupService,
210
		@IHistoryService private historyService: IHistoryService
E
Erich Gamma 已提交
211 212 213 214 215 216 217 218
	) {
		super(id, label);
	}

	protected abstract getReferenceEditorSide(): Position;

	protected abstract getTargetEditorSide(): Position;

219
	public run(): TPromise<any> {
E
Erich Gamma 已提交
220 221

		// Require at least the reference editor to be visible
222
		const editors = this.editorService.getVisibleEditors();
E
Erich Gamma 已提交
223 224
		let referenceEditor: IEditor;
		for (let i = 0; i < editors.length; i++) {
225
			const editor = editors[i];
E
Erich Gamma 已提交
226 227 228

			// Target editor exists so focus it
			if (editor.position === this.getTargetEditorSide()) {
229
				this.editorGroupService.focusGroup(editor.position);
230 231

				return TPromise.as(true);
E
Erich Gamma 已提交
232 233 234 235 236 237 238 239 240
			}

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

		// Require the reference editor to be visible and supporting split editor
241
		if (referenceEditor && (<EditorInput>referenceEditor.input).supportsSplitEditor()) {
242 243 244 245 246

			// Options
			let options: EditorOptions;
			if (referenceEditor instanceof BaseTextEditor) {
				options = new TextEditorOptions();
247
				options.pinned = true;
248
				(<TextEditorOptions>options).fromEditor(referenceEditor.getControl());
249 250
			} else {
				options = EditorOptions.create({ pinned: true });
251 252 253
			}

			return this.editorService.openEditor(referenceEditor.input, options, this.getTargetEditorSide());
E
Erich Gamma 已提交
254 255 256 257
		}

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

				// For now only support to open files from history to the side
				if (!!getUntitledOrFileResource(input)) {
263
					return this.editorService.openEditor(input, { pinned: true }, this.getTargetEditorSide());
E
Erich Gamma 已提交
264 265 266 267
				}
			}
		}

A
Alex Dima 已提交
268
		return TPromise.as(true);
E
Erich Gamma 已提交
269 270 271
	}
}

272 273
export class FocusSecondGroupAction extends BaseFocusSideGroupAction {

B
Benjamin Pasero 已提交
274
	public static ID = 'workbench.action.focusSecondEditorGroup';
B
Benjamin Pasero 已提交
275
	public static LABEL = nls.localize('focusSecondEditorGroup', "Focus Center Editor Group");
E
Erich Gamma 已提交
276 277 278 279 280

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService,
281
		@IEditorGroupService editorGroupService: IEditorGroupService,
282
		@IHistoryService historyService: IHistoryService
E
Erich Gamma 已提交
283
	) {
284
		super(id, label, editorService, editorGroupService, historyService);
E
Erich Gamma 已提交
285 286 287 288 289 290 291 292 293 294 295
	}

	protected getReferenceEditorSide(): Position {
		return Position.LEFT;
	}

	protected getTargetEditorSide(): Position {
		return Position.CENTER;
	}
}

296 297
export class FocusThirdGroupAction extends BaseFocusSideGroupAction {

B
Benjamin Pasero 已提交
298
	public static ID = 'workbench.action.focusThirdEditorGroup';
B
Benjamin Pasero 已提交
299
	public static LABEL = nls.localize('focusThirdEditorGroup', "Focus Right Editor Group");
E
Erich Gamma 已提交
300 301 302 303 304

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService,
305
		@IEditorGroupService editorGroupService: IEditorGroupService,
306
		@IHistoryService historyService: IHistoryService
E
Erich Gamma 已提交
307
	) {
308
		super(id, label, editorService, editorGroupService, historyService);
E
Erich Gamma 已提交
309 310 311 312 313 314 315 316 317 318 319
	}

	protected getReferenceEditorSide(): Position {
		return Position.CENTER;
	}

	protected getTargetEditorSide(): Position {
		return Position.RIGHT;
	}
}

B
Benjamin Pasero 已提交
320
export class FocusPreviousGroup extends Action {
321

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

325 326 327 328 329 330
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
331 332 333
		super(id, label);
	}

334
	public run(): TPromise<any> {
E
Erich Gamma 已提交
335 336

		// Require an active editor
337
		const activeEditor = this.editorService.getActiveEditor();
E
Erich Gamma 已提交
338
		if (!activeEditor) {
A
Alex Dima 已提交
339
			return TPromise.as(true);
E
Erich Gamma 已提交
340 341 342 343 344 345 346 347 348 349
		}


		// Find the next position to the left
		let nextPosition: Position = Position.LEFT;
		if (activeEditor.position === Position.RIGHT) {
			nextPosition = Position.CENTER;
		}

		// Focus next position if provided
350
		this.editorGroupService.focusGroup(nextPosition);
351 352

		return TPromise.as(true);
E
Erich Gamma 已提交
353 354 355
	}
}

B
Benjamin Pasero 已提交
356
export class FocusNextGroup extends Action {
357

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

E
Erich Gamma 已提交
361 362 363 364 365 366 367 368 369 370 371
	private navigateActions: Action[];

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

		this.navigateActions = [];
372 373 374
		this.navigateActions[Position.LEFT] = instantiationService.createInstance(FocusFirstGroupAction, FocusFirstGroupAction.ID, FocusFirstGroupAction.LABEL);
		this.navigateActions[Position.CENTER] = instantiationService.createInstance(FocusSecondGroupAction, FocusSecondGroupAction.ID, FocusSecondGroupAction.LABEL);
		this.navigateActions[Position.RIGHT] = instantiationService.createInstance(FocusThirdGroupAction, FocusThirdGroupAction.ID, FocusThirdGroupAction.LABEL);
E
Erich Gamma 已提交
375 376
	}

377
	public run(event?: any): TPromise<any> {
E
Erich Gamma 已提交
378 379 380

		// Find the next position to the right to use
		let nextPosition: Position;
381
		const activeEditor = this.editorService.getActiveEditor();
E
Erich Gamma 已提交
382 383 384 385 386 387 388 389 390
		if (!activeEditor) {
			nextPosition = Position.LEFT;
		} else if (activeEditor.position === Position.LEFT) {
			nextPosition = Position.CENTER;
		} else if (activeEditor.position === Position.CENTER) {
			nextPosition = Position.RIGHT;
		}

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

A
Alex Dima 已提交
395
		return TPromise.as(true);
E
Erich Gamma 已提交
396 397 398 399 400 401 402 403
	}
}

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");

404
	constructor( @IWorkbenchEditorService private editorService: IWorkbenchEditorService) {
E
Erich Gamma 已提交
405 406 407 408 409 410 411 412
		super(OpenToSideAction.OPEN_TO_SIDE_ID, OpenToSideAction.OPEN_TO_SIDE_LABEL);

		this.class = 'quick-open-sidebyside';

		this.updateEnablement();
	}

	private updateEnablement(): void {
413
		const activeEditor = this.editorService.getActiveEditor();
E
Erich Gamma 已提交
414 415 416
		this.enabled = (!activeEditor || activeEditor.position !== Position.RIGHT);
	}

417
	public run(context: any): TPromise<any> {
E
Erich Gamma 已提交
418 419
		let entry = toEditorQuickOpenEntry(context);
		if (entry) {
B
Benjamin Pasero 已提交
420
			let typedInputPromise: TPromise<EditorInput>;
421
			const input = entry.getInput();
B
Benjamin Pasero 已提交
422 423 424
			if (input instanceof EditorInput) {
				typedInputPromise = TPromise.as(input);
			} else {
B
Benjamin Pasero 已提交
425
				typedInputPromise = this.editorService.createInput(<IResourceInput>input);
B
Benjamin Pasero 已提交
426 427 428
			}

			return typedInputPromise.then(typedInput => this.editorService.openEditor(typedInput, entry.getOptions(), true));
E
Erich Gamma 已提交
429 430
		}

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

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

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

	public static ID = 'workbench.action.closeEditor';
	public static LABEL = nls.localize('closeEditor', "Close Editor");

458 459 460 461 462 463
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
I
isidor 已提交
464
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
465 466
	}

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

470
		// Close Active Editor
471
		if (typeof position !== 'number') {
472
			const activeEditor = this.editorService.getActiveEditor();
B
Benjamin Pasero 已提交
473
			if (activeEditor) {
474
				return this.editorService.closeEditor(activeEditor.position, activeEditor.input);
B
Benjamin Pasero 已提交
475
			}
476 477
		}

I
isidor 已提交
478
		let input = context ? context.editor : null;
I
isidor 已提交
479
		if (!input) {
B
Benjamin Pasero 已提交
480

I
isidor 已提交
481
			// Get Top Editor at Position
482
			const visibleEditors = this.editorService.getVisibleEditors();
I
isidor 已提交
483
			if (visibleEditors[position]) {
484
				input = visibleEditors[position].input;
I
isidor 已提交
485 486 487 488 489
			}
		}

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

A
Alex Dima 已提交
492
		return TPromise.as(false);
E
Erich Gamma 已提交
493 494 495
	}
}

B
Benjamin Pasero 已提交
496
export class CloseLeftEditorsInGroupAction extends Action {
497

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

501 502 503
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
504 505
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private groupService: IEditorGroupService
506
	) {
507 508 509
		super(id, label);
	}

B
Benjamin Pasero 已提交
510
	public run(context?: IEditorContext): TPromise<any> {
511
		const editor = getTarget(this.editorService, this.groupService, context);
B
Benjamin Pasero 已提交
512 513
		if (editor) {
			return this.editorService.closeEditors(editor.position, editor.input, Direction.LEFT);
514 515 516 517 518 519 520 521
		}

		return TPromise.as(false);
	}
}

export class CloseRightEditorsInGroupAction extends Action {

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

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

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

		return TPromise.as(false);
	}
}

E
Erich Gamma 已提交
544 545
export class CloseAllEditorsAction extends Action {

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

E
Erich Gamma 已提交
549
	constructor(id: string, label: string, @IWorkbenchEditorService private editorService: IWorkbenchEditorService) {
I
isidor 已提交
550
		super(id, label, 'action-close-all-files');
E
Erich Gamma 已提交
551 552
	}

553
	public run(): TPromise<any> {
554
		return this.editorService.closeAllEditors();
E
Erich Gamma 已提交
555 556 557
	}
}

558 559 560 561 562
export class CloseEditorsInOtherGroupsAction extends Action {

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

563 564 565 566 567 568
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
569 570 571
		super(id, label);
	}

B
Benjamin Pasero 已提交
572
	public run(context?: IEditorContext): TPromise<any> {
573
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
574
		if (typeof position !== 'number') {
575
			const activeEditor = this.editorService.getActiveEditor();
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
			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 已提交
592
	public static LABEL = nls.localize('closeOtherEditorsInGroup', "Close Other Editors");
E
Erich Gamma 已提交
593

594 595 596 597 598 599
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
600 601 602
		super(id, label);
	}

B
Benjamin Pasero 已提交
603
	public run(context?: IEditorContext): TPromise<any> {
604
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
I
isidor 已提交
605
		let input = context ? context.editor : null;
I
isidor 已提交
606 607

		// If position or input are not passed in take the position and input of the active editor.
608 609
		const active = this.editorService.getActiveEditor();
		if (active) {
I
isidor 已提交
610
			position = typeof position === 'number' ? position : active.position;
611
			input = input ? input : <EditorInput>active.input;
I
isidor 已提交
612 613 614 615
		}

		if (typeof position === 'number' && input) {
			return this.editorService.closeEditors(position, input);
616 617 618
		}

		return TPromise.as(false);
E
Erich Gamma 已提交
619 620 621
	}
}

B
Benjamin Pasero 已提交
622
export class CloseEditorsInGroupAction extends Action {
I
isidor 已提交
623

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

627 628 629 630 631 632
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
B
Benjamin Pasero 已提交
633
		super(id, label);
I
isidor 已提交
634 635
	}

B
Benjamin Pasero 已提交
636
	public run(context?: IEditorContext): TPromise<any> {
637
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
I
isidor 已提交
638
		if (typeof position !== 'number') {
639
			const activeEditor = this.editorService.getActiveEditor();
I
isidor 已提交
640 641 642 643 644 645 646 647
			if (activeEditor) {
				position = activeEditor.position;
			}
		}

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

		return TPromise.as(false);
I
isidor 已提交
650 651 652
	}
}

B
Benjamin Pasero 已提交
653
export class MoveGroupLeftAction extends Action {
E
Erich Gamma 已提交
654

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

658 659 660 661 662 663
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
664 665 666
		super(id, label);
	}

B
Benjamin Pasero 已提交
667
	public run(context?: IEditorContext): TPromise<any> {
668
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
669
		if (typeof position !== 'number') {
670
			const activeEditor = this.editorService.getActiveEditor();
671 672 673 674 675 676
			if (activeEditor && (activeEditor.position === Position.CENTER || activeEditor.position === Position.RIGHT)) {
				position = activeEditor.position;
			}
		}

		if (typeof position === 'number') {
677
			const newPosition = (position === Position.CENTER) ? Position.LEFT : Position.CENTER;
E
Erich Gamma 已提交
678

B
Benjamin Pasero 已提交
679
			// Move group
680
			this.editorGroupService.moveGroup(position, newPosition);
E
Erich Gamma 已提交
681 682
		}

A
Alex Dima 已提交
683
		return TPromise.as(false);
E
Erich Gamma 已提交
684 685 686
	}
}

B
Benjamin Pasero 已提交
687
export class MoveGroupRightAction extends Action {
E
Erich Gamma 已提交
688

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

692 693 694 695 696 697
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
698 699 700
		super(id, label);
	}

B
Benjamin Pasero 已提交
701
	public run(context?: IEditorContext): TPromise<any> {
702
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
703
		if (typeof position !== 'number') {
704 705
			const activeEditor = this.editorService.getActiveEditor();
			const editors = this.editorService.getVisibleEditors();
706 707 708 709 710 711 712

			if ((editors.length === 2 && activeEditor.position === Position.LEFT) || (editors.length === 3 && activeEditor.position !== Position.RIGHT)) {
				position = activeEditor.position;
			}
		}

		if (typeof position === 'number') {
713
			const newPosition = (position === Position.LEFT) ? Position.CENTER : Position.RIGHT;
E
Erich Gamma 已提交
714

B
Benjamin Pasero 已提交
715
			// Move group
716
			this.editorGroupService.moveGroup(position, newPosition);
E
Erich Gamma 已提交
717 718
		}

A
Alex Dima 已提交
719
		return TPromise.as(false);
E
Erich Gamma 已提交
720 721 722
	}
}

723
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
724

725 726 727
	public static ID = 'workbench.action.minimizeOtherEditors';
	public static LABEL = nls.localize('minimizeOtherEditorGroups', "Minimize Other Editor Groups");

728
	constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
E
Erich Gamma 已提交
729 730 731
		super(id, label);
	}

732
	public run(): TPromise<any> {
733
		this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
734

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

739
export class EvenGroupWidthsAction extends Action {
E
Erich Gamma 已提交
740

741 742 743
	public static ID = 'workbench.action.evenEditorWidths';
	public static LABEL = nls.localize('evenEditorGroups', "Even Editor Group Widths");

744
	constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
E
Erich Gamma 已提交
745 746 747
		super(id, label);
	}

748
	public run(): TPromise<any> {
749
		this.editorGroupService.arrangeGroups(GroupArrangement.EVEN_WIDTH);
E
Erich Gamma 已提交
750

A
Alex Dima 已提交
751
		return TPromise.as(false);
E
Erich Gamma 已提交
752 753 754
	}
}

755
export class MaximizeGroupAction extends Action {
756

757 758 759
	public static ID = 'workbench.action.maximizeEditor';
	public static LABEL = nls.localize('maximizeEditor', "Maximize Editor Group and Hide Sidebar");

760 761 762 763
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
764
		@IEditorGroupService private editorGroupService: IEditorGroupService,
765 766 767 768 769
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

770
	public run(): TPromise<any> {
771
		if (this.editorService.getActiveEditor()) {
772
			this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
773 774 775
			this.partService.setSideBarHidden(true);
		}

A
Alex Dima 已提交
776
		return TPromise.as(false);
777 778 779
	}
}

B
Benjamin Pasero 已提交
780
export class KeepEditorAction extends Action {
781

B
Benjamin Pasero 已提交
782 783
	public static ID = 'workbench.action.keepEditor';
	public static LABEL = nls.localize('keepEditor', "Keep Editor");
784 785 786 787

	constructor(
		id: string,
		label: string,
788
		@IEditorGroupService private editorGroupService: IEditorGroupService,
789 790 791 792 793
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
794
	public run(context?: IEditorContext): TPromise<any> {
795
		const target = getTarget(this.editorService, this.editorGroupService, context);
B
Benjamin Pasero 已提交
796 797
		if (target) {
			this.editorGroupService.pinEditor(target.position, target.input);
798 799 800 801 802 803
		}

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
804 805 806 807 808 809 810 811 812 813 814 815 816
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;
}

817 818
export abstract class BaseNavigateEditorAction extends Action {

819 820 821 822 823 824
	constructor(
		id: string,
		label: string,
		protected editorGroupService: IEditorGroupService,
		protected editorService: IWorkbenchEditorService
	) {
825 826 827 828
		super(id, label);
	}

	public run(): TPromise<any> {
829
		const model = this.editorGroupService.getStacksModel();
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
		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");

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

	protected navigate(): IEditorIdentifier {
856
		return this.editorGroupService.getStacksModel().next();
857 858 859 860 861 862 863 864
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

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

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

	protected navigate(): IEditorIdentifier {
875
		return this.editorGroupService.getStacksModel().previous();
876
	}
B
Benjamin Pasero 已提交
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
}

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 已提交
909
}
910 911 912 913 914 915 916 917 918

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,
919
		@IHistoryService private historyService: IHistoryService,
920
		@IEditorGroupService private editorGroupService: IEditorGroupService,
921 922 923 924 925 926
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
927
		const stacks = this.editorGroupService.getStacksModel();
928 929

		// Find an editor that was closed and is currently not opened in the group
930
		let lastClosedEditor = this.historyService.popLastClosedEditor();
931
		while (lastClosedEditor && stacks.activeGroup && stacks.activeGroup.indexOf(lastClosedEditor.editor) >= 0) {
932
			lastClosedEditor = this.historyService.popLastClosedEditor();
933 934 935
		}

		if (lastClosedEditor) {
936
			this.editorService.openEditor(lastClosedEditor.editor, { pinned: true, index: lastClosedEditor.index });
937 938 939 940
		}

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
941 942
}

943
export const NAVIGATE_IN_LEFT_GROUP_PREFIX = 'edt left ';
B
Benjamin Pasero 已提交
944

945
export class ShowEditorsInLeftGroupAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
946

947 948
	public static ID = 'workbench.action.showEditorsInLeftGroup';
	public static LABEL = nls.localize('showEditorsInLeftGroup', "Show Editors in Left Group");
B
Benjamin Pasero 已提交
949

950 951 952 953 954 955
	constructor(
		actionId: string,
		actionLabel: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
956
		super(actionId, actionLabel, NAVIGATE_IN_LEFT_GROUP_PREFIX, quickOpenService);
957 958

		this.class = 'show-group-editors-action';
B
Benjamin Pasero 已提交
959
	}
960
}
961

962 963 964 965 966 967 968 969 970 971 972 973 974 975
export const NAVIGATE_IN_CENTER_GROUP_PREFIX = 'edt center ';

export class ShowEditorsInCenterGroupAction extends QuickOpenAction {

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

	constructor(
		actionId: string,
		actionLabel: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(actionId, actionLabel, NAVIGATE_IN_CENTER_GROUP_PREFIX, quickOpenService);
976 977

		this.class = 'show-group-editors-action';
978 979
	}
}
980

981 982 983 984 985 986 987 988 989 990 991 992 993 994
export const NAVIGATE_IN_RIGHT_GROUP_PREFIX = 'edt right ';

export class ShowEditorsInRightGroupAction extends QuickOpenAction {

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

	constructor(
		actionId: string,
		actionLabel: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(actionId, actionLabel, NAVIGATE_IN_RIGHT_GROUP_PREFIX, quickOpenService);
995 996

		this.class = 'show-group-editors-action';
997
	}
B
Benjamin Pasero 已提交
998 999
}

B
Benjamin Pasero 已提交
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
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)) {
			case Position.CENTER:
				return this.quickOpenService.show((groupCount === 2) ? NAVIGATE_IN_RIGHT_GROUP_PREFIX : NAVIGATE_IN_CENTER_GROUP_PREFIX);
			case Position.RIGHT:
				return this.quickOpenService.show(NAVIGATE_IN_RIGHT_GROUP_PREFIX);
		}

		return this.quickOpenService.show(NAVIGATE_IN_LEFT_GROUP_PREFIX);
	}
}

1032
export const NAVIGATE_ALL_EDITORS_GROUP_PREFIX = 'edt ';
B
Benjamin Pasero 已提交
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043

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

1044
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1045 1046 1047 1048 1049

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
1050
		@IKeybindingService private keybindingService: IKeybindingService,
1051
		@IEditorGroupService private editorGroupService: IEditorGroupService,
1052
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
B
Benjamin Pasero 已提交
1053 1054 1055 1056 1057
	) {
		super(id, label);
	}

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

1060
		const stacks = this.editorGroupService.getStacksModel();
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
		if (stacks.activeGroup) {
			const activePosition = stacks.positionOfGroup(stacks.activeGroup);
			const count = stacks.groups.length;
			let prefix = NAVIGATE_IN_LEFT_GROUP_PREFIX;

			if (activePosition === Position.CENTER && count === 3) {
				prefix = NAVIGATE_IN_CENTER_GROUP_PREFIX;
			} else if (activePosition === Position.RIGHT || (activePosition === Position.CENTER && count === 2)) {
				prefix = NAVIGATE_IN_RIGHT_GROUP_PREFIX;
			}

B
Benjamin Pasero 已提交
1072
			this.quickOpenService.show(prefix, { quickNavigateConfiguration: { keybindings: keys } });
1073
		}
B
Benjamin Pasero 已提交
1074 1075 1076 1077 1078

		return TPromise.as(true);
	}
}

1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

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

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

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

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

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

1113
export class OpenPreviousEditorFromHistoryAction extends Action {
B
Benjamin Pasero 已提交
1114

1115
	public static ID = 'workbench.action.openPreviousEditorFromHistory';
B
Benjamin Pasero 已提交
1116
	public static LABEL = nls.localize('navigateEditorHistoryByInput', "Open Previous Editor from History");
B
Benjamin Pasero 已提交
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127

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

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

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

		return TPromise.as(true);
	}
}

1136 1137 1138 1139 1140 1141 1142 1143 1144
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,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
1145
		@IEditorGroupService private editorGroupService: IEditorGroupService,
1146 1147 1148 1149 1150 1151 1152
		@IHistoryService private historyService: IHistoryService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {

1153
		// Editor history
1154 1155 1156 1157 1158 1159
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1160 1161 1162 1163 1164 1165 1166 1167
export class RemoveFromEditorHistoryAction extends Action {

	public static ID = 'workbench.action.removeFromEditorHistory';
	public static LABEL = nls.localize('removeFromEditorHistory', "Remove From Editor History");

	constructor(
		id: string,
		label: string,
1168
		@IEditorGroupService private editorGroupService: IEditorGroupService,
1169 1170 1171 1172 1173 1174 1175 1176 1177
		@IQuickOpenService private quickOpenService: IQuickOpenService,
		@IHistoryService private historyService: IHistoryService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {

		// Listen for next editor to open
1178
		const unbind = this.editorGroupService.onEditorOpening(e => {
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
			unbind.dispose(); // listen once

			e.prevent();
			this.historyService.remove(e.editorInput);
		});

		// Bring up quick open
		this.quickOpenService.show().then(() => {
			unbind.dispose(); // make sure to unbind if quick open is closing
		});

		return TPromise.as(true);
	}
}

1194 1195
interface IEditorPickOpenEntry extends IPickOpenEntry {
	identifier: IEditorIdentifier;
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222
}

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

1223 1224 1225 1226
		return TPromise.as(true);
	}
}

1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
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 = {
1242
			to: ActiveEditorMovePositioning.LEFT
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
		};
		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 = {
1265
			to: ActiveEditorMovePositioning.RIGHT
1266 1267 1268 1269 1270 1271 1272
		};
		this.commandService.executeCommand(EditorCommands.MoveActiveEditor, args);

		return TPromise.as(true);
	}
}

1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316
export class MoveEditorToLeftGroupAction extends Action {

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

	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();
		if (activeEditor && activeEditor.position !== Position.LEFT) {
			this.editorGroupService.moveEditor(activeEditor.input, activeEditor.position, activeEditor.position - 1);
		}

		return TPromise.as(true);
	}
}

export class MoveEditorToRightGroupAction extends Action {

	public static ID = 'workbench.action.moveEditorToRightGroup';
	public static LABEL = nls.localize('moveEditorToRightGroup', "Move Editor into Group to the Right");

	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();
		if (activeEditor && activeEditor.position !== Position.RIGHT) {
			this.editorGroupService.moveEditor(activeEditor.input, activeEditor.position, activeEditor.position + 1);
		}

1317 1318
		return TPromise.as(true);
	}
D
Daniel Imms 已提交
1319
}