Skip to content

Commit 540a57e

Browse files
committed
grid - adopt IOpenEditorEvent
1 parent d3082d7 commit 540a57e

11 files changed

Lines changed: 90 additions & 86 deletions

File tree

src/vs/platform/editor/common/editor.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ export interface IEditorService {
2222
openEditor(input: IResourceInput, sideBySide?: boolean): TPromise<IEditor>;
2323
}
2424

25-
export interface IEditorInputWithOptions {
26-
editor: IEditorInput;
27-
options?: IEditorOptions;
28-
}
29-
30-
export function isEditorInputWithOptions(obj: any): obj is IEditorInputWithOptions {
31-
const editorInputWithOptions = obj as IEditorInputWithOptions;
32-
33-
return !!editorInputWithOptions && !!editorInputWithOptions.editor;
34-
}
35-
3625
export interface IEditorModel {
3726

3827
onDispose: Event<void>;

src/vs/workbench/browser/parts/editor/editorPart.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,11 +947,11 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
947947
}
948948

949949
// Editor opening event (can be prevented and overridden)
950-
const event = new EditorOpeningEvent(input, options, position);
950+
const event = new EditorOpeningEvent(null, input, options);
951951
this._onEditorOpening.fire(event);
952952
const prevented = event.isPrevented();
953953
if (prevented) {
954-
return prevented();
954+
return prevented() as any;
955955
}
956956

957957
// Open through UI

