Files can now be moved from the output to the input

This commit is contained in:
n1474335 2017-12-27 02:26:24 +00:00
parent a0aa363203
commit e81122739b
4 changed files with 27 additions and 24 deletions

View file

@ -84,7 +84,7 @@ InputWaiter.prototype.setFile = function(file) {
fileOverlay.style.display = "block"; fileOverlay.style.display = "block";
fileName.textContent = file.name; fileName.textContent = file.name;
fileSize.textContent = file.size.toLocaleString() + " bytes"; fileSize.textContent = file.size.toLocaleString() + " bytes";
fileType.textContent = file.type; fileType.textContent = file.type || "unknown";
fileLoaded.textContent = "0%"; fileLoaded.textContent = "0%";
}; };

View file

@ -159,7 +159,7 @@ Manager.prototype.initialiseEventListeners = function() {
this.addMultiEventListener("#output-html", "mousedown dblclick select", this.highlighter.outputHtmlMousedown, this.highlighter); this.addMultiEventListener("#output-html", "mousedown dblclick select", this.highlighter.outputHtmlMousedown, this.highlighter);
this.addDynamicListener(".file-switch", "click", this.output.fileSwitch, this.output); 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-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)); document.getElementById("show-file-overlay").addEventListener("click", this.output.showFileOverlayClick.bind(this.output));
// Options // Options

View file

@ -18,6 +18,7 @@ const OutputWaiter = function(app, manager) {
this.manager = manager; this.manager = manager;
this.dishBuffer = null; this.dishBuffer = null;
this.dishStr = null;
}; };
@ -47,7 +48,10 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) {
const inputHighlighter = document.getElementById("input-highlighter"); const inputHighlighter = document.getElementById("input-highlighter");
let scriptElements, lines, length; let scriptElements, lines, length;
if (!preserveBuffer) this.closeFile(); if (!preserveBuffer) {
this.closeFile();
document.getElementById("show-file-overlay").style.display = "none";
}
switch (type) { switch (type) {
case "html": case "html":
@ -60,6 +64,7 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) {
outputText.value = ""; outputText.value = "";
outputHtml.innerHTML = data; outputHtml.innerHTML = data;
length = data.length; length = data.length;
this.dishStr = Utils.stripHtmlTags(data, true);
// Execute script sections // Execute script sections
scriptElements = outputHtml.querySelectorAll("script"); scriptElements = outputHtml.querySelectorAll("script");
@ -80,6 +85,7 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) {
outputText.value = ""; outputText.value = "";
outputHtml.innerHTML = ""; outputHtml.innerHTML = "";
length = data.byteLength; length = data.byteLength;
this.dishStr = "";
this.setFile(data); this.setFile(data);
break; break;
@ -96,6 +102,7 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) {
lines = data.count("\n") + 1; lines = data.count("\n") + 1;
length = data.length; length = data.length;
this.dishStr = data;
break; 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(), const startTime = new Date().getTime(),
showFileOverlay = document.getElementById("show-file-overlay"), showFileOverlay = document.getElementById("show-file-overlay"),
sliceFromEl = document.getElementById("output-file-slice-from"), sliceFromEl = document.getElementById("output-file-slice-from"),
@ -233,7 +240,7 @@ OutputWaiter.prototype.adjustWidth = function() {
*/ */
OutputWaiter.prototype.saveClick = function() { OutputWaiter.prototype.saveClick = function() {
if (!this.dishBuffer) { if (!this.dishBuffer) {
this.dishBuffer = new Uint8Array(Utils.strToCharcode(this.app.dishStr)).buffer; this.dishBuffer = new Uint8Array(Utils.strToCharcode(this.dishStr)).buffer;
} }
this.downloadFile(); this.downloadFile();
}; };
@ -254,14 +261,14 @@ OutputWaiter.prototype.copyClick = function() {
textarea.style.height = 0; textarea.style.height = 0;
textarea.style.border = "none"; textarea.style.border = "none";
textarea.value = this.app.dishStr; textarea.value = this.dishStr;
document.body.appendChild(textarea); document.body.appendChild(textarea);
// Select and copy the contents of this textarea // Select and copy the contents of this textarea
let success = false; let success = false;
try { try {
textarea.select(); textarea.select();
success = textarea.value && document.execCommand("copy"); success = this.dishStr && document.execCommand("copy");
} catch (err) { } catch (err) {
success = false; success = false;
} }
@ -284,7 +291,17 @@ OutputWaiter.prototype.copyClick = function() {
OutputWaiter.prototype.switchClick = function() { OutputWaiter.prototype.switchClick = function() {
this.switchOrigData = this.manager.input.get(); this.switchOrigData = this.manager.input.get();
document.getElementById("undo-switch").disabled = false; 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} * @returns {boolean}
*/ */
OutputWaiter.prototype.containsCR = function() { OutputWaiter.prototype.containsCR = function() {
return this.app.dishStr.indexOf("\r") >= 0; return this.dishStr.indexOf("\r") >= 0;
}; };
export default OutputWaiter; export default OutputWaiter;

View file

@ -1,4 +1,3 @@
import Utils from "../core/Utils.js";
import ChefWorker from "worker-loader?inline&fallback=false!../core/ChefWorker.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); 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.app.progress = response.progress;
this.manager.recipe.updateBreakpointIndicator(response.progress); this.manager.recipe.updateBreakpointIndicator(response.progress);
this.manager.output.set(response.result, response.type, response.duration); this.manager.output.set(response.result, response.type, response.duration);