fix file explorer update events 1/2

pull/1/head
serapath 7 years ago committed by yann300
parent f9e518ac52
commit e891772417
  1. 2
      src/app.js
  2. 12
      src/app/files/browser-files.js
  3. 33
      src/app/files/file-explorer.js
  4. 1
      src/app/files/shared-folder.js

@ -497,7 +497,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
switchFile: function (path) {
fileManager.switchFile(path)
},
event: this.event,
event: fileManager.event,
currentFile: function () {
return config.get('currentFile')
},

@ -118,19 +118,21 @@ function Files (storage) {
this.resolveDirectory = function (path, callback) {
var self = this
if (path[0] === '/') path = path.substring(1)
if (path[0] === '.' && path[1] === '/') path = path.substring(2)
if (!path) return callback(null, { [self.type]: { } })
path = self.removePrefix('' + (path || ''))
var filesList = {}
var tree = {}
// add r/w filesList to the list
storage.keys().forEach((path) => {
// NOTE: as a temporary measure do not show the config file
if (path !== '.remix.config') {
filesList[self.type + '/' + path] = false
filesList[path] = false
}
})
// add r/o files to the list
Object.keys(readonly).forEach((path) => {
filesList[self.type + '/' + path] = true
filesList[path] = true
})
Object.keys(filesList).forEach(function (path) {
@ -139,7 +141,7 @@ function Files (storage) {
'/content': self.get(path)
})
})
return callback(null, tree[path] || {})
return callback(null, tree)
function hashmapize (obj, path, val) {
var nodes = path.split('/')
var i = 0
@ -155,7 +157,9 @@ function Files (storage) {
}
this.removePrefix = function (path) {
return path.indexOf(this.type + '/') === 0 ? path.replace(this.type + '/', '') : path
path = path.indexOf(this.type) === 0 ? path.replace(this.type, '') : path
if (path[0] === '/') return path.substring(1)
return path
}
// rename .browser-solidity.json to .remix.config

@ -53,6 +53,8 @@ var css = csjs`
`
module.exports = fileExplorer
var focusElement = null
function fileExplorer (appAPI, files) {
var self = this
this.files = files
@ -101,7 +103,7 @@ function fileExplorer (appAPI, files) {
}
},
formatSelf: function formatSelf (key, data, li) {
var isRoot = data.path.indexOf('/') === -1
var isRoot = data.path === self.files.type
return yo`<label class="${data.children ? css.folder : css.file}"
data-path="${data.path}"
style="${isRoot ? 'font-weight:bold;' : ''}"
@ -125,7 +127,7 @@ function fileExplorer (appAPI, files) {
if (!fileTree) return
var newTree = normalize(path, fileTree)
var tree = self.treeView.renderProperties(newTree, false)
childrenContainer.appendChild(tree)
;[...tree.children].forEach(child => childrenContainer.appendChild(child))
})
})
@ -143,7 +145,6 @@ function fileExplorer (appAPI, files) {
<i class="fa fa-trash" aria-hidden="true"></i>
</span>
`
appAPI.event.register('currentFileChanged', (newFile, explorer) => {
if (explorer === files) {
fileFocus(newFile)
@ -157,7 +158,6 @@ function fileExplorer (appAPI, files) {
fileEvents.register('fileAdded', fileAdded)
var filepath = null
var focusElement = null
var textUnderEdit = null
var textInRename = false
@ -335,19 +335,20 @@ function fileExplorer (appAPI, files) {
function fileFocus (path) {
if (filepath === path) return
filepath = path
var el = getElement(filepath)
expandPathTo(el)
setTimeout(function focusNode () { el.click() }, 0)
setTimeout(function focusNode () {
// @TODO: fix file tree expand logic to account for async remixd loading logic
var el = getElement(filepath)
expandPathTo(el)
setTimeout(function focusNode () { el.click() }, 0)
}, 0)
}
function fileRemoved (filepath) {
// @TODO: only important if currently visible in TreeView
var li = getElement(filepath)
if (li) li.parentElement.removeChild(li)
}
function fileRenamed (oldName, newName, isFolder) {
// @TODO: only important if currently visible in TreeView
var li = getElement(oldName)
if (li) {
oldName = oldName.split('/')
@ -369,13 +370,15 @@ function fileExplorer (appAPI, files) {
}
function fileAdded (filepath) {
// @TODO: only important if currently visible in TreeView
self.files.resolveDirectory('./', (error, files) => {
var folderpath = filepath.split('/').slice(0, -1).join('/')
self.files.resolveDirectory(folderpath, (error, fileTree) => {
if (error) console.error(error)
var element = self.treeView.render(files)
element.className = css.fileexplorer
self.element.parentElement.replaceChild(element, self.element)
self.element = element
if (!fileTree) return
fileTree = normalize(folderpath, fileTree)
var newTree = self.treeView.renderProperties(fileTree, false)
var currentTree = self.treeView.nodeAt(folderpath)
currentTree.innerHTML = ''
;[...newTree.children].forEach(child => currentTree.appendChild(child))
})
}
}

@ -159,6 +159,7 @@ module.exports = class SharedFolder {
resolveDirectory (path, callback) {
var self = this
if (path[0] === '/') path = path.substring(1)
if (path[0] === '.' && path[1] === '/') path = path.substring(2)
if (!path) return callback(null, { [self.type]: { } })
path = self.removePrefix('' + (path || ''))
self.remixd.dir(path, callback)

Loading…
Cancel
Save