From 6a1366de98bc18b973b67454111b17d2a4961e88 Mon Sep 17 00:00:00 2001 From: isidor Date: Thu, 15 Jun 2017 16:02:54 +0200 Subject: [PATCH] explorerView: remove use of root fully --- .../parts/files/browser/views/explorerView.ts | 77 ++++++++++--------- .../parts/files/common/explorerModel.ts | 13 ++-- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/vs/workbench/parts/files/browser/views/explorerView.ts b/src/vs/workbench/parts/files/browser/views/explorerView.ts index 7366bde9697..bc207163e9c 100644 --- a/src/vs/workbench/parts/files/browser/views/explorerView.ts +++ b/src/vs/workbench/parts/files/browser/views/explorerView.ts @@ -340,10 +340,6 @@ export class ExplorerView extends CollapsibleView { return toResource(input, { supportSideBySide: true, filter: 'file' }); } - private get root(): FileStat { - return this.explorerViewer ? (this.explorerViewer.getInput()) : null; - } - private get isCreated(): boolean { return this.explorerViewer && this.explorerViewer.getInput(); } @@ -687,7 +683,11 @@ export class ExplorerView extends CollapsibleView { } private doRefresh(): TPromise { - const targetsToResolve: URI[] = []; + const targetsToResolve: { root: FileStat, resource: URI, options: { resolveTo: URI[] } }[] = []; + this.model.roots.forEach(root => { + const rootAndTargets = { root, resource: root.resource, options: { resolveTo: [] } }; + targetsToResolve.push(rootAndTargets); + }); let targetsToExpand: URI[] = []; if (this.settings[ExplorerView.MEMENTO_EXPANDED_FOLDER_RESOURCES]) { @@ -698,48 +698,50 @@ export class ExplorerView extends CollapsibleView { if (!this.isCreated) { const activeFile = this.getActiveFile(); if (activeFile) { - targetsToResolve.push(activeFile); + const root = this.contextService.getRoot(activeFile); + if (root) { + const found = targetsToResolve.filter(t => t.root.resource.toString() === root.toString()).pop(); + found.options.resolveTo.push(activeFile); + } } - if (targetsToExpand.length) { - targetsToResolve.push(...targetsToExpand); - } + targetsToExpand.forEach(toExpand => { + const root = this.contextService.getRoot(toExpand); + if (root) { + const found = targetsToResolve.filter(ttr => ttr.resource.toString() === root.toString()).pop(); + found.options.resolveTo.push(toExpand); + } + }); } // Subsequent refresh: Receive targets through expanded folders in tree else { - this.getResolvedDirectories(this.root, targetsToResolve); + targetsToResolve.forEach(t => { + this.getResolvedDirectories(t.root, t.options.resolveTo); + }); } // Load Root Stat with given target path configured - const options: IResolveFileOptions = { resolveTo: targetsToResolve }; - const promise = this.fileService.resolveFile(this.contextService.getWorkspace().resource, options).then(stat => { - let explorerPromise: TPromise; - + const promise = this.fileService.resolveFiles(targetsToResolve).then(stats => { // Convert to model - const modelStat = FileStat.create(stat, options.resolveTo); - - // First time refresh: The stat becomes the input of the viewer - if (!this.isCreated) { - explorerPromise = this.explorerViewer.setInput(modelStat).then(() => { - - // Make sure to expand all folders that where expanded in the previous session - if (targetsToExpand) { - return this.explorerViewer.expandAll(targetsToExpand.map(expand => this.root.find(expand))); - } + const modelStats = stats.map((stat, index) => FileStat.create(stat, targetsToResolve[index].options.resolveTo)); + // Subsequent refresh: Merge stat into our local model and refresh tree + modelStats.forEach((modelStat, index) => FileStat.mergeLocalWithDisk(modelStat, this.model.roots[index])); - return TPromise.as(null); - }); + if (this.isCreated) { + return this.explorerViewer.refresh(); } - // Subsequent refresh: Merge stat into our local model and refresh tree - else { - FileStat.mergeLocalWithDisk(modelStat, this.root); + // First time refresh: The stat becomes the input of the viewer + return this.explorerViewer.setInput(this.model).then(() => { - explorerPromise = this.explorerViewer.refresh(this.root); - } + // Make sure to expand all folders that where expanded in the previous session + if (targetsToExpand) { + return this.explorerViewer.expandAll(targetsToExpand.map(expand => this.model.findFirst(expand))); + } - return explorerPromise; + return TPromise.as(null); + }); }, (e: any) => TPromise.wrapError(e)); this.progressService.showWhile(promise, this.partService.isCreated() ? 800 : 3200 /* less ugly initial startup */); @@ -796,23 +798,24 @@ export class ExplorerView extends CollapsibleView { return TPromise.as(null); } - const fileStat = this.root.find(resource); + const fileStat = this.model.findFirst(resource); if (fileStat) { return this.doSelect(fileStat, reveal); } // Stat needs to be resolved first and then revealed const options: IResolveFileOptions = { resolveTo: [resource] }; - return this.fileService.resolveFile(this.contextService.getWorkspace().resource, options).then(stat => { + const rootUri = this.contextService.getRoot(resource); + return this.fileService.resolveFile(rootUri, options).then(stat => { // Convert to model const modelStat = FileStat.create(stat, options.resolveTo); - + const root = this.model.roots.filter(r => r.resource.toString() === rootUri.toString()).pop(); // Update Input with disk Stat - FileStat.mergeLocalWithDisk(modelStat, this.root); + FileStat.mergeLocalWithDisk(modelStat, root); // Select and Reveal - return this.explorerViewer.refresh(this.root).then(() => this.doSelect(this.root.find(resource), reveal)); + return this.explorerViewer.refresh(root).then(() => this.doSelect(root.find(resource), reveal)); }, (e: any) => this.messageService.show(Severity.Error, e)); } diff --git a/src/vs/workbench/parts/files/common/explorerModel.ts b/src/vs/workbench/parts/files/common/explorerModel.ts index 7dfe1c667fa..6edd5279360 100644 --- a/src/vs/workbench/parts/files/common/explorerModel.ts +++ b/src/vs/workbench/parts/files/common/explorerModel.ts @@ -53,11 +53,6 @@ export class Model { return null; } - - public rootForResource(resource: URI): FileStat { - // TODO@Isidor temporary until we have a utility method for this - return this.roots[0]; - } } export class FileStat implements IFileStat { @@ -148,9 +143,11 @@ export class FileStat implements IFileStat { // Map resource => stat const oldLocalChildren = new ResourceMap(); - local.children.forEach((localChild: FileStat) => { - oldLocalChildren.set(localChild.resource, localChild); - }); + if (local.children) { + local.children.forEach((localChild: FileStat) => { + oldLocalChildren.set(localChild.resource, localChild); + }); + } // Clear current children local.children = []; -- GitLab