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

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

export class SplitEditorAction extends Action {

M
Matt Bierner 已提交
29 30
	public static readonly ID = 'workbench.action.splitEditor';
	public static readonly LABEL = nls.localize('splitEditor', "Split Editor");
31

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

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

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

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

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

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

		switch (editorCount) {

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

			// Special case two editors opened
			case 2:

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

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

94 95 96
					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 已提交
97 98 99 100
					});
				}
		}

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

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

110
export class JoinTwoGroupsAction extends Action {
I
initialshl 已提交
111

M
Matt Bierner 已提交
112 113
	public static readonly ID = 'workbench.action.joinTwoGroups';
	public static readonly LABEL = nls.localize('joinTwoGroups', "Join Editors of Two Groups");
I
initialshl 已提交
114 115 116 117 118 119

	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService
	) {
120
		super(id, label);
I
initialshl 已提交
121 122
	}

123
	public run(context?: IEditorIdentifier): TPromise<any> {
I
initialshl 已提交
124

125
		const editorStacksModel = this.editorGroupService.getStacksModel();
I
initialshl 已提交
126 127

		// Return if has no other group to join to
128
		if (editorStacksModel.groups.length < 2) {
I
initialshl 已提交
129 130 131
			return TPromise.as(true);
		}

132 133 134 135 136 137 138 139 140
		let fromPosition: number;
		let toPosition: number;

		// Joining group is from context, or the active group
		if (context) {
			fromPosition = editorStacksModel.positionOfGroup(context.group);
		} else {
			fromPosition = editorStacksModel.positionOfGroup(editorStacksModel.activeGroup);
		}
I
initialshl 已提交
141

142 143 144
		// Target group is next group if joining from position one, otherwise it is the previous group
		if (fromPosition === Position.ONE) {
			toPosition = fromPosition + 1;
I
initialshl 已提交
145
		} else {
146
			toPosition = fromPosition - 1;
I
initialshl 已提交
147 148
		}

149 150
		const fromGroup = editorStacksModel.groupAt(fromPosition);
		const toGroup = editorStacksModel.groupAt(toPosition);
I
initialshl 已提交
151

152 153
		const activeEditor = fromGroup.activeEditor;
		const fromGroupEditors = fromGroup.getEditors();
I
initialshl 已提交
154

155 156 157 158 159 160 161 162 163 164 165
		// Insert the editors to the start if moving to the next group, otherwise insert to the end
		// If an editor exists in both groups, its index is respected as in the joining group
		const movingToNextGroup = fromPosition < toPosition;
		let index = movingToNextGroup ? 0 : toGroup.count;

		// Inactive and preserve focus options are used to prevent unnecessary switchings of active editor or group
		fromGroupEditors.forEach(e => {
			const inactive = e !== activeEditor;
			this.editorGroupService.moveEditor(e, fromPosition, toPosition, { index, inactive, preserveFocus: inactive });
			index = movingToNextGroup ? index + 1 : toGroup.count;
		});
I
initialshl 已提交
166

167 168
		// Focus may be lost when the joining group is closed, regain focus on the target group
		this.editorGroupService.focusGroup(toGroup);
I
initialshl 已提交
169 170 171 172 173

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
174
export class NavigateBetweenGroupsAction extends Action {
175

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

179 180 181 182 183 184
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private editorGroupService: IEditorGroupService
	) {
E
Erich Gamma 已提交
185 186 187
		super(id, label);
	}

188
	public run(): TPromise<any> {
E
Erich Gamma 已提交
189 190

		// Can cycle split with active editor
191
		const activeEditor = this.editorService.getActiveEditor();
E
Erich Gamma 已提交
192
		if (!activeEditor) {
A
Alex Dima 已提交
193
			return TPromise.as(false);
E
Erich Gamma 已提交
194 195
		}

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

201
		this.editorGroupService.focusGroup(<Position>newIndex);
202 203

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

207 208
export class FocusActiveGroupAction extends Action {

M
Matt Bierner 已提交
209 210
	public static readonly ID = 'workbench.action.focusActiveEditorGroup';
	public static readonly LABEL = nls.localize('focusActiveEditorGroup', "Focus Active Editor Group");
211 212 213 214 215 216 217 218 219 220

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

	public run(): TPromise<any> {
B
hygiene  
Benjamin Pasero 已提交
221 222
		const activeEditor = this.editorService.getActiveEditor();
		if (activeEditor) {
D
Daniel Imms 已提交
223
			activeEditor.focus();
B
hygiene  
Benjamin Pasero 已提交
224
		}
D
Daniel Imms 已提交
225

226
		return TPromise.as(true);
E
Erich Gamma 已提交
227 228 229
	}
}

230 231
export class FocusFirstGroupAction extends Action {

M
Matt Bierner 已提交
232 233
	public static readonly ID = 'workbench.action.focusFirstEditorGroup';
	public static readonly LABEL = nls.localize('focusFirstEditorGroup', "Focus First Editor Group");
E
Erich Gamma 已提交
234 235 236 237 238

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
239
		@IEditorGroupService private editorGroupService: IEditorGroupService,
240
		@IHistoryService private historyService: IHistoryService
E
Erich Gamma 已提交
241 242 243 244
	) {
		super(id, label);
	}

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

B
Benjamin Pasero 已提交
247
		// Find left/top editor and focus it
248
		const editors = this.editorService.getVisibleEditors();
B
Benjamin Pasero 已提交
249
		for (let editor of editors) {
250 251
			if (editor.position === Position.ONE) {
				this.editorGroupService.focusGroup(Position.ONE);
252 253

				return TPromise.as(true);
E
Erich Gamma 已提交
254 255 256 257
			}
		}

		// Since no editor is currently opened, try to open last history entry to the target side
258
		const history = this.historyService.getHistory();
259 260
		if (history.length > 0) {
			const input = history[0];
261
			if (input instanceof EditorInput) {
262
				return this.editorService.openEditor(input, null, Position.ONE);
E
Erich Gamma 已提交
263
			}
264 265

			return this.editorService.openEditor(input as IResourceInput, Position.ONE);
E
Erich Gamma 已提交
266 267
		}

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

272
export abstract class BaseFocusSideGroupAction extends Action {
E
Erich Gamma 已提交
273 274 275 276 277

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
278
		@IEditorGroupService private editorGroupService: IEditorGroupService,
279
		@IHistoryService private historyService: IHistoryService
E
Erich Gamma 已提交
280 281 282 283 284 285 286 287
	) {
		super(id, label);
	}

	protected abstract getReferenceEditorSide(): Position;

	protected abstract getTargetEditorSide(): Position;

288
	public run(): TPromise<any> {
E
Erich Gamma 已提交
289 290

		// Require at least the reference editor to be visible
291
		const editors = this.editorService.getVisibleEditors();
E
Erich Gamma 已提交
292 293
		let referenceEditor: IEditor;
		for (let i = 0; i < editors.length; i++) {
294
			const editor = editors[i];
E
Erich Gamma 已提交
295 296 297

			// Target editor exists so focus it
			if (editor.position === this.getTargetEditorSide()) {
298
				this.editorGroupService.focusGroup(editor.position);
299 300

				return TPromise.as(true);
E
Erich Gamma 已提交
301 302 303 304 305 306 307 308 309
			}

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

		// Require the reference editor to be visible and supporting split editor
310
		if (referenceEditor && (<EditorInput>referenceEditor.input).supportsSplitEditor()) {
311 312 313

			// Options
			let options: EditorOptions;
S
Sandeep Somavarapu 已提交
314 315
			const codeEditor = getCodeEditor(referenceEditor);
			if (codeEditor) {
316
				options = TextEditorOptions.fromEditor(codeEditor, { pinned: true });
317 318
			} else {
				options = EditorOptions.create({ pinned: true });
319 320 321
			}

			return this.editorService.openEditor(referenceEditor.input, options, this.getTargetEditorSide());
E
Erich Gamma 已提交
322 323 324 325
		}

		// Otherwise try to find a history entry to open to the target editor side
		else if (referenceEditor) {
326
			const history = this.historyService.getHistory();
B
Benjamin Pasero 已提交
327
			for (let input of history) {
B
Benjamin Pasero 已提交
328 329 330 331 332 333
				if (input instanceof EditorInput) {
					if (input.supportsSplitEditor()) {
						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 已提交
334 335 336 337
				}
			}
		}

A
Alex Dima 已提交
338
		return TPromise.as(true);
E
Erich Gamma 已提交
339 340 341
	}
}

342 343
export class FocusSecondGroupAction extends BaseFocusSideGroupAction {

M
Matt Bierner 已提交
344 345
	public static readonly ID = 'workbench.action.focusSecondEditorGroup';
	public static readonly LABEL = nls.localize('focusSecondEditorGroup', "Focus Second Editor Group");
E
Erich Gamma 已提交
346 347 348 349 350

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService,
351
		@IEditorGroupService editorGroupService: IEditorGroupService,
352
		@IHistoryService historyService: IHistoryService
E
Erich Gamma 已提交
353
	) {
354
		super(id, label, editorService, editorGroupService, historyService);
E
Erich Gamma 已提交
355 356 357
	}

	protected getReferenceEditorSide(): Position {
358
		return Position.ONE;
E
Erich Gamma 已提交
359 360 361
	}

	protected getTargetEditorSide(): Position {
362
		return Position.TWO;
E
Erich Gamma 已提交
363 364 365
	}
}

366 367
export class FocusThirdGroupAction extends BaseFocusSideGroupAction {

M
Matt Bierner 已提交
368 369
	public static readonly ID = 'workbench.action.focusThirdEditorGroup';
	public static readonly LABEL = nls.localize('focusThirdEditorGroup', "Focus Third Editor Group");
E
Erich Gamma 已提交
370 371 372 373 374

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService,
375
		@IEditorGroupService editorGroupService: IEditorGroupService,
376
		@IHistoryService historyService: IHistoryService
E
Erich Gamma 已提交
377
	) {
378
		super(id, label, editorService, editorGroupService, historyService);
E
Erich Gamma 已提交
379 380 381
	}

	protected getReferenceEditorSide(): Position {
382
		return Position.TWO;
E
Erich Gamma 已提交
383 384 385
	}

	protected getTargetEditorSide(): Position {
386
		return Position.THREE;
E
Erich Gamma 已提交
387 388 389
	}
}

B
Benjamin Pasero 已提交
390
export class FocusPreviousGroup extends Action {
391

M
Matt Bierner 已提交
392 393
	public static readonly ID = 'workbench.action.focusPreviousGroup';
	public static readonly LABEL = nls.localize('focusPreviousGroup', "Focus Previous Group");
E
Erich Gamma 已提交
394

395 396 397 398 399 400
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
401 402 403
		super(id, label);
	}

404
	public run(): TPromise<any> {
E
Erich Gamma 已提交
405 406

		// Require an active editor
407
		const activeEditor = this.editorService.getActiveEditor();
E
Erich Gamma 已提交
408
		if (!activeEditor) {
A
Alex Dima 已提交
409
			return TPromise.as(true);
E
Erich Gamma 已提交
410 411
		}

412 413
		const stacks = this.editorGroupService.getStacksModel();
		const groupCount = stacks.groups.length;
E
Erich Gamma 已提交
414

415 416 417
		// Nothing to do if the only group
		if (groupCount === 1) {
			return TPromise.as(true);
E
Erich Gamma 已提交
418 419
		}

420 421 422
		// Nevigate to the previous group or to the last group if the first group is active
		const newPositionIndex = (activeEditor.position + groupCount - 1) % groupCount;
		this.editorGroupService.focusGroup(<Position>newPositionIndex);
423 424

		return TPromise.as(true);
E
Erich Gamma 已提交
425 426 427
	}
}

