Merge pull request #725 from ethereum/appjs

move createNonclashingName to Helper
pull/1/head
yann300 7 years ago committed by GitHub
commit 63f6082393
  1. 13
      src/app.js
  2. 3
      src/app/panels/file-panel.js
  3. 8
      src/lib/helper.js

@ -12,6 +12,7 @@ var OffsetToLineColumnConverter = require('./lib/offsetToLineColumnConverter')
var QueryParams = require('./lib/query-params')
var GistHandler = require('./lib/gist-handler')
var helpers = require('./lib/helpers')
var Storage = require('./storage')
var Browserfiles = require('./app/files/browser-files')
var chromeCloudStorageSync = require('./app/files/chromeCloudStorageSync')
@ -215,19 +216,10 @@ function run () {
filesProviders: filesProviders
})
function createNonClashingName (path) {
var counter = ''
if (path.endsWith('.sol')) path = path.substring(0, path.lastIndexOf('.sol'))
while (filesProviders['browser'].exists(path + counter + '.sol')) {
counter = (counter | 0) + 1
}
return path + counter + '.sol'
}
// Add files received from remote instance (i.e. another browser-solidity)
function loadFiles (filesSet) {
for (var f in filesSet) {
filesProviders['browser'].set(createNonClashingName(f), filesSet[f].content)
filesProviders['browser'].set(helpers.createNonClashingName(f, filesProviders['browser']), filesSet[f].content)
}
fileManager.switchFile()
}
@ -273,7 +265,6 @@ function run () {
// ---------------- FilePanel --------------------
var FilePanelAPI = {
createName: createNonClashingName,
switchFile: function (path) {
fileManager.switchFile(path)
},

@ -10,6 +10,7 @@ var modalDialog = require('../ui/modaldialog')
var modalDialogCustom = require('../ui/modal-dialog-custom')
var QueryParams = require('../../lib/query-params')
var queryParams = new QueryParams()
var helpers = require('../../lib/helpers')
var remix = require('ethereum-remix')
var styleGuide = remix.ui.styleGuide
@ -245,7 +246,7 @@ function filepanel (appAPI, filesProvider) {
}
function createNewFile () {
var newName = filesProvider['browser'].type + '/' + appAPI.createName('Untitled.sol')
var newName = filesProvider['browser'].type + '/' + helpers.createNonClashingName('Untitled.sol', filesProvider['browser'])
if (!filesProvider['browser'].set(newName, '')) {
modalDialogCustom.alert('Failed to create file ' + newName)
} else {

@ -7,5 +7,13 @@ module.exports = {
if (data.length < 5) return data
var len = data.length
return data.slice(0, 5) + '...' + data.slice(len - 5, len)
},
createNonClashingName (path, fileProvider) {
var counter = ''
if (path.endsWith('.sol')) path = path.substring(0, path.lastIndexOf('.sol'))
while (fileProvider.exists(path + counter + '.sol')) {
counter = (counter | 0) + 1
}
return path + counter + '.sol'
}
}

Loading…
Cancel
Save