Add mime type detection to tab title.

Move addition of close tab button back
This commit is contained in:
j433866 2019-06-13 11:13:53 +01:00
parent 6ee76e3bf0
commit 84204c1d12
2 changed files with 42 additions and 16 deletions

View File

@ -8,6 +8,7 @@
import Utils from "./Utils";
import DishError from "./errors/DishError";
import BigNumber from "bignumber.js";
import {detectFileType} from "./lib/FileType";
import log from "loglevel";
/**
@ -141,6 +142,23 @@ class Dish {
}
/**
* Detects the MIME type of the current dish
*
* @returns {string}
*/
async detectDishType() {
const data = new Uint8Array(this.value),
types = detectFileType(data);
if (!types.length || !types[0].mime || !types[0].mime === "text/plain") {
return null;
} else {
return types[0].mime;
}
}
/**
* Returns the title of the data up to the specified length
*
@ -158,6 +176,13 @@ class Dish {
case Dish.LIST_FILE:
title = `${this.value.length} file(s)`;
break;
case Dish.ARRAY_BUFFER:
case Dish.BYTE_ARRAY:
title = await this.detectDishType();
if (title === null) {
title = await this.get("string");
}
break;
default:
title = await this.get("string");
}

View File

@ -159,6 +159,22 @@ class TabWaiter {
newTab.appendChild(newTabContent);
if (io === "input") {
const newTabButton = document.createElement("button"),
newTabButtonIcon = document.createElement("i");
newTabButton.type = "button";
newTabButton.className = "btn btn-primary bmd-btn-icon btn-close-tab";
newTabButtonIcon.classList.add("material-icons");
newTabButtonIcon.innerText = "clear";
newTabButton.appendChild(newTabButtonIcon);
newTabButton.addEventListener("click", this.manager.input.removeTabClick.bind(this.manager.input));
newTab.appendChild(newTabButton);
}
return newTab;
}
@ -170,22 +186,7 @@ class TabWaiter {
* @returns {Element}
*/
createInputTabElement(inputNum, active=false) {
const newTab = this.createTabElement(inputNum, active, "input"),
newTabButton = document.createElement("button"),
newTabButtonIcon = document.createElement("i");
newTabButton.type = "button";
newTabButton.className = "btn btn-primary bmd-btn-icon btn-close-tab";
newTabButtonIcon.classList.add("material-icons");
newTabButtonIcon.innerText = "clear";
newTabButton.appendChild(newTabButtonIcon);
newTabButton.addEventListener("click", this.manager.input.removeTabClick.bind(this.manager.input));
newTab.appendChild(newTabButton);
return newTab;
return this.createTabElement(inputNum, active, "input");
}
/**