B
Benjamin Pasero 已提交
428
export class FocusNextGroup extends Action {
429

M
Matt Bierner 已提交
430 431
	public static readonly ID = 'workbench.action.focusNextGroup';
	public static readonly LABEL = nls.localize('focusNextGroup', "Focus Next Group");
432

E
Erich Gamma 已提交
433 434 435
	constructor(
		id: string,
		label: string,
436 437
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
E
Erich Gamma 已提交
438 439 440 441
	) {
		super(id, label);
	}

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

444
		const activeEditor = this.editorService.getActiveEditor();
445

446 447
		if (!activeEditor) {
			return TPromise.as(true);
E
Erich Gamma 已提交
448 449
		}

450 451 452 453 454 455
		const stacks = this.editorGroupService.getStacksModel();
		const groupCount = stacks.groups.length;

		// Nowhere to switch if the only group
		if (groupCount === 1) {
			return TPromise.as(true);
E
Erich Gamma 已提交
456 457
		}

458 459 460 461
		// Nevigate to the next group or to the first group if the last group is active
		const newPositionIndex = (activeEditor.position + 1) % groupCount;
		this.editorGroupService.focusGroup(<Position>newPositionIndex);

A
Alex Dima 已提交
462
		return TPromise.as(true);
E
Erich Gamma 已提交
463 464 465 466 467
	}
}

