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. 37
      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 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 {
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 = {
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

Loading…
Cancel
Save