expand file explorer at load

pull/1/head
yann300 6 years ago
parent 3dc104d11e
commit 129ba4b8a1
  1. 36
      src/app/files/file-explorer.js

@ -210,24 +210,9 @@ function fileExplorer (localRegistry, files, menuItems) {
self.treeView.event.register('nodeClick', function (path, childrenContainer) { self.treeView.event.register('nodeClick', function (path, childrenContainer) {
if (!childrenContainer) return if (!childrenContainer) return
if (childrenContainer.style.display === 'none') return if (childrenContainer.style.display === 'none') return
self.updatePath(path)
files.resolveDirectory(path, (error, fileTree) => {
if (error) console.error(error)
if (!fileTree) return
var newTree = normalize(path, fileTree)
self.treeView.updateNodeFromJSON(path, newTree, true)
})
}) })
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 // register to main app, trigger when the current file in the editor changed
self._deps.fileManager.events.on('currentFileChanged', (newFile) => { self._deps.fileManager.events.on('currentFileChanged', (newFile) => {
const explorer = self._deps.fileManager.fileProviderOf(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 () { fileExplorer.prototype.hide = function () {
if (this.container) this.container.style.display = 'none' if (this.container) this.container.style.display = 'none'
} }
@ -547,7 +541,17 @@ fileExplorer.prototype.ensureRoot = function (cb) {
self.container.appendChild(element) self.container.appendChild(element)
self.element = element self.element = element
if (cb) cb() 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 module.exports = fileExplorer

Loading…
Cancel
Save