export class OpenToSideAction extends Action {

M
Matt Bierner 已提交
468 469
	public static readonly OPEN_TO_SIDE_ID = 'workbench.action.openToSide';
	public static readonly OPEN_TO_SIDE_LABEL = nls.localize('openToSide', "Open to the Side");
E
Erich Gamma 已提交
470

471 472
	constructor(
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
473
		@IEditorGroupService private editorGroupService: IEditorGroupService
474
	) {
E
Erich Gamma 已提交
475 476 477
		super(OpenToSideAction.OPEN_TO_SIDE_ID, OpenToSideAction.OPEN_TO_SIDE_LABEL);

		this.updateEnablement();
478 479 480 481
		this.updateClass();
	}

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

484
		this.class = editorGroupLayoutVertical ? 'quick-open-sidebyside-vertical' : 'quick-open-sidebyside-horizontal';
E
Erich Gamma 已提交
485 486 487
	}

	private updateEnablement(): void {
488
		const activeEditor = this.editorService.getActiveEditor();
489
		this.enabled = (!activeEditor || activeEditor.position !== Position.THREE);
E
Erich Gamma 已提交
490 491
	}

492
	public run(context: any): TPromise<any> {
E
Erich Gamma 已提交
493 494
		let entry = toEditorQuickOpenEntry(context);
		if (entry) {
495
			const input = entry.getInput();
B
Benjamin Pasero 已提交
496
			if (input instanceof EditorInput) {
497
				return this.editorService.openEditor(input, entry.getOptions(), true);
B
Benjamin Pasero 已提交
498 499
			}

500 501 502 503
			const resourceInput = input as IResourceInput;
			resourceInput.options = mixin(resourceInput.options, entry.getOptions());

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

A
Alex Dima 已提交
506
		return TPromise.as(false);
E
Erich Gamma 已提交
507 508 509
	}
}

