diff --git a/include/codeboot.js b/include/codeboot.js index d1aec79c..e7fd71ed 100644 --- a/include/codeboot.js +++ b/include/codeboot.js @@ -1260,8 +1260,8 @@ CodeBootVM.prototype.menuLangHTML = function () { \ \ '; @@ -1279,7 +1279,7 @@ CodeBootVM.prototype.menuSettingsLangHTML = function () { var name = levels[level]; var id_and_level = id + '-' + level; var svg = lang.prototype.getSVG(level, false); - html += '' + vm.SVG['checkmark'] + '  ' + svg.onLight + '  ' + name + ''; @@ -1312,24 +1312,24 @@ CodeBootVM.prototype.menuSettingsHTML = function () { \ \ @@ -1343,15 +1343,15 @@ CodeBootVM.prototype.menuContextHTML = function () { return '\n\ \n\ '; @@ -1412,13 +1412,13 @@ CodeBootVM.prototype.helpHTML = function () { \ \ \ @@ -2306,13 +2306,13 @@ CodeBootVM.prototype.helpHTML = function () { \ \ \ @@ -2967,7 +2967,12 @@ CodeBootVM.prototype.initRoot = function (opts, floating) { vm.setAttribute('data-cb-editable', vm.editable); if (content !== null) { - vm.fs.newFile(filename, content); + if (vm.editable){ + vm.fs.parseContentIntoFiles(filename, content) + } + else{ + vm.fs.openFileWithContentOrNew(content) + } } // In order to resize the repl's height, the CodeMirror-scroll @@ -2998,8 +3003,7 @@ CodeBootVM.prototype.initRoot = function (opts, floating) { if (vm.root.tagName === 'PRE') { - - content = vm.root.innerText; + content = $.trim(vm.root.innerText); var elem = document.createElement('div'); elem.className = 'cb-vm'; diff --git a/include/fs.js b/include/fs.js index 41610516..979878a2 100644 --- a/include/fs.js +++ b/include/fs.js @@ -390,7 +390,6 @@ CodeBootFileSystem.prototype.newMenuItem = function (elem, cls, text) { var item = document.createElement('a'); item.className = cls; - item.href = '#'; var span = document.createElement('span'); span.innerText = text; @@ -685,11 +684,74 @@ CodeBootFileSystem.prototype.openFileExistingOrNew = function (filename) { } }; +CodeBootFileSystem.prototype.openFileWithContentOrNew = function (content){ + + var fs = this; + + for (var filename in fs.files) { + file_content = fs.files[filename].getContent(); + if (content == file_content) { + fs.openFile(filename) + return true + } + } + + fs.newFile(undefined, content) + return false + +} + CodeBootFileSystem.prototype.removeAllEditors = function () { var fs = this; fs.fem.removeAllEditors(); }; +CodeBootFileSystem.prototype.parseContentIntoFiles = function (filename, content){ + + var fs = this; + + var lines = $.trim(content).split("\n") + var files = [] + var content = "" + + for (let line of lines){ + line = $.trim(line) + if (line.length > 0 && line[0] === "#"){ + + i = 1; + while (line.length > i && line[i] === "#") i++ + while (line.length > i && line[i] === " ") i++ + + if (line.length > i + 5 && line.substring(i, i+5).toLowerCase() === "file:"){ + content = $.trim(content) + if (content.length > 0) files.push([filename, content]) + content = "" + filename = $.trim(line.substring(i+5, line.length)) + } + + } + else { + content += line + "\n" + } + + } + + content = $.trim(content) + if (content.length > 0) files.push([filename, content]) + + for (file of files){ + filename = file[0] + content = file[1] + + if (filename === undefined){ + fs.openFileWithContentOrNew(content) + } + else{ + fs.newFile(filename, content) + } + } +} + //----------------------------------------------------------------------------- function CodeBootFileEditorManager(fs) {