Skip to content

Commit

Permalink
Adopt the model change events in favour of the group events (#139090)
Browse files Browse the repository at this point in the history
* deprecate `onDidGroupChange`

* adopt `GROUP_LOCKED` from model

* adopt `GROUP_INDEX` from model

* adopt `GROUP_ACTIVE` from model

* adopt `EDITOR_PIN` from model

* adopt `EDITOR_STICKY` from model

* adopt `EDITOR_CAPABILITIES` from model

* adopt `EDITOR_LABEL` from model

* adopt `EDITOR_WILL_DISPOSE` from model

* adopt `EDITOR_DIRTY` from model

* adopt `EDITOR_MOVE` from model

* adopt `EDITOR_CLOSE` from model

* adopt `EDITOR_OPEN` from model

* adopt `EDITOR_ACTIVE` from model but also introduce new event

* remove onDidGroupChange

* group change => group model change

* fix regression with tracking empty editor area
  • Loading branch information
bpasero committed Dec 15, 2021
1 parent 36bb6a6 commit cc76605
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 271 deletions.
34 changes: 17 additions & 17 deletions src/vs/workbench/api/browser/mainThreadEditorTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { ExtHostContext, IExtHostEditorTabsShape, IExtHostContext, MainContext, IEditorTabDto } from 'vs/workbench/api/common/extHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { EditorResourceAccessor, IUntypedEditorInput, SideBySideEditor, GroupChangeKind } from 'vs/workbench/common/editor';
import { EditorResourceAccessor, IUntypedEditorInput, SideBySideEditor, GroupModelChangeKind } from 'vs/workbench/common/editor';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { isGroupEditorCloseEvent, isGroupEditorMoveEvent, isGroupEditorOpenEvent } from 'vs/workbench/common/editor/editorGroupModel';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
Expand Down Expand Up @@ -157,7 +157,7 @@ export class MainThreadEditorTabs {
}

private _onDidGroupActivate(event: IEditorsChangeEvent): void {
if (event.kind !== GroupChangeKind.GROUP_INDEX && event.kind !== GroupChangeKind.EDITOR_ACTIVE) {
if (event.kind !== GroupModelChangeKind.GROUP_INDEX && event.kind !== GroupModelChangeKind.EDITOR_ACTIVE) {
return;
}
this._findAndUpdateActiveTab();
Expand Down Expand Up @@ -188,15 +188,15 @@ export class MainThreadEditorTabs {
// let eventString = '[';
// events.forEach(event => {
// switch (event.kind) {
// case GroupChangeKind.GROUP_INDEX: eventString += 'GROUP_INDEX, '; break;
// case GroupChangeKind.EDITOR_ACTIVE: eventString += 'EDITOR_ACTIVE, '; break;
// case GroupChangeKind.EDITOR_PIN: eventString += 'EDITOR_PIN, '; break;
// case GroupChangeKind.EDITOR_OPEN: eventString += 'EDITOR_OPEN, '; break;
// case GroupChangeKind.EDITOR_CLOSE: eventString += 'EDITOR_CLOSE, '; break;
// case GroupChangeKind.EDITOR_MOVE: eventString += 'EDITOR_MOVE, '; break;
// case GroupChangeKind.EDITOR_LABEL: eventString += 'EDITOR_LABEL, '; break;
// case GroupChangeKind.GROUP_ACTIVE: eventString += 'GROUP_ACTIVE, '; break;
// case GroupChangeKind.GROUP_LOCKED: eventString += 'GROUP_LOCKED, '; break;
// case GroupModelChangeKind.GROUP_INDEX: eventString += 'GROUP_INDEX, '; break;
// case GroupModelChangeKind.EDITOR_ACTIVE: eventString += 'EDITOR_ACTIVE, '; break;
// case GroupModelChangeKind.EDITOR_PIN: eventString += 'EDITOR_PIN, '; break;
// case GroupModelChangeKind.EDITOR_OPEN: eventString += 'EDITOR_OPEN, '; break;
// case GroupModelChangeKind.EDITOR_CLOSE: eventString += 'EDITOR_CLOSE, '; break;
// case GroupModelChangeKind.EDITOR_MOVE: eventString += 'EDITOR_MOVE, '; break;
// case GroupModelChangeKind.EDITOR_LABEL: eventString += 'EDITOR_LABEL, '; break;
// case GroupModelChangeKind.GROUP_ACTIVE: eventString += 'GROUP_ACTIVE, '; break;
// case GroupModelChangeKind.GROUP_LOCKED: eventString += 'GROUP_LOCKED, '; break;
// default: eventString += 'UNKNOWN, '; break;
// }
// });
Expand All @@ -212,24 +212,24 @@ export class MainThreadEditorTabs {
events.forEach(event => {
// Call the correct function for the change type
switch (event.kind) {
case GroupChangeKind.EDITOR_OPEN:
case GroupModelChangeKind.EDITOR_OPEN:
this._onDidTabOpen(event);
break;
case GroupChangeKind.EDITOR_CLOSE:
case GroupModelChangeKind.EDITOR_CLOSE:
this._onDidTabClose(event);
break;
case GroupChangeKind.EDITOR_ACTIVE:
case GroupChangeKind.GROUP_ACTIVE:
case GroupModelChangeKind.EDITOR_ACTIVE:
case GroupModelChangeKind.GROUP_ACTIVE:
if (this._editorGroupsService.activeGroup.id !== event.groupId) {
return;
}
this._onDidGroupActivate(event);
break;
case GroupChangeKind.GROUP_INDEX:
case GroupModelChangeKind.GROUP_INDEX:
this._createTabsModel();
// Here we stop the loop as no need to process other events
break;
case GroupChangeKind.EDITOR_MOVE:
case GroupModelChangeKind.EDITOR_MOVE:
this._onDidTabMove(event);
break;
default:
Expand Down
109 changes: 27 additions & 82 deletions src/vs/workbench/browser/parts/editor/editorGroupView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*--------------------------------------------------------------------------------------------*/

import 'vs/css!./media/editorgroupview';
import { EditorGroupModel, IEditorOpenOptions, IGroupChangeEvent, IGroupEditorCloseEvent, IGroupEditorMoveEvent, IGroupEditorOpenEvent, ISerializedEditorGroupModel, isGroupEditorCloseEvent, isGroupEditorMoveEvent, isGroupEditorOpenEvent, isSerializedEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel';
import { GroupIdentifier, CloseDirection, IEditorCloseEvent, ActiveEditorDirtyContext, IEditorPane, EditorGroupEditorsCountContext, SaveReason, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, ActiveEditorStickyContext, ActiveEditorPinnedContext, EditorResourceAccessor, EditorInputCapabilities, IUntypedEditorInput, DEFAULT_EDITOR_ASSOCIATION, ActiveEditorGroupLockedContext, SideBySideEditor, EditorCloseContext, IEditorWillMoveEvent, IEditorWillOpenEvent, IMatchEditorOptions, GroupChangeKind } from 'vs/workbench/common/editor';
import { EditorGroupModel, IEditorOpenOptions, IGroupModelChangeEvent, ISerializedEditorGroupModel, isGroupEditorCloseEvent, isGroupEditorOpenEvent, isSerializedEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel';
import { GroupIdentifier, CloseDirection, IEditorCloseEvent, ActiveEditorDirtyContext, IEditorPane, EditorGroupEditorsCountContext, SaveReason, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, ActiveEditorStickyContext, ActiveEditorPinnedContext, EditorResourceAccessor, EditorInputCapabilities, IUntypedEditorInput, DEFAULT_EDITOR_ASSOCIATION, ActiveEditorGroupLockedContext, SideBySideEditor, EditorCloseContext, IEditorWillMoveEvent, IEditorWillOpenEvent, IMatchEditorOptions, GroupModelChangeKind, IActiveEditorChangeEvent } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
import { Event, Emitter, Relay } from 'vs/base/common/event';
Expand Down Expand Up @@ -87,12 +87,12 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
private readonly _onWillDispose = this._register(new Emitter<void>());
readonly onWillDispose = this._onWillDispose.event;

private readonly _onDidGroupChange = this._register(new Emitter<IGroupChangeEvent>());
readonly onDidGroupChange = this._onDidGroupChange.event;

private readonly _onDidModelChange = this._register(new Emitter<IGroupChangeEvent>());
private readonly _onDidModelChange = this._register(new Emitter<IGroupModelChangeEvent>());
readonly onDidModelChange = this._onDidModelChange.event;

private readonly _onDidActiveEditorChange = this._register(new Emitter<IActiveEditorChangeEvent>());
readonly onDidActiveEditorChange = this._onDidActiveEditorChange.event;

private readonly _onDidOpenEditorFail = this._register(new Emitter<EditorInput>());
readonly onDidOpenEditorFail = this._onDidOpenEditorFail.event;

Expand Down Expand Up @@ -266,32 +266,33 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
};

// Update group contexts based on group changes
this._register(this.onDidGroupChange(e => {
this._register(this.onDidModelChange(e => {
switch (e.kind) {
case GroupChangeKind.EDITOR_ACTIVE:
// Track the active editor and update context key that reflects
// the dirty state of this editor
observeActiveEditor();
case GroupModelChangeKind.GROUP_LOCKED:
groupLockedContext.set(this.isLocked);
break;
case GroupChangeKind.EDITOR_PIN:
case GroupModelChangeKind.EDITOR_PIN:
if (e.editor && e.editor === this.model.activeEditor) {
groupActiveEditorPinnedContext.set(this.model.isPinned(this.model.activeEditor));
}
break;
case GroupChangeKind.EDITOR_STICKY:
case GroupModelChangeKind.EDITOR_STICKY:
if (e.editor && e.editor === this.model.activeEditor) {
groupActiveEditorStickyContext.set(this.model.isSticky(this.model.activeEditor));
}
break;
case GroupChangeKind.GROUP_LOCKED:
groupLockedContext.set(this.isLocked);
break;
}

// Group editors count context
groupEditorsCountContext.set(this.count);
}));

// Track the active editor and update context key that reflects
// the dirty state of this editor
this._register(this.onDidActiveEditorChange(() => {
observeActiveEditor();
}));

observeActiveEditor();
}

Expand Down Expand Up @@ -535,76 +536,40 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this._register(this.accessor.onDidVisibilityChange(e => this.onDidVisibilityChange(e)));
}

private onDidGroupModelChange(e: IGroupChangeEvent): void {
private onDidGroupModelChange(e: IGroupModelChangeEvent): void {

// Re-emit to outside
this._onDidModelChange.fire(e);

// Handle within

if (e.kind === GroupChangeKind.GROUP_LOCKED) {
this.onDidChangeGroupLocked();
return;
}

if (!e.editor) {
return;
}

switch (e.kind) {
case GroupChangeKind.EDITOR_PIN:
this.onDidChangeEditorPinned(e.editor);
break;
case GroupChangeKind.EDITOR_STICKY:
this.onDidChangeEditorSticky(e.editor);
break;
case GroupChangeKind.EDITOR_MOVE:
if (isGroupEditorMoveEvent(e)) {
this.onDidMoveEditor(e.editor, e.oldEditorIndex, e.editorIndex);
}
break;
case GroupChangeKind.EDITOR_OPEN:
case GroupModelChangeKind.EDITOR_OPEN:
if (isGroupEditorOpenEvent(e)) {
this.onDidOpenEditor(e.editor, e.editorIndex);
}
break;
case GroupChangeKind.EDITOR_CLOSE:
case GroupModelChangeKind.EDITOR_CLOSE:
if (isGroupEditorCloseEvent(e)) {
this.handleOnDidCloseEditor(e.editor, e.editorIndex, e.context, e.sticky);
}
break;
case GroupChangeKind.EDITOR_WILL_DISPOSE:
case GroupModelChangeKind.EDITOR_WILL_DISPOSE:
this.onWillDisposeEditor(e.editor);
break;
case GroupChangeKind.EDITOR_DIRTY:
case GroupModelChangeKind.EDITOR_DIRTY:
this.onDidChangeEditorDirty(e.editor);
break;
case GroupChangeKind.EDITOR_LABEL:
case GroupModelChangeKind.EDITOR_LABEL:
this.onDidChangeEditorLabel(e.editor);
break;
case GroupChangeKind.EDITOR_CAPABILITIES:
this.onDidChangeEditorCapabilities(e.editor);
break;
}
}

private onDidChangeGroupLocked(): void {
this._onDidGroupChange.fire({ kind: GroupChangeKind.GROUP_LOCKED });
}

private onDidChangeEditorPinned(editor: EditorInput): void {
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_PIN, editor });
}

private onDidChangeEditorSticky(editor: EditorInput): void {
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_STICKY, editor });
}

private onDidMoveEditor(editor: EditorInput, oldEditorIndex: number, editorIndex: number): void {
const event: IGroupEditorMoveEvent = { kind: GroupChangeKind.EDITOR_MOVE, editor, oldEditorIndex, editorIndex };
this._onDidGroupChange.fire(event);
}

private onDidOpenEditor(editor: EditorInput, editorIndex: number): void {

/* __GDPR__
Expand All @@ -618,10 +583,6 @@ export class EditorGroupView extends Themable implements IEditorGroupView {

// Update container
this.updateContainer();

// Event
const event: IGroupEditorOpenEvent = { kind: GroupChangeKind.EDITOR_OPEN, editor, editorIndex };
this._onDidGroupChange.fire(event);
}

private handleOnDidCloseEditor(editor: EditorInput, editorIndex: number, context: EditorCloseContext, sticky: boolean): void {
Expand Down Expand Up @@ -661,8 +622,6 @@ export class EditorGroupView extends Themable implements IEditorGroupView {

// Event
this._onDidCloseEditor.fire({ groupId: this.id, editor, context, index: editorIndex, sticky });
const event: IGroupEditorCloseEvent = { kind: GroupChangeKind.EDITOR_CLOSE, editor, editorIndex, context, sticky };
this._onDidGroupChange.fire(event);
}

private canDispose(editor: EditorInput): boolean {
Expand Down Expand Up @@ -776,24 +735,12 @@ export class EditorGroupView extends Themable implements IEditorGroupView {

// Forward to title control
this.titleAreaControl.updateEditorDirty(editor);

// Event
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_DIRTY, editor });
}

private onDidChangeEditorLabel(editor: EditorInput): void {

// Forward to title control
this.titleAreaControl.updateEditorLabel(editor);

// Event
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_LABEL, editor });
}

private onDidChangeEditorCapabilities(editor: EditorInput): void {

// Event
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_CAPABILITIES, editor });
}

private onDidVisibilityChange(visible: boolean): void {
Expand Down Expand Up @@ -843,8 +790,6 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
if (this._index !== newIndex) {
this._index = newIndex;
this.model.setIndex(newIndex);

this._onDidGroupChange.fire({ kind: GroupChangeKind.GROUP_INDEX });
}
}

Expand All @@ -861,8 +806,8 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
// Update styles
this.updateStyles();

// Event
this._onDidGroupChange.fire({ kind: GroupChangeKind.GROUP_ACTIVE });
// Update model
this.model.setActive(undefined /* entire group got active */);
}

//#endregion
Expand Down Expand Up @@ -1119,7 +1064,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {

// Editor change event
if (changed) {
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_ACTIVE, editor });
this._onDidActiveEditorChange.fire({ editor });
}

// Handle errors but do not bubble them up
Expand Down Expand Up @@ -1535,7 +1480,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
}

// Events
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_ACTIVE });
this._onDidActiveEditorChange.fire({ editor: undefined });

// Remove empty group if we should
if (closeEmptyGroup) {
Expand Down
20 changes: 11 additions & 9 deletions src/vs/workbench/browser/parts/editor/editorPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { contrastBorder, editorBackground } from 'vs/platform/theme/common/color
import { GroupDirection, IAddGroupOptions, GroupsArrangement, GroupOrientation, IMergeGroupOptions, MergeGroupMode, GroupsOrder, GroupLocation, IFindGroupScope, EditorGroupLayout, GroupLayoutArgument, IEditorGroupsService, IEditorSideGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IView, orthogonal, LayoutPriority, IViewSize, Direction, SerializableGrid, Sizing, ISerializedGrid, Orientation, GridBranchNode, isGridBranchNode, GridNode, createSerializedGrid, Grid } from 'vs/base/browser/ui/grid/grid';
import { GroupIdentifier, EditorInputWithOptions, IEditorPartOptions, IEditorPartOptionsChangeEvent, GroupChangeKind } from 'vs/workbench/common/editor';
import { GroupIdentifier, EditorInputWithOptions, IEditorPartOptions, IEditorPartOptionsChangeEvent, GroupModelChangeKind } from 'vs/workbench/common/editor';
import { EDITOR_GROUP_BORDER, EDITOR_PANE_BACKGROUND } from 'vs/workbench/common/theme';
import { distinct, coalesce, firstOrDefault } from 'vs/base/common/arrays';
import { IEditorGroupsAccessor, IEditorGroupView, getEditorPartOptions, impactsEditorPartOptions, IEditorPartCreationOptions } from 'vs/workbench/browser/parts/editor/editor';
Expand Down Expand Up @@ -550,21 +550,23 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
this.doSetGroupActive(groupView);
}));

// Track editor change
groupDisposables.add(groupView.onDidGroupChange(e => {
// Track group changes
groupDisposables.add(groupView.onDidModelChange(e => {
switch (e.kind) {
case GroupChangeKind.EDITOR_ACTIVE:
this.updateContainer();
case GroupModelChangeKind.GROUP_LOCKED:
this._onDidChangeGroupLocked.fire(groupView);
break;
case GroupChangeKind.GROUP_INDEX:
case GroupModelChangeKind.GROUP_INDEX:
this._onDidChangeGroupIndex.fire(groupView);
break;
case GroupChangeKind.GROUP_LOCKED:
this._onDidChangeGroupLocked.fire(groupView);
break;
}
}));

// Track active editor change after it occurred
groupDisposables.add(groupView.onDidActiveEditorChange(() => {
this.updateContainer();
}));

// Track dispose
Event.once(groupView.onWillDispose)(() => {
dispose(groupDisposables);
Expand Down

0 comments on commit cc76605

Please sign in to comment.