From e81122739bf4a134a00734208fccdef2e2058771 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Wed, 27 Dec 2017 02:26:24 +0000 Subject: [PATCH] Files can now be moved from the output to the input --- src/web/InputWaiter.js | 2 +- src/web/Manager.js | 2 +- src/web/OutputWaiter.js | 33 +++++++++++++++++++++++++-------- src/web/WorkerWaiter.js | 14 -------------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/web/InputWaiter.js b/src/web/InputWaiter.js index 62a579bb..f6818b11 100755 --- a/src/web/InputWaiter.js +++ b/src/web/InputWaiter.js @@ -84,7 +84,7 @@ InputWaiter.prototype.setFile = function(file) { fileOverlay.style.display = "block"; fileName.textContent = file.name; fileSize.textContent = file.size.toLocaleString() + " bytes"; - fileType.textContent = file.type; + fileType.textContent = file.type || "unknown"; fileLoaded.textContent = "0%"; }; diff --git a/src/web/Manager.js b/src/web/Manager.js index 4b89942a..39aaf409 100755 --- a/src/web/Manager.js +++ b/src/web/Manager.js @@ -159,7 +159,7 @@ Manager.prototype.initialiseEventListeners = function() { this.addMultiEventListener("#output-html", "mousedown dblclick select", this.highlighter.outputHtmlMousedown, this.highlighter); this.addDynamicListener(".file-switch", "click", this.output.fileSwitch, this.output); this.addDynamicListener("#output-file-download", "click", this.output.downloadFile, this.output); - this.addDynamicListener("#output-file-slice", "click", this.output.displayFile, this.output); + this.addDynamicListener("#output-file-slice", "click", this.output.displayFileSlice, this.output); document.getElementById("show-file-overlay").addEventListener("click", this.output.showFileOverlayClick.bind(this.output)); // Options diff --git a/src/web/OutputWaiter.js b/src/web/OutputWaiter.js index ca1f3605..51def0b4 100755 --- a/src/web/OutputWaiter.js +++ b/src/web/OutputWaiter.js @@ -18,6 +18,7 @@ const OutputWaiter = function(app, manager) { this.manager = manager; this.dishBuffer = null; + this.dishStr = null; }; @@ -47,7 +48,10 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) { const inputHighlighter = document.getElementById("input-highlighter"); let scriptElements, lines, length; - if (!preserveBuffer) this.closeFile(); + if (!preserveBuffer) { + this.closeFile(); + document.getElementById("show-file-overlay").style.display = "none"; + } switch (type) { case "html": @@ -60,6 +64,7 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) { outputText.value = ""; outputHtml.innerHTML = data; length = data.length; + this.dishStr = Utils.stripHtmlTags(data, true); // Execute script sections scriptElements = outputHtml.querySelectorAll("script"); @@ -80,6 +85,7 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) { outputText.value = ""; outputHtml.innerHTML = ""; length = data.byteLength; + this.dishStr = ""; this.setFile(data); break; @@ -96,6 +102,7 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) { lines = data.count("\n") + 1; length = data.length; + this.dishStr = data; break; } @@ -143,9 +150,9 @@ OutputWaiter.prototype.downloadFile = function() { /** - * Handler for file display events. + * Handler for file slice display events. */ -OutputWaiter.prototype.displayFile = function() { +OutputWaiter.prototype.displayFileSlice = function() { const startTime = new Date().getTime(), showFileOverlay = document.getElementById("show-file-overlay"), sliceFromEl = document.getElementById("output-file-slice-from"), @@ -233,7 +240,7 @@ OutputWaiter.prototype.adjustWidth = function() { */ OutputWaiter.prototype.saveClick = function() { if (!this.dishBuffer) { - this.dishBuffer = new Uint8Array(Utils.strToCharcode(this.app.dishStr)).buffer; + this.dishBuffer = new Uint8Array(Utils.strToCharcode(this.dishStr)).buffer; } this.downloadFile(); }; @@ -254,14 +261,14 @@ OutputWaiter.prototype.copyClick = function() { textarea.style.height = 0; textarea.style.border = "none"; - textarea.value = this.app.dishStr; + textarea.value = this.dishStr; document.body.appendChild(textarea); // Select and copy the contents of this textarea let success = false; try { textarea.select(); - success = textarea.value && document.execCommand("copy"); + success = this.dishStr && document.execCommand("copy"); } catch (err) { success = false; } @@ -284,7 +291,17 @@ OutputWaiter.prototype.copyClick = function() { OutputWaiter.prototype.switchClick = function() { this.switchOrigData = this.manager.input.get(); document.getElementById("undo-switch").disabled = false; - this.app.setInput(this.app.dishStr); + if (this.dishBuffer) { + this.manager.input.setFile(new File([this.dishBuffer], "output.dat")); + this.manager.input.handleLoaderMessage({ + data: { + progress: 100, + fileBuffer: this.dishBuffer + } + }); + } else { + this.app.setInput(this.dishStr); + } }; @@ -378,7 +395,7 @@ OutputWaiter.prototype.setStatusMsg = function(msg) { * @returns {boolean} */ OutputWaiter.prototype.containsCR = function() { - return this.app.dishStr.indexOf("\r") >= 0; + return this.dishStr.indexOf("\r") >= 0; }; export default OutputWaiter; diff --git a/src/web/WorkerWaiter.js b/src/web/WorkerWaiter.js index 3ed9e7ea..402b56b0 100644 --- a/src/web/WorkerWaiter.js +++ b/src/web/WorkerWaiter.js @@ -1,4 +1,3 @@ -import Utils from "../core/Utils.js"; import ChefWorker from "worker-loader?inline&fallback=false!../core/ChefWorker.js"; /** @@ -111,19 +110,6 @@ WorkerWaiter.prototype.bakingComplete = function(response) { this.app.handleError(response.error); } - switch (response.type) { - case "html": - this.app.dishStr = Utils.stripHtmlTags(response.result, true); - break; - case "ArrayBuffer": - this.app.dishStr = ""; - break; - case "string": - default: - this.app.dishStr = response.result; - break; - } - this.app.progress = response.progress; this.manager.recipe.updateBreakpointIndicator(response.progress); this.manager.output.set(response.result, response.type, response.duration);