diff --git a/src/project.ts b/src/project.ts index 8a3a75c5..e79894c9 100644 --- a/src/project.ts +++ b/src/project.ts @@ -32,22 +32,26 @@ export class CodeProject { this.store = store; worker.onmessage = (e) => { - var notfinal = this.pendingWorkerMessages > 1; - if (notfinal) { - this.sendBuild(); - this.pendingWorkerMessages = 1; - } else { - if (this.callbackBuildStatus) this.callbackBuildStatus(false); - if (!this.isCompiling) { console.log(this.pendingWorkerMessages); console.trace(); } // debug compile problems - this.isCompiling = false; - this.pendingWorkerMessages = 0; - } - if (e.data && !e.data.unchanged) { - this.processBuildResult(e.data); - if (this.callbackBuildResult) this.callbackBuildResult(e.data); // call with data when changed - } + this.receiveWorkerMessage(e.data); }; } + + receiveWorkerMessage(data : WorkerResult) { + var notfinal = this.pendingWorkerMessages > 1; + if (notfinal) { + this.sendBuild(); + this.pendingWorkerMessages = 1; + } else { + if (this.callbackBuildStatus) this.callbackBuildStatus(false); + if (!this.isCompiling) { console.log(this.pendingWorkerMessages); console.trace(); } // debug compile problems + this.isCompiling = false; + this.pendingWorkerMessages = 0; + } + if (data && !data.unchanged) { + this.processBuildResult(data); + if (this.callbackBuildResult) this.callbackBuildResult(data); // call with data when changed + } + } preloadWorker(path:string) { var tool = this.platform.getToolForFilename(path); @@ -235,6 +239,19 @@ export class CodeProject { sendBuild() { if (!this.mainpath) throw "need to call setMainFile first"; var maindata = this.getFile(this.mainpath); + // if binary blob, just return it as ROM + if (maindata instanceof Uint8Array) { + this.isCompiling = true; + this.receiveWorkerMessage({ + output:maindata, + errors:[], + listings:null, + symbolmap:null, + params:{} + }); + return; + } + // otherwise, make it a string var text = typeof maindata === "string" ? maindata : ''; // TODO: load dependencies of non-main files this.loadFileDependencies(text, (err, depends) => { diff --git a/src/ui.ts b/src/ui.ts index f223f1d1..6f64dfa3 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -206,7 +206,6 @@ function loadProject(preset_id:string) { alert(err); } else if (result && result.length) { // we need this to build create functions for the editor - // TODO: can't use binary file as main refreshWindowList(); // show main file projectWindows.createOrShow(preset_id); diff --git a/src/views.ts b/src/views.ts index 575afb1d..31293110 100644 --- a/src/views.ts +++ b/src/views.ts @@ -25,7 +25,6 @@ export interface ProjectView { setTimingResult?(result:CodeAnalyzer) : void; }; -// TODO: move to different namespace declare var CodeMirror; declare var VirtualList; @@ -36,8 +35,9 @@ function jumpToLine(ed, i:number) { ed.scrollTo(null, t - middleHeight - 5); } +// TODO: https://stackoverflow.com/questions/10463518/converting-em-to-px-in-javascript-and-getting-default-font-size function getVisibleEditorLineHeight() : number{ - return $(".CodeMirror-line:visible").first().height(); + return $("#booksMenuButton").first().height(); } ///// diff --git a/src/workertypes.ts b/src/workertypes.ts index 06a6d771..606f1688 100644 --- a/src/workertypes.ts +++ b/src/workertypes.ts @@ -94,4 +94,6 @@ export interface WorkerResult { listings:CodeListingMap, symbolmap:{[sym:string]:number}, params:{}, + unchanged?:boolean, } +