Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions include/codeboot.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,8 @@ CodeBootVM.prototype.menuLangHTML = function () {
<div class="dropdown-menu cb-menu-settings-lang">\
' + vm.menuSettingsLangHTML() + '\
<div class="dropdown-divider"></div>\
<a href="#" class="dropdown-item" data-toggle="modal" data-target="#cb-about-box">About codeBoot v' + CodeBoot.prototype.cb.version + '</a>\
<a href="#" class="dropdown-item" data-toggle="modal" data-target="#cb-help-box">Help</a>\
<a class="dropdown-item" data-toggle="modal" data-target="#cb-about-box">About codeBoot v' + CodeBoot.prototype.cb.version + '</a>\
<a class="dropdown-item" data-toggle="modal" data-target="#cb-help-box">Help</a>\
</div>\
</span>\
';
Expand All @@ -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 += '<a href="#" class="dropdown-item" data-cb-setting-lang="' +
html += '<a class="dropdown-item" data-cb-setting-lang="' +
id_and_level +
'">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;' +
svg.onLight + '</i>&nbsp;&nbsp;' + name + '</a>';
Expand Down Expand Up @@ -1312,24 +1312,24 @@ CodeBootVM.prototype.menuSettingsHTML = function () {
<div class="dropdown-menu">\
\
<h5 class="dropdown-header">Animation speed</h5>\
<a href="#" class="dropdown-item" data-cb-setting-speed="slow">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Slow</a>\
<a href="#" class="dropdown-item" data-cb-setting-speed="normal">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Normal</a>\
<a href="#" class="dropdown-item" data-cb-setting-speed="fast">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Fast</a>\
<a href="#" class="dropdown-item" data-cb-setting-speed="turbo">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Turbo</a>\
<a href="#" class="dropdown-item" data-cb-setting-speed="lightning">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Lightning</a>\
<a class="dropdown-item" data-cb-setting-speed="slow">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Slow</a>\
<a class="dropdown-item" data-cb-setting-speed="normal">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Normal</a>\
<a class="dropdown-item" data-cb-setting-speed="fast">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Fast</a>\
<a class="dropdown-item" data-cb-setting-speed="turbo">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Turbo</a>\
<a class="dropdown-item" data-cb-setting-speed="lightning">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Lightning</a>\
\
<div class="dropdown-divider"></div>\
\
<h5 class="dropdown-header">Editing</h5>\
<a href="#" class="dropdown-item" data-cb-setting-show-line-numbers>' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Show line numbers</a>\
<a href="#" class="dropdown-item" data-cb-setting-large-font>' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Large font</a>\
<a class="dropdown-item" data-cb-setting-show-line-numbers>' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Show line numbers</a>\
<a class="dropdown-item" data-cb-setting-large-font>' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Large font</a>\
\
<div class="dropdown-divider"></div>\
\
<h5 class="dropdown-header">Playground</h5>\
<a href="#" class="dropdown-item" data-cb-setting-playground="show-drawing-window">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Show drawing window</a>\
<a href="#" class="dropdown-item" data-cb-setting-playground="show-pixels-window">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Show pixels window</a>\
<a href="#" class="dropdown-item" data-cb-setting-playground="show-html-window">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Show HTML window</a>\
<a class="dropdown-item" data-cb-setting-playground="show-drawing-window">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Show drawing window</a>\
<a class="dropdown-item" data-cb-setting-playground="show-pixels-window">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Show pixels window</a>\
<a class="dropdown-item" data-cb-setting-playground="show-html-window">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Show HTML window</a>\
\
</div>\
</span>\
Expand All @@ -1343,15 +1343,15 @@ CodeBootVM.prototype.menuContextHTML = function () {
return '\n\
<div class="cb-menu-context dropdown-menu" style="display: none;">\n\
\n\
<a href="#" class="dropdown-item" data-cb-context-presentation="full">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Full window</a>\n\
<a class="dropdown-item" data-cb-context-presentation="full">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Full window</a>\n\
\n\
<a href="#" class="dropdown-item" data-cb-context-presentation="floating">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Floating window</a>\n\
<a class="dropdown-item" data-cb-context-presentation="floating">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Floating window</a>\n\
\n\
<a href="#" class="dropdown-item" data-cb-context-presentation="hidden">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Hide codeBoot</a>\n\
<a class="dropdown-item" data-cb-context-presentation="hidden">' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Hide codeBoot</a>\n\
\n\
<a href="#" class="dropdown-item" data-cb-context-bundle-state>' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Bundle state to clipboard</a>\n\
<a class="dropdown-item" data-cb-context-bundle-state>' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Bundle state to clipboard</a>\n\
\n\
<a href="#" class="dropdown-item" data-cb-context-bundle-executable>' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Bundle executable to clipboard</a>\n\
<a class="dropdown-item" data-cb-context-bundle-executable>' + vm.SVG['checkmark'] + '&nbsp;&nbsp;Bundle executable to clipboard</a>\n\
\n\
</div>\n\
';
Expand Down Expand Up @@ -1412,13 +1412,13 @@ CodeBootVM.prototype.helpHTML = function () {
<!-- WORKED ON TABS -->\
<ul class="nav nav-tabs" id="helpTab" role="tablist">\
<li class="nav-item">\
<a class="nav-link active" id="keybindings-tab" data-toggle="tab" href="#keybindings" role="tab" aria-controls="keybindings" aria-selected="true">Key bindings</a>\
<a class="nav-link active" id="keybindings-tab" data-toggle="tab" role="tab" aria-controls="keybindings" aria-selected="true">Key bindings</a>\
</li>\
<li class="nav-item">\
<a class="nav-link" id="files-tab" data-toggle="tab" href="#files" role="tab" aria-controls="files" aria-selected="false">Files</a>\
<a class="nav-link" id="files-tab" data-toggle="tab" role="tab" aria-controls="files" aria-selected="false">Files</a>\
</li>\
<li class="nav-item">\
<a class="nav-link" id="grammar-tab" data-toggle="tab" href="#grammar" role="tab" aria-controls="grammar" aria-selected="false">Grammar</a>\
<a class="nav-link" id="grammar-tab" data-toggle="tab" role="tab" aria-controls="grammar" aria-selected="false">Grammar</a>\
</li>\
</ul>\
\
Expand Down Expand Up @@ -2306,13 +2306,13 @@ CodeBootVM.prototype.helpHTML = function () {
\
<ul class="nav nav-tabs" id="grammarTab" role="tablist">\
<li class="nav-item">\
<a class="nav-link active" id="statements-tab" data-toggle="tab" href="#statements" role="tab" aria-controls="statements" aria-selected="true">Statements</a>\
<a class="nav-link active" id="statements-tab" data-toggle="tab" role="tab" aria-controls="statements" aria-selected="true">Statements</a>\
</li>\
<li class="nav-item">\
<a class="nav-link" id="expressions-tab" data-toggle="tab" href="#expressions" role="tab" aria-controls="expressions" aria-selected="false">Expressions</a>\
<a class="nav-link" id="expressions-tab" data-toggle="tab" role="tab" aria-controls="expressions" aria-selected="false">Expressions</a>\
</li>\
<li class="nav-item">\
<a class="nav-link" id="tokenEx-tab" data-toggle="tab" href="#tokenEx" role="tab" aria-controls="tokenEx" aria-selected="false">Token examples</a>\
<a class="nav-link" id="tokenEx-tab" data-toggle="tab" role="tab" aria-controls="tokenEx" aria-selected="false">Token examples</a>\
</li>\
</ul>\
\
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down
64 changes: 63 additions & 1 deletion include/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down