From a2cc7a84dbacd134b55984f343f9ee485c380097 Mon Sep 17 00:00:00 2001 From: j433866 Date: Wed, 27 Mar 2019 13:48:54 +0000 Subject: [PATCH] Sync output tabs to input tabs. Output tabs are created when input tabs are. Fix initial bake not working --- src/web/InputWaiter.mjs | 30 ++++++++++++----- src/web/Manager.mjs | 1 + src/web/OutputWaiter.mjs | 72 ++++++++++++++++++++++++++++++++++------ 3 files changed, 84 insertions(+), 19 deletions(-) diff --git a/src/web/InputWaiter.mjs b/src/web/InputWaiter.mjs index 6d5c0bcd..3b50fd41 100755 --- a/src/web/InputWaiter.mjs +++ b/src/web/InputWaiter.mjs @@ -82,11 +82,18 @@ class InputWaiter { } else { inputs.push({ inputNum: inputNum, - input: this.inputs[inputNum] + input: this.inputs[inputNum] || "" }); } } + if (inputs.length === 0) { + inputs.push({ + inputNum: this.getActiveTab(), + input: "" + }); + } + return inputs; } @@ -495,6 +502,9 @@ class InputWaiter { tabsList.appendChild(newTab); + this.manager.output.addTab(newTabNum.toString()); + this.manager.output.changeTab(document.getElementById(`output-tab-${newTabNum.toString()}`).firstElementChild); + if (changeTab) { this.changeTab(newTabContent); } @@ -511,20 +521,18 @@ class InputWaiter { if (tabLiItem.classList.contains("active-input-tab")) { if (tabLiItem.previousElementSibling) { this.changeTab(tabLiItem.previousElementSibling.firstElementChild); - - window.dispatchEvent(this.manager.statechange); } else if (tabLiItem.nextElementSibling) { this.changeTab(tabLiItem.nextElementSibling.firstElementChild); - - window.dispatchEvent(this.manager.statechange); } } const tabNum = tabLiItem.id.replace("input-tab-", ""); - delete this.fileBuffers[tabNum]; - delete this.inputs[tabNum]; + this.fileBuffers[tabNum] = undefined; + this.inputs[tabNum] = undefined; tabList.removeChild(tabLiItem); + + this.manager.output.removeTab(tabNum, this.getActiveTab()); } else { const tabNum = tabLiItem.id.replace("input-tab-", ""); delete this.fileBuffers[tabNum]; @@ -560,7 +568,7 @@ class InputWaiter { * * @param {Element} tabElement The tab element to change to */ - changeTab(tabElement) { + changeTab(tabElement, changeOutput=true) { const liItem = tabElement.parentElement; const newTabNum = liItem.id.replace("input-tab-", ""); const currentTabNum = this.getActiveTab(); @@ -585,6 +593,10 @@ class InputWaiter { document.getElementById("input-file").style.display = "none"; } + if (changeOutput) { + this.manager.output.changeTab(document.getElementById(`output-tab-${newTabNum.toString()}`).firstElementChild); + } + } /** @@ -596,7 +608,7 @@ class InputWaiter { if (!mouseEvent.srcElement) { return; } - this.changeTab(mouseEvent.srcElement); + this.changeTab(mouseEvent.srcElement, true); } diff --git a/src/web/Manager.mjs b/src/web/Manager.mjs index 264bb0a8..8bc7f76d 100755 --- a/src/web/Manager.mjs +++ b/src/web/Manager.mjs @@ -177,6 +177,7 @@ class Manager { this.addDynamicListener("#output-file-slice i", "click", this.output.displayFileSlice, this.output); document.getElementById("show-file-overlay").addEventListener("click", this.output.showFileOverlayClick.bind(this.output)); this.addDynamicListener(".extract-file,.extract-file i", "click", this.output.extractFileClick, this.output); + this.addDynamicListener("#output-tabs ul li .output-tab-content", "click", this.output.changeTabClick, this.output); // Options document.getElementById("options").addEventListener("click", this.options.optionsClick.bind(this.options)); diff --git a/src/web/OutputWaiter.mjs b/src/web/OutputWaiter.mjs index 1f49fa24..7572c5d1 100755 --- a/src/web/OutputWaiter.mjs +++ b/src/web/OutputWaiter.mjs @@ -50,13 +50,7 @@ class OutputWaiter { this.outputs = outputs; const activeTab = this.manager.input.getActiveTab(); - const tabs = document.getElementById("output-tabs").getElementsByTagName("li"); - for (let i = tabs.length - 1; i >= 0; i--) { - document.getElementById("output-tabs").firstElementChild.removeChild(tabs.item(i)); - } - for (let i = 0; i < outputs.length; i++) { - this.addTab(outputs[i].inputNum); if (outputs[i].inputNum === activeTab) { await this.set(outputs[i].data.result, outputs[i].data.type, outputs[0].data.duration); } @@ -611,11 +605,69 @@ class OutputWaiter { * * @param {Element} tabElement */ - changeTab(tabElement) { + changeTab(tabElement, changeInput=false) { const liItem = tabElement.parentElement; - const newTabNum = liItem.id.replace("input-tab-", ""); - const currentTabNum = this.getActiveTab(); - const outputText = document.getElementById("output-text"); + const newTabNum = liItem.id.replace("output-tab-", ""); + const currentTabNum = this.manager.input.getActiveTab(); + + const activeTabs = document.getElementsByClassName("active-output-tab"); + for (let i = 0; i < activeTabs.length; i++) { + activeTabs.item(i).classList.remove("active-output-tab"); + } + + document.getElementById(`output-tab-${currentTabNum}`).classList.remove("active-output-tab"); + liItem.classList.add("active-output-tab"); + + for (let i = 0; i < this.outputs.length; i++) { + if (this.outputs[i].inputNum === newTabNum) { + this.set(this.outputs[i].data.result, this.outputs[i].data.type, this.outputs[0].data.duration); + } + } + if (changeInput) { + this.manager.input.changeTab(document.getElementById(`input-tab-${newTabNum}`).firstElementChild, false); + } + } + + /** + * Handler for changing tabs event + * + * @param {event} mouseEvent + */ + changeTabClick(mouseEvent) { + if (!mouseEvent.srcElement) { + return; + } + this.changeTab(mouseEvent.srcElement, true); + } + + /** + * Removes a tab from the output window, along with the value for it in outputs + * + * @param {string} inputNum + * @param {string} newActiveNum + */ + removeTab(inputNum, newActiveNum) { + const tabLiItem = document.getElementById(`output-tab-${inputNum}`); + + if (tabLiItem.parentElement.children.length === 2) { + document.getElementById("output-tabs").style.display = "none"; + + document.getElementById("output-wrapper").style.height = "calc(100% - var(--title-height))"; + document.getElementById("output-highlighter").style.height = "calc(100% - var(--title-height))"; + document.getElementById("output-file").style.height = "calc(100% - var(--title-height))"; + + } + + tabLiItem.parentElement.removeChild(tabLiItem); + + for (let i = 0; i < this.outputs.length; i++) { + if (this.outputs[i].inputNum === inputNum) { + this.outputs.splice(i, 1); + break; + } + } + + this.changeTab(document.getElementById(`output-tab-${newActiveNum}`), false); } }