diff --git a/src/vs/workbench/parts/files/browser/views/explorerView.ts b/src/vs/workbench/parts/files/browser/views/explorerView.ts index 9a909c26683806cd2a6eb70fbfaf0114ffc63057..d59a6116a2d74c3343fb9a8f5661373c0c4f1c02 100644 --- a/src/vs/workbench/parts/files/browser/views/explorerView.ts +++ b/src/vs/workbench/parts/files/browser/views/explorerView.ts @@ -32,7 +32,7 @@ import { FileStat, Model } from 'vs/workbench/parts/files/common/explorerModel'; import { IListService } from 'vs/platform/list/browser/listService'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IPartService } from 'vs/workbench/services/part/common/partService'; -import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkbenchState, WorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -166,7 +166,7 @@ export class ExplorerView extends CollapsibleView { }; this.toDispose.push(this.themeService.onDidFileIconThemeChange(onFileIconThemeChange)); - this.toDispose.push(this.contextService.onDidChangeWorkspaceFolders(() => this.refreshFromEvent())); + this.toDispose.push(this.contextService.onDidChangeWorkspaceFolders((e) => this.refreshFromEvent(e.added))); onFileIconThemeChange(this.themeService.getFileIconTheme()); } @@ -676,11 +676,11 @@ export class ExplorerView extends CollapsibleView { })); } - private refreshFromEvent(): void { + private refreshFromEvent(newRoots: WorkspaceFolder[] = []): void { if (this.isVisible()) { this.explorerRefreshDelayer.trigger(() => { if (!this.explorerViewer.getHighlight()) { - return this.doRefresh(); + return this.doRefresh(newRoots); } return TPromise.as(null); @@ -722,7 +722,7 @@ export class ExplorerView extends CollapsibleView { }); } - private doRefresh(): TPromise { + private doRefresh(newRoots: WorkspaceFolder[] = []): TPromise { const targetsToResolve: { root: FileStat, resource: URI, options: { resolveTo: URI[] } }[] = []; this.model.roots.forEach(root => { const rootAndTargets = { root, resource: root.resource, options: { resolveTo: [] } }; @@ -732,9 +732,8 @@ export class ExplorerView extends CollapsibleView { let targetsToExpand: URI[] = []; if (this.settings[ExplorerView.MEMENTO_EXPANDED_FOLDER_RESOURCES]) { targetsToExpand = this.settings[ExplorerView.MEMENTO_EXPANDED_FOLDER_RESOURCES].map((e: string) => URI.parse(e)); - } else if (this.model.roots.length === 1) { - targetsToExpand = this.model.roots.map(root => root.resource); // always expand if there is just one root } + targetsToExpand.push(...newRoots.map(r => r.uri)); // First time refresh: Receive target through active editor input or selection and also include settings from previous session if (!this.isCreated) { @@ -784,16 +783,11 @@ export class ExplorerView extends CollapsibleView { modelStats.forEach((modelStat, index) => FileStat.mergeLocalWithDisk(modelStat, this.model.roots[index])); const input = this.contextService.getWorkbenchState() === WorkbenchState.FOLDER ? this.model.roots[0] : this.model; + const statsToExpand = this.explorerViewer.getExpandedElements().concat(targetsToExpand.map(target => this.model.findClosest(target))); if (input === this.explorerViewer.getInput()) { - return this.explorerViewer.refresh(); + return this.explorerViewer.refresh().then(() => this.explorerViewer.expandAll(statsToExpand)); } - // Preserve expanded elements if tree input changed. - // If it is a brand new tree just expand elements from memento - const expanded = this.explorerViewer.getExpandedElements(); - const statsToExpand = expanded.length ? [this.model.roots[0]].concat(expanded) : - targetsToExpand.map(expand => this.model.findClosest(expand)); - // Display roots only when multi folder workspace // Make sure to expand all folders that where expanded in the previous session return this.explorerViewer.setInput(input).then(() => this.explorerViewer.expandAll(statsToExpand));