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';

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

export class SplitEditorAction extends Action {

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

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

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

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

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

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

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

		switch (editorCount) {

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

			// Special case two editors opened
			case 2:

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

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

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

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

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

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

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

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

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

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

		// Cycle to the left and use module to start at 0 again
		let visibleEditors = this.editorService.getVisibleEditors();
		let editorCount = visibleEditors.length;
		let newIndex = (activeEditor.position + 1) % editorCount;

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

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

138 139
export class FocusFirstGroupAction extends Action {

B
Benjamin Pasero 已提交
140
	public static ID = 'workbench.action.focusFirstEditorGroup';
B
Benjamin Pasero 已提交
141
	public static LABEL = nls.localize('focusFirstEditorGroup', "Focus Left Editor Group");
E
Erich Gamma 已提交
142 143 144 145 146

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
147
		@IEditorGroupService private editorGroupService: IEditorGroupService,
148
		@IHistoryService private historyService: IHistoryService
E
Erich Gamma 已提交
149 150 151 152
	) {
		super(id, label);
	}

153
	public run(): TPromise<any> {
E
Erich Gamma 已提交
154 155 156

		// Find left editor and focus it
		let editors = this.editorService.getVisibleEditors();
B
Benjamin Pasero 已提交
157
		for (let editor of editors) {
E
Erich Gamma 已提交
158
			if (editor.position === Position.LEFT) {
159
				this.editorGroupService.focusGroup(Position.LEFT);
160 161

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

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

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

A
Alex Dima 已提交
175
		return TPromise.as(true);
E
Erich Gamma 已提交
176 177 178
	}
}

179
export abstract class BaseFocusSideGroupAction extends Action {
E
Erich Gamma 已提交
180 181 182 183 184

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
185
		@IEditorGroupService private editorGroupService: IEditorGroupService,
186
		@IHistoryService private historyService: IHistoryService
E
Erich Gamma 已提交
187 188 189 190 191 192 193 194
	) {
		super(id, label);
	}

	protected abstract getReferenceEditorSide(): Position;

	protected abstract getTargetEditorSide(): Position;

195
	public run(): TPromise<any> {
E
Erich Gamma 已提交
196 197 198 199 200 201 202 203 204

		// Require at least the reference editor to be visible
		let editors = this.editorService.getVisibleEditors();
		let referenceEditor: IEditor;
		for (let i = 0; i < editors.length; i++) {
			let editor = editors[i];

			// Target editor exists so focus it
			if (editor.position === this.getTargetEditorSide()) {
205
				this.editorGroupService.focusGroup(editor.position);
206 207

				return TPromise.as(true);
E
Erich Gamma 已提交
208 209 210 211 212 213 214 215 216
			}

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

		// Require the reference editor to be visible and supporting split editor
217
		if (referenceEditor && (<EditorInput>referenceEditor.input).supportsSplitEditor()) {
218 219 220 221 222

			// Options
			let options: EditorOptions;
			if (referenceEditor instanceof BaseTextEditor) {
				options = new TextEditorOptions();
223
				options.pinned = true;
224
				(<TextEditorOptions>options).viewState(referenceEditor.getControl().saveViewState());
225 226
			} else {
				options = EditorOptions.create({ pinned: true });
227 228 229
			}

			return this.editorService.openEditor(referenceEditor.input, options, this.getTargetEditorSide());
E
Erich Gamma 已提交
230 231 232 233
		}

		// Otherwise try to find a history entry to open to the target editor side
		else if (referenceEditor) {
234
			let history = this.historyService.getHistory();
B
Benjamin Pasero 已提交
235
			for (let input of history) {
E
Erich Gamma 已提交
236 237 238

				// For now only support to open files from history to the side
				if (!!getUntitledOrFileResource(input)) {
239
					return this.editorService.openEditor(input, { pinned: true }, this.getTargetEditorSide());
E
Erich Gamma 已提交
240 241 242 243
				}
			}
		}

A
Alex Dima 已提交
244
		return TPromise.as(true);
E
Erich Gamma 已提交
245 246 247
	}
}

248 249
export class FocusSecondGroupAction extends BaseFocusSideGroupAction {

B
Benjamin Pasero 已提交
250
	public static ID = 'workbench.action.focusSecondEditorGroup';
B
Benjamin Pasero 已提交
251
	public static LABEL = nls.localize('focusSecondEditorGroup', "Focus Center Editor Group");
E
Erich Gamma 已提交
252 253 254 255 256

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService,
257
		@IEditorGroupService editorGroupService: IEditorGroupService,
258
		@IHistoryService historyService: IHistoryService
E
Erich Gamma 已提交
259
	) {
260
		super(id, label, editorService, editorGroupService, historyService);
E
Erich Gamma 已提交
261 262 263 264 265 266 267 268 269 270 271
	}

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

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

272 273
export class FocusThirdGroupAction extends BaseFocusSideGroupAction {

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

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

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

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

B
Benjamin Pasero 已提交
296
export class FocusPreviousGroup extends Action {
297

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

301 302 303 304 305 306
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
307 308 309
		super(id, label);
	}

310
	public run(): TPromise<any> {
E
Erich Gamma 已提交
311 312 313 314

		// Require an active editor
		let activeEditor = this.editorService.getActiveEditor();
		if (!activeEditor) {
A
Alex Dima 已提交
315
			return TPromise.as(true);
E
Erich Gamma 已提交
316 317 318 319 320 321 322 323 324 325
		}


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

		// Focus next position if provided
326
		this.editorGroupService.focusGroup(nextPosition);
327 328

		return TPromise.as(true);
E
Erich Gamma 已提交
329 330 331
	}
}

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

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

E
Erich Gamma 已提交
337 338 339 340 341 342 343 344 345 346 347
	private navigateActions: Action[];

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

		this.navigateActions = [];
348 349 350
		this.navigateActions[Position.LEFT] = instantiationService.createInstance(FocusFirstGroupAction, FocusFirstGroupAction.ID, FocusFirstGroupAction.LABEL);
		this.navigateActions[Position.CENTER] = instantiationService.createInstance(FocusSecondGroupAction, FocusSecondGroupAction.ID, FocusSecondGroupAction.LABEL);
		this.navigateActions[Position.RIGHT] = instantiationService.createInstance(FocusThirdGroupAction, FocusThirdGroupAction.ID, FocusThirdGroupAction.LABEL);
E
Erich Gamma 已提交
351 352
	}

353
	public run(event?: any): TPromise<any> {
E
Erich Gamma 已提交
354 355 356 357 358 359 360 361 362 363 364 365 366

		// Find the next position to the right to use
		let nextPosition: Position;
		let activeEditor = this.editorService.getActiveEditor();
		if (!activeEditor) {
			nextPosition = Position.LEFT;
		} else if (activeEditor.position === Position.LEFT) {
			nextPosition = Position.CENTER;
		} else if (activeEditor.position === Position.CENTER) {
			nextPosition = Position.RIGHT;
		}

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

A
Alex Dima 已提交
371
		return TPromise.as(true);
E
Erich Gamma 已提交
372 373 374 375 376 377 378 379
	}
}

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

380
	constructor( @IWorkbenchEditorService private editorService: IWorkbenchEditorService) {
E
Erich Gamma 已提交
381 382 383 384 385 386 387 388 389 390 391 392
		super(OpenToSideAction.OPEN_TO_SIDE_ID, OpenToSideAction.OPEN_TO_SIDE_LABEL);

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

		this.updateEnablement();
	}