510
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
511 512 513

	// QuickOpenEntryGroup
	if (element instanceof QuickOpenEntryGroup) {
514
		const group = <QuickOpenEntryGroup>element;
E
Erich Gamma 已提交
515 516 517 518 519 520 521 522 523 524 525 526 527 528
		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 {
529

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

533 534 535
	constructor(
		id: string,
		label: string,
I
isidor 已提交
536
		@ICommandService private commandService: ICommandService
537
	) {
I
isidor 已提交
538
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
539 540
	}

I
isidor 已提交
541
	public run(context?: IEditorCommandsContext): TPromise<any> {
542
		return this.commandService.executeCommand(CLOSE_EDITOR_COMMAND_ID, void 0, context);
E
Erich Gamma 已提交
543 544 545
	}
}

M
misoguy 已提交
546 547
export class RevertAndCloseEditorAction extends Action {

M
Matt Bierner 已提交
548 549
	public static readonly ID = 'workbench.action.revertAndCloseActiveEditor';
	public static readonly LABEL = nls.localize('revertAndCloseActiveEditor', "Revert and Close Editor");
M
misoguy 已提交
550 551 552 553 554 555 556 557 558 559 560

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

	public run(): TPromise<any> {
		const activeEditor = this.editorService.getActiveEditor();
B
Benjamin Pasero 已提交
561 562 563 564
		if (activeEditor && activeEditor.input) {
			const input = activeEditor.input;
			const position = activeEditor.position;

565 566 567 568 569 570 571 572
			// first try a normal revert where the contents of the editor are restored
			return activeEditor.input.revert().then(() => this.editorService.closeEditor(position, input), error => {
				// if that fails, since we are about to close the editor, we accept that
				// the editor cannot be reverted and instead do a soft revert that just
				// enables us to close the editor. With this, a user can always close a
				// dirty editor even when reverting fails.
				return activeEditor.input.revert({ soft: true }).then(() => this.editorService.closeEditor(position, input));
			});
M
misoguy 已提交
573 574 575 576 577 578
		}

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
579
export class CloseLeftEditorsInGroupAction extends Action {
580

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

584 585 586
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
587 588
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private groupService: IEditorGroupService
589
	) {
590 591 592
		super(id, label);
	}

593
	public run(context?: IEditorIdentifier): TPromise<any> {
594
		const editor = getTarget(this.editorService, this.groupService, context);
B
Benjamin Pasero 已提交
595
		if (editor) {
B
Benjamin Pasero 已提交
596
			return this.editorService.closeEditors(editor.position, { except: editor.input, direction: Direction.LEFT });
597 598 599 600 601 602
		}

		return TPromise.as(false);
	}
}

E
Erich Gamma 已提交
603 604
export class CloseAllEditorsAction extends Action {

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

608 609 610 611 612 613
	constructor(
		id: string,
		label: string,
		@ITextFileService private textFileService: ITextFileService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
I
isidor 已提交
614
		super(id, label, 'action-close-all-files');
E
Erich Gamma 已提交
615 616
	}

617
	public run(): TPromise<any> {
618 619 620

		// Just close all if there are no or one dirty editor
		if (this.textFileService.getDirty().length < 2) {
B
Benjamin Pasero 已提交
621
			return this.editorService.closeEditors();
622 623 624
		}

		// Otherwise ask for combined confirmation
625 626 627 628
		return this.textFileService.confirmSave().then(confirm => {
			if (confirm === ConfirmResult.CANCEL) {
				return void 0;
			}
629

630 631 632 633 634
			let saveOrRevertPromise: TPromise<boolean>;
			if (confirm === ConfirmResult.DONT_SAVE) {
				saveOrRevertPromise = this.textFileService.revertAll(null, { soft: true }).then(() => true);
			} else {
				saveOrRevertPromise = this.textFileService.saveAll(true).then(res => res.results.every(r => r.success));
635
			}
636

637 638
			return saveOrRevertPromise.then(success => {
				if (success) {
B
Benjamin Pasero 已提交
639
					return this.editorService.closeEditors();
640 641 642 643
				}

				return void 0;
			});
644
		});
E
Erich Gamma 已提交
645 646 647
	}
}

648 649
export class CloseEditorsInOtherGroupsAction extends Action {

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

653 654 655 656 657 658
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
659 660 661
		super(id, label);
	}

662
	public run(context?: IEditorIdentifier): TPromise<any> {
663
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
664
		if (typeof position !== 'number') {
665
			const activeEditor = this.editorService.getActiveEditor();
666 667 668 669 670 671
			if (activeEditor) {
				position = activeEditor.position;
			}
		}

		if (typeof position === 'number') {
B
Benjamin Pasero 已提交
672
			return this.editorService.closeEditors(POSITIONS.filter(p => p !== position));
673 674 675 676 677 678
		}

		return TPromise.as(false);
	}
}

B
Benjamin Pasero 已提交
679
export class MoveGroupLeftAction extends Action {
E
Erich Gamma 已提交
680

M
Matt Bierner 已提交
681 682
	public static readonly ID = 'workbench.action.moveActiveEditorGroupLeft';
	public static readonly LABEL = nls.localize('moveActiveGroupLeft', "Move Editor Group Left");
683

684 685 686 687 688 689
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
690 691 692
		super(id, label);
	}

693
	public run(context?: IEditorIdentifier): TPromise<any> {
694
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
695
		if (typeof position !== 'number') {
696
			const activeEditor = this.editorService.getActiveEditor();
697
			if (activeEditor && (activeEditor.position === Position.TWO || activeEditor.position === Position.THREE)) {
698 699 700 701 702
				position = activeEditor.position;
			}
		}

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

B
Benjamin Pasero 已提交
705
			// Move group
706
			this.editorGroupService.moveGroup(position, newPosition);
E
Erich Gamma 已提交
707 708
		}

A
Alex Dima 已提交
709
		return TPromise.as(false);
E
Erich Gamma 已提交
710 711 712
	}
}

