unique name for create file

pull/5370/head
LianaHus 5 years ago
parent a1e755e31b
commit c3efdd588c
  1. 6
      src/app/files/file-explorer.js
  2. 25
      src/app/files/fileProvider.js
  3. 1
      src/lib/helper.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)

@ -131,24 +131,29 @@ 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)
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()) {
window.remixFileSystem.rmdirSync(unprefixedpath, console.log)
} else {
window.remixFileSystem.unlinkSync(unprefixedpath, console.log)
this.remove(curPath)
window.remixFileSystem.rmdirSync(curPath, console.log)
} else { // delete file
window.remixFileSystem.unlinkSync(curPath, console.log)
}
this.event.trigger('fileRemoved', [this._normalizePath(unprefixedpath)])
return true
} catch (e) {
console.log(e)
return false
}
})
}
}
rename (oldPath, newPath, isFolder) {

@ -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

Loading…
Cancel
Save