	private updateEnablement(): void {
		let activeEditor = this.editorService.getActiveEditor();
		this.enabled = (!activeEditor || activeEditor.position !== Position.RIGHT);
	}

393
	public run(context: any): TPromise<any> {
E
Erich Gamma 已提交
394 395
		let entry = toEditorQuickOpenEntry(context);
		if (entry) {
B
Benjamin Pasero 已提交
396 397 398 399 400
			let typedInputPromise: TPromise<EditorInput>;
			let input = entry.getInput();
			if (input instanceof EditorInput) {
				typedInputPromise = TPromise.as(input);
			} else {
B
Benjamin Pasero 已提交
401
				typedInputPromise = this.editorService.createInput(<IResourceInput>input);
B
Benjamin Pasero 已提交
402 403 404
			}

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

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

411
export function toEditorQuickOpenEntry(element: any): IEditorQuickOpenEntry {
E
Erich Gamma 已提交
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429

	// QuickOpenEntryGroup
	if (element instanceof QuickOpenEntryGroup) {
		let group = <QuickOpenEntryGroup>element;
		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 {
430 431 432 433

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

434 435 436 437 438 439
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
I
isidor 已提交
440
		super(id, label, 'close-editor-action');
E
Erich Gamma 已提交
441 442
	}

B
Benjamin Pasero 已提交
443
	public run(context?: IEditorContext): TPromise<any> {
444
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
445

446
		// Close Active Editor
447
		if (typeof position !== 'number') {
B
Benjamin Pasero 已提交
448 449
			let activeEditor = this.editorService.getActiveEditor();
			if (activeEditor) {
450
				return this.editorService.closeEditor(activeEditor.position, activeEditor.input);
B
Benjamin Pasero 已提交
451
			}
452 453
		}

I
isidor 已提交
454
		let input = context ? context.editor : null;
I
isidor 已提交
455
		if (!input) {
B
Benjamin Pasero 已提交
456

I
isidor 已提交
457 458 459
			// Get Top Editor at Position
			let visibleEditors = this.editorService.getVisibleEditors();
			if (visibleEditors[position]) {
460
				input = visibleEditors[position].input;
I
isidor 已提交
461 462 463 464 465
			}
		}

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

A
Alex Dima 已提交
468
		return TPromise.as(false);
E
Erich Gamma 已提交
469 470 471
	}
}

B
Benjamin Pasero 已提交
472
export class CloseLeftEditorsInGroupAction extends Action {
473

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

477 478 479
	constructor(
		id: string,
		label: string,
B
Benjamin Pasero 已提交
480 481
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IEditorGroupService private groupService: IEditorGroupService
482
	) {
483 484 485
		super(id, label);
	}

B
Benjamin Pasero 已提交
486
	public run(context?: IEditorContext): TPromise<any> {
B
Benjamin Pasero 已提交
487 488 489
		let editor = getTarget(this.editorService, this.groupService, context);
		if (editor) {
			return this.editorService.closeEditors(editor.position, editor.input, Direction.LEFT);
490 491 492 493 494 495 496 497
		}

		return TPromise.as(false);
	}
}

export class CloseRightEditorsInGroupAction extends Action {

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

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

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

		return TPromise.as(false);
	}
}

E
Erich Gamma 已提交
520 521
export class CloseAllEditorsAction extends Action {

522 523 524
	public static ID = 'workbench.action.closeAllEditors';
	public static LABEL = nls.localize('closeAllEditors', "Close All Editors");

E
Erich Gamma 已提交
525
	constructor(id: string, label: string, @IWorkbenchEditorService private editorService: IWorkbenchEditorService) {
I
isidor 已提交
526
		super(id, label, 'action-close-all-files');
E
Erich Gamma 已提交
527 528
	}

529
	public run(): TPromise<any> {
530
		return this.editorService.closeAllEditors();
E
Erich Gamma 已提交
531 532 533
	}
}

534 535 536 537 538
export class CloseEditorsInOtherGroupsAction extends Action {

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

539 540 541 542 543 544
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
545 546 547
		super(id, label);
	}

B
Benjamin Pasero 已提交
548
	public run(context?: IEditorContext): TPromise<any> {
549
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
550
		if (typeof position !== 'number') {
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
			let activeEditor = this.editorService.getActiveEditor();
			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 已提交
568
	public static LABEL = nls.localize('closeOtherEditorsInGroup', "Close Other Editors");
E
Erich Gamma 已提交
569

570 571 572 573 574 575
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
576 577 578
		super(id, label);
	}

B
Benjamin Pasero 已提交
579
	public run(context?: IEditorContext): TPromise<any> {
580
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
I
isidor 已提交
581
		let input = context ? context.editor : null;
I
isidor 已提交
582 583

		// If position or input are not passed in take the position and input of the active editor.
584 585
		const active = this.editorService.getActiveEditor();
		if (active) {
I
isidor 已提交
586
			position = typeof position === 'number' ? position : active.position;
587
			input = input ? input : <EditorInput>active.input;
I
isidor 已提交
588 589 590 591
		}

		if (typeof position === 'number' && input) {
			return this.editorService.closeEditors(position, input);
592 593 594
		}

		return TPromise.as(false);
E
Erich Gamma 已提交
595 596 597
	}
}

B
Benjamin Pasero 已提交
598
export class CloseEditorsInGroupAction extends Action {
I
isidor 已提交
599

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

603 604 605 606 607 608
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
B
Benjamin Pasero 已提交
609
		super(id, label);
I
isidor 已提交
610 611
	}

B
Benjamin Pasero 已提交
612
	public run(context?: IEditorContext): TPromise<any> {
613
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
I
isidor 已提交
614 615 616 617 618 619 620 621 622 623
		if (typeof position !== 'number') {
			let activeEditor = this.editorService.getActiveEditor();
			if (activeEditor) {
				position = activeEditor.position;
			}
		}

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

		return TPromise.as(false);
I
isidor 已提交
626 627 628
	}
}

B
Benjamin Pasero 已提交
629
export class MoveGroupLeftAction extends Action {
E
Erich Gamma 已提交
630

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

634 635 636 637 638 639
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
640 641 642
		super(id, label);
	}

B
Benjamin Pasero 已提交
643
	public run(context?: IEditorContext): TPromise<any> {
644
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
645
		if (typeof position !== 'number') {
646 647 648 649 650 651 652 653
			let activeEditor = this.editorService.getActiveEditor();
			if (activeEditor && (activeEditor.position === Position.CENTER || activeEditor.position === Position.RIGHT)) {
				position = activeEditor.position;
			}
		}

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

B
Benjamin Pasero 已提交
655
			// Move group
656
			this.editorGroupService.moveGroup(position, newPosition);
E
Erich Gamma 已提交
657 658
		}

A
Alex Dima 已提交
659
		return TPromise.as(false);
E
Erich Gamma 已提交
660 661 662
	}
}

