Switch to aggregate model events
This commit is contained in:
parent
816dc4c28e
commit
22218e385d
|
@ -4,7 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import 'vs/css!./media/editorgroupview';
|
||||
import { EditorGroupModel, IEditorOpenOptions, ISerializedEditorGroupModel, isSerializedEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel';
|
||||
import { EditorGroupModel, EditorGroupModelChangeKind, IEditorOpenOptions, ISerializedEditorGroupModel, isSerializedEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel';
|
||||
import { GroupIdentifier, CloseDirection, IEditorCloseEvent, ActiveEditorDirtyContext, IEditorPane, EditorGroupEditorsCountContext, SaveReason, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, ActiveEditorStickyContext, ActiveEditorPinnedContext, EditorResourceAccessor, IEditorMoveEvent, EditorInputCapabilities, IEditorOpenEvent, IUntypedEditorInput, DEFAULT_EDITOR_ASSOCIATION, ActiveEditorGroupLockedContext, SideBySideEditor, EditorCloseContext, IEditorWillMoveEvent, IEditorWillOpenEvent } from 'vs/workbench/common/editor';
|
||||
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
||||
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
|
||||
|
@ -523,16 +523,52 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
|||
private registerListeners(): void {
|
||||
|
||||
// Model Events
|
||||
this._register(this.model.onDidChangeLocked(() => this.onDidChangeGroupLocked()));
|
||||
this._register(this.model.onDidChangeEditorPinned(editor => this.onDidChangeEditorPinned(editor)));
|
||||
this._register(this.model.onDidChangeEditorSticky(editor => this.onDidChangeEditorSticky(editor)));
|
||||
this._register(this.model.onDidMoveEditor(event => this.onDidMoveEditor(event)));
|
||||
this._register(this.model.onDidOpenEditor(editor => this.onDidOpenEditor(editor)));
|
||||
this._register(this.model.onDidCloseEditor(editor => this.handleOnDidCloseEditor(editor)));
|
||||
this._register(this.model.onWillDisposeEditor(editor => this.onWillDisposeEditor(editor)));
|
||||
this._register(this.model.onDidChangeEditorDirty(editor => this.onDidChangeEditorDirty(editor)));
|
||||
this._register(this.model.onDidChangeEditorLabel(editor => this.onDidChangeEditorLabel(editor)));
|
||||
this._register(this.model.onDidChangeEditorCapabilities(editor => this.onDidChangeEditorCapabilities(editor)));
|
||||
this._register(this.model.onDidModelChange(e => {
|
||||
switch (e.kind) {
|
||||
case EditorGroupModelChangeKind.LOCK:
|
||||
this.onDidChangeGroupLocked();
|
||||
break;
|
||||
case EditorGroupModelChangeKind.PINNED:
|
||||
if (e.editorInputOrEvent instanceof EditorInput) {
|
||||
this.onDidChangeEditorPinned(e.editorInputOrEvent);
|
||||
}
|
||||
break;
|
||||
case EditorGroupModelChangeKind.STICKY:
|
||||
if (e.editorInputOrEvent instanceof EditorInput) {
|
||||
this.onDidChangeEditorSticky(e.editorInputOrEvent);
|
||||
}
|
||||
break;
|
||||
case EditorGroupModelChangeKind.MOVE:
|
||||
this.onDidMoveEditor(e.editorInputOrEvent as IEditorMoveEvent);
|
||||
break;
|
||||
case EditorGroupModelChangeKind.OPEN:
|
||||
this.onDidOpenEditor(e.editorInputOrEvent as IEditorOpenEvent);
|
||||
break;
|
||||
case EditorGroupModelChangeKind.CLOSE:
|
||||
this.handleOnDidCloseEditor(e.editorInputOrEvent as IEditorCloseEvent);
|
||||
break;
|
||||
case EditorGroupModelChangeKind.DISPOSE:
|
||||
if (e.editorInputOrEvent instanceof EditorInput) {
|
||||
this.onWillDisposeEditor(e.editorInputOrEvent);
|
||||
}
|
||||
break;
|
||||
case EditorGroupModelChangeKind.DIRTY:
|
||||
if (e.editorInputOrEvent instanceof EditorInput) {
|
||||
this.onDidChangeEditorDirty(e.editorInputOrEvent);
|
||||
}
|
||||
break;
|
||||
case EditorGroupModelChangeKind.LABEL:
|
||||
if (e.editorInputOrEvent instanceof EditorInput) {
|
||||
this.onDidChangeEditorLabel(e.editorInputOrEvent);
|
||||
}
|
||||
break;
|
||||
case EditorGroupModelChangeKind.CAPABILITIES:
|
||||
if (e.editorInputOrEvent instanceof EditorInput) {
|
||||
this.onDidChangeEditorCapabilities(e.editorInputOrEvent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}));
|
||||
|
||||
// Option Changes
|
||||
this._register(this.accessor.onDidChangeEditorPartOptions(e => this.onDidChangeEditorPartOptions(e)));
|
||||
|
|
|
@ -70,7 +70,7 @@ export interface IMatchOptions {
|
|||
strictEquals?: boolean;
|
||||
}
|
||||
|
||||
export enum EditorModelChangeKind {
|
||||
export enum EditorGroupModelChangeKind {
|
||||
LOCK,
|
||||
ACTIVATE,
|
||||
OPEN,
|
||||
|
@ -84,8 +84,8 @@ export enum EditorModelChangeKind {
|
|||
STICKY
|
||||
}
|
||||
|
||||
export interface EditorModelChangeEvent {
|
||||
kind: EditorModelChangeKind;
|
||||
export interface EditorGroupModelChangeEvent {
|
||||
kind: EditorGroupModelChangeKind;
|
||||
editorInputOrEvent?: EditorInput | IEditorOpenEvent | IEditorCloseEvent | IEditorMoveEvent;
|
||||
}
|
||||
|
||||
|
@ -95,40 +95,7 @@ export class EditorGroupModel extends Disposable {
|
|||
|
||||
//#region events
|
||||
|
||||
private readonly _onDidChangeLocked = this._register(new Emitter<void>());
|
||||
readonly onDidChangeLocked = this._onDidChangeLocked.event;
|
||||
|
||||
private readonly _onDidActivateEditor = this._register(new Emitter<EditorInput>());
|
||||
readonly onDidActivateEditor = this._onDidActivateEditor.event;
|
||||
|
||||
private readonly _onDidOpenEditor = this._register(new Emitter<IEditorOpenEvent>());
|
||||
readonly onDidOpenEditor = this._onDidOpenEditor.event;
|
||||
|
||||
private readonly _onDidCloseEditor = this._register(new Emitter<IEditorCloseEvent>());
|
||||
readonly onDidCloseEditor = this._onDidCloseEditor.event;
|
||||
|
||||
private readonly _onWillDisposeEditor = this._register(new Emitter<EditorInput>());
|
||||
readonly onWillDisposeEditor = this._onWillDisposeEditor.event;
|
||||
|
||||
private readonly _onDidChangeEditorDirty = this._register(new Emitter<EditorInput>());
|
||||
readonly onDidChangeEditorDirty = this._onDidChangeEditorDirty.event;
|
||||
|
||||
private readonly _onDidChangeEditorLabel = this._register(new Emitter<EditorInput>());
|
||||
readonly onDidChangeEditorLabel = this._onDidChangeEditorLabel.event;
|
||||
|
||||
private readonly _onDidChangeEditorCapabilities = this._register(new Emitter<EditorInput>());
|
||||
readonly onDidChangeEditorCapabilities = this._onDidChangeEditorCapabilities.event;
|
||||
|
||||
private readonly _onDidMoveEditor = this._register(new Emitter<IEditorMoveEvent>());
|
||||
readonly onDidMoveEditor = this._onDidMoveEditor.event;
|
||||
|
||||
private readonly _onDidChangeEditorPinned = this._register(new Emitter<EditorInput>());
|
||||
readonly onDidChangeEditorPinned = this._onDidChangeEditorPinned.event;
|
||||
|
||||
private readonly _onDidChangeEditorSticky = this._register(new Emitter<EditorInput>());
|
||||
readonly onDidChangeEditorSticky = this._onDidChangeEditorSticky.event;
|
||||
|
||||
private readonly _onDidModelChange = this._register(new Emitter<EditorModelChangeEvent>());
|
||||
private readonly _onDidModelChange = this._register(new Emitter<EditorGroupModelChangeEvent>());
|
||||
readonly onDidModelChange = this._onDidModelChange.event;
|
||||
|
||||
//#endregion
|
||||
|
@ -308,8 +275,7 @@ export class EditorGroupModel extends Disposable {
|
|||
this.registerEditorListeners(newEditor);
|
||||
|
||||
// Event
|
||||
this._onDidOpenEditor.fire({ editor: newEditor, groupId: this.id, index: targetIndex });
|
||||
this._onDidModelChange.fire(({ kind: EditorModelChangeKind.OPEN, editorInputOrEvent: { editor: newEditor, groupId: this.id, index: targetIndex } }));
|
||||
this._onDidModelChange.fire(({ kind: EditorGroupModelChangeKind.OPEN, editorInputOrEvent: { editor: newEditor, groupId: this.id, index: targetIndex } }));
|
||||
|
||||
// Handle active
|
||||
if (makeActive) {
|
||||
|
@ -360,32 +326,29 @@ export class EditorGroupModel extends Disposable {
|
|||
// Re-emit disposal of editor input as our own event
|
||||
listeners.add(Event.once(editor.onWillDispose)(() => {
|
||||
if (this.indexOf(editor) >= 0) {
|
||||
this._onWillDisposeEditor.fire(editor);
|
||||
this._onDidModelChange.fire(({ kind: EditorModelChangeKind.DISPOSE, editorInputOrEvent: editor }));
|
||||
this._onDidModelChange.fire(({ kind: EditorGroupModelChangeKind.DISPOSE, editorInputOrEvent: editor }));
|
||||
}
|
||||
}));
|
||||
|
||||
// Re-Emit dirty state changes
|
||||
listeners.add(editor.onDidChangeDirty(() => {
|
||||
this._onDidChangeEditorDirty.fire(editor);
|
||||
this._onDidModelChange.fire(({ kind: EditorModelChangeKind.DIRTY, editorInputOrEvent: editor }));
|
||||
this._onDidModelChange.fire(({ kind: EditorGroupModelChangeKind.DIRTY, editorInputOrEvent: editor }));
|
||||
}));
|
||||
|
||||
// Re-Emit label changes
|
||||
listeners.add(editor.onDidChangeLabel(() => {
|
||||
this._onDidChangeEditorLabel.fire(editor);
|
||||
this._onDidModelChange.fire(({ kind: EditorModelChangeKind.LABEL, editorInputOrEvent: editor }));
|
||||
this._onDidModelChange.fire(({ kind: EditorGroupModelChangeKind.LABEL, editorInputOrEvent: editor }));
|
||||
}));
|
||||
|
||||
// Re-Emit capability changes
|
||||
listeners.add(editor.onDidChangeCapabilities(() => {
|
||||
this._onDidChangeEditorCapabilities.fire(editor);
|
||||
this._onDidModelChange.fire(({ kind: EditorModelChangeKind.CAPABILITIES, editorInputOrEvent: editor }));
|
||||
this._onDidModelChange.fire(({ kind: EditorGroupModelChangeKind.CAPABILITIES, editorInputOrEvent: editor }));
|
||||
}));
|
||||
|
||||
// Clean up dispose listeners once the editor gets closed
|
||||
listeners.add(this.onDidCloseEditor(event => {
|
||||
if (event.editor.matches(editor)) {
|
||||
listeners.add(this.onDidModelChange(event => {
|
||||
|
||||
if (event.kind === EditorGroupModelChangeKind.CLOSE && (event.editorInputOrEvent as IEditorCloseEvent).editor.matches(editor)) {
|
||||
dispose(listeners);
|
||||
}
|
||||
}));
|
||||
|
@ -400,8 +363,7 @@ export class EditorGroupModel extends Disposable {
|
|||
this.splice(replaceIndex, false, replaceWith);
|
||||
|
||||
if (event) {
|
||||
this._onDidCloseEditor.fire(event);
|
||||
this._onDidModelChange.fire({ kind: EditorModelChangeKind.CLOSE, editorInputOrEvent: event });
|
||||
this._onDidModelChange.fire({ kind: EditorGroupModelChangeKind.CLOSE, editorInputOrEvent: event });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -409,8 +371,7 @@ export class EditorGroupModel extends Disposable {
|
|||
const event = this.doCloseEditor(candidate, context, openNext);
|
||||
|
||||
if (event) {
|
||||
this._onDidCloseEditor.fire(event);
|
||||
this._onDidModelChange.fire({ kind: EditorModelChangeKind.CLOSE, editorInputOrEvent: event });
|
||||
this._onDidModelChange.fire({ kind: EditorGroupModelChangeKind.CLOSE, editorInputOrEvent: event });
|
||||
|
||||
return event;
|
||||
}
|
||||
|
@ -495,8 +456,7 @@ export class EditorGroupModel extends Disposable {
|
|||
this.editors.splice(toIndex, 0, editor);
|
||||
|
||||
// Event
|
||||
this._onDidMoveEditor.fire({ editor, groupId: this.id, index, newIndex: toIndex, target: this.id });
|
||||
this._onDidModelChange.fire({ kind: EditorModelChangeKind.MOVE, editorInputOrEvent: { editor, groupId: this.id, index, newIndex: toIndex, target: this.id } });
|
||||
this._onDidModelChange.fire({ kind: EditorGroupModelChangeKind.MOVE, editorInputOrEvent: { editor, groupId: this.id, index, newIndex: toIndex, target: this.id } });
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
@ -527,8 +487,7 @@ export class EditorGroupModel extends Disposable {
|
|||
this.mru.unshift(editor);
|
||||
|
||||
// Event
|
||||
this._onDidActivateEditor.fire(editor);
|
||||
this._onDidModelChange.fire({ kind: EditorModelChangeKind.ACTIVATE, editorInputOrEvent: editor });
|
||||
this._onDidModelChange.fire({ kind: EditorGroupModelChangeKind.ACTIVATE, editorInputOrEvent: editor });
|
||||
}
|
||||
|
||||
pin(candidate: EditorInput): EditorInput | undefined {
|
||||
|
@ -553,8 +512,7 @@ export class EditorGroupModel extends Disposable {
|
|||
this.preview = null;
|
||||
|
||||
// Event
|
||||
this._onDidChangeEditorPinned.fire(editor);
|
||||
this._onDidModelChange.fire({ kind: EditorModelChangeKind.PINNED, editorInputOrEvent: editor });
|
||||
this._onDidModelChange.fire({ kind: EditorGroupModelChangeKind.PINNED, editorInputOrEvent: editor });
|
||||
}
|
||||
|
||||
unpin(candidate: EditorInput): EditorInput | undefined {
|
||||
|
@ -580,8 +538,7 @@ export class EditorGroupModel extends Disposable {
|
|||
this.preview = editor;
|
||||
|
||||
// Event
|
||||
this._onDidChangeEditorPinned.fire(editor);
|
||||
this._onDidModelChange.fire({ kind: EditorModelChangeKind.PINNED, editorInputOrEvent: editor });
|
||||
this._onDidModelChange.fire({ kind: EditorGroupModelChangeKind.PINNED, editorInputOrEvent: editor });
|
||||
|
||||
// Close old preview editor if any
|
||||
if (oldPreview) {
|
||||
|
@ -628,7 +585,7 @@ export class EditorGroupModel extends Disposable {
|
|||
this.sticky++;
|
||||
|
||||
// Event
|
||||
this._onDidChangeEditorSticky.fire(editor);
|
||||
this._onDidModelChange.fire({ kind: EditorGroupModelChangeKind.STICKY, editorInputOrEvent: editor });
|
||||
}
|
||||
|
||||
unstick(candidate: EditorInput): EditorInput | undefined {
|
||||
|
@ -656,7 +613,7 @@ export class EditorGroupModel extends Disposable {
|
|||
this.sticky--;
|
||||
|
||||
// Event
|
||||
this._onDidChangeEditorSticky.fire(editor);
|
||||
this._onDidModelChange.fire({ kind: EditorGroupModelChangeKind.STICKY, editorInputOrEvent: editor });
|
||||
}
|
||||
|
||||
isSticky(candidateOrIndex: EditorInput | number): boolean {
|
||||
|
@ -807,8 +764,7 @@ export class EditorGroupModel extends Disposable {
|
|||
if (this.isLocked !== locked) {
|
||||
this.locked = locked;
|
||||
|
||||
this._onDidChangeLocked.fire();
|
||||
this._onDidModelChange.fire({ kind: EditorModelChangeKind.LOCK });
|
||||
this._onDidModelChange.fire({ kind: EditorGroupModelChangeKind.LOCK });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { EditorGroupModel, ISerializedEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel';
|
||||
import { EditorGroupModel, EditorGroupModelChangeKind, ISerializedEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel';
|
||||
import { EditorExtensions, IEditorFactoryRegistry, IFileEditorInput, IEditorSerializer, CloseDirection, EditorsOrder, IResourceDiffEditorInput, IResourceSideBySideEditorInput, SideBySideEditor, EditorCloseContext, IEditorCloseEvent, IEditorOpenEvent, IEditorMoveEvent } from 'vs/workbench/common/editor';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { TestLifecycleService, workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
|
@ -105,14 +105,34 @@ suite('EditorGroupModel', () => {
|
|||
disposed: []
|
||||
};
|
||||
|
||||
group.onDidChangeLocked(() => groupEvents.locked.push(group.id));
|
||||
group.onDidOpenEditor(e => groupEvents.opened.push(e));
|
||||
group.onDidCloseEditor(e => groupEvents.closed.push(e));
|
||||
group.onDidActivateEditor(e => groupEvents.activated.push(e));
|
||||
group.onDidChangeEditorPinned(e => group.isPinned(e) ? groupEvents.pinned.push(e) : groupEvents.unpinned.push(e));
|
||||
group.onDidChangeEditorSticky(e => group.isSticky(e) ? groupEvents.sticky.push(e) : groupEvents.unsticky.push(e));
|
||||
group.onDidMoveEditor(e => groupEvents.moved.push(e));
|
||||
group.onWillDisposeEditor(e => groupEvents.disposed.push(e));
|
||||
group.onDidModelChange(e => {
|
||||
switch (e.kind) {
|
||||
case EditorGroupModelChangeKind.LOCK:
|
||||
groupEvents.locked.push(group.id);
|
||||
break;
|
||||
case EditorGroupModelChangeKind.OPEN:
|
||||
groupEvents.opened.push(e.editorInputOrEvent as IEditorOpenEvent);
|
||||
break;
|
||||
case EditorGroupModelChangeKind.CLOSE:
|
||||
groupEvents.closed.push(e.editorInputOrEvent as IEditorCloseEvent);
|
||||
break;
|
||||
case EditorGroupModelChangeKind.ACTIVATE:
|
||||
groupEvents.activated.push(e.editorInputOrEvent as EditorInput);
|
||||
break;
|
||||
case EditorGroupModelChangeKind.PINNED:
|
||||
group.isPinned(e.editorInputOrEvent as EditorInput) ? groupEvents.pinned.push(e.editorInputOrEvent as EditorInput) : groupEvents.unpinned.push(e.editorInputOrEvent as EditorInput);
|
||||
break;
|
||||
case EditorGroupModelChangeKind.STICKY:
|
||||
group.isSticky(e.editorInputOrEvent as EditorInput) ? groupEvents.sticky.push(e.editorInputOrEvent as EditorInput) : groupEvents.unsticky.push(e.editorInputOrEvent as EditorInput);
|
||||
break;
|
||||
case EditorGroupModelChangeKind.MOVE:
|
||||
groupEvents.moved.push(e.editorInputOrEvent as IEditorMoveEvent);
|
||||
break;
|
||||
case EditorGroupModelChangeKind.DISPOSE:
|
||||
groupEvents.disposed.push(e.editorInputOrEvent as EditorInput);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
return groupEvents;
|
||||
}
|
||||
|
@ -278,7 +298,11 @@ suite('EditorGroupModel', () => {
|
|||
assert.strictEqual(clone.isLocked, false); // locking does not clone over
|
||||
|
||||
let didEditorLabelChange = false;
|
||||
const toDispose = clone.onDidChangeEditorLabel(() => didEditorLabelChange = true);
|
||||
const toDispose = clone.onDidModelChange((e) => {
|
||||
if (e.kind === EditorGroupModelChangeKind.LABEL) {
|
||||
didEditorLabelChange = true;
|
||||
}
|
||||
});
|
||||
input1.setLabel();
|
||||
assert.ok(didEditorLabelChange);
|
||||
|
||||
|
@ -1825,23 +1849,31 @@ suite('EditorGroupModel', () => {
|
|||
group2.openEditor(input2, { pinned: true, active: true });
|
||||
|
||||
let dirty1Counter = 0;
|
||||
group1.onDidChangeEditorDirty(() => {
|
||||
dirty1Counter++;
|
||||
group1.onDidModelChange((e) => {
|
||||
if (e.kind === EditorGroupModelChangeKind.DIRTY) {
|
||||
dirty1Counter++;
|
||||
}
|
||||
});
|
||||
|
||||
let dirty2Counter = 0;
|
||||
group2.onDidChangeEditorDirty(() => {
|
||||
dirty2Counter++;
|
||||
group2.onDidModelChange((e) => {
|
||||
if (e.kind === EditorGroupModelChangeKind.DIRTY) {
|
||||
dirty2Counter++;
|
||||
}
|
||||
});
|
||||
|
||||
let label1ChangeCounter = 0;
|
||||
group1.onDidChangeEditorLabel(() => {
|
||||
label1ChangeCounter++;
|
||||
group1.onDidModelChange((e) => {
|
||||
if (e.kind === EditorGroupModelChangeKind.LABEL) {
|
||||
label1ChangeCounter++;
|
||||
}
|
||||
});
|
||||
|
||||
let label2ChangeCounter = 0;
|
||||
group2.onDidChangeEditorLabel(() => {
|
||||
label2ChangeCounter++;
|
||||
group2.onDidModelChange((e) => {
|
||||
if (e.kind === EditorGroupModelChangeKind.LABEL) {
|
||||
label2ChangeCounter++;
|
||||
}
|
||||
});
|
||||
|
||||
(<TestEditorInput>input1).setDirty();
|
||||
|
|
Loading…
Reference in a new issue