editorActions.ts 38.3 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 10 11 12 13 14 15 16 17 18
import { Action } from 'vs/base/common/actions';
import { EditorInput, getUntitledOrFileResource, TextEditorOptions, EditorOptions, IEditorIdentifier, IEditorContext, ActiveEditorMoveArguments, ActiveEditorMovePositioning, EditorCommands } from 'vs/workbench/common/editor';
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';
import { IQuickOpenService } from 'vs/workbench/services/quickopen/common/quickOpenService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { Position, IEditor, Direction, IResourceInput, IEditorInput } from 'vs/platform/editor/common/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
19
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
J
Johannes Rieken 已提交
20 21 22 23
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IEditorGroupService, GroupArrangement } from 'vs/workbench/services/group/common/groupService';
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
import { ICommandService } from 'vs/platform/commands/common/commands';
E
Erich Gamma 已提交
24 25 26

export class SplitEditorAction extends Action {

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

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

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

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

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

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

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

		switch (editorCount) {

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

			// Special case two editors opened
			case 2:

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

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

91 92 93
					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 已提交
94 95 96 97
					});
				}
		}

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

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

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

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

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

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

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

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

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

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

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

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

163 164
export class FocusFirstGroupAction extends Action {

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

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

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

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

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

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

194 195 196
			// For now only support to open files from history to the side
			if (input instanceof EditorInput) {
				if (!!getUntitledOrFileResource(input)) {
197
					return this.editorService.openEditor(input, null, Position.ONE);
198 199
				}
			} else {
200
				return this.editorService.openEditor(input as IResourceInput, Position.ONE);
E
Erich Gamma 已提交
201 202 203
			}
		}

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

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

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

	protected abstract getReferenceEditorSide(): Position;

	protected abstract getTargetEditorSide(): Position;

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

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

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

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

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

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

			// Options
			let options: EditorOptions;
			if (referenceEditor instanceof BaseTextEditor) {
				options = new TextEditorOptions();
252
				options.pinned = true;
253
				(<TextEditorOptions>options).fromEditor(referenceEditor.getControl());
254 255
			} else {
				options = EditorOptions.create({ pinned: true });
256 257 258
			}

			return this.editorService.openEditor(referenceEditor.input, options, this.getTargetEditorSide());
E
Erich Gamma 已提交
259 260 261 262
		}

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

				// For now only support to open files from history to the side
267 268 269 270 271 272
				if (input instanceof EditorInput) {
					if (!!getUntitledOrFileResource(input)) {
						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 已提交
273 274 275 276
				}
			}
		}

A
Alex Dima 已提交
277
		return TPromise.as(true);
E
Erich Gamma 已提交
278 279 280
	}
}

281 282
export class FocusSecondGroupAction extends BaseFocusSideGroupAction {

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

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

	protected getReferenceEditorSide(): Position {
297
		return Position.ONE;
E
Erich Gamma 已提交
298 299 300
	}

	protected getTargetEditorSide(): Position {
301
		return Position.TWO;
E
Erich Gamma 已提交
302 303 304
	}
}

305 306
export class FocusThirdGroupAction extends BaseFocusSideGroupAction {

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

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

	protected getReferenceEditorSide(): Position {
321
		return Position.TWO;
E
Erich Gamma 已提交
322 323 324
	}

	protected getTargetEditorSide(): Position {
325
		return Position.THREE;
E
Erich Gamma 已提交
326 327 328
	}
}

B
Benjamin Pasero 已提交
329
export class FocusPreviousGroup extends Action {
330

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

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

343
	public run(): TPromise<any> {
E
Erich Gamma 已提交
344 345

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


B
Benjamin Pasero 已提交
352
		// Find the next position to the left/top
353 354 355
		let nextPosition: Position = Position.ONE;
		if (activeEditor.position === Position.THREE) {
			nextPosition = Position.TWO;
E
Erich Gamma 已提交
356 357 358
		}

		// Focus next position if provided
359
		this.editorGroupService.focusGroup(nextPosition);
360 361

		return TPromise.as(true);
E
Erich Gamma 已提交
362 363 364
	}
}

B
Benjamin Pasero 已提交
365
export class FocusNextGroup extends Action {
366

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

E
Erich Gamma 已提交
370 371 372 373 374 375 376 377 378 379 380
	private navigateActions: Action[];

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

		this.navigateActions = [];
381 382 383
		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 已提交
384 385
	}

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

B
Benjamin Pasero 已提交
388
		// Find the next position to the right/bottom to use
E
Erich Gamma 已提交
389
		let nextPosition: Position;
