can add include/linked files to project

This commit is contained in:
Steven Hugg 2018-11-24 15:43:08 -05:00
parent 9bd8053dbd
commit 764fafa035
3 changed files with 61 additions and 0 deletions

View File

@ -50,6 +50,13 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<li><a class="dropdown-item" href="#" id="item_new_file">New Project...</a></li>
<li><a class="dropdown-item" href="#" id="item_upload_file">Upload File...</a></li>
<li><a class="dropdown-item" href="#" id="item_reset_file">Revert to Original...</a></li>
<li class="dropdown dropdown-submenu">
<a tabindex="-1" href="#">Add Files to Project</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#" id="item_addfile_include">Add Include File...</a></li>
<li><a class="dropdown-item" href="#" id="item_addfile_link">Add Linked File...</a></li>
</ul>
</li>
<li class="dropdown dropdown-submenu">
<a tabindex="-1" href="#">Download</a>
<ul class="dropdown-menu">

View File

@ -886,6 +886,52 @@ function _lookupHelp() {
}
}
function addFileToProject(type, ext, linefn) {
var wnd = projectWindows.getActive();
if (wnd && wnd.insertText) {
var filename = prompt("Add "+type+" File to Project", "filename"+ext);
if (filename) {
var path = "local/" + filename;
var newline = "\n" + linefn(filename) + "\n";
current_project.loadFiles([path], (err, result) => {
if (result && result.length) {
alert(filename + " already exists");
} else {
current_project.updateFile(path, "\n");
}
wnd.insertText(newline);
refreshWindowList();
});
}
} else {
alert("Can't insert text in this window -- switch back to main file");
}
}
function _addIncludeFile() {
var fn = getCurrentMainFilename();
var tool = platform.getToolForFilename(fn);
if (fn.endsWith(".c") || tool == 'sdcc' || tool == 'cc65')
addFileToProject("Header", ".h", (s) => { return '#include "'+s+'"' });
else if (tool == 'dasm')
addFileToProject("Include File", ".h", (s) => { return '\tinclude "'+s+'"' });
else if (tool == 'ca65' || tool == 'sdasz80' || tool == 'zmac')
addFileToProject("Include File", ".h", (s) => { return '\t.include "'+s+'"' });
else if (tool == 'verilator')
addFileToProject("Verilog File", ".v", (s) => { return '`include "'+s+'"' });
else
alert("Can't add include file to this project type (" + tool + ")");
}
function _addLinkFile() {
var fn = getCurrentMainFilename();
var tool = platform.getToolForFilename(fn);
if (fn.endsWith(".c") || tool == 'sdcc' || tool == 'cc65')
addFileToProject("Linked C", ".c", (s) => { return '//#link "'+s+'"' });
else
alert("Can't add linked file to this project type (" + tool + ")");
}
function setupDebugControls(){
$("#dbg_reset").click(resetAndDebug);
@ -957,6 +1003,8 @@ function setupDebugControls(){
if (platform.showHelp) {
$("#dbg_help").show().click(_lookupHelp);
}
$("#item_addfile_include").click(_addIncludeFile);
$("#item_addfile_link").click(_addLinkFile);
updateDebugWindows();
// setup replay slider
if (platform.setRecorder && platform.advance) {

View File

@ -15,6 +15,7 @@ export interface ProjectView {
tick?() : void;
getValue?() : string;
setText?(text : string) : void;
insertText?(text : string) : void;
getCursorPC?() : number;
getSourceFile?() : SourceFile;
setGutterBytes?(line:number, s:string) : void;
@ -129,6 +130,11 @@ export class SourceEditor implements ProjectView {
this.editor.clearHistory();
}
insertText(text:string) {
var cur = this.editor.getCursor();
this.editor.replaceRange(text, cur, cur);
}
getValue() : string {
return this.editor.getValue();
}