diff --git a/src/app/files.js b/src/app/files.js index 53b53451e1..42aa3f6c90 100644 --- a/src/app/files.js +++ b/src/app/files.js @@ -107,6 +107,47 @@ function Files (storage) { return files } + // + // Tree model for files + // { + // 'a': { }, // empty directory 'a' + // 'b': { + // 'c': {}, // empty directory 'b/c' + // 'd': { '/readonly': true, '/content': 'Hello World' } // files 'b/c/d' + // 'e': { '/readonly': false, '/path': 'b/c/d' } // symlink to 'b/c/d' + // 'f': { '/readonly': false, '/content': '', '/mode': 0755 } + // } + // } + // + this.listAsTree = function () { + function hashmapize (obj, path, val) { + var nodes = path.split('/') + var i = 0 + + for (; i < nodes.length - 1; i++) { + var node = nodes[i] + if (obj[node] === undefined) { + obj[node] = {} + } + obj = obj[node] + } + + obj[nodes[i]] = val + } + + var tree = {} + + var self = this + storage.keys().forEach(function (path) { + hashmapize(tree, path, { + '/readonly': self.isReadOnly(path), + '/content': self.get(path) + }) + }) + + return tree + } + // rename .browser-solidity.json to .remix.config if (this.exists('.browser-solidity.json')) { this.rename('.browser-solidity.json', '.remix.config')