B
Benjamin Pasero 已提交
663
export class MoveGroupRightAction extends Action {
E
Erich Gamma 已提交
664

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

668 669 670 671 672 673
	constructor(
		id: string,
		label: string,
		@IEditorGroupService private editorGroupService: IEditorGroupService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
E
Erich Gamma 已提交
674 675 676
		super(id, label);
	}

B
Benjamin Pasero 已提交
677
	public run(context?: IEditorContext): TPromise<any> {
678
		let position = context ? this.editorGroupService.getStacksModel().positionOfGroup(context.group) : null;
679
		if (typeof position !== 'number') {
680 681 682 683 684 685 686 687 688 689
			let activeEditor = this.editorService.getActiveEditor();
			let editors = this.editorService.getVisibleEditors();

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

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

B
Benjamin Pasero 已提交
691
			// Move group
692
			this.editorGroupService.moveGroup(position, newPosition);
E
Erich Gamma 已提交
693 694
		}

A
Alex Dima 已提交
695
		return TPromise.as(false);
E
Erich Gamma 已提交
696 697 698
	}
}

699
export class MinimizeOtherGroupsAction extends Action {
E
Erich Gamma 已提交
700

701 702 703
	public static ID = 'workbench.action.minimizeOtherEditors';
	public static LABEL = nls.localize('minimizeOtherEditorGroups', "Minimize Other Editor Groups");

704
	constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
E
Erich Gamma 已提交
705 706 707
		super(id, label);
	}