B
Benjamin Pasero 已提交
713
export class MoveGroupRightAction extends Action {
E
Erich Gamma 已提交
714

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

718 719 720 721 722 723
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
724 725 726
		super(id, label);
	}

727
	public run(context?: IEditorIdentifier): TPromise<any> {
728
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
729
		if (typeof position !== 'number') {
730 731
			const activeEditor = this.editorService.getActiveEditor();
			const editors = this.editorService.getVisibleEditors();
732

733
			if ((editors.length === 2 && activeEditor.position === Position.ONE) || (editors.length === 3 && activeEditor.position !== Position.THREE)) {
734 735 736 737 738
				position = activeEditor.position;
			}
		}

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

B
Benjamin Pasero 已提交
741
			// Move group
742
			this.editorGroupService.moveGroup(position, newPosition);
E
Erich Gamma 已提交
743 744
		}

A
Alex Dima 已提交
745
		return TPromise.as(false);
E
Erich Gamma 已提交
746 747 748
	}
}

749
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
750

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

754
	constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
E
Erich Gamma 已提交
755 756 757
		super(id, label);
	}

758
	public run(): TPromise<any> {
759
		this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
760

A
Alex Dima 已提交
761
		return TPromise.as(false);
E
Erich Gamma 已提交
762 763 764
	}
}