390
		const activeEditor = this.editorService.getActiveEditor();
E
Erich Gamma 已提交
391
		if (!activeEditor) {
392 393 394 395 396
			nextPosition = Position.ONE;
		} else if (activeEditor.position === Position.ONE) {
			nextPosition = Position.TWO;
		} else if (activeEditor.position === Position.TWO) {
			nextPosition = Position.THREE;
E
Erich Gamma 已提交
397 398 399
		}

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

A
Alex Dima 已提交
404
		return TPromise.as(true);
E
Erich Gamma 已提交
405 406 407 408 409 410 411 412
	}
}

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

413 414 415 416
	constructor(
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IConfigurationService private configurationService: IConfigurationService
	) {
E
Erich Gamma 已提交
417 418 419
		super(OpenToSideAction.OPEN_TO_SIDE_ID, OpenToSideAction.OPEN_TO_SIDE_LABEL);

		this.updateEnablement();
420 421 422 423 424 425 426
		this.updateClass();
	}

	public updateClass(): void {
		const editorLayoutVertical = this.configurationService.lookup('workbench.editor.sideBySideLayout').value !== 'horizontal';

		this.class = editorLayoutVertical ? 'quick-open-sidebyside-vertical' : 'quick-open-sidebyside-horizontal';
E
Erich Gamma 已提交
427 428 429
	}

	private updateEnablement(): void {
430
		const activeEditor = this.editorService.getActiveEditor();
431
		this.enabled = (!activeEditor || activeEditor.position !== Position.THREE);
E
Erich Gamma 已提交
432 433
	}

434
	public run(context: any): TPromise<any> {
E
Erich Gamma 已提交
435 436
		let entry = toEditorQuickOpenEntry(context);
		if (entry) {
B
Benjamin Pasero 已提交
437
			let typedInputPromise: TPromise<EditorInput>;
438
			const input = entry.getInput();
B
Benjamin Pasero 已提交
439 440 441
			if (input instanceof EditorInput) {
				typedInputPromise = TPromise.as(input);
			} else {
B
Benjamin Pasero 已提交
442
				typedInputPromise = this.editorService.createInput(<IResourceInput>input);
B
Benjamin Pasero 已提交
443 444 445
			}

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

A
Alex Dima 已提交
448
		return TPromise.as(false);
E
Erich Gamma 已提交
449 450 451
	}
}

452
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
453 454 455

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

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

475 476 477 478 479 480
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
I
isidor 已提交
481
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
482 483
	}

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

487
		// Close Active Editor
488
		if (typeof position !== 'number') {
489
			const activeEditor = this.editorService.getActiveEditor();
B
Benjamin Pasero 已提交
490
			if (activeEditor) {
491
				return this.editorService.closeEditor(activeEditor.position, activeEditor.input);
B
Benjamin Pasero 已提交
492
			}
493 494
		}

I
isidor 已提交
495
		let input = context ? context.editor : null;
I
isidor 已提交
496
		if (!input) {
B
Benjamin Pasero 已提交
497

I
isidor 已提交
498
			// Get Top Editor at Position
499
			const visibleEditors = this.editorService.getVisibleEditors();
I
isidor 已提交
500
			if (visibleEditors[position]) {
501
				input = visibleEditors[position].input;
I
isidor 已提交
502 503 504 505 506
			}
		}

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

A
Alex Dima 已提交
509
		return TPromise.as(false);
E
Erich Gamma 已提交
510 511 512
	}
}

B
Benjamin Pasero 已提交
513
export class CloseLeftEditorsInGroupAction extends Action {
514

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

518 519 520
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
521 522
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private groupService: IEditorGroupService
523
	) {
524 525 526
		super(id, label);
	}

B
Benjamin Pasero 已提交
527
	public run(context?: IEditorContext): TPromise<any> {
528
		const editor = getTarget(this.editorService, this.groupService, context);
B
Benjamin Pasero 已提交
529 530
		if (editor) {
			return this.editorService.closeEditors(editor.position, editor.input, Direction.LEFT);
531 532 533 534 535 536 537 538
		}

		return TPromise.as(false);
	}
}

export class CloseRightEditorsInGroupAction extends Action {

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

B
Benjamin Pasero 已提交
542 543 544 545 546 547
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private groupService: IEditorGroupService
	) {
548 549 550
		super(id, label);
	}

B
Benjamin Pasero 已提交
551
	public run(context?: IEditorContext): TPromise<any> {
552
		const editor = getTarget(this.editorService, this.groupService, context);
B
Benjamin Pasero 已提交
553 554
		if (editor) {
			return this.editorService.closeEditors(editor.position, editor.input, Direction.RIGHT);
555 556 557 558 559 560
		}

		return TPromise.as(false);
	}
}

