Commit 7ba84628 authored by yann300's avatar yann300

update createNonClashingName and caller

parent aa543766
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
var $ = require('jquery') var $ = require('jquery')
var csjs = require('csjs-inject') var csjs = require('csjs-inject')
var yo = require('yo-yo') var yo = require('yo-yo')
var async = require('async')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
...@@ -463,15 +464,21 @@ Please make a backup of your contracts and start using http://remix.ethereum.org ...@@ -463,15 +464,21 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
function loadFiles (filesSet, fileProvider) { function loadFiles (filesSet, fileProvider) {
if (!fileProvider) fileProvider = 'browser' if (!fileProvider) fileProvider = 'browser'
for (var f in filesSet) { async.each(Object.keys(filesSet), (file, callback) => {
var name = helper.createNonClashingName(f, filesProviders[fileProvider]) helper.createNonClashingName(file, filesProviders[fileProvider],
if (helper.checkSpecialChars(name)) { (error, name) => {
modalDialogCustom.alert('Special characters are not allowed') if (error) {
return modalDialogCustom.alert('Unexpected error loading the file ' + error)
} } else if (helper.checkSpecialChars(name)) {
filesProviders[fileProvider].set(name, filesSet[f].content) modalDialogCustom.alert('Special characters are not allowed')
} } else {
fileManager.switchFile() filesProviders[fileProvider].set(name, filesSet[file].content)
}
callback()
})
}, (error) => {
if (!error) fileManager.switchFile()
})
} }
// Replace early callback with instant response // Replace early callback with instant response
......
...@@ -224,12 +224,14 @@ function filepanel (appAPI, filesProvider) { ...@@ -224,12 +224,14 @@ function filepanel (appAPI, filesProvider) {
function createNewFile () { function createNewFile () {
modalDialogCustom.prompt(null, 'File Name', 'Untitled.sol', (input) => { modalDialogCustom.prompt(null, 'File Name', 'Untitled.sol', (input) => {
var newName = filesProvider['browser'].type + '/' + helper.createNonClashingName(input, filesProvider['browser']) filesProvider['browser'].type + '/' + helper.createNonClashingName(input, filesProvider['browser'], (error, newName) => {
if (!filesProvider['browser'].set(newName, '')) { if (error) return modalDialogCustom.alert('Failed to create file ' + newName + ' ' + error)
modalDialogCustom.alert('Failed to create file ' + newName) if (!filesProvider['browser'].set(newName, '')) {
} else { modalDialogCustom.alert('Failed to create file ' + newName)
appAPI.switchFile(newName) } else {
} appAPI.switchFile(newName)
}
})
}) })
} }
......
...@@ -161,12 +161,14 @@ function makeRecorder (events, appAPI, appEvents) { ...@@ -161,12 +161,14 @@ function makeRecorder (events, appAPI, appEvents) {
var fileProvider = appAPI.fileProviderOf(path) var fileProvider = appAPI.fileProviderOf(path)
if (fileProvider) { if (fileProvider) {
var newFile = path + input var newFile = path + input
newFile = helper.createNonClashingName(newFile, fileProvider, '.json') helper.createNonClashingName(newFile, fileProvider, (error, newFile) => {
if (!fileProvider.set(newFile, txJSON)) { if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error)
modalDialogCustom.alert('Failed to create file ' + newFile) if (!fileProvider.set(newFile, txJSON)) {
} else { modalDialogCustom.alert('Failed to create file ' + newFile)
appAPI.switchFile(newFile) } else {
} appAPI.switchFile(newFile)
}
})
} }
}) })
} }
......
var async = require('async')
module.exports = { module.exports = {
shortenAddress: function (address, etherBalance) { shortenAddress: function (address, etherBalance) {
var len = address.length var len = address.length
...@@ -9,7 +11,7 @@ module.exports = { ...@@ -9,7 +11,7 @@ module.exports = {
var len = data.length var len = data.length
return data.slice(0, 5) + '...' + data.slice(len - 5, len) return data.slice(0, 5) + '...' + data.slice(len - 5, len)
}, },
createNonClashingName (name, fileProvider) { createNonClashingName (name, fileProvider, cb) {
var counter = '' var counter = ''
var ext = 'sol' var ext = 'sol'
var reg = /(.*)\.([^.]+)/g var reg = /(.*)\.([^.]+)/g
...@@ -18,10 +20,22 @@ module.exports = { ...@@ -18,10 +20,22 @@ module.exports = {
name = split[1] name = split[1]
ext = split[2] ext = split[2]
} }
while (fileProvider.exists(name + counter + '.' + ext)) { var exist = true
counter = (counter | 0) + 1 async.whilst(
} () => { return exist },
return name + counter + '.' + ext (callback) => {
fileProvider.exists(name + counter + '.' + ext, (error, currentExist) => {
if (error) {
callback(error)
} else {
exist = currentExist
if (exist) counter = (counter | 0) + 1
callback()
}
})
},
(error) => { cb(error, name + counter + '.' + ext) }
)
}, },
checkSpecialChars (name) { checkSpecialChars (name) {
return name.match(/[/:*?"<>\\'|]/) != null return name.match(/[/:*?"<>\\'|]/) != null
......
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