765
export class EvenGroupWidthsAction extends Action {
E
Erich Gamma 已提交
766

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

770
	constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
E
Erich Gamma 已提交
771 772 773
		super(id, label);
	}

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

A
Alex Dima 已提交
777
		return TPromise.as(false);
E
Erich Gamma 已提交
778 779 780
	}
}

781
export class MaximizeGroupAction extends Action {
782

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

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

796
	public run(): TPromise<any> {
797
		if (this.editorService.getActiveEditor()) {
798
			this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
799
			return this.partService.setSideBarHidden(true);
800 801
		}

A
Alex Dima 已提交
802
		return TPromise.as(false);
803 804 805
	}
}

806
function getTarget(editorService: IWorkbenchEditorService, editorGroupService: IEditorGroupService, context?: IEditorIdentifier): { input: IEditorInput, position: Position } {
B
Benjamin Pasero 已提交
807 808 809 810 811 812 813 814 815 816 817 818
	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;
}

819 820
export abstract class BaseNavigateEditorAction extends Action {

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

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

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

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

	protected navigate(): IEditorIdentifier {
858
		return this.editorGroupService.getStacksModel().next(true /* jump groups */);
859 860 861 862 863
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

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

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

	protected navigate(): IEditorIdentifier {
877 878 879 880 881 882
		return this.editorGroupService.getStacksModel().previous(true /* jump groups */);
	}
}

export class OpenNextEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
883 884
	public static readonly ID = 'workbench.action.nextEditorInGroup';
	public static readonly LABEL = nls.localize('nextEditorInGroup', "Open Next Editor in Group");
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901

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

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

export class OpenPreviousEditorInGroup extends BaseNavigateEditorAction {

M
Matt Bierner 已提交
902 903
	public static readonly ID = 'workbench.action.previousEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousEditorInGroup', "Open Previous Editor in Group");
904 905 906 907 908 909 910 911 912 913 914 915

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

	protected navigate(): IEditorIdentifier {
		return this.editorGroupService.getStacksModel().previous(false /* do NOT jump groups */);
916
	}
B
Benjamin Pasero 已提交
917 918
}

919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937
export class OpenLastEditorInGroup extends BaseNavigateEditorAction {

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

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

	protected navigate(): IEditorIdentifier {
		return this.editorGroupService.getStacksModel().last();
	}
}

B
Benjamin Pasero 已提交
938 939
export class NavigateForwardAction extends Action {

M
Matt Bierner 已提交
940 941
	public static readonly ID = 'workbench.action.navigateForward';
	public static readonly LABEL = nls.localize('navigateNext', "Go Forward");
B
Benjamin Pasero 已提交
942 943 944 945 946 947 948 949 950 951 952 953 954 955

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

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

		return TPromise.as(null);
	}
}

export class NavigateBackwardsAction extends Action {

M
Matt Bierner 已提交
956 957
	public static readonly ID = 'workbench.action.navigateBack';
	public static readonly LABEL = nls.localize('navigatePrevious', "Go Back");
B
Benjamin Pasero 已提交
958 959 960 961 962 963 964 965 966 967

	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 已提交
968
}
969

970 971
export class NavigateLastAction extends Action {

M
Matt Bierner 已提交
972 973
	public static readonly ID = 'workbench.action.navigateLast';
	public static readonly LABEL = nls.localize('navigateLast', "Go Last");
974 975 976 977 978 979 980 981 982 983 984 985

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

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

		return TPromise.as(null);
	}
}

986 987
export class ReopenClosedEditorAction extends Action {

M
Matt Bierner 已提交
988 989
	public static readonly ID = 'workbench.action.reopenClosedEditor';
	public static readonly LABEL = nls.localize('reopenClosedEditor', "Reopen Closed Editor");
990 991 992 993

	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
994
		@IHistoryService private historyService: IHistoryService
995 996 997 998 999
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
1000
		this.historyService.reopenLastClosedEditor();
1001 1002 1003

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
1004 1005
}

1006
export class ClearRecentFilesAction extends Action {
C
22768  
Cristian 已提交
1007

M
Matt Bierner 已提交
1008 1009
	public static readonly ID = 'workbench.action.clearRecentFiles';
	public static readonly LABEL = nls.localize('clearRecentFiles', "Clear Recently Opened");
C
22768  
Cristian 已提交
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019

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

	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
1020
		this.windowsService.clearRecentlyOpened();
C
22768  
Cristian 已提交
1021 1022 1023 1024 1025

