diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 1ca85827e9..0d9de5d4b9 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -210,24 +210,9 @@ function fileExplorer (localRegistry, files, menuItems) { self.treeView.event.register('nodeClick', function (path, childrenContainer) { if (!childrenContainer) return if (childrenContainer.style.display === 'none') return - - files.resolveDirectory(path, (error, fileTree) => { - if (error) console.error(error) - if (!fileTree) return - var newTree = normalize(path, fileTree) - self.treeView.updateNodeFromJSON(path, newTree, true) - }) + self.updatePath(path) }) - function normalize (path, filesList) { - var prefix = path.split('/')[0] - var newList = {} - Object.keys(filesList).forEach(key => { - newList[prefix + '/' + key] = filesList[key].isDirectory ? {} : { '/content': true } - }) - return newList - } - // register to main app, trigger when the current file in the editor changed self._deps.fileManager.events.on('currentFileChanged', (newFile) => { const explorer = self._deps.fileManager.fileProviderOf(newFile) @@ -310,6 +295,15 @@ function fileExplorer (localRegistry, files, menuItems) { } } +fileExplorer.prototype.updatePath = function (path) { + this.files.resolveDirectory(path, (error, fileTree) => { + if (error) console.error(error) + if (!fileTree) return + var newTree = normalize(path, fileTree) + this.treeView.updateNodeFromJSON(path, newTree, true) + }) +} + fileExplorer.prototype.hide = function () { if (this.container) this.container.style.display = 'none' } @@ -547,7 +541,17 @@ fileExplorer.prototype.ensureRoot = function (cb) { self.container.appendChild(element) self.element = element if (cb) cb() + self.treeView.expand(self.files.type) + }) +} + +function normalize (path, filesList) { + var prefix = path.split('/')[0] + var newList = {} + Object.keys(filesList).forEach(key => { + newList[prefix + '/' + key] = filesList[key].isDirectory ? {} : { '/content': true } }) + return newList } module.exports = fileExplorer