E
Erich Gamma 已提交
561 562
export class CloseAllEditorsAction extends Action {

563 564 565
	public static ID = 'workbench.action.closeAllEditors';
	public static LABEL = nls.localize('closeAllEditors', "Close All Editors");

E
Erich Gamma 已提交
566
	constructor(id: string, label: string, @IWorkbenchEditorService private editorService: IWorkbenchEditorService) {
I
isidor 已提交
567
		super(id, label, 'action-close-all-files');
E
Erich Gamma 已提交
568 569
	}

570
	public run(): TPromise<any> {
571
		return this.editorService.closeAllEditors();
E
Erich Gamma 已提交
572 573 574
	}
}

575 576 577 578 579
export class CloseEditorsInOtherGroupsAction extends Action {

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

580 581 582 583 584 585
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
586 587 588
		super(id, label);
	}

B
Benjamin Pasero 已提交
589
	public run(context?: IEditorContext): TPromise<any> {
590
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
591
		if (typeof position !== 'number') {
592
			const activeEditor = this.editorService.getActiveEditor();
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
			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 已提交
609
	public static LABEL = nls.localize('closeOtherEditorsInGroup', "Close Other Editors");
E
Erich Gamma 已提交
610

611 612 613 614 615 616
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
617 618 619
		super(id, label);
	}

B
Benjamin Pasero 已提交
620
	public run(context?: IEditorContext): TPromise<any> {
621
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
I
isidor 已提交
622
		let input = context ? context.editor : null;
I
isidor 已提交
623 624

		// If position or input are not passed in take the position and input of the active editor.
625 626
		const active = this.editorService.getActiveEditor();
		if (active) {
I
isidor 已提交
627
			position = typeof position === 'number' ? position : active.position;
628
			input = input ? input : <EditorInput>active.input;
I
isidor 已提交
629 630 631 632
		}

		if (typeof position === 'number' && input) {
			return this.editorService.closeEditors(position, input);
633 634 635
		}

		return TPromise.as(false);
E
Erich Gamma 已提交
636 637 638
	}
}

B
Benjamin Pasero 已提交
639
export class CloseEditorsInGroupAction extends Action {
I
isidor 已提交
640

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

644 645 646 647 648 649
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
B
Benjamin Pasero 已提交
650
		super(id, label);
I
isidor 已提交
651 652
	}

B
Benjamin Pasero 已提交
653
	public run(context?: IEditorContext): TPromise<any> {
654
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
I
isidor 已提交
655
		if (typeof position !== 'number') {
656
			const activeEditor = this.editorService.getActiveEditor();
I
isidor 已提交
657 658 659 660 661 662 663 664
			if (activeEditor) {
				position = activeEditor.position;
			}
		}

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

		return TPromise.as(false);
I
isidor 已提交
667 668 669
	}
}

B
Benjamin Pasero 已提交
670
export class MoveGroupLeftAction extends Action {
E
Erich Gamma 已提交
671

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

675 676 677 678 679 680
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
681 682 683
		super(id, label);
	}

B
Benjamin Pasero 已提交
684
	public run(context?: IEditorContext): TPromise<any> {
685
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
686
		if (typeof position !== 'number') {
687
			const activeEditor = this.editorService.getActiveEditor();
688
			if (activeEditor && (activeEditor.position === Position.TWO || activeEditor.position === Position.THREE)) {
689 690 691 692 693
				position = activeEditor.position;
			}
		}

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

B
Benjamin Pasero 已提交
696
			// Move group
697
			this.editorGroupService.moveGroup(position, newPosition);
E
Erich Gamma 已提交
698 699
		}

A
Alex Dima 已提交
700
		return TPromise.as(false);
E
Erich Gamma 已提交
701 702 703
	}
}

