|
|
|
@ -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
|
|
|
|
|