Commit 0a37e6a3 authored by Dave Hoover's avatar Dave Hoover

Pulling some utility calls into editor in order to simplify app.js

parent 5474e89c
...@@ -45,7 +45,7 @@ var run = function() { ...@@ -45,7 +45,7 @@ var run = function() {
} }
window.localStorage[key] = content; window.localStorage[key] = content;
} }
editor.setCacheFile(utils.fileKey(Object.keys(files)[0])); editor.setCacheFile(Object.keys(files)[0]);
updateFiles(); updateFiles();
} }
...@@ -228,7 +228,7 @@ var run = function() { ...@@ -228,7 +228,7 @@ var run = function() {
var content = window.localStorage.getItem( utils.fileKey(originalName) ); var content = window.localStorage.getItem( utils.fileKey(originalName) );
window.localStorage[utils.fileKey( newName )] = content; window.localStorage[utils.fileKey( newName )] = content;
window.localStorage.removeItem( utils.fileKey( originalName) ); window.localStorage.removeItem( utils.fileKey( originalName) );
editor.setCacheFile(utils.fileKey( newName )); editor.setCacheFile(newName);
} }
updateFiles(); updateFiles();
...@@ -252,13 +252,13 @@ var run = function() { ...@@ -252,13 +252,13 @@ var run = function() {
function showFileHandler(ev) { function showFileHandler(ev) {
ev.preventDefault(); ev.preventDefault();
editor.setCacheFile(utils.fileKey( $(this).find('.name').text() )); editor.setCacheFile($(this).find('.name').text());
updateFiles(); updateFiles();
return false; return false;
} }
function fileTabFromKey(key) { function fileTabFromKey() {
var name = utils.fileNameFromKey(key); var name = editor.getCacheFile();
return $('#files .file').filter(function(){ return $(this).find('.name').text() == name; }); return $('#files .file').filter(function(){ return $(this).find('.name').text() == name; });
} }
...@@ -274,7 +274,7 @@ var run = function() { ...@@ -274,7 +274,7 @@ var run = function() {
} }
if (editor.cacheFileIsPresent()) { if (editor.cacheFileIsPresent()) {
var active = fileTabFromKey(editor.getCacheFile()); var active = fileTabFromKey();
active.addClass('active'); active.addClass('active');
editor.resetSession(); editor.resetSession();
} }
...@@ -454,7 +454,7 @@ var run = function() { ...@@ -454,7 +454,7 @@ var run = function() {
var errFile = err[1]; var errFile = err[1];
var errLine = parseInt(err[2], 10) - 1; var errLine = parseInt(err[2], 10) - 1;
var errCol = err[4] ? parseInt(err[4], 10) : 0; var errCol = err[4] ? parseInt(err[4], 10) : 0;
if (errFile == '' || errFile == utils.fileNameFromKey(editor.getCacheFile())) { if (errFile == '' || errFile == editor.getCacheFile()) {
compiler.addAnnotation({ compiler.addAnnotation({
row: errLine, row: errLine,
column: errCol, column: errCol,
...@@ -463,9 +463,9 @@ var run = function() { ...@@ -463,9 +463,9 @@ var run = function() {
}); });
} }
$error.click(function(ev){ $error.click(function(ev){
if (errFile != '' && errFile != utils.fileNameFromKey(editor.getCacheFile()) && editor.getFiles().indexOf(utils.fileKey(errFile)) !== -1) { if (errFile != '' && errFile != editor.getCacheFile() && editor.getFiles().indexOf(utils.fileKey(errFile)) !== -1) {
// Switch to file // Switch to file
editor.setCacheFile(utils.fileKey(errFile)); editor.setCacheFile(errFile);
updateFiles(); updateFiles();
//@TODO could show some error icon in files with errors //@TODO could show some error icon in files with errors
} }
......
...@@ -15,11 +15,11 @@ function Editor(loadingFromGist) { ...@@ -15,11 +15,11 @@ function Editor(loadingFromGist) {
}; };
this.setCacheFile = function(cacheFile) { this.setCacheFile = function(cacheFile) {
SOL_CACHE_FILE = cacheFile; SOL_CACHE_FILE = utils.fileKey(cacheFile);
}; };
this.getCacheFile = function() { this.getCacheFile = function() {
return SOL_CACHE_FILE; return utils.fileNameFromKey(SOL_CACHE_FILE);
}; };
this.cacheFileIsPresent = function() { this.cacheFileIsPresent = function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment