Merge pull request #1060 from ethereum/bugfix_fileexplorer

Fix - File explorer
pull/1/head
yann300 7 years ago committed by GitHub
commit 5a723d2c7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/app/files/chromeCloudStorageSync.js
  2. 11
      src/app/files/file-explorer.js
  3. 68
      src/app/panels/file-panel.js

@ -46,16 +46,19 @@ module.exports = function (filesProviders) {
}) })
} }
for (var y in filesProviders['browser'].list()) { filesProviders['browser'].resolve('browser', (error, files) => {
console.log('checking', y) if (!error) {
filesProviders['browser'].get(y, (error, content) => { Object.keys(files).forEach((path) => {
filesProviders['browser'].get(path, (error, content) => {
if (error) { if (error) {
console.log(error) console.log(error)
} else { } else {
obj[y] = content obj[path] = content
count++ count++
check(y) check(path)
} }
}) })
})
} }
})
} }

@ -228,14 +228,23 @@ function fileExplorer (appAPI, files) {
} }
} }
fileExplorer.prototype.hide = function () {
if (this.container) this.container.style.display = 'none'
}
fileExplorer.prototype.show = function () {
if (this.container) this.container.style.display = 'block'
}
fileExplorer.prototype.init = function () { fileExplorer.prototype.init = function () {
this.container = yo`<div></div>` this.container = yo`<div></div>`
return this.container return this.container
} }
fileExplorer.prototype.ensureRoot = function (cb) { fileExplorer.prototype.ensureRoot = function (cb) {
cb = cb || (() => {})
var self = this var self = this
if (self.element && cb) return cb() if (self.element) return cb()
self.files.resolveDirectory('/', (error, files) => { self.files.resolveDirectory('/', (error, files) => {
if (error) console.error(error) if (error) console.error(error)

@ -21,6 +21,23 @@ var limit = 60
var canUpload = window.File || window.FileReader || window.FileList || window.Blob var canUpload = window.File || window.FileReader || window.FileList || window.Blob
var ghostbar = yo`<div class=${css.ghostbar}></div>` var ghostbar = yo`<div class=${css.ghostbar}></div>`
/*
Overview of APIs:
* fileManager: @args fileProviders (browser, shared-folder, swarm, github, etc ...) & config & editor
- listen on browser & localhost file provider (`fileRenamed` & `fileRemoved`)
- update the tabs, switchFile
- trigger `currentFileChanged`
- set the current file in the config
* fileProvider: currently browser, swarm, localhost, github, gist
- link to backend
- provide properties `type`, `readonly`
- provide API `resolveDirectory`, `remove`, `exists`, `rename`, `get`, `set`
- trigger `fileExternallyChanged`, `fileRemoved`, `fileRenamed`, `fileRenamedError`, `fileAdded`
* file-explorer: treeview @args fileProvider
- listen on events triggered by fileProvider
- call fileProvider API
*/
function filepanel (appAPI, filesProvider) { function filepanel (appAPI, filesProvider) {
var self = this var self = this
var fileExplorer = new FileExplorer(appAPI, filesProvider['browser']) var fileExplorer = new FileExplorer(appAPI, filesProvider['browser'])
@ -89,7 +106,6 @@ function filepanel (appAPI, filesProvider) {
self.event = event self.event = event
var element = template() var element = template()
fileExplorer.ensureRoot() fileExplorer.ensureRoot()
var containerFileSystem = element.querySelector('.filesystemexplorer')
var websocketconn = element.querySelector('.websocketconn') var websocketconn = element.querySelector('.websocketconn')
filesProvider['localhost'].remixd.event.register('connecting', (event) => { filesProvider['localhost'].remixd.event.register('connecting', (event) => {
websocketconn.style.color = styles.colors.yellow websocketconn.style.color = styles.colors.yellow
@ -99,22 +115,19 @@ function filepanel (appAPI, filesProvider) {
filesProvider['localhost'].remixd.event.register('connected', (event) => { filesProvider['localhost'].remixd.event.register('connected', (event) => {
websocketconn.style.color = styles.colors.green websocketconn.style.color = styles.colors.green
websocketconn.setAttribute('title', 'Connected to localhost. ' + JSON.stringify(event)) websocketconn.setAttribute('title', 'Connected to localhost. ' + JSON.stringify(event))
fileSystemExplorer.show()
}) })
filesProvider['localhost'].remixd.event.register('errored', (event) => { filesProvider['localhost'].remixd.event.register('errored', (event) => {
websocketconn.style.color = styles.colors.red websocketconn.style.color = styles.colors.red
websocketconn.setAttribute('title', 'localhost connection errored. ' + JSON.stringify(event)) websocketconn.setAttribute('title', 'localhost connection errored. ' + JSON.stringify(event))
if (fileSystemExplorer.element && containerFileSystem.children.length > 0) { fileSystemExplorer.hide()
containerFileSystem.removeChild(fileSystemExplorer.element)
}
}) })
filesProvider['localhost'].remixd.event.register('closed', (event) => { filesProvider['localhost'].remixd.event.register('closed', (event) => {
websocketconn.style.color = styles.colors.black websocketconn.style.color = styles.colors.black
websocketconn.setAttribute('title', 'localhost connection closed. ' + JSON.stringify(event)) websocketconn.setAttribute('title', 'localhost connection closed. ' + JSON.stringify(event))
if (fileSystemExplorer.element && containerFileSystem.children.length > 0) { fileSystemExplorer.hide()
containerFileSystem.removeChild(fileSystemExplorer.element)
}
}) })
fileExplorer.events.register('focus', function (path) { fileExplorer.events.register('focus', function (path) {
@ -256,6 +269,8 @@ function filepanel (appAPI, filesProvider) {
modalDialogCustom.confirm(null, `Created a gist at ${data.html_url}. Would you like to open it in a new window?`, () => { modalDialogCustom.confirm(null, `Created a gist at ${data.html_url}. Would you like to open it in a new window?`, () => {
window.open(data.html_url, '_blank') window.open(data.html_url, '_blank')
}) })
} else {
modalDialogCustom.alert(data.message + ' ' + data.documentation_url)
} }
} }
} }
@ -309,33 +324,24 @@ function filepanel (appAPI, filesProvider) {
} }
// return all the files, except the temporary/readonly ones.. // return all the files, except the temporary/readonly ones..
function packageFiles (files, callback) { function packageFiles (filesProvider, callback) {
var ret = {} var ret = {}
// @TODO remove use of `list()` filesProvider.resolveDirectory('browser', (error, files) => {
var filtered = Object.keys(files.list()).filter(function (path) { if (!files.isReadOnly(path)) { return path } }) if (error) callback(error)
async.eachSeries(filtered, function (path, cb) { else {
ret[path.replace(files.type + '/', '')] = { content: files.get(path) } async.eachSeries(Object.keys(files), (path, cb) => {
filesProvider.get(path, (error, content) => {
if (error) cb(error)
else {
ret[path] = { content }
cb() cb()
}, () => { }
callback(null, ret) })
}, (error) => {
callback(error, ret)
})
}
}) })
} }
/*
Overview of APIs:
* fileManager: @args fileProviders (browser, shared-folder, swarm, github, etc ...) & config & editor
- listen on browser & localhost file provider (`fileRenamed` & `fileRemoved`)
- update the tabs, switchFile
- trigger `currentFileChanged`
- set the current file in the config
* fileProvider: currently browser, swarm, localhost, github, gist
- link to backend
- provide properties `type`, `readonly`
- provide API `resolveDirectory`, `remove`, `exists`, `rename`, `get`, `set`
- trigger `fileExternallyChanged`, `fileRemoved`, `fileRenamed`, `fileRenamedError`, `fileAdded`
* file-explorer: treeview @args fileProvider
- listen on events triggered by fileProvider
- call fileProvider API
*/
module.exports = filepanel module.exports = filepanel

Loading…
Cancel
Save