src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,11 @@ export class NextEditorGroupView extends Themable implements INextEditorGroupVie
582582
openEditor(editor: EditorInput, options?: EditorOptions): Thenable<void> {
583583

584584
// Editor opening event allows for prevention
585-
const event = new EditorOpeningEvent(editor, options, this._group.id); // TODO@grid position => group ID
585+
const event = new EditorOpeningEvent(this, editor, options);
586586
this._onWillOpenEditor.fire(event);
587587
const prevented = event.isPrevented();
588588
if (prevented) {
589-
return prevented().then(() => void 0); // TODO@grid do we need the BaseEditor return type still in the event?
589+
return prevented();
590590
}
591591

592592
// Proceed with opening

src/vs/workbench/common/editor.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as types from 'vs/base/common/types';
1111
import URI from 'vs/base/common/uri';
1212
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
1313
import { IEditor, IEditorViewState, ScrollType } from 'vs/editor/common/editorCommon';
14-
import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, Position, Verbosity, IEditor as IBaseEditor, IRevertOptions } from 'vs/platform/editor/common/editor';
14+
import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, Position, Verbosity, IRevertOptions } from 'vs/platform/editor/common/editor';
1515
import { IInstantiationService, IConstructorSignature0 } from 'vs/platform/instantiation/common/instantiation';
1616
import { RawContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1717
import { Registry } from 'vs/platform/registry/common/platform';
@@ -274,9 +274,9 @@ export abstract class EditorInput implements IEditorInput {
274274
}
275275

276276
export interface IEditorOpeningEvent {
277-
input: IEditorInput;
277+
editor: IEditorInput;
278278
options?: IEditorOptions;
279-
position: Position;
279+
group: INextEditorGroup;
280280

281281
/**
282282
* Allows to prevent the opening of an editor by providing a callback
@@ -285,32 +285,32 @@ export interface IEditorOpeningEvent {
285285
* to return a promise that resolves to NULL to prevent the opening
286286
* altogether.
287287
*/
288-
prevent(callback: () => TPromise<IBaseEditor>): void;
288+
prevent(callback: () => Thenable<any>): void;
289289
}
290290

291291
export class EditorOpeningEvent implements IEditorOpeningEvent {
292-
private override: () => TPromise<IBaseEditor>;
292+
private override: () => Thenable<any>;
293293

294-
constructor(private _input: IEditorInput, private _options: IEditorOptions, private _position: Position) {
294+
constructor(private _group: INextEditorGroup, private _editor: IEditorInput, private _options: IEditorOptions) {
295295
}
296296

297-
public get input(): IEditorInput {
298-
return this._input;
297+
public get group(): INextEditorGroup {
298+
return this._group;
299299
}
300300

301-
public get options(): IEditorOptions {
302-
return this._options;
301+
public get editor(): IEditorInput {
302+
return this._editor;
303303
}
304304

305-
public get position(): Position {
306-
return this._position;
305+
public get options(): IEditorOptions {
306+
return this._options;
307307
}
308308

309-
public prevent(callback: () => TPromise<IBaseEditor>): void {
309+
public prevent(callback: () => Thenable<any>): void {
310310
this.override = callback;
311311
}
312312

313-
public isPrevented(): () => TPromise<IBaseEditor> {
313+
public isPrevented(): () => Thenable<any> {
314314
return this.override;
315315
}
316316
}
@@ -519,6 +519,17 @@ export class EditorModel extends Disposable implements IEditorModel {
519519
}
520520
}
521521

522+
export interface IEditorInputWithOptions {
523+
editor: IEditorInput;
524+
options?: IEditorOptions;
525+
}
526+
527+
export function isEditorInputWithOptions(obj: any): obj is IEditorInputWithOptions {
528+
const editorInputWithOptions = obj as IEditorInputWithOptions;
529+
530+
return !!editorInputWithOptions && !!editorInputWithOptions.editor;
531+
}
532+
522533
/**
523534
* The editor options is the base class of options that can be passed in when opening an editor.
524535
*/

src/vs/workbench/parts/files/electron-browser/fileActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,13 +1104,13 @@ export class GlobalCompareResourcesAction extends Action {
11041104

11051105
// Compare with next editor that opens
11061106
const unbind = once(this.editorGroupService.onEditorOpening)(e => {
1107-
const resource = e.input.getResource();
1107+
const resource = e.editor.getResource();
11081108
if (resource) {
11091109
e.prevent(() => {
11101110
return this.editorService.openEditor({
11111111
leftResource: activeResource,
11121112
rightResource: resource
1113-
});
1113+
}).then(() => void 0);
11141114
});
11151115
}
11161116
});

src/vs/workbench/parts/preferences/common/preferencesContribution.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class PreferencesContribution implements IWorkbenchContribution {
6060
}
6161

6262
private onEditorOpening(event: IEditorOpeningEvent): void {
63-
const resource = event.input.getResource();
63+
const resource = event.editor.getResource();
6464
if (
6565
!resource || resource.scheme !== 'file' || // require a file path opening
6666
!endsWith(resource.fsPath, 'settings.json') || // file must end in settings.json
@@ -72,23 +72,21 @@ export class PreferencesContribution implements IWorkbenchContribution {
7272
// If the file resource was already opened before in the group, do not prevent
7373
// the opening of that resource. Otherwise we would have the same settings
7474
// opened twice (https://github.com/Microsoft/vscode/issues/36447)
75-
const stacks = this.editorGroupService.getStacksModel();
76-
const group = stacks.groupAt(event.position);
77-
if (group && group.contains(event.input)) {
75+
if (event.group.isOpened(event.editor)) {
7876
return;
7977
}
8078

8179
// Global User Settings File
8280
if (resource.fsPath === this.environmentService.appSettingsPath) {
83-
return event.prevent(() => this.preferencesService.openGlobalSettings(event.options, event.position));
81+
return event.prevent(() => this.preferencesService.openGlobalSettings(event.options, event.group));
8482
}
8583

8684
// Single Folder Workspace Settings File
8785
const state = this.workspaceService.getWorkbenchState();
8886
if (state === WorkbenchState.FOLDER) {
8987
const folders = this.workspaceService.getWorkspace().folders;
9088
if (resource.fsPath === folders[0].toResource(FOLDER_SETTINGS_PATH).fsPath) {
91-
return event.prevent(() => this.preferencesService.openWorkspaceSettings(event.options, event.position));
89+
return event.prevent(() => this.preferencesService.openWorkspaceSettings(event.options, event.group));
9290
}
9391
}
9492

@@ -97,7 +95,7 @@ export class PreferencesContribution implements IWorkbenchContribution {
9795
const folders = this.workspaceService.getWorkspace().folders;
9896
for (let i = 0; i < folders.length; i++) {
9997
if (resource.fsPath === folders[i].toResource(FOLDER_SETTINGS_PATH).fsPath) {
100-
return event.prevent(() => this.preferencesService.openFolderSettings(folders[i].uri, event.options, event.position));
98+
return event.prevent(() => this.preferencesService.openFolderSettings(folders[i].uri, event.options, event.group));
10199
}
102100
}
103101
}

src/vs/workbench/services/editor/browser/nextEditorService.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
'use strict';
77

88
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
9-
import { IEditorInput, IResourceInput, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditor, ITextEditorOptions, IEditorOptions, IEditorInputWithOptions, isEditorInputWithOptions } from 'vs/platform/editor/common/editor';
10-
import { GroupIdentifier, IFileEditorInput, IEditorInputFactoryRegistry, Extensions as EditorExtensions, IFileInputFactory, EditorInput, SideBySideEditorInput, EditorOptions, TextEditorOptions, IEditorOpeningEvent } from 'vs/workbench/common/editor';
9+
import { IEditorInput, IResourceInput, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditor, ITextEditorOptions, IEditorOptions } from 'vs/platform/editor/common/editor';
10+
import { GroupIdentifier, IFileEditorInput, IEditorInputFactoryRegistry, Extensions as EditorExtensions, IFileInputFactory, EditorInput, SideBySideEditorInput, IEditorInputWithOptions, isEditorInputWithOptions, EditorOptions, TextEditorOptions, IEditorOpeningEvent } from 'vs/workbench/common/editor';
1111
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
1212
import { DataUriEditorInput } from 'vs/workbench/common/editor/dataUriEditorInput';
1313
import { Registry } from 'vs/platform/registry/common/platform';
@@ -163,9 +163,9 @@ export class NextEditorService extends Disposable implements INextEditorService
163163

164164
//#region openEditor()
165165

166-
openEditor(editor: IEditorInput, options?: IEditorOptions, group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor>;
167-
openEditor(editor: IResourceEditor, group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor>;
168-
openEditor(editor: IEditorInput | IResourceEditor, optionsOrGroup?: IEditorOptions | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE, group?: GroupIdentifier): Thenable<IEditor> {
166+
openEditor(editor: IEditorInput, options?: IEditorOptions, group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor>;
167+
openEditor(editor: IResourceEditor, group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor>;
168+
openEditor(editor: IEditorInput | IResourceEditor, optionsOrGroup?: IEditorOptions | INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE, group?: GroupIdentifier): Thenable<IEditor> {
169169

170170
// Typed Editor Support
171171
if (editor instanceof EditorInput) {
@@ -189,17 +189,22 @@ export class NextEditorService extends Disposable implements INextEditorService
189189
const typedInput = this.createInput(textInput);
190190
if (typedInput) {
191191
const editorOptions = TextEditorOptions.from(textInput);
192-
const targetGroup = this.findTargetGroup(typedInput, editorOptions, optionsOrGroup as GroupIdentifier);
192+
const targetGroup = this.findTargetGroup(typedInput, editorOptions, optionsOrGroup as INextEditorGroup | GroupIdentifier);
193193

194194
return targetGroup.openEditor(typedInput, editorOptions).then(() => targetGroup.activeControl);
195195
}
196196

197197
return TPromise.wrap<IEditor>(null);
198198
}
199199

200-
private findTargetGroup(input: IEditorInput, options?: IEditorOptions, group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): INextEditorGroup {
200+
private findTargetGroup(input: IEditorInput, options?: IEditorOptions, group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): INextEditorGroup {
201201
let targetGroup: INextEditorGroup;
202202

203+
// Group: Instance of Group
204+
if (group && typeof group !== 'number') {
205+
return group;
206+
}
207+
203208
// Group: Active Group
204209
if (group === ACTIVE_GROUP) {
205210
targetGroup = this.nextEditorGroupsService.activeGroup;
@@ -271,9 +276,9 @@ export class NextEditorService extends Disposable implements INextEditorService
271276

272277
//#region openEditors()
273278

274-
openEditors(editors: IEditorInputWithOptions[], group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor[]>;
275-
openEditors(editors: IResourceEditor[], group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor[]>;
276-
openEditors(editors: (IEditorInputWithOptions | IResourceEditor)[], group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor[]> {
279+
openEditors(editors: IEditorInputWithOptions[], group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor[]>;
280+
openEditors(editors: IResourceEditor[], group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor[]>;
281+
openEditors(editors: (IEditorInputWithOptions | IResourceEditor)[], group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor[]> {
277282

278283
// Convert to typed editors and options
279284
const typedEditors: IEditorInputWithOptions[] = [];

src/vs/workbench/services/editor/common/nextEditorService.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
'use strict';
77

88
import { createDecorator, ServiceIdentifier, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
9-
import { IEditorInput, IResourceInput, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditor, IEditorOptions, IEditorInputWithOptions } from 'vs/platform/editor/common/editor';
10-
import { GroupIdentifier, IEditorOpeningEvent } from 'vs/workbench/common/editor';
9+
import { IEditorInput, IResourceInput, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditor, IEditorOptions } from 'vs/platform/editor/common/editor';
10+
import { GroupIdentifier, IEditorOpeningEvent, IEditorInputWithOptions } from 'vs/workbench/common/editor';
1111
import { Event } from 'vs/base/common/event';
1212
import { IEditor as ICodeEditor } from 'vs/editor/common/editorCommon';
13+
import { INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService';
1314

1415
export const INextEditorService = createDecorator<INextEditorService>('nextEditorService');
1516

@@ -90,7 +91,7 @@ export interface INextEditorService {
9091
* active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side
9192
* of the currently active group.
9293
*/
93-
openEditor(editor: IEditorInput, options?: IEditorOptions, group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor>;
94+
openEditor(editor: IEditorInput, options?: IEditorOptions, group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor>;
9495

9596
/**
9697
* Open an editor in an editor group.
@@ -100,7 +101,7 @@ export interface INextEditorService {
100101
* active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side
101102
* of the currently active group.
102103
*/
103-
openEditor(editor: IResourceEditor, group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor>;
104+
openEditor(editor: IResourceEditor, group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<IEditor>;
104105

105106
/**
106107
* Open editors in an editor group.
@@ -110,8 +111,8 @@ export interface INextEditorService {
110111
* active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side
111112
* of the currently active group.
112113
*/
113-
openEditors(editors: IEditorInputWithOptions[], group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<ReadonlyArray<IEditor>>;
114-
openEditors(editors: IResourceEditor[], group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<ReadonlyArray<IEditor>>;
114+
openEditors(editors: IEditorInputWithOptions[], group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<ReadonlyArray<IEditor>>;
115+
openEditors(editors: IResourceEditor[], group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable<ReadonlyArray<IEditor>>;
115116

116117
/**
117118
* Find out if the provided editor (or resource of an editor) is opened in any group.

src/vs/workbench/services/group/common/nextEditorGroupsService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import { Event } from 'vs/base/common/event';
99
import { createDecorator, ServiceIdentifier, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
10-
import { GroupIdentifier, IEditorOpeningEvent } from 'vs/workbench/common/editor';
11-
import { IEditorInput, IEditor, IEditorOptions, IEditorInputWithOptions, Direction } from 'vs/platform/editor/common/editor';
10+
import { GroupIdentifier, IEditorOpeningEvent, IEditorInputWithOptions } from 'vs/workbench/common/editor';
11+
import { IEditorInput, IEditor, IEditorOptions, Direction } from 'vs/platform/editor/common/editor';
1212

1313
export const INextEditorGroupsService = createDecorator<INextEditorGroupsService>('nextEditorGroupsService');
1414

0 commit comments

Comments
 (0)