import { stageManager } from "./stage-manager"; import { FileParser } from "../parser/file-parser"; import { ParserOrchestrator } from "../parser/parser-orchestrator"; class HeaderMenu { constructor() { } bootstrap() { $("body").on("click", "#save", this.save.bind(this)); $("body").on("click", "#open", this.open.bind(this)); $("body").on("change", "#input-file", this.onFileChanged.bind(this)); } save() { const layer = stageManager.getCurrentLayer(); const file = layer.actionManager.save(); const name = prompt("Sallet como", layer.name.replace(/ /g, "_").toLowerCase()); if (name == undefined) return; const a = document.createElement("a"), url = URL.createObjectURL(file); a.href = url; a.download = `${name}.geo`; document.body.appendChild(a); a.click(); setTimeout(function () { document.body.removeChild(a); window.URL.revokeObjectURL(url); }, 0); } open() { $("#input-file").click(); } onFileChanged() { const files = $("#input-file")[0].files; if (files == undefined || files.length === 0) return; const reader = new FileReader(); reader.onload = function () { const result = reader.result; const parser = new FileParser(result); const map = parser.parse(); const orchestrator = new ParserOrchestrator(map); orchestrator.orchestrate(); }; reader.readAsText(files[0]); } } export const headerMenu = new HeaderMenu();