can add include/linked files to project
This commit is contained in:
parent
9bd8053dbd
commit
764fafa035
|
@ -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">
|
||||
|
|
48
src/ui.ts
48
src/ui.ts
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue