diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index b46dc6a439..4c7f0cb332 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -579,13 +579,11 @@ fileExplorer.prototype.copyFiles = function () { } } -fileExplorer.prototype.createNewFile = function (parentFolder) { +fileExplorer.prototype.createNewFile = function (parentFolder = 'browser') { let self = this modalDialogCustom.prompt('Create new file', 'File Name (e.g Untitled.sol)', 'Untitled.sol', (input) => { - helper.createNonClashingName(input, self.files, (error, newName) => { + helper.createNonClashingName(parentFolder + '/' + input, self.files, (error, newName) => { if (error) return modalDialogCustom.alert('Failed to create file ' + newName + ' ' + error) - const currentPath = !parentFolder ? self._deps.fileManager.currentPath() : parentFolder - newName = currentPath ? currentPath + '/' + newName : self.files.type + '/' + newName if (!self.files.set(newName, '')) { modalDialogCustom.alert('Failed to create file ' + newName) diff --git a/src/app/files/fileProvider.js b/src/app/files/fileProvider.js index 9d288f3223..b7cfb2822e 100644 --- a/src/app/files/fileProvider.js +++ b/src/app/files/fileProvider.js @@ -131,23 +131,28 @@ class FileProvider { return false } + /** + * Removes the folder recursively + * @param {*} path is the folder to be removed + */ remove (path) { - var unprefixedpath = this.removePrefix(path) - if (!this._exists(unprefixedpath)) { - return false - } - const stat = window.remixFileSystem.statSync(unprefixedpath) - try { - if (stat.isDirectory()) { - window.remixFileSystem.rmdirSync(unprefixedpath, console.log) - } else { - window.remixFileSystem.unlinkSync(unprefixedpath, console.log) - } - this.event.trigger('fileRemoved', [this._normalizePath(unprefixedpath)]) - return true - } catch (e) { - console.log(e) - return false + path = this.removePrefix(path) + if (window.remixFileSystem.existsSync(path)) { + window.remixFileSystem.readdirSync(path).forEach((file, index) => { + let curPath = path + '/' + file + let stat = window.remixFileSystem.statSync(curPath) + try { + if (stat.isDirectory()) { + this.remove(curPath) + window.remixFileSystem.rmdirSync(curPath, console.log) + } else { // delete file + window.remixFileSystem.unlinkSync(curPath, console.log) + } + } catch (e) { + console.log(e) + return false + } + }) } } diff --git a/src/lib/helper.js b/src/lib/helper.js index b72c3aa3a0..e2d12e83ed 100644 --- a/src/lib/helper.js +++ b/src/lib/helper.js @@ -12,6 +12,7 @@ module.exports = { return data.slice(0, 5) + '...' + data.slice(len - 5, len) }, createNonClashingNameWithPrefix (name, fileProvider, prefix, cb) { + if (name === '') name = 'Undefined' var counter = '' var ext = 'sol' var reg = /(.*)\.([^.]+)/g