editorService.ts 6.1 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, Direction, IResourceInput, IEditorModel, ITextEditorModel} from 'vs/platform/editor/common/editor';
B
Benjamin Pasero 已提交
10
import {IEditorStacksModel} from 'vs/workbench/common/editor/editorStacksModel';
11
import Event from 'vs/base/common/event';
12
import {EditorInputEvent} from 'vs/workbench/common/events';
E
Erich Gamma 已提交
13

14
export enum GroupArrangement {
E
Erich Gamma 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27
	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>;

28 29 30 31 32
	/**
	 * Emitted when editors or inputs change. Examples: opening, closing of editors. Active editor change.
	 */
	onEditorsChanged: Event<void>;

33 34 35 36 37
	/**
	 * Emitted when an editor is about to open.
	 */
	onEditorOpening: Event<EditorInputEvent>;

38 39 40 41 42
	/**
	 * Emitted when a editors are moved to another position.
	 */
	onEditorsMoved: Event<void>;

B
Benjamin Pasero 已提交
43 44 45 46 47
	/**
	 * Emitted when opening an editor fails.
	 */
	onEditorOpenFail: Event<IEditorInput>;

E
Erich Gamma 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
	/**
	 * 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;

	/**
72 73
	 * 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 已提交
74 75 76 77 78 79 80 81 82 83 84
	 */
	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>;

	/**
85 86
	 * 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 已提交
87
	 */
B
Benjamin Pasero 已提交
88 89
	openEditors(editors: { input: IResourceInput, position: Position }[]): TPromise<IEditor[]>;
	openEditors(editors: { input: IEditorInput, position: Position, options?: IEditorOptions }[]): TPromise<IEditor[]>;
E
Erich Gamma 已提交
90

91 92 93 94 95 96 97
	/**
	 * Given a list of editors to replace, will look across all groups where this editor is open (active or hidden)
	 * and replace it with the new editor and the provied options.
	 */
	replaceEditors(editors: { toReplace: IResourceInput, replaceWith: IResourceInput }[]): TPromise<IEditor[]>;
	replaceEditors(editors: { toReplace: IEditorInput, replaceWith: IEditorInput, options?: IEditorOptions }[]): TPromise<IEditor[]>;

E
Erich Gamma 已提交
98
	/**
99
	 * Closes the editor at the provided position.
E
Erich Gamma 已提交
100
	 */
101
	closeEditor(position: Position, input: IEditorInput): TPromise<void>;
E
Erich Gamma 已提交
102 103

	/**
104 105 106
	 * Closes editors of a specific group at the provided position. If the optional editor is provided to exclude, it
	 * will not be closed. The direction can be used in that case to control if all other editors should get closed,
	 * or towards a specific direction.
E
Erich Gamma 已提交
107
	 */
108 109 110
	closeEditors(position: Position, except?: IEditorInput, direction?: Direction): TPromise<void>;

	/**
111
	 * Closes all editors across all groups. The optional position allows to keep one group alive.
112
	 */
113
	closeAllEditors(except?: Position): TPromise<void>;
E
Erich Gamma 已提交
114

115 116 117 118 119 120 121 122 123 124
	/**
	 * Adds the pinned state to an editor, removing it from being a preview editor.
	 */
	pinEditor(position: Position, input: IEditorInput): void;

	/**
	 * Removes the pinned state of an editor making it a preview editor.
	 */
	unpinEditor(position: Position, input: IEditorInput): void;

E
Erich Gamma 已提交
125
	/**
126
	 * Keyboard focus the editor group at the provided position.
E
Erich Gamma 已提交
127
	 */
128
	focusGroup(position: Position): void;
E
Erich Gamma 已提交
129

130
	/**
131
	 * Activate the editor group at the provided position without moving focus.
132
	 */
133
	activateGroup(position: Position): void;
134

B
Benjamin Pasero 已提交
135
	/**
B
Benjamin Pasero 已提交
136
	 * Moves an editor from one group to another. The index in the group is optional.
B
Benjamin Pasero 已提交
137
	 */
138
	moveEditor(input: IEditorInput, from: Position, to: Position, index?: number): void;
B
Benjamin Pasero 已提交
139

E
Erich Gamma 已提交
140
	/**
B
Benjamin Pasero 已提交
141
	 * Allows to move the editor group from one position to another.
E
Erich Gamma 已提交
142
	 */
B
Benjamin Pasero 已提交
143
	moveGroup(from: Position, to: Position): void;
E
Erich Gamma 已提交
144 145

	/**
146
	 * Allows to arrange editor groups according to the GroupArrangement enumeration.
E
Erich Gamma 已提交
147
	 */
148
	arrangeGroups(arrangement: GroupArrangement): void;
E
Erich Gamma 已提交
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

	/**
	 * 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
	 */
165
	createInput(input: IResourceInput): TPromise<IEditorInput>;
B
Benjamin Pasero 已提交
166 167 168 169 170

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