B
Benjamin Pasero 已提交
704
export class MoveGroupRightAction extends Action {
E
Erich Gamma 已提交
705

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

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

B
Benjamin Pasero 已提交
718
	public run(context?: IEditorContext): TPromise<any> {
719
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
720
		if (typeof position !== 'number') {
721 722
			const activeEditor = this.editorService.getActiveEditor();
			const editors = this.editorService.getVisibleEditors();
723

724
			if ((editors.length === 2 && activeEditor.position === Position.ONE) || (editors.length === 3 && activeEditor.position !== Position.THREE)) {
725 726 727 728 729
				position = activeEditor.position;
			}
		}

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

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

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

740
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
741

742 743 744
	public static ID = 'workbench.action.minimizeOtherEditors';
	public static LABEL = nls.localize('minimizeOtherEditorGroups', "Minimize Other Editor Groups");

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

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

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

756
export class EvenGroupWidthsAction extends Action {
E
Erich Gamma 已提交
757

758 759 760
	public static ID = 'workbench.action.evenEditorWidths';
	public static LABEL = nls.localize('evenEditorGroups', "Even Editor Group Widths");

761
	constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
E
Erich Gamma 已提交
762 763 764
		super(id, label);
	}

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

A
Alex Dima 已提交
768
		return TPromise.as(false);
E
Erich Gamma 已提交
769 770 771
	}
}

772
export class MaximizeGroupAction extends Action {
773

774 775 776
	public static ID = 'workbench.action.maximizeEditor';
	public static LABEL = nls.localize('maximizeEditor', "Maximize Editor Group and Hide Sidebar");

777 778 779 780
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
781
		@IEditorGroupService private editorGroupService: IEditorGroupService,
782 783 784 785 786
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

787
	public run(): TPromise<any> {
788
		if (this.editorService.getActiveEditor()) {
789
			this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
790 791 792
			this.partService.setSideBarHidden(true);
		}

A
Alex Dima 已提交
793
		return TPromise.as(false);
794 795 796
	}
}

B
Benjamin Pasero 已提交
797
export class KeepEditorAction extends Action {
798

B
Benjamin Pasero 已提交
799 800
	public static ID = 'workbench.action.keepEditor';
	public static LABEL = nls.localize('keepEditor', "Keep Editor");
801 802 803 804

	constructor(
		id: string,
		label: string,
805
		@IEditorGroupService private editorGroupService: IEditorGroupService,
806 807 808 809 810
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
811
	public run(context?: IEditorContext): TPromise<any> {
812
		const target = getTarget(this.editorService, this.editorGroupService, context);
B
Benjamin Pasero 已提交
813 814
		if (target) {
			this.editorGroupService.pinEditor(target.position, target.input);
815 816 817 818 819 820
		}

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
821 822 823 824 825 826 827 828 829 830 831 832 833
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;
}

834 835
export abstract class BaseNavigateEditorAction extends Action {

836 837 838 839 840 841
	constructor(
		id: string,
		label: string,
		protected editorGroupService: IEditorGroupService,
		protected editorService: IWorkbenchEditorService
	) {
842 843 844 845
		super(id, label);
	}

	public run(): TPromise<any> {
846
		const model = this.editorGroupService.getStacksModel();
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862
		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");

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

	protected navigate(): IEditorIdentifier {
873
		return this.editorGroupService.getStacksModel().next();
874 875 876 877 878 879 880 881
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

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

882 883 884 885 886 887 888
	constructor(
		id: string,
		label: string,
		@IEditorGroupService editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, editorGroupService, editorService);
889 890 891
	}

	protected navigate(): IEditorIdentifier {
892
		return this.editorGroupService.getStacksModel().previous();
893
	}
B
Benjamin Pasero 已提交
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
}

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 已提交
926
}
927 928 929 930 931 932 933 934 935

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,
936
		@IHistoryService private historyService: IHistoryService,
937
		@IEditorGroupService private editorGroupService: IEditorGroupService,
938 939 940 941 942 943
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
944
		this.historyService.reopenLastClosedEditor();
945 946 947

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
948 949
}

950
export const NAVIGATE_IN_GROUP_ONE_PREFIX = 'edt one ';
B
Benjamin Pasero 已提交
951

952
export class ShowEditorsInGroupOneAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
953

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

957 958 959
	constructor(
		actionId: string,
		actionLabel: string,
960
		@IQuickOpenService quickOpenService: IQuickOpenService
961
	) {
962
		super(actionId, actionLabel, NAVIGATE_IN_GROUP_ONE_PREFIX, quickOpenService);
963 964

		this.class = 'show-group-editors-action';
B
Benjamin Pasero 已提交
965
	}
966
}
967

968
export const NAVIGATE_IN_GROUP_TWO_PREFIX = 'edt two ';
969

970
export class ShowEditorsInGroupTwoAction extends QuickOpenAction {
971

972 973
	public static ID = 'workbench.action.showEditorsInSecondGroup';
	public static LABEL = nls.localize('showEditorsInSecondGroup', "Show Editors in Second Group");
974 975 976 977

