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

import {TPromise} from 'vs/base/common/winjs.base';
import {createDecorator, ServiceIdentifier} from 'vs/platform/instantiation/common/instantiation';
9
import {IEditorService, IEditor, IEditorInput, IEditorOptions, Position, IResourceInput, IEditorModel, ITextEditorModel} from 'vs/platform/editor/common/editor';
B
Benjamin Pasero 已提交
10
import {IEditorStacksModel} from 'vs/workbench/common/editor/editorStacksModel';
E
Erich Gamma 已提交
11

12
export enum GroupArrangement {
E
Erich Gamma 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
	MINIMIZE_OTHERS,
	EVEN_WIDTH
}

export var IWorkbenchEditorService = createDecorator<IWorkbenchEditorService>('editorService');

/**
 * The editor service allows to open editors and work on the active
 * editor input and models.
 */
export interface IWorkbenchEditorService extends IEditorService {
	serviceId : ServiceIdentifier<any>;

	/**
	 * Returns the currently active editor or null if none.
	 */
	getActiveEditor(): IEditor;

	/**
	 * Returns the currently active editor input or null if none.
	 */
	getActiveEditorInput(): IEditorInput;

	/**
	 * Returns an array of visible editors.
	 */
	getVisibleEditors(): IEditor[];

	/**
	 * Returns iff the provided input is currently visible.
	 *
	 * @param includeDiff iff set to true, will also consider diff editors to find out if the provided
	 * input is opened either on the left or right hand side of the diff editor.
	 */
	isVisible(input: IEditorInput, includeDiff: boolean): boolean;

	/**
50 51
	 * Opens an Editor on the given input with the provided options at the given position. If sideBySide parameter
	 * is provided, causes the editor service to decide in what position to open the input.
E
Erich Gamma 已提交
52 53 54 55 56 57 58 59 60 61 62
	 */
	openEditor(input: IEditorInput, options?: IEditorOptions, position?: Position): TPromise<IEditor>;
	openEditor(input: IEditorInput, options?: IEditorOptions, sideBySide?: boolean): TPromise<IEditor>;

	/**
	 * Specific overload to open an instance of IResourceInput.
	 */
	openEditor(input: IResourceInput, position?: Position): TPromise<IEditor>;
	openEditor(input: IResourceInput, sideBySide?: boolean): TPromise<IEditor>;

	/**
63 64
	 * Similar to #openEditor() but allows to open multiple editors for different positions at the same time. If there are
	 * more than one editor per position, only the first one will be active and the others stacked behind inactive.
E
Erich Gamma 已提交
65
	 */
B
Benjamin Pasero 已提交
66 67
	openEditors(editors: { input: IResourceInput, position: Position }[]): TPromise<IEditor[]>;
	openEditors(editors: { input: IEditorInput, position: Position, options?: IEditorOptions }[]): TPromise<IEditor[]>;
E
Erich Gamma 已提交
68 69

	/**
70
	 * Closes the editor at the provided position.
E
Erich Gamma 已提交
71
	 */
72
	closeEditor(position: Position, input: IEditorInput): TPromise<void>;
E
Erich Gamma 已提交
73 74 75 76 77 78 79

	/**
	 * Closes all editors or only others that are not active.
	 */
	closeEditors(othersOnly?: boolean): TPromise<void>;

	/**
B
Benjamin Pasero 已提交
80
	 * Keyboard focus the editor group at the provided position. If position is not provided, the current active group is focused.
E
Erich Gamma 已提交
81
	 */
B
Benjamin Pasero 已提交
82
	focusGroup(position?: Position): TPromise<IEditor>;
E
Erich Gamma 已提交
83

84
	/**
85
	 * Activate the editor group at the provided position without moving focus.
86
	 */
87
	activateGroup(position: Position): void;
88

E
Erich Gamma 已提交
89
	/**
B
Benjamin Pasero 已提交
90
	 * Allows to move the editor group from one position to another.
E
Erich Gamma 已提交
91
	 */
B
Benjamin Pasero 已提交
92
	moveGroup(from: Position, to: Position): void;
E
Erich Gamma 已提交
93 94

	/**
95
	 * Allows to arrange editor groups according to the GroupArrangement enumeration.
E
Erich Gamma 已提交
96
	 */
97
	arrangeGroups(arrangement: GroupArrangement): void;
E
Erich Gamma 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

	/**
	 * Resolves an input to its model representation. The optional parameter refresh allows to specify
	 * if a cached model should be returned (false) or a new version (true). The default is returning a
	 * cached version.
	 */
	resolveEditorModel(input: IEditorInput, refresh?: boolean): TPromise<IEditorModel>;

	/**
	 * Specific overload to resolve a IResourceInput to an editor model with a text representation.
	 */
	resolveEditorModel(input: IResourceInput, refresh?: boolean): TPromise<ITextEditorModel>;

	/**
	 * Allows to resolve an untyped input to a workbench typed instanceof editor input
	 */
	inputToType(input: IResourceInput): TPromise<IEditorInput>;
B
Benjamin Pasero 已提交
115 116 117 118 119

	/**
	 * Provides access to the editor stacks model
	 */
	getStacksModel(): IEditorStacksModel;
E
Erich Gamma 已提交
120
}