From d15d5242f03bfbb0b98b0490d15eab3fc7cf4874 Mon Sep 17 00:00:00 2001 From: isidor Date: Wed, 11 May 2016 10:54:33 +0200 Subject: [PATCH] open editors: react on editor group updates --- .../files/browser/views/openEditorsView.ts | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/parts/files/browser/views/openEditorsView.ts b/src/vs/workbench/parts/files/browser/views/openEditorsView.ts index ab6668168f8..f89ba95062a 100644 --- a/src/vs/workbench/parts/files/browser/views/openEditorsView.ts +++ b/src/vs/workbench/parts/files/browser/views/openEditorsView.ts @@ -16,10 +16,11 @@ import {IInstantiationService} from 'vs/platform/instantiation/common/instantiat import {IEventService} from 'vs/platform/event/common/event'; import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; import {EventType as WorkbenchEventType, UntitledEditorEvent} from 'vs/workbench/common/events'; +import {EditorInput} from 'vs/workbench/common/editor'; import {AdaptiveCollapsibleViewletView} from 'vs/workbench/browser/viewlet'; import {ITextFileService, TextFileChangeEvent, EventType as FileEventType, AutoSaveMode, IFilesConfiguration} from 'vs/workbench/parts/files/common/files'; import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; -import {IEditorStacksModel} from 'vs/workbench/common/editor/editorStacksModel'; +import {IEditorStacksModel, IEditorGroup} from 'vs/workbench/common/editor/editorStacksModel'; import {Renderer, DataSource, Controller} from 'vs/workbench/parts/files/browser/views/openEditorsViewer'; const $ = dom.emmet; @@ -104,6 +105,11 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView { private registerListeners(): void { // update on model changes + this.toDispose.push(this.model.onGroupActivated(e => this.onEditorGroupUpdated(e))); + this.toDispose.push(this.model.onGroupClosed(e => this.onEditorGroupUpdated(e))); + this.toDispose.push(this.model.onGroupMoved(e => this.onEditorGroupUpdated(e))); + this.toDispose.push(this.model.onGroupOpened(e => this.onEditorGroupUpdated(e))); + this.toDispose.push(this.model.onGroupRenamed(e => this.onEditorGroupUpdated(e))); // listen to untitled this.toDispose.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DIRTY, (e: UntitledEditorEvent) => this.onUntitledFileDirty())); @@ -119,6 +125,36 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView { this.toDispose.push(this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationUpdated(e.config))); } + private onEditorGroupUpdated(e: IEditorGroup): void { + if (this.isDisposed) { + return; + } + + // View size + this.expandedBodySize = this.getExpandedBodySize(this.model); + + if (this.tree) { + // Show in tree + this.tree.refresh().done(null, errors.onUnexpectedError); + + // Make sure to keep active editor input highlighted + if (this.model.activeGroup) { + this.highlightEntry(this.model.activeGroup.activeEditor); + } + } + } + + private highlightEntry(entry: EditorInput): void { + this.tree.clearFocus(); + this.tree.clearSelection(); + + if (entry) { + this.tree.setFocus(entry); + this.tree.setSelection([entry]); + this.tree.reveal(entry).done(null, errors.onUnexpectedError); + } + } + private onConfigurationUpdated(configuration: IFilesConfiguration): void { // TODO@isidor change configuration name let visibleOpenEditors = configuration && configuration.explorer && configuration.explorer.workingFiles && configuration.explorer.workingFiles.maxVisible; -- GitLab