Merge pull request #111 from Denton-L/fix-110

Fix #110
pull/1/head
chriseth 9 years ago committed by GitHub
commit 2583e189df
  1. 8
      src/app.js
  2. 13
      src/app/editor.js

@ -193,8 +193,12 @@ var run = function () {
$fileNameInputEl.off('blur'); $fileNameInputEl.off('blur');
$fileNameInputEl.off('keyup'); $fileNameInputEl.off('keyup');
if (newName !== originalName && confirm('Are you sure you want to rename: ' + originalName + ' to ' + newName + '?')) { if (newName !== originalName && confirm(
storage.exists(utils.fileKey(newName))
? 'Are you sure you want to overwrite: ' + newName + ' with ' + originalName + '?'
: 'Are you sure you want to rename: ' + originalName + ' to ' + newName + '?')) {
storage.rename(utils.fileKey(originalName), utils.fileKey(newName)); storage.rename(utils.fileKey(originalName), utils.fileKey(newName));
editor.renameSession(utils.fileKey(originalName), utils.fileKey(newName));
editor.setCacheFile(utils.fileKey(newName)); editor.setCacheFile(utils.fileKey(newName));
} }
@ -211,6 +215,7 @@ var run = function () {
if (confirm('Are you sure you want to remove: ' + name + ' from local storage?')) { if (confirm('Are you sure you want to remove: ' + name + ' from local storage?')) {
storage.remove(utils.fileKey(name)); storage.remove(utils.fileKey(name));
editor.removeSession(utils.fileKey(name));
editor.setNextFile(utils.fileKey(name)); editor.setNextFile(utils.fileKey(name));
updateFiles(); updateFiles();
} }
@ -234,6 +239,7 @@ var run = function () {
var files = editor.getFiles(); var files = editor.getFiles();
$filesEl.find('.file').remove(); $filesEl.find('.file').remove();
$('#output').empty();
for (var f in files) { for (var f in files) {
$filesEl.append(fileTabTemplate(files[f])); $filesEl.append(fileTabTemplate(files[f]));

@ -21,7 +21,6 @@ function Editor (loadingFromGist, storage) {
untitledCount = (untitledCount - 0) + 1; untitledCount = (untitledCount - 0) + 1;
} }
SOL_CACHE_FILE = SOL_CACHE_UNTITLED + untitledCount; SOL_CACHE_FILE = SOL_CACHE_UNTITLED + untitledCount;
sessions[SOL_CACHE_FILE] = null;
this.setCacheFileContent(''); this.setCacheFileContent('');
}; };
@ -31,7 +30,6 @@ function Editor (loadingFromGist, storage) {
fileReader.onload = function (e) { fileReader.onload = function (e) {
storage.set(cacheName, e.target.result); storage.set(cacheName, e.target.result);
sessions[cacheName] = null;
SOL_CACHE_FILE = cacheName; SOL_CACHE_FILE = cacheName;
callback(); callback();
}; };
@ -64,6 +62,17 @@ function Editor (loadingFromGist, storage) {
editor.focus(); editor.focus();
}; };
this.removeSession = function (fileKey) {
delete sessions[fileKey];
};
this.renameSession = function (oldFileKey, newFileKey) {
if (oldFileKey !== newFileKey) {
sessions[newFileKey] = sessions[oldFileKey];
this.removeSession(oldFileKey);
}
};
this.hasFile = function (name) { this.hasFile = function (name) {
return this.getFiles().indexOf(utils.fileKey(name)) !== -1; return this.getFiles().indexOf(utils.fileKey(name)) !== -1;
}; };

Loading…
Cancel
Save