		return TPromise.as(false);
	}
}

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

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

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

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

1042
export class ShowEditorsInGroupTwoAction extends QuickOpenAction {
1043

M
Matt Bierner 已提交
1044 1045
	public static readonly ID = 'workbench.action.showEditorsInSecondGroup';
	public static readonly LABEL = nls.localize('showEditorsInSecondGroup', "Show Editors in Second Group");
1046 1047 1048 1049

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

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

1058
export class ShowEditorsInGroupThreeAction extends QuickOpenAction {
1059

M
Matt Bierner 已提交
1060 1061
	public static readonly ID = 'workbench.action.showEditorsInThirdGroup';
	public static readonly LABEL = nls.localize('showEditorsInThirdGroup', "Show Editors in Third Group");
1062 1063 1064 1065

	constructor(
		actionId: string,
		actionLabel: string,
1066
		@IQuickOpenService quickOpenService: IQuickOpenService
1067
	) {
1068
		super(actionId, actionLabel, NAVIGATE_IN_GROUP_THREE_PREFIX, quickOpenService);
1069 1070

		this.class = 'show-group-editors-action';
1071
	}
B
Benjamin Pasero 已提交
1072 1073
}

B
Benjamin Pasero 已提交
1074 1075
export class ShowAllEditorsAction extends QuickOpenAction {

M
Matt Bierner 已提交
1076 1077
	public static readonly ID = 'workbench.action.showAllEditors';
	public static readonly LABEL = nls.localize('showAllEditors', "Show All Editors");
B
Benjamin Pasero 已提交
1078 1079 1080 1081 1082 1083

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

1084
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1085 1086 1087 1088 1089

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
1090
		@IKeybindingService private keybindingService: IKeybindingService,
1091
		@IEditorGroupService private editorGroupService: IEditorGroupService
B
Benjamin Pasero 已提交
1092 1093 1094 1095 1096
	) {
		super(id, label);
	}

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

1099
		const stacks = this.editorGroupService.getStacksModel();
1100 1101
		if (stacks.activeGroup) {
			const activePosition = stacks.positionOfGroup(stacks.activeGroup);
1102
			let prefix = NAVIGATE_IN_GROUP_ONE_PREFIX;
1103

B
Benjamin Pasero 已提交
1104
			if (activePosition === Position.TWO) {
1105
				prefix = NAVIGATE_IN_GROUP_TWO_PREFIX;
B
Benjamin Pasero 已提交
1106
			} else if (activePosition === Position.THREE) {
1107
				prefix = NAVIGATE_IN_GROUP_THREE_PREFIX;
1108 1109
			}

B
Benjamin Pasero 已提交
1110
			this.quickOpenService.show(prefix, { quickNavigateConfiguration: { keybindings: keys } });
1111
		}
B
Benjamin Pasero 已提交
1112 1113 1114 1115 1116

		return TPromise.as(true);
	}
}

1117 1118
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1119 1120
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditorInGroup', "Open Previous Recently Used Editor in Group");
1121 1122 1123 1124 1125 1126

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IKeybindingService keybindingService: IKeybindingService,
1127
		@IEditorGroupService editorGroupService: IEditorGroupService
1128
	) {
1129
		super(id, label, quickOpenService, keybindingService, editorGroupService);
1130 1131 1132 1133 1134
	}
}

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

M
Matt Bierner 已提交
1135 1136
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditorInGroup';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditorInGroup', "Open Next Recently Used Editor in Group");
1137 1138 1139 1140 1141 1142

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IKeybindingService keybindingService: IKeybindingService,
1143
		@IEditorGroupService editorGroupService: IEditorGroupService
1144
	) {
1145
		super(id, label, quickOpenService, keybindingService, editorGroupService);
1146 1147 1148
	}
}

1149
export class OpenPreviousEditorFromHistoryAction extends Action {
B
Benjamin Pasero 已提交
1150

M
Matt Bierner 已提交
1151 1152
	public static readonly ID = 'workbench.action.openPreviousEditorFromHistory';
	public static readonly LABEL = nls.localize('navigateEditorHistoryByInput', "Open Previous Editor from History");
B
Benjamin Pasero 已提交
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163

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

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

B
Benjamin Pasero 已提交
1166
		this.quickOpenService.show(null, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1167 1168 1169 1170 1171

		return TPromise.as(true);
	}
}