708
	public run(): TPromise<any> {
709
		this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
E
Erich Gamma 已提交
710

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

715
export class EvenGroupWidthsAction extends Action {
E
Erich Gamma 已提交
716

717 718 719
	public static ID = 'workbench.action.evenEditorWidths';
	public static LABEL = nls.localize('evenEditorGroups', "Even Editor Group Widths");

720
	constructor(id: string, label: string, @IEditorGroupService private editorGroupService: IEditorGroupService) {
E
Erich Gamma 已提交
721 722 723
		super(id, label);
	}

724
	public run(): TPromise<any> {
725
		this.editorGroupService.arrangeGroups(GroupArrangement.EVEN_WIDTH);
E
Erich Gamma 已提交
726

A
Alex Dima 已提交
727
		return TPromise.as(false);
E
Erich Gamma 已提交
728 729 730
	}
}

731
export class MaximizeGroupAction extends Action {
732

733 734 735
	public static ID = 'workbench.action.maximizeEditor';
	public static LABEL = nls.localize('maximizeEditor', "Maximize Editor Group and Hide Sidebar");

736 737 738 739
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
740
		@IEditorGroupService private editorGroupService: IEditorGroupService,
741 742 743 744 745
		@IPartService private partService: IPartService
	) {
		super(id, label);
	}

746
	public run(): TPromise<any> {
747
		if (this.editorService.getActiveEditor()) {
748
			this.editorGroupService.arrangeGroups(GroupArrangement.MINIMIZE_OTHERS);
749 750 751
			this.partService.setSideBarHidden(true);
		}

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

B
Benjamin Pasero 已提交
756
export class KeepEditorAction extends Action {
757

B
Benjamin Pasero 已提交
758 759
	public static ID = 'workbench.action.keepEditor';
	public static LABEL = nls.localize('keepEditor', "Keep Editor");
760 761 762 763

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

B
Benjamin Pasero 已提交
770 771 772 773
	public run(context?: IEditorContext): TPromise<any> {
		let target = getTarget(this.editorService, this.editorGroupService, context);
		if (target) {
			this.editorGroupService.pinEditor(target.position, target.input);
774 775 776 777 778 779
		}

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
780 781 782 783 784 785 786 787 788 789 790 791 792
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;
}

793 794
export abstract class BaseNavigateEditorAction extends Action {

795 796 797 798 799 800
	constructor(
		id: string,
		label: string,
		protected editorGroupService: IEditorGroupService,
		protected editorService: IWorkbenchEditorService
	) {
801 802 803 804
		super(id, label);
	}

	public run(): TPromise<any> {
805
		const model = this.editorGroupService.getStacksModel();
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
		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");

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

	protected navigate(): IEditorIdentifier {
832
		return this.editorGroupService.getStacksModel().next();
833 834 835 836 837 838 839 840
	}
}

export class OpenPreviousEditor extends BaseNavigateEditorAction {

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

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

	protected navigate(): IEditorIdentifier {
851
		return this.editorGroupService.getStacksModel().previous();
852
	}
B
Benjamin Pasero 已提交
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
}

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 已提交
885
}
886 887 888 889 890 891 892 893 894

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,
895
		@IHistoryService private historyService: IHistoryService,
896
		@IEditorGroupService private editorGroupService: IEditorGroupService,
897 898 899 900 901 902
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
903
		const stacks = this.editorGroupService.getStacksModel();
904 905

		// Find an editor that was closed and is currently not opened in the group
906
		let lastClosedEditor = this.historyService.popLastClosedEditor();
907
		while (lastClosedEditor && stacks.activeGroup && stacks.activeGroup.indexOf(lastClosedEditor) >= 0) {
908
			lastClosedEditor = this.historyService.popLastClosedEditor();
909 910 911
		}

		if (lastClosedEditor) {
912
			this.editorService.openEditor(lastClosedEditor, { pinned: true });
913 914 915 916
		}

		return TPromise.as(false);
	}
B
Benjamin Pasero 已提交
917 918
}

919
export const NAVIGATE_IN_LEFT_GROUP_PREFIX = 'edt left ';
B
Benjamin Pasero 已提交
920

921
export class ShowEditorsInLeftGroupAction extends QuickOpenAction {
B
Benjamin Pasero 已提交
922

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

926 927 928 929 930 931
	constructor(
		actionId: string,
		actionLabel: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
	) {
932
		super(actionId, actionLabel, NAVIGATE_IN_LEFT_GROUP_PREFIX, quickOpenService);
933 934

		this.class = 'show-group-editors-action';
B
Benjamin Pasero 已提交
935
	}
936
}
937

938 939 940 941 942 943 944 945 946 947 948 949 950 951
export const NAVIGATE_IN_CENTER_GROUP_PREFIX = 'edt center ';

export class ShowEditorsInCenterGroupAction extends QuickOpenAction {

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

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

		this.class = 'show-group-editors-action';
954 955
	}
}
956

