Simplified TabWaiter structure

This commit is contained in:
n1474335 2022-10-21 13:57:46 +01:00
parent 01508a2459
commit 5efd125d9b
7 changed files with 58 additions and 233 deletions

View file

@ -156,7 +156,7 @@ class App {
this.manager.input.inputWorker.postMessage({ this.manager.input.inputWorker.postMessage({
action: "autobake", action: "autobake",
data: { data: {
activeTab: this.manager.tabs.getActiveInputTab() activeTab: this.manager.tabs.getActiveTab("input")
} }
}); });
} else { } else {
@ -174,7 +174,7 @@ class App {
// Reset status using cancelBake // Reset status using cancelBake
this.manager.worker.cancelBake(true, false); this.manager.worker.cancelBake(true, false);
const activeTab = this.manager.tabs.getActiveInputTab(); const activeTab = this.manager.tabs.getActiveTab("input");
if (activeTab === -1) return; if (activeTab === -1) return;
let progress = 0; let progress = 0;
@ -221,7 +221,7 @@ class App {
setInput(input) { setInput(input) {
// Get the currently active tab. // Get the currently active tab.
// If there isn't one, assume there are no inputs so use inputNum of 1 // If there isn't one, assume there are no inputs so use inputNum of 1
let inputNum = this.manager.tabs.getActiveInputTab(); let inputNum = this.manager.tabs.getActiveTab("input");
if (inputNum === -1) inputNum = 1; if (inputNum === -1) inputNum = 1;
this.manager.input.updateInputValue(inputNum, input); this.manager.input.updateInputValue(inputNum, input);

View file

@ -126,7 +126,7 @@ class BindingsWaiter {
break; break;
case "KeyW": // Close tab case "KeyW": // Close tab
e.preventDefault(); e.preventDefault();
this.manager.input.removeInput(this.manager.tabs.getActiveInputTab()); this.manager.input.removeInput(this.manager.tabs.getActiveTab("input"));
break; break;
case "ArrowLeft": // Go to previous tab case "ArrowLeft": // Go to previous tab
e.preventDefault(); e.preventDefault();

View file

@ -83,7 +83,7 @@ class HighlighterWaiter {
*/ */
displayHighlights(pos, direction) { displayHighlights(pos, direction) {
if (!pos) return; if (!pos) return;
if (this.manager.tabs.getActiveInputTab() !== this.manager.tabs.getActiveOutputTab()) return; if (this.manager.tabs.getActiveTab("input") !== this.manager.tabs.getActiveTab("output")) return;
const io = direction === "forward" ? "output" : "input"; const io = direction === "forward" ? "output" : "input";
this.highlight(io, pos); this.highlight(io, pos);

View file

@ -208,7 +208,7 @@ class InputWaiter {
action: "updateMaxTabs", action: "updateMaxTabs",
data: { data: {
maxTabs: numTabs, maxTabs: numTabs,
activeTab: this.manager.tabs.getActiveInputTab() activeTab: this.manager.tabs.getActiveTab("input")
} }
}); });
} }
@ -237,7 +237,7 @@ class InputWaiter {
action: "updateMaxTabs", action: "updateMaxTabs",
data: { data: {
maxTabs: this.maxTabs, maxTabs: this.maxTabs,
activeTab: this.manager.tabs.getActiveInputTab() activeTab: this.manager.tabs.getActiveTab("input")
} }
}); });
this.inputWorker.postMessage({ this.inputWorker.postMessage({
@ -357,7 +357,7 @@ class InputWaiter {
if (Object.prototype.hasOwnProperty.call(r, "progress") && if (Object.prototype.hasOwnProperty.call(r, "progress") &&
Object.prototype.hasOwnProperty.call(r, "inputNum")) { Object.prototype.hasOwnProperty.call(r, "inputNum")) {
this.manager.tabs.updateInputTabProgress(r.inputNum, r.progress, 100); this.manager.tabs.updateTabProgress(r.inputNum, r.progress, 100, "input");
} }
const transferable = Object.prototype.hasOwnProperty.call(r, "fileBuffer") ? [r.fileBuffer] : undefined; const transferable = Object.prototype.hasOwnProperty.call(r, "fileBuffer") ? [r.fileBuffer] : undefined;
@ -400,7 +400,7 @@ class InputWaiter {
this.changeTab(r.data, this.app.options.syncTabs); this.changeTab(r.data, this.app.options.syncTabs);
break; break;
case "updateTabHeader": case "updateTabHeader":
this.manager.tabs.updateInputTabHeader(r.data.inputNum, r.data.input); this.manager.tabs.updateTabHeader(r.data.inputNum, r.data.input, "input");
break; break;
case "loadingInfo": case "loadingInfo":
this.showLoadingInfo(r.data, true); this.showLoadingInfo(r.data, true);
@ -473,7 +473,7 @@ class InputWaiter {
*/ */
async set(inputNum, inputData, silent=false) { async set(inputNum, inputData, silent=false) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
const activeTab = this.manager.tabs.getActiveInputTab(); const activeTab = this.manager.tabs.getActiveTab("input");
if (inputNum !== activeTab) return; if (inputNum !== activeTab) return;
if (inputData.file) { if (inputData.file) {
@ -519,7 +519,7 @@ class InputWaiter {
* @param {number} progress * @param {number} progress
*/ */
setFile(inputNum, inputData) { setFile(inputNum, inputData) {
const activeTab = this.manager.tabs.getActiveInputTab(); const activeTab = this.manager.tabs.getActiveTab("input");
if (inputNum !== activeTab) return; if (inputNum !== activeTab) return;
// Create file details panel // Create file details panel
@ -542,7 +542,7 @@ class InputWaiter {
* @param {number} inputNum * @param {number} inputNum
*/ */
clearFile(inputNum) { clearFile(inputNum) {
const activeTab = this.manager.tabs.getActiveInputTab(); const activeTab = this.manager.tabs.getActiveTab("input");
if (inputNum !== activeTab) return; if (inputNum !== activeTab) return;
// Clear file details panel // Clear file details panel
@ -557,9 +557,9 @@ class InputWaiter {
* @param {number} inputNum - The inputNum of the input which has finished loading * @param {number} inputNum - The inputNum of the input which has finished loading
*/ */
fileLoaded(inputNum) { fileLoaded(inputNum) {
this.manager.tabs.updateInputTabProgress(inputNum, 100, 100); this.manager.tabs.updateTabProgress(inputNum, 100, 100, "input");
const activeTab = this.manager.tabs.getActiveInputTab(); const activeTab = this.manager.tabs.getActiveTab("input");
if (activeTab !== inputNum) return; if (activeTab !== inputNum) return;
this.inputWorker.postMessage({ this.inputWorker.postMessage({
@ -580,7 +580,7 @@ class InputWaiter {
* @param {number | string} progress - Either a number or "error" * @param {number | string} progress - Either a number or "error"
*/ */
updateFileProgress(inputNum, progress) { updateFileProgress(inputNum, progress) {
// const activeTab = this.manager.tabs.getActiveInputTab(); // const activeTab = this.manager.tabs.getActiveTab("input");
// if (inputNum !== activeTab) return; // if (inputNum !== activeTab) return;
// TODO // TODO
@ -727,10 +727,10 @@ class InputWaiter {
inputChange(e) { inputChange(e) {
debounce(function(e) { debounce(function(e) {
const value = this.getInput(); const value = this.getInput();
const activeTab = this.manager.tabs.getActiveInputTab(); const activeTab = this.manager.tabs.getActiveTab("input");
this.updateInputValue(activeTab, value); this.updateInputValue(activeTab, value);
this.manager.tabs.updateInputTabHeader(activeTab, value.slice(0, 100).replace(/[\n\r]/g, "")); this.manager.tabs.updateTabHeader(activeTab, value.slice(0, 100).replace(/[\n\r]/g, ""), "input");
// Fire the statechange event as the input has been modified // Fire the statechange event as the input has been modified
window.dispatchEvent(this.manager.statechange); window.dispatchEvent(this.manager.statechange);
@ -813,7 +813,7 @@ class InputWaiter {
*/ */
loadUIFiles(files) { loadUIFiles(files) {
const numFiles = files.length; const numFiles = files.length;
const activeTab = this.manager.tabs.getActiveInputTab(); const activeTab = this.manager.tabs.getActiveTab("input");
log.debug(`Loading ${numFiles} files.`); log.debug(`Loading ${numFiles} files.`);
// Display the number of files as pending so the user // Display the number of files as pending so the user
@ -912,7 +912,7 @@ class InputWaiter {
setTimeout(function() { setTimeout(function() {
this.inputWorker.postMessage({ this.inputWorker.postMessage({
action: "getLoadProgress", action: "getLoadProgress",
data: this.manager.tabs.getActiveInputTab() data: this.manager.tabs.getActiveTab("input")
}); });
}.bind(this), 100); }.bind(this), 100);
} }
@ -925,8 +925,8 @@ class InputWaiter {
* @param {boolean} [changeOutput=false] - If true, also changes the output * @param {boolean} [changeOutput=false] - If true, also changes the output
*/ */
changeTab(inputNum, changeOutput) { changeTab(inputNum, changeOutput) {
if (this.manager.tabs.getInputTabItem(inputNum) !== null) { if (this.manager.tabs.getTabItem(inputNum, "input") !== null) {
this.manager.tabs.changeInputTab(inputNum); this.manager.tabs.changeTab(inputNum, "input");
this.inputWorker.postMessage({ this.inputWorker.postMessage({
action: "setInput", action: "setInput",
data: { data: {
@ -935,7 +935,7 @@ class InputWaiter {
} }
}); });
} else { } else {
const minNum = Math.min(...this.manager.tabs.getInputTabList()); const minNum = Math.min(...this.manager.tabs.getTabList("input"));
let direction = "right"; let direction = "right";
if (inputNum < minNum) { if (inputNum < minNum) {
direction = "left"; direction = "left";
@ -1070,8 +1070,8 @@ class InputWaiter {
const tabsWrapper = document.getElementById("input-tabs"), const tabsWrapper = document.getElementById("input-tabs"),
numTabs = tabsWrapper.children.length; numTabs = tabsWrapper.children.length;
if (!this.manager.tabs.getInputTabItem(inputNum) && numTabs < this.maxTabs) { if (!this.manager.tabs.getTabItem(inputNum, "input") && numTabs < this.maxTabs) {
const newTab = this.manager.tabs.createInputTabElement(inputNum, changeTab); const newTab = this.manager.tabs.createTabElement(inputNum, changeTab, "input");
tabsWrapper.appendChild(newTab); tabsWrapper.appendChild(newTab);
if (numTabs > 0) { if (numTabs > 0) {
@ -1101,7 +1101,7 @@ class InputWaiter {
* @param {boolean} tabsRight - True if there are input tabs to the right of the displayed tabs * @param {boolean} tabsRight - True if there are input tabs to the right of the displayed tabs
*/ */
refreshTabs(nums, activeTab, tabsLeft, tabsRight) { refreshTabs(nums, activeTab, tabsLeft, tabsRight) {
this.manager.tabs.refreshInputTabs(nums, activeTab, tabsLeft, tabsRight); this.manager.tabs.refreshTabs(nums, activeTab, tabsLeft, tabsRight, "input");
this.inputWorker.postMessage({ this.inputWorker.postMessage({
action: "setInput", action: "setInput",
@ -1120,7 +1120,7 @@ class InputWaiter {
*/ */
removeInput(inputNum) { removeInput(inputNum) {
let refresh = false; let refresh = false;
if (this.manager.tabs.getInputTabItem(inputNum) !== null) { if (this.manager.tabs.getTabItem(inputNum, "input") !== null) {
refresh = true; refresh = true;
} }
this.inputWorker.postMessage({ this.inputWorker.postMessage({
@ -1213,7 +1213,7 @@ class InputWaiter {
* Changes to the next (right) tab * Changes to the next (right) tab
*/ */
changeTabRight() { changeTabRight() {
const activeTab = this.manager.tabs.getActiveInputTab(); const activeTab = this.manager.tabs.getActiveTab("input");
if (activeTab === -1) return; if (activeTab === -1) return;
this.inputWorker.postMessage({ this.inputWorker.postMessage({
action: "changeTabRight", action: "changeTabRight",
@ -1227,7 +1227,7 @@ class InputWaiter {
* Changes to the previous (left) tab * Changes to the previous (left) tab
*/ */
changeTabLeft() { changeTabLeft() {
const activeTab = this.manager.tabs.getActiveInputTab(); const activeTab = this.manager.tabs.getActiveTab("input");
if (activeTab === -1) return; if (activeTab === -1) return;
this.inputWorker.postMessage({ this.inputWorker.postMessage({
action: "changeTabLeft", action: "changeTabLeft",
@ -1242,7 +1242,7 @@ class InputWaiter {
*/ */
async goToTab() { async goToTab() {
const inputNums = await this.getInputNums(); const inputNums = await this.getInputNums();
let tabNum = window.prompt(`Enter tab number (${inputNums.min} - ${inputNums.max}):`, this.manager.tabs.getActiveInputTab().toString()); let tabNum = window.prompt(`Enter tab number (${inputNums.min} - ${inputNums.max}):`, this.manager.tabs.getActiveTab("input").toString());
if (tabNum === null) return; if (tabNum === null) return;
tabNum = parseInt(tabNum, 10); tabNum = parseInt(tabNum, 10);

View file

@ -273,7 +273,7 @@ class OutputWaiter {
const numTabs = this.manager.tabs.calcMaxTabs(); const numTabs = this.manager.tabs.calcMaxTabs();
if (numTabs !== this.maxTabs) { if (numTabs !== this.maxTabs) {
this.maxTabs = numTabs; this.maxTabs = numTabs;
this.refreshTabs(this.manager.tabs.getActiveOutputTab(), "right"); this.refreshTabs(this.manager.tabs.getActiveTab("output"), "right");
} }
} }
@ -351,7 +351,7 @@ class OutputWaiter {
this.outputs[inputNum].data = data; this.outputs[inputNum].data = data;
const tabItem = this.manager.tabs.getOutputTabItem(inputNum); const tabItem = this.manager.tabs.getTabItem(inputNum, "output");
if (tabItem) tabItem.style.background = ""; if (tabItem) tabItem.style.background = "";
if (set) this.set(inputNum); if (set) this.set(inputNum);
@ -431,7 +431,7 @@ class OutputWaiter {
this.outputs[inputNum].progress = progress; this.outputs[inputNum].progress = progress;
if (progress !== false) { if (progress !== false) {
this.manager.tabs.updateOutputTabProgress(inputNum, progress, total); this.manager.tabs.updateTabProgress(inputNum, progress, total, "output");
} }
} }
@ -470,7 +470,7 @@ class OutputWaiter {
*/ */
async set(inputNum) { async set(inputNum) {
inputNum = parseInt(inputNum, 10); inputNum = parseInt(inputNum, 10);
if (inputNum !== this.manager.tabs.getActiveOutputTab() || if (inputNum !== this.manager.tabs.getActiveTab("output") ||
!this.outputExists(inputNum)) return; !this.outputExists(inputNum)) return;
this.toggleLoader(true); this.toggleLoader(true);
@ -565,7 +565,7 @@ class OutputWaiter {
* @param {number} activeTab * @param {number} activeTab
*/ */
setFile(buf, activeTab) { setFile(buf, activeTab) {
if (activeTab !== this.manager.tabs.getActiveOutputTab()) return; if (activeTab !== this.manager.tabs.getActiveTab("output")) return;
// Display file overlay in output area with details // Display file overlay in output area with details
const fileOverlay = document.getElementById("output-file"), const fileOverlay = document.getElementById("output-file"),
fileSize = document.getElementById("output-file-size"), fileSize = document.getElementById("output-file-size"),
@ -694,7 +694,7 @@ class OutputWaiter {
* Handler for file download events. * Handler for file download events.
*/ */
async downloadFile() { async downloadFile() {
const dish = this.getOutputDish(this.manager.tabs.getActiveOutputTab()); const dish = this.getOutputDish(this.manager.tabs.getActiveTab("output"));
if (dish === null) { if (dish === null) {
this.app.alert("Could not find any output data to download. Has this output been baked?", 3000); this.app.alert("Could not find any output data to download. Has this output been baked?", 3000);
return; return;
@ -849,9 +849,9 @@ class OutputWaiter {
const tabsWrapper = document.getElementById("output-tabs"); const tabsWrapper = document.getElementById("output-tabs");
const numTabs = tabsWrapper.children.length; const numTabs = tabsWrapper.children.length;
if (!this.manager.tabs.getOutputTabItem(inputNum) && numTabs < this.maxTabs) { if (!this.manager.tabs.getTabItem(inputNum, "output") && numTabs < this.maxTabs) {
// Create a new tab element // Create a new tab element
const newTab = this.manager.tabs.createOutputTabElement(inputNum, changeTab); const newTab = this.manager.tabs.reateTabElement(inputNum, changeTab, "output");
tabsWrapper.appendChild(newTab); tabsWrapper.appendChild(newTab);
} else if (numTabs === this.maxTabs) { } else if (numTabs === this.maxTabs) {
// Can't create a new tab // Can't create a new tab
@ -873,11 +873,11 @@ class OutputWaiter {
*/ */
changeTab(inputNum, changeInput = false) { changeTab(inputNum, changeInput = false) {
if (!this.outputExists(inputNum)) return; if (!this.outputExists(inputNum)) return;
const currentNum = this.manager.tabs.getActiveOutputTab(); const currentNum = this.manager.tabs.getActiveTab("output");
this.hideMagicButton(); this.hideMagicButton();
if (!this.manager.tabs.changeOutputTab(inputNum)) { if (!this.manager.tabs.changeTab(inputNum, "output")) {
let direction = "right"; let direction = "right";
if (currentNum > inputNum) { if (currentNum > inputNum) {
direction = "left"; direction = "left";
@ -887,7 +887,7 @@ class OutputWaiter {
const tabsLeft = (newOutputs[0] !== this.getSmallestInputNum()); const tabsLeft = (newOutputs[0] !== this.getSmallestInputNum());
const tabsRight = (newOutputs[newOutputs.length - 1] !== this.getLargestInputNum()); const tabsRight = (newOutputs[newOutputs.length - 1] !== this.getLargestInputNum());
this.manager.tabs.refreshOutputTabs(newOutputs, inputNum, tabsLeft, tabsRight); this.manager.tabs.refreshTabs(newOutputs, inputNum, tabsLeft, tabsRight, "output");
for (let i = 0; i < newOutputs.length; i++) { for (let i = 0; i < newOutputs.length; i++) {
this.displayTabInfo(newOutputs[i]); this.displayTabInfo(newOutputs[i]);
@ -977,7 +977,7 @@ class OutputWaiter {
* Handler for changing to the left tab * Handler for changing to the left tab
*/ */
changeTabLeft() { changeTabLeft() {
const currentTab = this.manager.tabs.getActiveOutputTab(); const currentTab = this.manager.tabs.getActiveTab("output");
this.changeTab(this.getPreviousInputNum(currentTab), this.app.options.syncTabs); this.changeTab(this.getPreviousInputNum(currentTab), this.app.options.syncTabs);
} }
@ -985,7 +985,7 @@ class OutputWaiter {
* Handler for changing to the right tab * Handler for changing to the right tab
*/ */
changeTabRight() { changeTabRight() {
const currentTab = this.manager.tabs.getActiveOutputTab(); const currentTab = this.manager.tabs.getActiveTab("output");
this.changeTab(this.getNextInputNum(currentTab), this.app.options.syncTabs); this.changeTab(this.getNextInputNum(currentTab), this.app.options.syncTabs);
} }
@ -996,7 +996,7 @@ class OutputWaiter {
const min = this.getSmallestInputNum(), const min = this.getSmallestInputNum(),
max = this.getLargestInputNum(); max = this.getLargestInputNum();
let tabNum = window.prompt(`Enter tab number (${min} - ${max}):`, this.manager.tabs.getActiveOutputTab().toString()); let tabNum = window.prompt(`Enter tab number (${min} - ${max}):`, this.manager.tabs.getActiveTab("output").toString());
if (tabNum === null) return; if (tabNum === null) return;
tabNum = parseInt(tabNum, 10); tabNum = parseInt(tabNum, 10);
@ -1115,7 +1115,7 @@ class OutputWaiter {
removeTab(inputNum) { removeTab(inputNum) {
if (!this.outputExists(inputNum)) return; if (!this.outputExists(inputNum)) return;
const tabElement = this.manager.tabs.getOutputTabItem(inputNum); const tabElement = this.manager.tabs.getTabItem(inputNum, "output");
this.removeOutput(inputNum); this.removeOutput(inputNum);
@ -1134,7 +1134,7 @@ class OutputWaiter {
tabsLeft = (newNums[0] !== this.getSmallestInputNum() && newNums.length > 0), tabsLeft = (newNums[0] !== this.getSmallestInputNum() && newNums.length > 0),
tabsRight = (newNums[newNums.length - 1] !== this.getLargestInputNum() && newNums.length > 0); tabsRight = (newNums[newNums.length - 1] !== this.getLargestInputNum() && newNums.length > 0);
this.manager.tabs.refreshOutputTabs(newNums, activeTab, tabsLeft, tabsRight); this.manager.tabs.refreshTabs(newNums, activeTab, tabsLeft, tabsRight, "output");
for (let i = 0; i < newNums.length; i++) { for (let i = 0; i < newNums.length; i++) {
this.displayTabInfo(newNums[i]); this.displayTabInfo(newNums[i]);
@ -1158,12 +1158,12 @@ class OutputWaiter {
tabStr = await this.getDishTitle(this.getOutputDish(inputNum), 100); tabStr = await this.getDishTitle(this.getOutputDish(inputNum), 100);
tabStr = tabStr.replace(/[\n\r]/g, ""); tabStr = tabStr.replace(/[\n\r]/g, "");
} }
this.manager.tabs.updateOutputTabHeader(inputNum, tabStr); this.manager.tabs.updateTabHeader(inputNum, tabStr, "output");
if (this.manager.worker.recipeConfig !== undefined) { if (this.manager.worker.recipeConfig !== undefined) {
this.manager.tabs.updateOutputTabProgress(inputNum, this.outputs[inputNum].progress, this.manager.worker.recipeConfig.length); this.manager.tabs.updateTabProgress(inputNum, this.outputs[inputNum].progress, this.manager.worker.recipeConfig.length, "output");
} }
const tabItem = this.manager.tabs.getOutputTabItem(inputNum); const tabItem = this.manager.tabs.getTabItem(inputNum, "output");
if (tabItem) { if (tabItem) {
if (this.outputs[inputNum].status === "error") { if (this.outputs[inputNum].status === "error") {
tabItem.style.color = "#FF0000"; tabItem.style.color = "#FF0000";
@ -1178,7 +1178,7 @@ class OutputWaiter {
*/ */
async backgroundMagic() { async backgroundMagic() {
this.hideMagicButton(); this.hideMagicButton();
const dish = this.getOutputDish(this.manager.tabs.getActiveOutputTab()); const dish = this.getOutputDish(this.manager.tabs.getActiveTab("output"));
if (!this.app.options.autoMagic || dish === null) return; if (!this.app.options.autoMagic || dish === null) return;
const buffer = await this.getDishBuffer(dish); const buffer = await this.getDishBuffer(dish);
const sample = buffer.slice(0, 1000) || ""; const sample = buffer.slice(0, 1000) || "";
@ -1268,7 +1268,7 @@ class OutputWaiter {
sliceToEl = document.getElementById("output-file-slice-to"), sliceToEl = document.getElementById("output-file-slice-to"),
sliceFrom = parseInt(sliceFromEl.value, 10) * 1024, sliceFrom = parseInt(sliceFromEl.value, 10) * 1024,
sliceTo = parseInt(sliceToEl.value, 10) * 1024, sliceTo = parseInt(sliceToEl.value, 10) * 1024,
output = this.outputs[this.manager.tabs.getActiveOutputTab()].data; output = this.outputs[this.manager.tabs.getActiveTab("output")].data;
let str; let str;
if (output.type === "ArrayBuffer") { if (output.type === "ArrayBuffer") {
@ -1296,7 +1296,7 @@ class OutputWaiter {
this.toggleLoader(true); this.toggleLoader(true);
const outputFile = document.getElementById("output-file"), const outputFile = document.getElementById("output-file"),
showFileOverlay = document.getElementById("show-file-overlay"), showFileOverlay = document.getElementById("show-file-overlay"),
output = this.outputs[this.manager.tabs.getActiveOutputTab()].data; output = this.outputs[this.manager.tabs.getActiveTab("output")].data;
let str; let str;
if (output.type === "ArrayBuffer") { if (output.type === "ArrayBuffer") {
@ -1326,7 +1326,7 @@ class OutputWaiter {
this.outputTextEl.classList.add("blur"); this.outputTextEl.classList.add("blur");
showFileOverlay.style.display = "none"; showFileOverlay.style.display = "none";
this.set(this.manager.tabs.getActiveOutputTab()); this.set(this.manager.tabs.getActiveTab("output"));
} }
/** /**
@ -1352,7 +1352,7 @@ class OutputWaiter {
* Copies the output to the clipboard * Copies the output to the clipboard
*/ */
async copyClick() { // TODO - do we need this? async copyClick() { // TODO - do we need this?
const dish = this.getOutputDish(this.manager.tabs.getActiveOutputTab()); const dish = this.getOutputDish(this.manager.tabs.getActiveTab("output"));
if (dish === null) { if (dish === null) {
this.app.alert("Could not find data to copy. Has this output been baked yet?", 3000); this.app.alert("Could not find data to copy. Has this output been baked yet?", 3000);
return; return;
@ -1373,7 +1373,7 @@ class OutputWaiter {
* Moves the current output into the input textarea. * Moves the current output into the input textarea.
*/ */
async switchClick() { async switchClick() {
const activeTab = this.manager.tabs.getActiveOutputTab(); const activeTab = this.manager.tabs.getActiveTab("output");
const switchButton = document.getElementById("switch"); const switchButton = document.getElementById("switch");
switchButton.classList.add("spin"); switchButton.classList.add("spin");

View file

@ -48,24 +48,6 @@ class TabWaiter {
return -1; return -1;
} }
/**
* Gets the currently active input tab number
*
* @returns {number}
*/
getActiveInputTab() {
return this.getActiveTab("input");
}
/**
* Gets the currently active output tab number
*
* @returns {number}
*/
getActiveOutputTab() {
return this.getActiveTab("output");
}
/** /**
* Gets the li element for the tab of a given input number * Gets the li element for the tab of a given input number
* *
@ -83,26 +65,6 @@ class TabWaiter {
return null; return null;
} }
/**
* Gets the li element for an input tab of the given input number
*
* @param {inputNum} - The inputNum of the tab we're trying to get
* @returns {Element}
*/
getInputTabItem(inputNum) {
return this.getTabItem(inputNum, "input");
}
/**
* Gets the li element for an output tab of the given input number
*
* @param {number} inputNum
* @returns {Element}
*/
getOutputTabItem(inputNum) {
return this.getTabItem(inputNum, "output");
}
/** /**
* Gets a list of tab numbers for the currently displayed tabs * Gets a list of tab numbers for the currently displayed tabs
* *
@ -120,24 +82,6 @@ class TabWaiter {
return nums; return nums;
} }
/**
* Gets a list of tab numbers for the currently displayed input tabs
*
* @returns {number[]}
*/
getInputTabList() {
return this.getTabList("input");
}
/**
* Gets a list of tab numbers for the currently displayed output tabs
*
* @returns {number[]}
*/
getOutputTabList() {
return this.getTabList("output");
}
/** /**
* Creates a new tab element for the tab bar * Creates a new tab element for the tab bar
* *
@ -154,11 +98,8 @@ class TabWaiter {
const newTabContent = document.createElement("div"); const newTabContent = document.createElement("div");
newTabContent.classList.add(`${io}-tab-content`); newTabContent.classList.add(`${io}-tab-content`);
newTabContent.innerText = `Tab ${inputNum.toString()}`; newTabContent.innerText = `Tab ${inputNum.toString()}`;
newTabContent.addEventListener("wheel", this.manager[io].scrollTab.bind(this.manager[io]), {passive: false}); newTabContent.addEventListener("wheel", this.manager[io].scrollTab.bind(this.manager[io]), {passive: false});
newTab.appendChild(newTabContent); newTab.appendChild(newTabContent);
if (io === "input") { if (io === "input") {
@ -166,52 +107,24 @@ class TabWaiter {
newTabButtonIcon = document.createElement("i"); newTabButtonIcon = document.createElement("i");
newTabButton.type = "button"; newTabButton.type = "button";
newTabButton.className = "btn btn-primary bmd-btn-icon btn-close-tab"; newTabButton.className = "btn btn-primary bmd-btn-icon btn-close-tab";
newTabButtonIcon.classList.add("material-icons"); newTabButtonIcon.classList.add("material-icons");
newTabButtonIcon.innerText = "clear"; newTabButtonIcon.innerText = "clear";
newTabButton.appendChild(newTabButtonIcon); newTabButton.appendChild(newTabButtonIcon);
newTabButton.addEventListener("click", this.manager.input.removeTabClick.bind(this.manager.input)); newTabButton.addEventListener("click", this.manager.input.removeTabClick.bind(this.manager.input));
newTab.appendChild(newTabButton); newTab.appendChild(newTabButton);
} }
return newTab; return newTab;
} }
/**
* Creates a new tab element for the input tab bar
*
* @param {number} inputNum - The inputNum of the new input tab
* @param {boolean} [active=false] - If true, sets the tab to active
* @returns {Element}
*/
createInputTabElement(inputNum, active=false) {
return this.createTabElement(inputNum, active, "input");
}
/**
* Creates a new tab element for the output tab bar
*
* @param {number} inputNum - The inputNum of the new output tab
* @param {boolean} [active=false] - If true, sets the tab to active
* @returns {Element}
*/
createOutputTabElement(inputNum, active=false) {
return this.createTabElement(inputNum, active, "output");
}
/** /**
* Displays the tab bar for both the input and output * Displays the tab bar for both the input and output
*/ */
showTabBar() { showTabBar() {
document.getElementById("input-tabs-wrapper").style.display = "block"; document.getElementById("input-tabs-wrapper").style.display = "block";
document.getElementById("output-tabs-wrapper").style.display = "block"; document.getElementById("output-tabs-wrapper").style.display = "block";
document.getElementById("input-wrapper").classList.add("show-tabs"); document.getElementById("input-wrapper").classList.add("show-tabs");
document.getElementById("output-wrapper").classList.add("show-tabs"); document.getElementById("output-wrapper").classList.add("show-tabs");
document.getElementById("save-all-to-file").style.display = "inline-block"; document.getElementById("save-all-to-file").style.display = "inline-block";
} }
@ -221,10 +134,8 @@ class TabWaiter {
hideTabBar() { hideTabBar() {
document.getElementById("input-tabs-wrapper").style.display = "none"; document.getElementById("input-tabs-wrapper").style.display = "none";
document.getElementById("output-tabs-wrapper").style.display = "none"; document.getElementById("output-tabs-wrapper").style.display = "none";
document.getElementById("input-wrapper").classList.remove("show-tabs"); document.getElementById("input-wrapper").classList.remove("show-tabs");
document.getElementById("output-wrapper").classList.remove("show-tabs"); document.getElementById("output-wrapper").classList.remove("show-tabs");
document.getElementById("save-all-to-file").style.display = "none"; document.getElementById("save-all-to-file").style.display = "none";
} }
@ -271,30 +182,6 @@ class TabWaiter {
} }
} }
/**
* Refreshes the input tabs, and changes to activeTab
*
* @param {number[]} nums - The inputNums to be displayed as tabs
* @param {number} activeTab - The tab to change to
* @param {boolean} tabsLeft - True if there are input tabs to the left of the displayed tabs
* @param {boolean} tabsRight - True if there are input tabs to the right of the displayed tabs
*/
refreshInputTabs(nums, activeTab, tabsLeft, tabsRight) {
this.refreshTabs(nums, activeTab, tabsLeft, tabsRight, "input");
}
/**
* Refreshes the output tabs, and changes to activeTab
*
* @param {number[]} nums - The inputNums to be displayed as tabs
* @param {number} activeTab - The tab to change to
* @param {boolean} tabsLeft - True if there are output tabs to the left of the displayed tabs
* @param {boolean} tabsRight - True if there are output tabs to the right of the displayed tabs
*/
refreshOutputTabs(nums, activeTab, tabsLeft, tabsRight) {
this.refreshTabs(nums, activeTab, tabsLeft, tabsRight, "output");
}
/** /**
* Changes the active tab to a different tab * Changes the active tab to a different tab
* *
@ -319,26 +206,6 @@ class TabWaiter {
return found; return found;
} }
/**
* Changes the active input tab to a different tab
*
* @param {number} inputNum
* @returns {boolean} - False if the tab is not currently being displayed
*/
changeInputTab(inputNum) {
return this.changeTab(inputNum, "input");
}
/**
* Changes the active output tab to a different tab
*
* @param {number} inputNum
* @returns {boolean} - False if the tab is not currently being displayed
*/
changeOutputTab(inputNum) {
return this.changeTab(inputNum, "output");
}
/** /**
* Updates the tab header to display a preview of the tab contents * Updates the tab header to display a preview of the tab contents
* *
@ -358,26 +225,6 @@ class TabWaiter {
tab.firstElementChild.innerText = headerData; tab.firstElementChild.innerText = headerData;
} }
/**
* Updates the input tab header to display a preview of the tab contents
*
* @param {number} inputNum - The inputNum of the tab to update the header of
* @param {string} data - The data to display in the tab header
*/
updateInputTabHeader(inputNum, data) {
this.updateTabHeader(inputNum, data, "input");
}
/**
* Updates the output tab header to display a preview of the tab contents
*
* @param {number} inputNum - The inputNum of the tab to update the header of
* @param {string} data - The data to display in the tab header
*/
updateOutputTabHeader(inputNum, data) {
this.updateTabHeader(inputNum, data, "output");
}
/** /**
* Updates the tab background to display the progress of the current tab * Updates the tab background to display the progress of the current tab
* *
@ -398,28 +245,6 @@ class TabWaiter {
} }
} }
/**
* Updates the input tab background to display its progress
*
* @param {number} inputNum
* @param {number} progress
* @param {number} total
*/
updateInputTabProgress(inputNum, progress, total) {
this.updateTabProgress(inputNum, progress, total, "input");
}
/**
* Updates the output tab background to display its progress
*
* @param {number} inputNum
* @param {number} progress
* @param {number} total
*/
updateOutputTabProgress(inputNum, progress, total) {
this.updateTabProgress(inputNum, progress, total, "output");
}
} }
export default TabWaiter; export default TabWaiter;

View file

@ -266,7 +266,7 @@ class WorkerWaiter {
if (progress !== false) { if (progress !== false) {
this.manager.output.updateOutputStatus("error", inputNum); this.manager.output.updateOutputStatus("error", inputNum);
if (inputNum === this.manager.tabs.getActiveInputTab()) { if (inputNum === this.manager.tabs.getActiveTab("input")) {
this.manager.recipe.updateBreakpointIndicator(progress); this.manager.recipe.updateBreakpointIndicator(progress);
} }
@ -335,16 +335,16 @@ class WorkerWaiter {
this.manager.output.updateOutputStatus("inactive", this.inputNums[i]); this.manager.output.updateOutputStatus("inactive", this.inputNums[i]);
} }
const tabList = this.manager.tabs.getOutputTabList(); const tabList = this.manager.tabs.getTabList("output");
for (let i = 0; i < tabList.length; i++) { for (let i = 0; i < tabList.length; i++) {
this.manager.tabs.getOutputTabItem(tabList[i]).style.background = ""; this.manager.tabs.getTabItem(tabList[i], "output").style.background = "";
} }
this.inputs = []; this.inputs = [];
this.inputNums = []; this.inputNums = [];
this.totalOutputs = 0; this.totalOutputs = 0;
this.loadingOutputs = 0; this.loadingOutputs = 0;
if (!silent) this.manager.output.set(this.manager.tabs.getActiveOutputTab()); if (!silent) this.manager.output.set(this.manager.tabs.getActiveTab("output"));
} }
/** /**