1172 1173
export class OpenNextRecentlyUsedEditorAction extends Action {

M
Matt Bierner 已提交
1174 1175
	public static readonly ID = 'workbench.action.openNextRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openNextRecentlyUsedEditor', "Open Next Recently Used Editor");
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189

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

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

		return TPromise.as(null);
	}
}

export class OpenPreviousRecentlyUsedEditorAction extends Action {

M
Matt Bierner 已提交
1190 1191
	public static readonly ID = 'workbench.action.openPreviousRecentlyUsedEditor';
	public static readonly LABEL = nls.localize('openPreviousRecentlyUsedEditor', "Open Previous Recently Used Editor");
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203

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

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

		return TPromise.as(null);
	}
}

1204 1205
export class ClearEditorHistoryAction extends Action {

M
Matt Bierner 已提交
1206 1207
	public static readonly ID = 'workbench.action.clearEditorHistory';
	public static readonly LABEL = nls.localize('clearEditorHistory', "Clear Editor History");
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218

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

	public run(): TPromise<any> {

1219
		// Editor history
1220 1221 1222 1223 1224 1225
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1226 1227
export class FocusLastEditorInStackAction extends Action {

M
Matt Bierner 已提交
1228 1229
	public static readonly ID = 'workbench.action.openLastEditorInGroup';
	public static readonly LABEL = nls.localize('focusLastEditorInStack', "Open Last Editor in Group");
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250

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

1251 1252 1253 1254
		return TPromise.as(true);
	}
}

1255 1256
export class MoveEditorLeftInGroupAction extends Action {

M
Matt Bierner 已提交
1257 1258
	public static readonly ID = 'workbench.action.moveEditorLeftInGroup';
	public static readonly LABEL = nls.localize('moveEditorLeft', "Move Editor Left");
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269

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

	public run(): TPromise<any> {
		const args: ActiveEditorMoveArguments = {
1270
			to: ActiveEditorMovePositioning.LEFT
1271 1272 1273 1274 1275 1276 1277 1278 1279
		};
		this.commandService.executeCommand(EditorCommands.MoveActiveEditor, args);

		return TPromise.as(true);
	}
}

export class MoveEditorRightInGroupAction extends Action {

M
Matt Bierner 已提交
1280 1281
	public static readonly ID = 'workbench.action.moveEditorRightInGroup';
	public static readonly LABEL = nls.localize('moveEditorRight', "Move Editor Right");
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292

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

	public run(): TPromise<any> {
		const args: ActiveEditorMoveArguments = {
1293
			to: ActiveEditorMovePositioning.RIGHT
1294 1295 1296 1297 1298 1299 1300
		};
		this.commandService.executeCommand(EditorCommands.MoveActiveEditor, args);

		return TPromise.as(true);
	}
}

1301
export class MoveEditorToPreviousGroupAction extends Action {
1302

M
Matt Bierner 已提交
1303 1304
	public static readonly ID = 'workbench.action.moveEditorToPreviousGroup';
	public static readonly LABEL = nls.localize('moveEditorToPreviousGroup', "Move Editor into Previous Group");
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316

	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();
1317
		if (activeEditor && activeEditor.position !== Position.ONE) {
1318 1319 1320 1321 1322 1323 1324
			this.editorGroupService.moveEditor(activeEditor.input, activeEditor.position, activeEditor.position - 1);
		}

		return TPromise.as(true);
	}
}

1325
export class MoveEditorToNextGroupAction extends Action {
1326

M
Matt Bierner 已提交
1327 1328
	public static readonly ID = 'workbench.action.moveEditorToNextGroup';
	public static readonly LABEL = nls.localize('moveEditorToNextGroup', "Move Editor into Next Group");
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340

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

1345 1346
		return TPromise.as(true);
	}
D
Daniel Imms 已提交
1347
}
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413

export abstract class MoveEditorToSpecificGroup extends Action {

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

	public run(): TPromise<any> {
		const activeEditor = this.editorService.getActiveEditor();
		if (activeEditor && activeEditor.position !== this.position) {
			this.editorGroupService.moveEditor(activeEditor.input, activeEditor.position, this.position);
		}

		return TPromise.as(true);
	}
}

export class MoveEditorToFirstGroupAction extends MoveEditorToSpecificGroup {

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

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

export class MoveEditorToSecondGroupAction extends MoveEditorToSpecificGroup {

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

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

export class MoveEditorToThirdGroupAction extends MoveEditorToSpecificGroup {

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

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