957 958 959 960 961 962 963 964 965 966 967 968 969 970
export const NAVIGATE_IN_RIGHT_GROUP_PREFIX = 'edt right ';

export class ShowEditorsInRightGroupAction extends QuickOpenAction {

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

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

		this.class = 'show-group-editors-action';
973
	}
B
Benjamin Pasero 已提交
974 975
}

B
Benjamin Pasero 已提交
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
export class ShowEditorsInGroupAction extends Action {

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

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

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

		switch (stacks.positionOfGroup(context.group)) {
			case Position.CENTER:
				return this.quickOpenService.show((groupCount === 2) ? NAVIGATE_IN_RIGHT_GROUP_PREFIX : NAVIGATE_IN_CENTER_GROUP_PREFIX);
			case Position.RIGHT:
				return this.quickOpenService.show(NAVIGATE_IN_RIGHT_GROUP_PREFIX);
		}

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

1008
export const NAVIGATE_ALL_EDITORS_GROUP_PREFIX = 'edt ';
B
Benjamin Pasero 已提交
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019

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

1020
export class BaseQuickOpenEditorInGroupAction extends Action {
B
Benjamin Pasero 已提交
1021 1022 1023 1024 1025

	constructor(
		id: string,
		label: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
1026
		@IKeybindingService private keybindingService: IKeybindingService,
1027
		@IEditorGroupService private editorGroupService: IEditorGroupService,
1028
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService
B
Benjamin Pasero 已提交
1029 1030 1031 1032 1033 1034 1035
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		let keys = this.keybindingService.lookupKeybindings(this.id);

1036
		const stacks = this.editorGroupService.getStacksModel();
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
		if (stacks.activeGroup) {
			const activePosition = stacks.positionOfGroup(stacks.activeGroup);
			const count = stacks.groups.length;
			let prefix = NAVIGATE_IN_LEFT_GROUP_PREFIX;

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

B
Benjamin Pasero 已提交
1048
			this.quickOpenService.show(prefix, { quickNavigateConfiguration: { keybindings: keys } });
1049
		}
B
Benjamin Pasero 已提交
1050 1051 1052 1053 1054

		return TPromise.as(true);
	}
}

1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
export class OpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

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

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

export class OpenNextRecentlyUsedEditorInGroupAction extends BaseQuickOpenEditorInGroupAction {

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

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

B
Benjamin Pasero 已提交
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
export class GlobalQuickOpenAction extends Action {

