Commit 5e667faf authored by LianaHus's avatar LianaHus

unique name for create file

parent 01b764d4
...@@ -579,13 +579,11 @@ fileExplorer.prototype.copyFiles = function () { ...@@ -579,13 +579,11 @@ fileExplorer.prototype.copyFiles = function () {
} }
} }
fileExplorer.prototype.createNewFile = function (parentFolder) { fileExplorer.prototype.createNewFile = function (parentFolder = 'browser') {
let self = this let self = this
modalDialogCustom.prompt('Create new file', 'File Name (e.g Untitled.sol)', 'Untitled.sol', (input) => { 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) 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, '')) { if (!self.files.set(newName, '')) {
modalDialogCustom.alert('Failed to create file ' + newName) modalDialogCustom.alert('Failed to create file ' + newName)
......
...@@ -131,23 +131,28 @@ class FileProvider { ...@@ -131,23 +131,28 @@ class FileProvider {
return false return false
} }
/**
* Removes the folder recursively
* @param {*} path is the folder to be removed
*/
remove (path) { remove (path) {
var unprefixedpath = this.removePrefix(path) path = this.removePrefix(path)
if (!this._exists(unprefixedpath)) { if (window.remixFileSystem.existsSync(path)) {
return false window.remixFileSystem.readdirSync(path).forEach((file, index) => {
} let curPath = path + '/' + file
const stat = window.remixFileSystem.statSync(unprefixedpath) let stat = window.remixFileSystem.statSync(curPath)
try { try {
if (stat.isDirectory()) { if (stat.isDirectory()) {
window.remixFileSystem.rmdirSync(unprefixedpath, console.log) this.remove(curPath)
} else { window.remixFileSystem.rmdirSync(curPath, console.log)
window.remixFileSystem.unlinkSync(unprefixedpath, console.log) } else { // delete file
} window.remixFileSystem.unlinkSync(curPath, console.log)
this.event.trigger('fileRemoved', [this._normalizePath(unprefixedpath)]) }
return true } catch (e) {
} catch (e) { console.log(e)
console.log(e) return false
return false }
})
} }
} }
......
...@@ -12,6 +12,7 @@ module.exports = { ...@@ -12,6 +12,7 @@ module.exports = {
return data.slice(0, 5) + '...' + data.slice(len - 5, len) return data.slice(0, 5) + '...' + data.slice(len - 5, len)
}, },
createNonClashingNameWithPrefix (name, fileProvider, prefix, cb) { createNonClashingNameWithPrefix (name, fileProvider, prefix, cb) {
if (name === '') name = 'Undefined'
var counter = '' var counter = ''
var ext = 'sol' var ext = 'sol'
var reg = /(.*)\.([^.]+)/g var reg = /(.*)\.([^.]+)/g
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment