From 91635e833342f59cd847c8565e02cc62c293b252 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 17 May 2018 17:33:16 +0200 Subject: [PATCH] grid - add onDidOpen event to groups --- .../parts/editor2/nextEditorGroupView.ts | 18 ++++++++----- .../group/common/nextEditorGroupsService.ts | 27 +++++++++++-------- .../browser/nextEditorGroupsService.test.ts | 16 ++++++++--- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts b/src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts index 2d280c2fef7..5619e646e2e 100644 --- a/src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts @@ -78,15 +78,18 @@ export class NextEditorGroupView extends Themable implements INextEditorGroupVie private _onWillOpenEditor: Emitter = this._register(new Emitter()); get onWillOpenEditor(): Event { return this._onWillOpenEditor.event; } + private _onDidOpenEditor: Emitter = this._register(new Emitter()); + get onDidOpenEditor(): Event { return this._onDidOpenEditor.event; } + + private _onDidOpenEditorFail: Emitter = this._register(new Emitter()); + get onDidOpenEditorFail(): Event { return this._onDidOpenEditorFail.event; } + private _onWillCloseEditor: Emitter = this._register(new Emitter()); get onWillCloseEditor(): Event { return this._onWillCloseEditor.event; } private _onDidCloseEditor: Emitter = this._register(new Emitter()); get onDidCloseEditor(): Event { return this._onDidCloseEditor.event; } - private _onDidOpenEditorFail: Emitter = this._register(new Emitter()); - get onDidOpenEditorFail(): Event { return this._onDidOpenEditorFail.event; } - //#endregion private _group: EditorGroup; @@ -365,6 +368,9 @@ export class NextEditorGroupView extends Themable implements INextEditorGroupVie // Update container this.updateContainer(); + + // Event + this._onDidOpenEditor.fire(editor); } private onDidEditorClose(event: EditorCloseEvent): void { @@ -389,9 +395,6 @@ export class NextEditorGroupView extends Themable implements INextEditorGroupVie } }); - // After close - this._onDidCloseEditor.fire(event); - /* __GDPR__ "editorClosed" : { "${include}": [ @@ -403,6 +406,9 @@ export class NextEditorGroupView extends Themable implements INextEditorGroupVie // Update container this.updateContainer(); + + // Event + this._onDidCloseEditor.fire(event); } private onDidEditorDispose(editor: EditorInput): void { diff --git a/src/vs/workbench/services/group/common/nextEditorGroupsService.ts b/src/vs/workbench/services/group/common/nextEditorGroupsService.ts index 0e1bb9df519..3343e90ab17 100644 --- a/src/vs/workbench/services/group/common/nextEditorGroupsService.ts +++ b/src/vs/workbench/services/group/common/nextEditorGroupsService.ts @@ -287,6 +287,22 @@ export interface INextEditorGroup { */ readonly onDidActiveEditorChange: Event; + /** + * Emitted when an editor is about to open. This can be prevented from + * the provided event. + */ + readonly onWillOpenEditor: Event; + + /** + * Emitted when an editor has opened successfully. + */ + readonly onDidOpenEditor: Event; + + /** + * Emitted when an editor failed to open. + */ + readonly onDidOpenEditorFail: Event; + /** * Emitted when an editor of this group is about to get closed. * @@ -300,17 +316,6 @@ export interface INextEditorGroup { */ readonly onDidCloseEditor: Event; - /** - * Emitted when an editor is about to open. This can be prevented from - * the provided event. - */ - readonly onWillOpenEditor: Event; - - /** - * Emitted when an editor failed to open. - */ - readonly onDidOpenEditorFail: Event; - /** * An event for when the label of the group changes. */ diff --git a/src/vs/workbench/services/group/test/browser/nextEditorGroupsService.test.ts b/src/vs/workbench/services/group/test/browser/nextEditorGroupsService.test.ts index 32dcff4d130..cdb90b74ff9 100644 --- a/src/vs/workbench/services/group/test/browser/nextEditorGroupsService.test.ts +++ b/src/vs/workbench/services/group/test/browser/nextEditorGroupsService.test.ts @@ -356,6 +356,16 @@ suite('Editor groups service (editor2)', () => { activeEditorChangeCounter++; }); + let editorWillOpenCounter = 0; + const editorWillOpenListener = group.onWillOpenEditor(() => { + editorWillOpenCounter++; + }); + + let editorDidOpenCounter = 0; + const editorDidOpenListener = group.onDidOpenEditor(() => { + editorDidOpenCounter++; + }); + let editorCloseCounter = 0; const editorCloseListener = group.onDidCloseEditor(() => { editorCloseCounter++; @@ -365,10 +375,6 @@ suite('Editor groups service (editor2)', () => { const editorWillCloseListener = group.onWillCloseEditor(() => { editorWillCloseCounter++; }); - let editorWillOpenCounter = 0; - const editorWillOpenListener = group.onWillOpenEditor(() => { - editorWillOpenCounter++; - }); const input = new TestEditorInput(URI.file('foo/bar')); const inputInactive = new TestEditorInput(URI.file('foo/bar/inactive')); @@ -382,6 +388,7 @@ suite('Editor groups service (editor2)', () => { assert.equal(group.isEmpty(), false); assert.equal(group.count, 2); assert.equal(editorWillOpenCounter, 2); + assert.equal(editorDidOpenCounter, 2); assert.equal(activeEditorChangeCounter, 1); assert.equal(group.getEditor(0), input); assert.equal(group.getEditor(1), inputInactive); @@ -413,6 +420,7 @@ suite('Editor groups service (editor2)', () => { editorCloseListener.dispose(); editorWillCloseListener.dispose(); editorWillOpenListener.dispose(); + editorDidOpenListener.dispose(); part.dispose(); }); }); -- GitLab