	public static ID = 'workbench.action.quickOpen';
	public static LABEL = nls.localize('quickOpen', "Go to File...");

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

		this.order = 100; // Allow other actions to position before or after
		this.class = 'quickopen';
	}

	public run(): TPromise<any> {
		this.quickOpenService.show(null);

		return TPromise.as(true);
	}
}

1108
export class OpenPreviousEditorFromHistoryAction extends Action {
B
Benjamin Pasero 已提交
1109

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

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

	public run(): TPromise<any> {
		let keys = this.keybindingService.lookupKeybindings(this.id);

B
Benjamin Pasero 已提交
1125
		this.quickOpenService.show(null, { quickNavigateConfiguration: { keybindings: keys } });
B
Benjamin Pasero 已提交
1126 1127 1128 1129 1130

		return TPromise.as(true);
	}
}

1131 1132 1133 1134 1135 1136 1137 1138 1139
export class ClearEditorHistoryAction extends Action {

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

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
1140
		@IEditorGroupService private editorGroupService: IEditorGroupService,
1141 1142 1143 1144 1145 1146 1147
		@IHistoryService private historyService: IHistoryService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {

1148
		// Editor history
1149 1150 1151 1152 1153 1154
		this.historyService.clear();

		return TPromise.as(true);
	}
}

1155 1156 1157 1158 1159 1160 1161 1162
export class RemoveFromEditorHistoryAction extends Action {

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

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

	public run(): TPromise<any> {

		// Listen for next editor to open
1173
		let unbind = this.editorGroupService.onEditorOpening(e => {
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
			unbind.dispose(); // listen once

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

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

		return TPromise.as(true);
	}
}

B
Benjamin Pasero 已提交
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
export class BaseQuickOpenNavigateAction extends Action {
	private navigateNext: boolean;

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

		this.navigateNext = navigateNext;
	}

	public run(event?: any): TPromise<any> {
		let keys = this.keybindingService.lookupKeybindings(this.id);

		this.quickOpenService.quickNavigate({
			keybindings: keys
		}, this.navigateNext);

		return TPromise.as(true);
	}
}

export class QuickOpenNavigateNextAction extends BaseQuickOpenNavigateAction {

	public static ID = 'workbench.action.quickOpenNavigateNext';
	public static LABEL = nls.localize('quickNavigateNext', "Navigate Next in Quick Open");

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

export class QuickOpenNavigatePreviousAction extends BaseQuickOpenNavigateAction {

	public static ID = 'workbench.action.quickOpenNavigatePrevious';
	public static LABEL = nls.localize('quickNavigatePrevious', "Navigate Previous in Quick Open");

	constructor(
		id: string,
		label: string,
		@IQuickOpenService quickOpenService: IQuickOpenService,
		@IKeybindingService keybindingService: IKeybindingService
	) {
		super(id, label, false, quickOpenService, keybindingService);
	}
1243 1244 1245 1246
}

interface IEditorPickOpenEntry extends IPickOpenEntry {
	identifier: IEditorIdentifier;
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
}

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

		return TPromise.as(true);
	}
B
Benjamin Pasero 已提交
1276
}