update createNonClashingName and caller

pull/3094/head
yann300 7 years ago
parent eb48b9204d
commit 130b7d3da2
  1. 25
      src/app.js
  2. 14
      src/app/panels/file-panel.js
  3. 14
      src/app/tabs/run-tab.js
  4. 24
      src/lib/helper.js

@ -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
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) {
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) {
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)
}
})
} }
}) })
} }

@ -1,3 +1,5 @@
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 = {
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 = {
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

Loading…
Cancel
Save