	constructor(
		actionId: string,
		actionLabel: string,
978
		@IQuickOpenService quickOpenService: IQuickOpenService
979
	) {
980
		super(actionId, actionLabel, NAVIGATE_IN_GROUP_TWO_PREFIX, quickOpenService);
981 982

		this.class = 'show-group-editors-action';
983 984
	}
}
985

986
export const NAVIGATE_IN_GROUP_THREE_PREFIX = 'edt three ';
987

988
export class ShowEditorsInGroupThreeAction extends QuickOpenAction {
989

990 991
	public static ID = 'workbench.action.showEditorsInThirdGroup';
	public static LABEL = nls.localize('showEditorsInThirdGroup', "Show Editors in Third Group");
992 993 994 995

	constructor(
		actionId: string,
		actionLabel: string,
996
		@IQuickOpenService quickOpenService: IQuickOpenService
997
	) {
998
		super(actionId, actionLabel, NAVIGATE_IN_GROUP_THREE_PREFIX, quickOpenService);
999 1000

		this.class = 'show-group-editors-action';
1001
	}
B
Benjamin Pasero 已提交
1002 1003
}

B
Benjamin Pasero 已提交
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
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)) {
1026
			case Position.TWO:
B
Benjamin Pasero 已提交
1027
				return this.quickOpenService.show(NAVIGATE_IN_GROUP_TWO_PREFIX);
1028
			case Position.THREE:
1029
				return this.quickOpenService.show(NAVIGATE_IN_GROUP_THREE_PREFIX);
B
Benjamin Pasero 已提交
1030 1031
		}

1032
		return this.quickOpenService.show(NAVIGATE_IN_GROUP_ONE_PREFIX);
B
Benjamin Pasero 已提交
1033 1034 1035
	}
}

1036
export const NAVIGATE_ALL_EDITORS_GROUP_PREFIX = 'edt ';
B
Benjamin Pasero 已提交
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047

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

1048
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1049 1050 1051 1052 1053

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
1054
		@IKeybindingService private keybindingService: IKeybindingService,
1055
		@IEditorGroupService private editorGroupService: IEditorGroupService
B
Benjamin Pasero 已提交
1056 1057 1058 1059 1060
	) {
		super(id, label);
	}

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

1063
		const stacks = this.editorGroupService.getStacksModel();
1064 1065 1066
		if (stacks.activeGroup) {
			const activePosition = stacks.positionOfGroup(stacks.activeGroup);
			const count = stacks.groups.length;
1067
			let prefix = NAVIGATE_IN_GROUP_ONE_PREFIX;
1068

1069
			if (activePosition === Position.TWO && count === 3) {
1070
				prefix = NAVIGATE_IN_GROUP_TWO_PREFIX;
1071
			} else if (activePosition === Position.THREE || (activePosition === Position.TWO && count === 2)) {
1072
				prefix = NAVIGATE_IN_GROUP_THREE_PREFIX;
1073 1074
			}

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

		return TPromise.as(true);
	}
}

1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
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,
1092
		@IEditorGroupService editorGroupService: IEditorGroupService
1093
	) {
1094
		super(id, label, quickOpenService, keybindingService, editorGroupService);
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
	}
}

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,
1108
		@IEditorGroupService editorGroupService: IEditorGroupService
1109
	) {
1110
		super(id, label, quickOpenService, keybindingService, editorGroupService);
1111 1112 1113
	}
}

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

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

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

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

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

		return TPromise.as(true);
	}
}

1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
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> {

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

		return TPromise.as(true);
	}
}

1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
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);
			}
		}

1184 1185 1186 1187
		return TPromise.as(true);
	}
}

1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
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 = {
1203
			to: ActiveEditorMovePositioning.LEFT
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
		};
		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 = {
1226
			to: ActiveEditorMovePositioning.RIGHT
1227 1228 1229 1230 1231 1232 1233
		};
		this.commandService.executeCommand(EditorCommands.MoveActiveEditor, args);

		return TPromise.as(true);
	}
}

1234
export class MoveEditorToPreviousGroupAction extends Action {
1235

1236 1237
	public static ID = 'workbench.action.moveEditorToPreviousGroup';
	public static LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249

	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();
1250
		if (activeEditor && activeEditor.position !== Position.ONE) {
1251 1252 1253 1254 1255 1256 1257
			this.editorGroupService.moveEditor(activeEditor.input, activeEditor.position, activeEditor.position - 1);
		}

		return TPromise.as(true);
	}
}

1258
export class MoveEditorToNextGroupAction extends Action {
1259

1260 1261
	public static ID = 'workbench.action.moveEditorToNextGroup';
	public static LABEL = nls.localize('moveEditorToNextGroup', "Move Editor into Next Group");
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273

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

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