change exists call async

pull/1/head
yann300 7 years ago
parent 26d5e1cb15
commit 7386911651
  1. 39
      src/app.js
  2. 7
      src/app/files/file-explorer.js
  3. 5
      src/app/panels/file-panel.js

@ -214,9 +214,16 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
// ----------------- Compiler ----------------- // ----------------- Compiler -----------------
var compiler = new Compiler((url, cb) => { var compiler = new Compiler((url, cb) => {
var provider = fileManager.fileProviderOf(url) var provider = fileManager.fileProviderOf(url)
if (provider && provider.exists(url)) { if (provider) {
provider.exists(url, (error, exist) => {
if (error) return cb(error)
if (exist) {
return provider.get(url, cb) return provider.get(url, cb)
} else {
return cb('file not found')
} }
})
} else {
handleImports.import(url, handleImports.import(url,
(loadingMsg) => { (loadingMsg) => {
$('#output').append($('<div/>').append($('<pre/>').text(loadingMsg))) $('#output').append($('<div/>').append($('<pre/>').text(loadingMsg)))
@ -229,6 +236,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
cb(error) cb(error)
} }
}) })
}
}) })
var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event) var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event)
@ -386,14 +394,26 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
this._components.contextView = new ContextView({ this._components.contextView = new ContextView({
contextualListener: this._components.contextualListener, contextualListener: this._components.contextualListener,
jumpTo: (position) => { jumpTo: (position) => {
function jumpToLine (lineColumn) {
if (lineColumn.start && lineColumn.start.line && lineColumn.start.column) {
editor.gotoLine(lineColumn.start.line, lineColumn.end.column + 1)
}
}
if (compiler.lastCompilationResult && compiler.lastCompilationResult.data) { if (compiler.lastCompilationResult && compiler.lastCompilationResult.data) {
var lineColumn = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) var lineColumn = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult)
var filename = compiler.getSourceName(position.file) var filename = compiler.getSourceName(position.file)
if (filename !== config.get('currentFile') && (filesProviders['browser'].exists(filename) || filesProviders['localhost'].exists(filename))) { // TODO: refactor with rendererAPI.errorClick
if (filename !== config.get('currentFile')) {
var provider = fileManager.fileProviderOf(filename)
if (provider) {
provider.exists(filename, (error, exist) => {
if (error) return console.log(error)
fileManager.switchFile(filename) fileManager.switchFile(filename)
jumpToLine(lineColumn)
})
} }
if (lineColumn.start && lineColumn.start.line && lineColumn.start.column) { } else {
editor.gotoLine(lineColumn.start.line, lineColumn.end.column + 1) jumpToLine(lineColumn)
} }
} }
} }
@ -541,12 +561,21 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
} }
}, },
errorClick: (errFile, errLine, errCol) => { errorClick: (errFile, errLine, errCol) => {
if (errFile !== config.get('currentFile') && (filesProviders['browser'].exists(errFile) || filesProviders['localhost'].exists(errFile))) { if (errFile !== config.get('currentFile')) {
// TODO: refactor with this._components.contextView.jumpTo
var provider = fileManager.fileProviderOf(errFile)
if (provider) {
provider.exists(errFile, (error, exist) => {
if (error) return console.log(error)
fileManager.switchFile(errFile) fileManager.switchFile(errFile)
editor.gotoLine(errLine, errCol)
})
} }
} else {
editor.gotoLine(errLine, errCol) editor.gotoLine(errLine, errCol)
} }
} }
}
var renderer = new Renderer(rendererAPI) var renderer = new Renderer(rendererAPI)
// ----------------- StaticAnalysis ----------------- // ----------------- StaticAnalysis -----------------

@ -221,12 +221,17 @@ function fileExplorer (appAPI, files) {
} else if (helper.checkSpecialChars(label.innerText)) { } else if (helper.checkSpecialChars(label.innerText)) {
modalDialogCustom.alert('Special characters are not allowed') modalDialogCustom.alert('Special characters are not allowed')
label.innerText = textUnderEdit label.innerText = textUnderEdit
} else if (!files.exists(newPath)) { } else {
files.exists(newPath, (error, exist) => {
if (error) return modalDialogCustom.alert('Unexpected error while renaming: ' + error)
if (!exist) {
files.rename(label.dataset.path, newPath, isFolder) files.rename(label.dataset.path, newPath, isFolder)
} else { } else {
modalDialogCustom.alert('File already exists.') modalDialogCustom.alert('File already exists.')
label.innerText = textUnderEdit label.innerText = textUnderEdit
} }
})
}
} }
if (event.which === 13) event.preventDefault() if (event.which === 13) event.preventDefault()

@ -175,12 +175,15 @@ function filepanel (appAPI, filesProvider) {
} }
var name = files.type + '/' + file.name var name = files.type + '/' + file.name
if (!files.exists(name)) { files.exists(name, (error, exist) => {
if (error) console.log(error)
if (!exist) {
loadFile() loadFile()
} else { } else {
modalDialogCustom.confirm(null, `The file ${name} already exists! Would you like to overwrite it?`, () => { loadFile() }) modalDialogCustom.confirm(null, `The file ${name} already exists! Would you like to overwrite it?`, () => { loadFile() })
} }
}) })
})
} }
// ----------------- resizeable ui --------------- // ----------------- resizeable ui ---------------

Loading…
Cancel
Save