Merge pull request #428 from ethereum/file-errors

Show alerts on file errors
pull/1/head
yann300 8 years ago committed by GitHub
commit 76c46ac193
  1. 31
      src/app.js
  2. 2
      src/app/files.js
  3. 2
      src/app/storage.js

@ -220,8 +220,11 @@ var run = function () {
$('.newFile').on('click', function () {
var newName = createNonClashingName('Untitled')
files.set(newName, '')
if (!files.set(newName, '')) {
alert('Failed to create file ' + newName)
} else {
switchToFile(newName)
}
})
// ----------------- file upload -------------
@ -233,9 +236,12 @@ var run = function () {
if (!files.exists(name) || confirm('The file ' + name + ' already exists! Would you like to overwrite it?')) {
var fileReader = new FileReader()
fileReader.onload = function (ev) {
files.set(name, ev.target.result)
if (!files.set(name, ev.target.result)) {
alert('Failed to create file ' + name)
} else {
switchToFile(name)
}
}
fileReader.readAsText(fileList[i])
}
}
@ -272,10 +278,14 @@ var run = function () {
files.exists(newName)
? 'Are you sure you want to overwrite: ' + newName + ' with ' + originalName + '?'
: 'Are you sure you want to rename: ' + originalName + ' to ' + newName + '?')) {
files.rename(originalName, newName)
if (!files.rename(originalName, newName)) {
alert('Error while renaming file')
} else {
currentFile = null
switchToFile(newName)
editor.discard(originalName)
}
}
return false
}
@ -289,10 +299,14 @@ var run = function () {
var name = $(this).parent().find('.name').text()
if (confirm('Are you sure you want to remove: ' + name + ' from local storage?')) {
files.remove(name)
if (!files.remove(name)) {
alert('Error while removing file')
} else {
currentFile = null
switchToNextFile()
editor.discard(name)
}
}
return false
})
@ -654,23 +668,28 @@ var run = function () {
function runCompiler () {
var files = {}
if (currentFile) {
var target = currentFile
files[target] = editor.get(currentFile)
compiler.compile(files, target)
}
}
function editorSyncFile () {
if (currentFile) {
var input = editor.get(currentFile)
files.set(currentFile, input)
}
}
var previousInput = ''
var compileTimeout = null
var saveTimeout = null
function editorOnChange () {
if (!currentFile) {
return
}
var input = editor.get(currentFile)
// if there's no change, don't do anything

@ -58,7 +58,7 @@ function Files (storage) {
}
this.isReadOnly = function (path) {
return !!readonly[path]
return readonly[path] !== undefined
}
this.remove = function (path) {

@ -2,7 +2,7 @@
function Storage () {
this.exists = function (name) {
return !!this.get(name)
return this.get(name) !== null
}
this.get = function (name) {

Loading…
Cancel
Save